YYC
2025-04-22 33ad92a73de17e8d72f30632ced04dca5719f76e
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
package com.fzzy.async.fzzy40.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1304;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1304Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40Gas;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1304Rep;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * 虫害检测数据同步
 *
 * @author chen
 * @date 2022-09-08 09:51
 */
@Slf4j
@Component
public class Fzzy40Sync1304 {
 
    @Autowired
    private Fzzy40Sync1304Rep fzzySync1304Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private Api1304Rep api1304Rep;
 
    @Autowired
    private ApiLogRep apiLogRep;
 
    /**
     * 同步并封装保存气体检测数据
     *
     * @param deptId 系统对应库区编码
     * @param start  起始时间
     * @param end    截止时间
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
        log.info("-------------1304接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1304);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40Gas> list = fzzySync1304Rep.findByReceiveDate(start, end);
            if (null == list || list.isEmpty()) {
                return;
            }
 
            Api1304 api1304;
            Api1105 api1105;
            List<Api1304> api1304List;
            for (Fz40Gas fz40Gas : list) {
                //获取货位信息
                api1105 = commonService.getApi1105Cache(fz40Gas.getDepotId());
                if (null == api1105) {
                    continue;
                }
 
                api1304 = new Api1304();
                api1304.setQtndjcdh(api1105.getHwdm() + fz40Gas.getBatchId());
                api1304.setJcsj(fz40Gas.getReceiveDate());
                api1304.setHwdm(api1105.getHwdm());
                api1304.setZylx("5");
 
                api1304 = updateGasInfo(api1304, fz40Gas.getPoints());
 
                api1304.setZhgxsj(new Date());
 
                api1304.setBizId(fz40Gas.getBatchId());
                api1304.setKqdm(api1105.getKqdm());
                api1304.setSyncTime(new Date());
                api1304List = api1304Rep.getDataByQtndjcdh(api1304.getQtndjcdh());
                if (null == api1304List || api1304List.isEmpty()) {
                    api1304.setCzbz(Constant.CZBZ_I);
                } else {
                    api1304.setCzbz(api1304List.get(0).getCzbz());
                }
                api1304Rep.save(api1304);
            }
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
 
    /**
     * 获取对应气体浓度集合:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;
     *
     * @param points
     * @return
     */
    private Api1304 updateGasInfo(Api1304 api1304, String points) {
        String[] attr = points.split(";");
 
        String[] arrt2;
        String o2 = "", co2 = "", ph3 = "", n2 = "";
        for (String temp : attr) {
            arrt2 = temp.split(",");
            o2 +=  "," + arrt2[2];
            co2 += "," + arrt2[1];
            ph3 += "," + arrt2[3];
            n2 += "," + arrt2[4];
        }
 
        if(o2.length() > 0){
            o2 = o2.substring(1);
        }
        if(co2.length() > 0){
            co2 = co2.substring(1);
        }
        if(ph3.length() > 0){
            ph3 = ph3.substring(1);
        }
        if(n2.length() > 0){
            n2 = n2.substring(1);
        }
        co2 += "|ppm";
        ph3 += "|ppm";
        api1304.setYqhlzjh(o2);
        api1304.setEyhthlzjh(co2);
        api1304.setLhqndzjh(ph3);
        api1304.setDqndzjh(n2);
        return api1304;
    }
 
}