YYC
2025-08-17 d52072155b4bc241b9efc0ad56a20c76c91c737d
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
package com.fzzy.push.shjdjw2023;
 
import com.alibaba.fastjson.JSON;
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.data.PushProtocol;
import com.fzzy.api.dto.ResponseDto;
import com.fzzy.api.entity.*;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.service.ApiRemoteService;
import com.fzzy.api.service.ApiTriggerService;
import com.fzzy.api.utils.AESUtils;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.api.view.repository.*;
import com.fzzy.push.sh2023.dto.ShAreaBjw;
import com.fzzy.push.shjdjw2023.dto.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
 
/**
 * 上海嘉定纪委监管平台-上传数据服务类
 *
 * @author czt
 * @date 2023/12/26
 */
@Slf4j
@Data
@Service
public class ShjdjwApiRemoteService2023 implements ApiRemoteService {
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ApiCommonService apiCommonService;
    @Autowired
    private ApiTriggerService apiTriggerService;
    @Autowired
    private ApiLogRep apiLogRep;
    @Autowired
    private Api1101Rep api1101Rep;
    @Autowired
    private Api1102Rep api1102Rep;
    @Autowired
    private Api1103Rep api1103Rep;
    @Autowired
    private Api1104Rep api1104Rep;
    @Autowired
    private Api1105Rep api1105Rep;
    @Autowired
    private Api1202Rep api1202Rep;
    @Autowired
    private Api1205Rep api1205Rep;
    @Autowired
    private Api1208Rep api1208Rep;
    @Autowired
    private Api1210Rep api1210Rep;
    @Autowired
    private Api1403Rep api1403Rep;
    @Autowired
    private Api1404Rep api1404Rep;
 
    @Override
    public String getProtocol() {
        return PushProtocol.SB_SHJdJW_2023.getCode();
    }
 
    @Override
    public ResponseDto pushData(ApiParam param, Object data) {
        return pushData(param, null, data);
    }
 
    @Override
    public ResponseDto pullData(ApiParam param, ApiConfs conf) {
        //该协议无此实现
        return null;
    }
 
