jiazx0107@163.com
2023-05-27 ff212e3d6cc57220133aff1d68b6bed02ba8a77b
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
package com.ld.igds.sh.timer;
 
import com.ld.igds.models.*;
import com.ld.igds.sh.service.impl.HApiShServiceImpl;
import com.ld.igds.util.ContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
 
/**
 * 定时保存稻谷出入库信息到接口表中
 * @author chen
 *
 */
@Slf4j
@Component(ShScheduled.BEAN_ID)
public class ShScheduled {
 
    public static final String BEAN_ID = "sh.shScheduled";
 
    @Autowired
    private HApiShServiceImpl hApiShService;
 
 
    /**
     *  每天23:30执行一次
     */
    @Scheduled(cron = "0 30 23 * * ?")
    public void scheduled() {
        log.info("==========系统定时获取稻谷入库信息==========");
        Date endTime = new Date();
        Date startTime = DateUtils.addDays(endTime, -1);
//        doExe(ContextUtil.getDefaultCompanyId(), startTime, endTime);
    }
 
 
    public void doExe(String companyId, Date startTime, Date endTime) {
 
        List<InoutRecord> inList = hApiShService.listInoutRecordByDay(companyId, startTime, endTime, null, "113");
        log.info("==========系统定时获取稻谷入库信息==========");
        if(null == inList || inList.isEmpty()){
            log.warn("==========系统未获取到当前时间段内稻谷出入库数据==========");
            return;
        }
        for (InoutRecord inoutRecord : inList) {
            if("IN".equals(inoutRecord.getType())){
                saveToLsRkjlD(inoutRecord);
            }
            if("OUT".equals(inoutRecord.getType())){
                saveToLsCcsslD(inoutRecord);
            }
        }
    }
 
    /**
     * 稻谷入库记录
     * @param data
     */
    public void saveToLsRkjlD(InoutRecord data){
        ToLsRkjlD dto = new ToLsRkjlD();
        dto.setNf(data.getFoodYear());
        dto.setRq(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
        dto.setFcqkCch(data.getPlateNum());
        dto.setFcqkLldw(data.getCustomerName());
        dto.setFcqkLssl(data.getSettleWeight());
        dto.setJsqkRksl(data.getSettleWeight());
        //dto.setJsqkKszs(data.getDeSum()); TODO 
 
        List<CheckItem> checkItems = hApiShService.listInoutChecks(data.getCompanyId(), data.getCheckId());
        if(null != checkItems && checkItems.size() > 0){
            for (CheckItem checkItem : checkItems) {
                //杂质
                if("C01".equals(checkItem.getStandardId())){
                    dto.setJsqkZlSf(Double.valueOf(checkItem.getValue()));
                }
                //杂质
                if("C02".equals(checkItem.getStandardId())){
                    dto.setJsqkZlZz(Double.valueOf(checkItem.getValue()));
                }
                //出糙
                if("C09".equals(checkItem.getStandardId())){
                    dto.setJsqkZlCc(Double.valueOf(checkItem.getValue()));
                }
                //谷外糙米
                if("C12".equals(checkItem.getStandardId())){
                    dto.setJsqkZlGwcm(Double.valueOf(checkItem.getValue()));
                }
                //含黄
                if("C99".equals(checkItem.getStandardId())){
                    dto.setJsqkZlHh(Double.valueOf(checkItem.getValue()));
                }
            }
        }
 
        dto.setDataDate(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
        dto.setUpdateTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
 
        hApiShService.saveToLsRkjlD(dto);
        log.info("==========系统定时保存稻谷入库信息到接口表中={}==========", dto);
    }
 
    public void saveToLsCcsslD(InoutRecord data){
 
        ToLsCcsslD dto = new ToLsCcsslD();
 
        dto.setNf(data.getFoodYear());
        dto.setRq(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
        dto.setChh(data.getPlateNum());
        dto.setThdw(data.getCustomerName());
        dto.setThc(data.getDepotId());
        dto.setFcsl(data.getSettleWeight());
      //  dto.setJcs(data.getCurStorage() - data.getSettleWeight()); TODO 
 
        dto.setDataDate(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
        dto.setUpdateTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
 
        hApiShService.saveToLsCcsslD(dto);
        log.info("==========系统定时保存稻谷出库信息到接口表中={}==========", dto);
    }
 
}