YYC
2023-09-11 9ad231b419cfb6c07385d06eb68961126651af2f
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.fzzy.async.fzzy40.impl;
 
import com.alibaba.fastjson.JSON;
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1102;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.ApiInfoData;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1102Rep;
import com.fzzy.api.view.repository.ApiInfoDataRep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40Depot;
import com.fzzy.async.fzzy40.entity.Fz40DepotConf;
import com.fzzy.async.fzzy40.repository.Fzzy40SyncDepotConfRep;
import com.fzzy.async.fzzy40.repository.Fzzy40SyncDepotRep;
import com.fzzy.push.sh2023.SH2023Constant;
import com.fzzy.push.sh2023.dto.SH2023Api2103;
import com.fzzy.push.sh2023.dto.SH2023Api2103Item;
import com.fzzy.push.sh2023.dto.ShAreaBjw;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 粮情检测设备信息同步
 *
 * @author czt
 * @date 2023-08-21
 */
@Slf4j
@Component
public class Fzzy40Sync2103 {
 
    @Autowired
    private Fzzy40SyncDepotRep fzzy40SyncDepotRep;
    @Autowired
    private Fzzy40SyncDepotConfRep fzzy40SyncDepotConfRep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private Api1102Rep api1102Rep;
    @Autowired
    private ApiLogRep apiLogRep;
    @Autowired
    private ApiInfoDataRep apiInfoDataRep;
 
 
    /**
     * 同步并封装保存温湿度检测数据
     *
     * @param kqdm
     * @param deptId 系统对应库区编码
     * @param start  起始时间
     * @param end    截止时间
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
 
        log.info("-------------1302接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1302);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40Depot> list = fzzy40SyncDepotRep.listDepotList(deptId);
 
            if (null == list || list.isEmpty()) {
                log.info("2103---粮情设备配置同步数据:没有查询到仓库信息");
                return;
            }
 
            List<Api1102> api1102List = api1102Rep.findPushData(kqdm);
            String bjw = "";
            if (null != api1102List && api1102List.size() > 0) {
                bjw = ShAreaBjw.getBjw(api1102List.get(0).getXzqhdm());
            }
 
            SH2023Api2103 sh2023Api2103;
            Api1105 api1105;
            List<Fz40DepotConf> depotConfList;
            Fz40DepotConf depotConf;
 
            List<ApiInfoData> apiInfoDataList;
            SH2023Api2103Item sh2023Api2103Item;
            List<SH2023Api2103Item> listItem;
            for (Fz40Depot fz40Depot : list) {
                //根据仓库编码获取配置信息
                depotConfList = fzzy40SyncDepotConfRep.findDataByDepotId(fz40Depot.getId());
                if (null == depotConfList || depotConfList.isEmpty()) {
                    continue;
                }
                //获取货位信息
                api1105 = commonService.getApi1105Cache(fz40Depot.getId());
                if (null == api1105) {
                    continue;
                }
 
                sh2023Api2103 = new SH2023Api2103();
                sh2023Api2103.setHwdm(api1105.getHwdm());
                depotConf = depotConfList.get(0);
                String[] strs = depotConf.getCableRule().split("-");
 
                sh2023Api2103.setDlcs(strs[0]);
                sh2023Api2103.setDlhs(strs[1]);
                sh2023Api2103.setDlls(strs[2]);
                // 1-3-5
                // 8-8-8
                //筒仓规则
                if (StringUtils.isNotEmpty(depotConf.getCableCir())) {
                    sh2023Api2103.setDlqs(String.valueOf(strs.length));
                    sh2023Api2103.setDlhs(null);
                    sh2023Api2103.setDlls(null);
 
                    //电缆圈排列详情
                    listItem = new ArrayList<>();
                    String[] cableCir = depotConf.getCableCir().split("-");
                    int num1 = 0;  //起始根
                    int num2 = 0;  //截止根
                    for (int i = 0; i < cableCir.length; i++) {
                        sh2023Api2103.setDlcs(cableCir[i]);
 
                        sh2023Api2103Item = new SH2023Api2103Item();
                        sh2023Api2103Item.setQh(i + 1 + "");
                        if (i == 0) {
                            num1 += 1;
                        } else {
                            num1 = num2 + 1;
                        }
                        num2 += Integer.valueOf(strs[i]);
                        sh2023Api2103Item.setQsdlbh(num1 + "");
                        sh2023Api2103Item.setJsdlbh(num2 + "");
                        sh2023Api2103Item.setCs(cableCir[i]);
                        sh2023Api2103Item.setYbj((i + 1) * 4 + "");
                        sh2023Api2103Item.setRowId(i + "");
                        listItem.add(sh2023Api2103Item);
                    }
                    sh2023Api2103.setDlqplxq(JSON.toJSONString(listItem));
                }
 
                sh2023Api2103.setScqd("1");
                sh2023Api2103.setSczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + "");
 
                sh2023Api2103.setZcqd("1");
                sh2023Api2103.setZczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + "");
 
                sh2023Api2103.setXcqd("1");
                sh2023Api2103.setXczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + "");
 
                sh2023Api2103.setYxfwqsc("1");
                sh2023Api2103.setYxfwjsc(strs[0]);
 
                sh2023Api2103.setBjw(bjw);
                sh2023Api2103.setZhgxsj(new Date());
 
                //持久化保存,单独存入非国标接口表
                ApiInfoData infoData = new ApiInfoData();
                infoData.setId(sh2023Api2103.getHwdm());
                infoData.setKqdm(kqdm);
                infoData.setInteType(Constant.API_CATEGORY_13);
                infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2103);
                infoData.setUpdateTime(new Date());
                infoData.setDataId(sh2023Api2103.getHwdm());
                infoData.setRemarks("粮情设备配置信息");
 
                //设置操作标志
                apiInfoDataList = apiInfoDataRep.getDataByInteAndData(SH2023Constant.SH_2023_API_CODE_2103, infoData.getDataId());
                if (null == apiInfoDataList || apiInfoDataList.isEmpty()) {
                    infoData.setCzbz(Constant.CZBZ_I);
                } else {
                    infoData.setCzbz(apiInfoDataList.get(0).getCzbz());
                }
 
                infoData.setData(JSON.toJSONString(sh2023Api2103));
                apiInfoDataRep.save(infoData);
 
                log.info("2103---粮情设备配置-同步数据:{}", sh2023Api2103.toString());
            }
 
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
 
    }
}