YYC
2025-11-19 5a62eb7bee15e489a33e6bdd337795addaf19c71
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.fzzy.async.fzzy61.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1216;
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.Api1216Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy61.entity.Fz61InoutStockCheck;
import com.fzzy.async.fzzy61.repository.Fzzy61Sync1216Rep;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * @Description 粮食购销-倒仓验收表
 * @Author CZT
 * @Date 2025/11/08 10:32
 */
@Slf4j
@Component
public class Fzzy61Sync1216 {
 
    @Autowired
    private Fzzy61Sync1216Rep fzzy61Sync1216Rep;
    @Autowired
    private ApiTriggerService apiTriggerService;
    @Autowired
    private Api1216Rep api1216Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private ApiLogRep apiLogRep;
 
    /**
     * 同步封仓确认信息
     *
     * @param deptId
     * @param start
     * @param end
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
 
        log.info("-------------1216接口数据开始同步------------------");
 
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1208);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz61InoutStockCheck> list = fzzy61Sync1216Rep.listData(deptId, start, end);
            if (null == list || list.isEmpty()) {
                log.info("-------------没有获取到封仓确认信息------------------");
                return;
            }
 
            Api1216 apiData;
            Api1105 api1105In;
            Api1105 api1105Out;
            List<Api1216> api1216List;
            for (Fz61InoutStockCheck inoutStockCheck : list) {
                //获取货位信息
                api1105Out = commonService.getApi1105Cache(inoutStockCheck.getDchwbm());
                if (null == api1105Out) {
                    continue;
                }
                //获取货位信息
                api1105In = commonService.getApi1105Cache(inoutStockCheck.getDrhwbm());
                if (null == api1105In) {
                    continue;
                }
 
                apiData = new Api1216();
                BeanUtils.copyProperties(inoutStockCheck, apiData);
                apiData.setBizId(inoutStockCheck.getDcysdh());
                apiData.setKqdm(kqdm);
                apiData.setDchwbm(api1105Out.getHwdm());
                apiData.setDrhwbm(api1105In.getHwdm());
 
                //粮食品种
                String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, inoutStockCheck.getDclspzdm().substring(0, 3));
                apiData.setDclspzdm(mappingCode);
 
                //粮食性质
                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSDJ, inoutStockCheck.getDclsdjdm());
                apiData.setDclsdjdm(mappingCode);
 
                //粮食品种
                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, inoutStockCheck.getDrlspzdm().substring(0, 3));
                apiData.setDrlspzdm(mappingCode);
 
                //粮食性质
                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSDJ, inoutStockCheck.getDrlsdjdm());
                apiData.setDrlsdjdm(mappingCode);
 
                api1216List = api1216Rep.getDataByBizId(apiData.getBizId());
                if (null == api1216List || api1216List.isEmpty()) {
                    apiData.setCzbz(Constant.CZBZ_I);
                } else {
                    apiData.setCzbz(api1216List.get(0).getCzbz());
                }
 
                //保存数据
                api1216Rep.save(apiData);
            }
 
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
}