CZT
2023-11-08 7ab13e3b8f4ab768dd68b1bd8e1f8bbce31fb8a6
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
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.service.ApiTriggerService;
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.Fz40InoutRecord;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1202Rep;
import com.fzzy.push.sh2023.SH2023Constant;
import com.fzzy.push.sh2023.dto.SH2023Api2101;
import com.fzzy.push.sh2023.dto.ShAreaBjw;
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:YAN
 */
@Slf4j
@Component
public class Fzzy40Sync2101 {
 
    @Autowired
    private Fzzy40Sync1202Rep fzzy40Sync1202Rep;
    @Autowired
    private Api1102Rep api1102Rep;
    @Autowired
    private ApiLogRep apiLogRep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private ApiInfoDataRep apiInfoDataRep;
    @Autowired
    private ApiTriggerService apiTriggerService;
 
    /**
     * 同步市储检斤单
     *
     * @param deptId
     * @param start
     * @param end
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
 
        log.info("-------------2101接口数据开始同步------------------");
 
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(SH2023Constant.SH_2023_API_CODE_2101);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40InoutRecord> list = fzzy40Sync1202Rep.listInoutRecord(deptId, start, end);
            if (null == list || list.isEmpty()) {
                log.debug("-------------没有获取到市储检斤单------------------");
                return;
            }
 
            SH2023Api2101 sh2023Api2101;
            Api1105 api1105;
            List<ApiInfoData> apiInfoDataList;
            List<Api1102> api1102List = api1102Rep.findPushData(kqdm);
            String bjw = "";
            if (null != api1102List && api1102List.size() > 0) {
                bjw = ShAreaBjw.getBjw(api1102List.get(0).getXzqhdm());
            }
            for (Fz40InoutRecord sysData : list) {
                sh2023Api2101 = new SH2023Api2101();
                sh2023Api2101.setJjdh(sysData.getCheckId());
                sh2023Api2101.setKqdm(kqdm);
                sh2023Api2101.setJjrq(sysData.getCompleteTime());
                sh2023Api2101.setJzrq(sysData.getCompleteTime());
                sh2023Api2101.setInbillno(sysData.getId().substring(2));
                sh2023Api2101.setZydh(sysData.getId());
                sh2023Api2101.setZylx("IN".equals(sysData.getType()) ? "1" : "4");
 
                sh2023Api2101.setCch(sysData.getPlateNum());
                String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSXZ, sysData.getFoodType());
                sh2023Api2101.setLsxzdm(mappingCode);
                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, sysData.getFoodVariety());
                sh2023Api2101.setLspzdmdl(mappingCode);
 
                sh2023Api2101.setLldm(kqdm);
 
 
                sh2023Api2101.setJz(sysData.getNetWeight());
                sh2023Api2101.setMz(sysData.getNetWeight());
                sh2023Api2101.setBzwzkl(sysData.getDePackage());
                sh2023Api2101.setZhgxsj(sysData.getUpdateTime());
 
                //获取货位信息
                api1105 = commonService.getApi1105Cache(sysData.getDepotId());
                sh2023Api2101.setAjdm(api1105.getAjdm());
                sh2023Api2101.setHwdm(api1105.getHwdm());
                sh2023Api2101.setPch(api1105.getHwdm() + sysData.getFoodYear());
                sh2023Api2101.setBjw(bjw);
 
                //持久化保存,单独存入非国标接口表
                ApiInfoData infoData = new ApiInfoData();
                infoData.setId(ContextUtil.getUUID());
                infoData.setKqdm(kqdm);
                infoData.setInteType(Constant.API_CATEGORY_12);
                infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2101);
                infoData.setUpdateTime(new Date());
                infoData.setDataId(sh2023Api2101.getJjdh());
                infoData.setRemarks("市储检斤单");
 
                //设置操作标志
                apiInfoDataList = apiInfoDataRep.getDataByInteAndData(SH2023Constant.SH_2023_API_CODE_2101, infoData.getDataId(), kqdm);
                if (null == apiInfoDataList || apiInfoDataList.isEmpty()) {
                    infoData.setCzbz(Constant.CZBZ_I);
                    sh2023Api2101.setCzbz(Constant.CZBZ_I);
                } else {
                    infoData.setCzbz(apiInfoDataList.get(0).getCzbz());
                    sh2023Api2101.setCzbz(apiInfoDataList.get(0).getCzbz());
                }
 
                infoData.setData(JSON.toJSONString(sh2023Api2101));
                apiInfoDataRep.save(infoData);
 
                log.info("2101---市储检斤单-同步数据:{}", sh2023Api2101);
 
            }
 
        } catch (Exception e) {
            log.error("---市储检斤单同步执行失败----{}", e);
            apiLog.setResult("同步市储检斤单失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
}