CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
package com.ld.igds.timer.zcl;
 
import com.alibaba.fastjson.JSON;
import com.ld.igds.common.impl.CommonDataServiceImpl;
import com.ld.igds.grain.dto.GrainData;
import com.ld.igds.grain.dto.GrainParam;
import com.ld.igds.grain.service.CoreGrainService;
import com.ld.igds.models.Depot;
import com.ld.igds.timer.zcl.dto.InteGrainDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
 
/**
 * @author: vince
 * @version:
 * @data:2019年12月7日
 */
@Slf4j
@Component
public class InteGrainScheduled {
 
    public static String COMPANY_IDS = "4003,5307,5311,5315";
 
    @Autowired
    private CoreGrainService grainService;
    @Autowired
    private CommonDataServiceImpl commonDataService;
    @Autowired
    private InteGrainManager inteGrainManager;
 
    /**
     * 每天9点和22点执行执行
     */
    @Scheduled(cron = "0 0 9,22 * * ?")
    public void scheduled() {
        log.info("系统定时将粮情存入中储粮的数据表中……");
        try {
            Date time = new Date();
            step0(time);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
    /**
     * 获取需要上传中储粮的组织编码
     *
     * @param time
     * @throws Exception
     */
    private void step0(Date time) throws Exception {
        String[] companyIds = COMPANY_IDS.split(",");
        if (companyIds.length < 1) {
            log.info("暂无组织需要将粮情存入中储粮的数据表……");
            return;
        }
 
        log.info("=====开始推送组织-({})粮情到中储粮需要的表中=====", Arrays.toString(companyIds));
        for (String companyId : companyIds) {
            step1(time, companyId);
        }
 
    }
 
    private void step1(Date time, String companyId) throws Exception {
        InteGrainDto inteGrainDto = null;
        Map<String, GrainData> grainMap = null;
        GrainParam param = new GrainParam();
        GrainData grain = null;
        Depot depot = null;
        param.setCompanyId(companyId);
        param.setCheckDate(time);
        grainMap = grainService.queryCheckDateMap(param);
        if (grainMap == null) {
            log.info("==========没有获取到组织={}的粮情数据取消推送==========", companyId);
            return;
        }
        log.info("grainMap=" + grainMap.toString());
        for (String depotId : grainMap.keySet()) {
            grain = grainMap.get(depotId);
            if (grain == null) {
                continue;
            }
            depot = commonDataService.getCacheDepot(grain.getCompanyId(), depotId);
            log.debug("grain=" + grain.toString());
            log.info("depot=" + depot.toString());
            log.info(JSON.toJSONString(grain));
            inteGrainDto = new InteGrainDto();
            inteGrainDto.setCompanyId(depot.getCompanyId());
            inteGrainDto.setDepotId(depot.getId());
            inteGrainDto.setDepotName(depot.getName());
            inteGrainDto.setBatchId(grain.getBatchId());
            inteGrainDto.setUuid(grain.getCompanyId() + grain.getDepotId() + grain.getBatchId());
            inteGrainDto.setHumidityIn(grain.getHumidityIn());
            inteGrainDto.setHumidityOut(grain.getHumidityOut());
            inteGrainDto.setTempIn(grain.getTempIn());
            inteGrainDto.setTempOut(grain.getTempOut());
            inteGrainDto.setReceiveDate(grain.getReceiveDate());
            inteGrainDto.setTempList(grain.getPoints());
 
            inteGrainDto.setCheckUser(grain.getCheckUser());
            inteGrainDto.setCable(grain.getCable());
            inteGrainDto.setCableCir(grain.getCableCir());
            inteGrainDto.setWeather(grain.getWeather());
            inteGrainDto.setRemark(grain.getRemark());
 
            log.debug("grainTempList=" + inteGrainDto.toString());
 
 
            inteGrainManager.toSaveGrain(inteGrainDto);
        }
 
        log.info("==========定时推送组织={}的粮情到中储粮的表中 推送完成!==========", companyId);
    }
 
}