    @Override
    public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) {
        String inteId = param.getInteId();
        String kqdm = param.getKqdm();
        String bizId = param.getBizId();
 
        try {
            if (null == conf) {
                conf = apiCommonService.getConf(kqdm);
            }
            //添加日志
            ApiLog apiLog = new ApiLog();
            apiLog.setId(ContextUtil.getUUID());
            apiLog.setInteId(inteId);
 
            if (StringUtils.isEmpty(inteId)) {
                ResponseDto responseDto = new ResponseDto(99, "没有获取到接口", bizId);
                apiLog.setStatus(99);
                apiLog.setResult("没有获取到接口");
                apiLogRep.save(apiLog);
                return responseDto;
            }
 
            //查询库区信息行政区划码
            List<Api1102> api1102List = api1102Rep.findPushData(kqdm);
            //获取json数据
            List<Object> list = getJsonData(inteId, data, api1102List.get(0).getXzqhdm());
            ShjdjwReqDto reqData = new ShjdjwReqDto();
            //接口ID
            reqData.setId(getInteId(inteId));
            //上传数据,加密
            reqData.setData(list);
 
            apiLog.setData(JSON.toJSONString(reqData));
            apiLog.setKqdm(kqdm);
            apiLog.setUploadTime(new Date());
            if (conf == null) {
                ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置", bizId);
                apiLog.setStatus(99);
                apiLog.setResult("没有获取到上传配置");
                apiLogRep.save(apiLog);
                return responseDto;
            }
 
            String jsonStr = JSON.toJSONString(reqData);
            log.info("上报数据信息=" + jsonStr);
            jsonStr = AESUtils.encryptByEcb(jsonStr, conf.getPublicKey());
 
            ShjdjwRespDto responseDto = Shjdjw2023HttpClientUtil.postPushData(conf.getApiUrl(), jsonStr, conf);
 
            responseDto.setBizId(bizId);
            apiLog.setStatus(responseDto.getCode() == 1 ? 0 : responseDto.getCode());
            apiLog.setResult(responseDto.getDescription());
            apiLogRep.save(apiLog);
            ResponseDto resd = new ResponseDto();
            resd.setSuccess(responseDto.getCode() == 1 ? 0 : responseDto.getCode());
            resd.setMsg(responseDto.getDescription());
            return resd;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return new ResponseDto(99, e.getMessage());
        }
    }
 
    /**
     * 获取接口id
     *
     * @param inteId
     * @return
     */
    private String getInteId(String inteId) {
        switch (inteId) {
            case "1101":
                return ShjdjwApiCodeConstant.API_CODE_1101_ID;
            case "1102":
                return ShjdjwApiCodeConstant.API_CODE_1102_ID;
            case "1103":
                return ShjdjwApiCodeConstant.API_CODE_1103_ID;
            case "1104":
                return ShjdjwApiCodeConstant.API_CODE_1104_ID;
            case "1105":
                return ShjdjwApiCodeConstant.API_CODE_1105_ID;
            case "1202":
                return ShjdjwApiCodeConstant.API_CODE_1202_ID;
            case "1203":
                return ShjdjwApiCodeConstant.API_CODE_1203_ID;
            case "1205":
                return ShjdjwApiCodeConstant.API_CODE_1205_ID;
            case "1209":
                return ShjdjwApiCodeConstant.API_CODE_1209_ID;
            case "1310":
                return ShjdjwApiCodeConstant.API_CODE_1310_ID;
            case "1403":
                return ShjdjwApiCodeConstant.API_CODE_1403_ID;
            case "1404":
                return ShjdjwApiCodeConstant.API_CODE_1404_ID;
            default:
                return inteId;
        }
    }
 
    /**
     * 转为JSON
     *
     * @param inteId
     * @param data
     * @param code
     * @return
     */
    private List<Object> getJsonData(String inteId, Object data, String code) {
 
        List<Object> list = new ArrayList<>();
        Object object = getJsonApiData(inteId, data, code);
        list.add(object);
        return list;
    }
 
    /**
     * 调整数据封装,获取json数据
     *
     * @param inteId
     * @param data
     * @return
     * @throws Exception
     */
 
    private Object getJsonApiData(String inteId, Object data, String code) {
        //具体根据接口进行封装
        if (ShjdjwApiCodeConstant.API_CODE_1101.equals(inteId)) {
            Shjdjw2023Api1101 api1101 = new Shjdjw2023Api1101();
            BeanUtils.copyProperties(data, api1101);
 
            return api1101;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1102.equals(inteId)) {
            Shjdjw2023Api1102 api1102 = new Shjdjw2023Api1102();
            BeanUtils.copyProperties(data, api1102);
 
            return api1102;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1103.equals(inteId)) {
            Shjdjw2023Api1103 api1103 = new Shjdjw2023Api1103();
            BeanUtils.copyProperties(data, api1103);
 
            return api1103;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1104.equals(inteId)) {
            Shjdjw2023Api1104 api1104 = new Shjdjw2023Api1104();
            Api1104 apiData = (Api1104) data;
 
            //查询仓房信息
            List<Api1103> api1103List = api1103Rep.findPushDataByCfdm(apiData.getCfbh());
            List<Api1104> api1104List = api1104Rep.findDataByCfbh(apiData.getCfbh());
            int num = 2;
            if (null != api1104List && api1104List.size() > 0) {
                num = api1104List.size();
            }
            if (null != api1103List && api1103List.size() > 0) {
                Api1103 api1103 = api1103List.get(0);
                BeanUtils.copyProperties(api1103, api1104);
                api1104.setCwc(api1103.getCwc() / num);
                api1104.setCnc(api1103.getCnc() / num);
                api1104.setSjcr(api1103.getSjcr() / num);
            }
            BeanUtils.copyProperties(apiData, api1104);
            api1104.setAjdm(apiData.getAjdh());
            api1104.setCfdm(apiData.getCfbh());
 
            //设置粮食性质代码(查看廒间对应的最新库存进行赋值)
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1104.getAjdm() + "01");
            if (null != api1208List && api1208List.size() > 0) {
                api1104.setLsxzdm(api1208List.get(0).getLsxzdm());
            }
 
            return api1104;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1105.equals(inteId)) {
            Shjdjw2023Api1105 api1105 = new Shjdjw2023Api1105();
            BeanUtils.copyProperties(data, api1105);
 
            return api1105;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1202.equals(inteId)) {
            Shjdjw2023Api1202 api1202 = new Shjdjw2023Api1202();
            Api1202 apiData = (Api1202) data;
            BeanUtils.copyProperties(apiData, api1202);
            api1202.setBjw(ShAreaBjw.getBjw(code));
            api1202.setJzrq(apiData.getCmsj());
            if (StringUtils.isEmpty(api1202.getCddm())) {
                api1202.setCddm(api1202.getHwdm().substring(2, 8));
            }
            if (StringUtils.isEmpty(api1202.getRkjsdh())) {
                api1202.setRkjsdh("0");
            }
            //设置粮食轮换年度,根据计划明细号查询计划明细,再根据计划明细查询轮换计划
            List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh());
            if (null != api1404List && api1404List.size() > 0) {
                if(StringUtils.isEmpty(api1202.getShnd())){
                    api1202.setShnd(api1404List.get(0).getShnd());
                }
                List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh());
                if (null != api1403List && api1403List.size() > 0) {
                    if (StringUtils.isNotEmpty(api1403List.get(0).getJhnd())) {
                        api1202.setLhnd(api1403List.get(0).getJhnd());
                    }
                }
            }
            //查询粮食性质转变单号(根据入库时间和货位代码查询粮食性质转变单)
            List<Api1210> api1210List = api1210Rep.findDataByHwdmAndTime(api1202.getHwdm(), api1202.getCmsj());
            if (null != api1210List && api1210List.size() > 0) {
                api1202.setLsxzzbdh(api1210List.get(0).getLsxzzbdh());
            }
            //设置批次号
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1202.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                api1202.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
            }
            //粮食性质
            api1202.setLsxzdm("200");
 
            return api1202;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1203.equals(inteId)) {
            Shjdjw2023Api1203 api1203 = new Shjdjw2023Api1203();
            Api1203 apiData = (Api1203) data;
            BeanUtils.copyProperties(apiData, api1203);
            api1203.setBjw(ShAreaBjw.getBjw(code));
            if (StringUtils.isEmpty(api1203.getJyxm())) {
                api1203.setJyxm("0");
            }
            if (StringUtils.isEmpty(api1203.getJyz())) {
                api1203.setJyz("0");
            }
            if (StringUtils.isEmpty(api1203.getZkj())) {
                api1203.setZkj("0");
            }
            if (StringUtils.isEmpty(api1203.getZkl())) {
                api1203.setZkl("0");
            }
            //设置批次号
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1203.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                api1203.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
            }
            //设置质检编码(默认等同于入库质检单号),若为船运,则设置为系统内船运的单号
            api1203.setZjbh(api1203.getRkjydh());
            List<Api1202> api1202List = api1202Rep.getDataById(api1203.getRkywdh());
            if (null != api1202List && api1202List.size() > 0) {
                if (api1202List.get(0).getYsgj().equals("3")) {
                    api1203.setZjbh(api1202List.get(0).getBizId().substring(2));
                }
            }
            return api1203;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1205.equals(inteId)) {
 
            Shjdjw2023Api1205 api1205 = new Shjdjw2023Api1205();
            Api1205 apiData = (Api1205) data;
            BeanUtils.copyProperties(apiData, api1205);
            api1205.setBjw(ShAreaBjw.getBjw(code));
 
            api1205.setJzrq(apiData.getCmsj());
            if (StringUtils.isEmpty(api1205.getCddm())) {
                api1205.setCddm(api1205.getHwdm().substring(2, 8));
            }
            if (StringUtils.isEmpty(api1205.getCkjsdh())) {
                api1205.setCkjsdh("0");
            }
 
            //设置粮食轮换年度
            List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh());
            if (null != api1404List && api1404List.size() > 0) {
                if(StringUtils.isEmpty(api1205.getShnd())){
                    api1205.setShnd(api1404List.get(0).getShnd());
                }
                List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh());
                if (null != api1403List && api1403List.size() > 0) {
                    if (StringUtils.isNotEmpty(api1403List.get(0).getJhnd())) {
                        api1205.setLhnd(api1403List.get(0).getJhnd());
                    }
                }
            }
 
            //设置批次号
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1205.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                api1205.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
            }
 
            //粮食性质
            api1205.setLsxzdm("200");
 
            return api1205;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1209.equals(inteId)) {
 
            Shjdjw2023Api1209 api1209 = new Shjdjw2023Api1209();
            Api1209 apiData = (Api1209) data;
 
            BeanUtils.copyProperties(apiData, api1209);
            api1209.setDjlx("2");
            api1209.setSzjl(apiData.getQzszkl());
            api1209.setZrshde(apiData.getQzzrshde());
            api1209.setBjw(ShAreaBjw.getBjw(code));
            api1209.setJzrq(apiData.getYwrq());
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1209.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                api1209.setPch(api1209.getHwdm() + api1208List.get(0).getShnd());
            }
 
            //粮食性质,暂时默认区级储备
            api1209.setLsxzdm("122");
 
            return api1209;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1310.equals(inteId)) {
            Shjdjw2023Api1310 api1310 = new Shjdjw2023Api1310();
            Api1310 apiData = (Api1310) data;
            BeanUtils.copyProperties(apiData, api1310);
            api1310.setBjw(ShAreaBjw.getBjw(code));
            api1310.setJyrq(apiData.getJysj());
 
            if (StringUtils.isEmpty(api1310.getJyxm())) {
                api1310.setJyxm("0");
            }
            if (StringUtils.isEmpty(api1310.getJyxmz())) {
                api1310.setJyxmz("0");
            }
            String lsxzdm = "122";
            String pch = "";
            List<Api1208> api1208List = api1208Rep.getDataByHwdm(api1310.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                if (StringUtils.isNotEmpty(api1208List.get(0).getLsxzdm())) {
                    lsxzdm = api1208List.get(0).getLsxzdm();
                    pch = apiData.getHwdm() + api1208List.get(0).getShnd();
                }
            }
            //设置批次号
            api1310.setPch(pch);
            api1310.setLsxzdm(lsxzdm);
            if (api1310.getYpsl() == 0.0) {
                api1310.setYpsl(5.0);
            }
            if (StringUtils.isEmpty(api1310.getQyrxm())) {
                api1310.setQyrxm("扦样人");
            }
            if (StringUtils.isEmpty(api1310.getJdrxm())) {
                api1310.setJdrxm("监督人");
            }
            if (StringUtils.isEmpty(api1310.getShrxm())) {
                api1310.setShrxm("审核人");
            }
            //设置空属性为默认值
            return api1310;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1403.equals(inteId)) {
            Shjdjw2023Api1403 api1403 = new Shjdjw2023Api1403();
            Api1403 apiData = (Api1403) data;
            BeanUtils.copyProperties(apiData, api1403);
            List<Api1101> api1101List = api1101Rep.findDataByDwdm(apiData.getLhjhdh().substring(0, 18));
 
            api1403.setJhzxdw(api1101List.get(0).getDwdm());
            api1403.setJhzxdwmc(api1101List.get(0).getDwmc());
            api1403.setBjw(ShAreaBjw.getBjw(code));
 
            //查询轮换计划的轮入数量和轮出数量
            List<Api1404> list = api1404Rep.getDataByLhjhdh(api1403.getLhjhdh());
            Double lrsl = 0.0, lcsl = 0.0; //用于统计轮入数量和轮出数量
            if (null != list && list.size() > 0) {
                for (Api1404 api1404 : list) {
                    if (null != api1404.getLhlx() && "2".equals(api1404.getLhlx())) {
                        lrsl += api1404.getLhsl();
                    }
                    if (null != api1404.getLhlx() && "1".equals(api1404.getLhlx())) {
                        lcsl += api1404.getLhsl();
                    }
                }
            }
            api1403.setLrsl(lrsl + "");
            api1403.setLcsl(lcsl + "");
 
            //设置空属性为默认值
            return api1403;
        }
        if (ShjdjwApiCodeConstant.API_CODE_1404.equals(inteId)) {
            Shjdjw2023Api1404 api1404 = new Shjdjw2023Api1404();
            BeanUtils.copyProperties(data, api1404);
            api1404.setMxzt("1");
            api1404.setBjw(ShAreaBjw.getBjw(code));
 
            //设置空属性为默认值
            return api1404;
        }
        return data;
    }
 
}