YYC
2025-09-28 14605ba25b4d950df29ac7a44bf65ccc3472ffff
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
package com.fzzy.async.fzzy61.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1404;
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.Api1404Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy61.entity.Fz61InoutPlan;
import com.fzzy.async.fzzy61.entity.Fz61InoutPlanDetail;
import com.fzzy.async.fzzy61.repository.Fzzy61Sync1403Rep;
import com.fzzy.async.fzzy61.repository.Fzzy61Sync1404Rep;
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.Date;
import java.util.List;
 
/**
 * 轮换计划明细
 *
 * @author czt
 * @date 2023-10-30 09:55
 */
@Slf4j
@Component
public class Fzzy61Sync1404 {
 
    @Autowired
    private Fzzy61Sync1403Rep fzzy61Sync1403Rep;
    @Autowired
    private Fzzy61Sync1404Rep fzzy61Sync1404Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private ApiTriggerService apiTriggerService;
    @Autowired
    private Api1404Rep api1404Rep;
    @Autowired
    private ApiLogRep apiLogRep;
 
    /**
     * 同步并封装保存轮换计划明细
     *
     * @param deptId 系统对应库区编码
     * @param start  起始时间
     * @param end    截止时间
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
        log.info("-------------1404轮换计划明细接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        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<Fz61InoutPlan> list = fzzy61Sync1403Rep.findDateByTime(deptId, start, end);
 
            if (null == list || list.isEmpty()) {
                return;
            }
 
            Api1404 api1404;
            List<Fz61InoutPlanDetail> fz61PlanDetails;
            Api1105 api1105;
            List<Api1404> api1404List;
            for (Fz61InoutPlan fz61Plan : list) {
 
                fz61PlanDetails = fzzy61Sync1404Rep.findDate(fz61Plan.getId());
                if (null == fz61PlanDetails || fz61PlanDetails.isEmpty()) {
                    continue;
                }
                int index = 10001;
                for (Fz61InoutPlanDetail fz61PlanDetail : fz61PlanDetails) {
                    api1105 = commonService.getApi1105Cache(fz61PlanDetail.getDepotId());
                    if (null == api1105) {
                        continue;
                    }
                    api1404 = new Api1404();
                    api1404.setLhjhdh(kqdm.substring(0, 18) + fz61PlanDetail.getPlanId().split("_")[1] + fz61PlanDetail.getPlanId().split("_")[2]);
                    api1404.setJhmxdh(api1404.getLhjhdh() + kqdm + String.valueOf(index).substring(1));
 
                    String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, fz61PlanDetail.getFoodVariety().substring(0,3));
                    api1404.setLspzdm(mappingCode);
                    api1404.setLsdjdm(fz61PlanDetail.getFoodLevel());
                    mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSXZ, fz61PlanDetail.getFoodType());
                    api1404.setLsxzdm(mappingCode);
                    api1404.setShnd(StringUtils.isEmpty(fz61PlanDetail.getYear())?fz61Plan.getYear():fz61PlanDetail.getYear());
                    api1404.setLhhwdm(api1105.getHwdm());
                    if(null == fz61PlanDetail.getPlanNum()){
                        fz61PlanDetail.setPlanNum(0.0);
                    }
                    api1404.setLhsl(fz61PlanDetail.getPlanNum()/1000);
                    api1404.setLhlx(fz61PlanDetail.getType());
                    api1404.setZhgxsj(new Date());
                    api1404.setKqdm(kqdm);
                    api1404.setBizId(fz61PlanDetail.getId());
                    api1404List = api1404Rep.getDataByJhmxdh(api1404.getJhmxdh());
                    if(null == api1404List || api1404List.isEmpty()){
                        api1404.setCzbz(Constant.CZBZ_I);
                    }else {
                        api1404.setCzbz(api1404List.get(0).getCzbz());
                    }
                    api1404Rep.save(api1404);
                    index ++;
                }
            }
        } catch (Exception e) {
            log.error("---轮换计划明细同步失败----{}", e.toString());
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
 
}