jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.ld.igds;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.models.InoutRecord;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Component
public class TestService extends HibernateDao {
 
    @Autowired
    private CoreCommonService commonService;
 
 
    private void initRecordCurStorage2(List<InoutRecord> listData) {
        if (null == listData || listData.isEmpty()) return;
 
        log.info("----------------开始执行重置出入库信息--------------");
 
        //更新实时库存
        Session session = this.getSessionFactory().openSession();
        try {
            InoutRecord perData;
            InoutRecord curData;
            for (int i = 1; i < listData.size(); i++) {
                perData = listData.get(i - 1);
                curData = listData.get(i);
                if ("IN".equals(perData.getType())) {
                    curData.setCurStorage(perData.getCurStorage() + perData.getSettleWeight());
                } else if ("OUT".equals(perData.getType())) {
                    curData.setCurStorage(perData.getCurStorage() - perData.getSettleWeight());
                } else if ("OVER".equals(perData.getType())) {
                    curData.setCurStorage(perData.getCurStorage() + perData.getSettleWeight());
                } else if ("LOSS".equals(perData.getType())) {
                    curData.setCurStorage(perData.getCurStorage() - perData.getSettleWeight());
                } else {
                    curData.setCurStorage(perData.getCurStorage());
                }
                listData.set(i, curData);
 
                //更新庫存
                String updateHql = "update " + InoutRecord.class.getName() + " set curStorage=:curStorage where companyId=:companyId and id=:id";
                Query query = session.createQuery(updateHql);
                query.setDouble("curStorage", curData.getCurStorage());
                query.setString("companyId", curData.getCompanyId());
                query.setString("id", curData.getId());
                query.executeUpdate();
                log.info("----------------DEPOTID={}----CUR={}----------", curData.getDepotId(), curData.getCurStorage());
            }
 
            log.info("----------------重置完成--------------");
 
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.clear();
            session.close();
        }
    }
 
 
    public void initRecordCurStorageOUT(String depotId, String startDate) {
        try {
            Date start = DateUtils.parseDate(startDate, "yyyy-MM-dd");
            //获取所有的详细
 
            String hql = " from " + InoutRecord.class.getName()
                    + " where progress=:progress and recordStatus <>:statusError and recordStatus <>:statusDel and depotId=:depotId"
                    + " and completeTime > :start and (type =:typOut or type=:typeOver) "
                    + " order by completeTime";
 
            Map<String, Object> param = new HashMap<>();
            param.put("progress", InoutConstant.PROGRESS_RECORD);
            param.put("statusError", InoutConstant.RECORD_STATUS_ERROR);
            param.put("statusDel", InoutConstant.RECORD_STATUS_DEL);
            param.put("depotId", depotId);
            param.put("start", start);
            param.put("typOut", InoutConstant.TYPE_OUT);
            param.put("typeOver", "OVER");
 
            List<InoutRecord> listData = this.query(hql, param);
 
 
            if (null == listData || listData.isEmpty()) return;
 
            //更新出入库列表
            this.initRecordCurStorage2(listData);
 
            InoutRecord lastData = listData.get(listData.size()-1);
 
            commonService.updateDepotStorage(lastData.getCompanyId(), lastData.getDepotId(), lastData.getCurStorage() - lastData.getSettleWeight());
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public void initRecordCurStorageIN(String depotId, String startDate) {
        try {
            Date start = DateUtils.parseDate(startDate, "yyyy-MM-dd");
            //获取所有的详细
            String hql = " from " + InoutRecord.class.getName()
                    + " where progress=:progress and recordStatus <>:statusError and recordStatus <>:statusDel and depotId=:depotId"
                    + " and completeTime > :start and (type =:typIn or type=:typeLOss) "
                    + " order by completeTime";
 
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("progress", InoutConstant.PROGRESS_RECORD);
            param.put("statusError", InoutConstant.RECORD_STATUS_ERROR);
            param.put("statusDel", InoutConstant.RECORD_STATUS_DEL);
            param.put("depotId", depotId);
            param.put("start", start);
            param.put("typIn", InoutConstant.TYPE_IN);
            param.put("typeLOss", "LOSS");
 
            List<InoutRecord> listData = this.query(hql, param);
 
            if (null == listData || listData.isEmpty()) return;
 
            this.initRecordCurStorage2(listData);
 
            InoutRecord lastData = listData.get(listData.size() - 1);
 
            // 重新计算客户完成量
            commonService.updateDepotStorage(lastData.getCompanyId(), lastData.getDepotId(), lastData.getCurStorage() + lastData.getSettleWeight());
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}