CZT
2023-10-27 dc66963d36e0a479e7334092241834b60bf8bbe2
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
package com.fzzy.async.fzzy35.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.*;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1404Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy35.entity.Fz35Plan;
import com.fzzy.async.fzzy35.entity.Fz35PlanDetail;
import com.fzzy.async.fzzy35.repository.Fzzy35Sync1403Rep;
import com.fzzy.async.fzzy35.repository.Fzzy35Sync1404Rep;
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 chen
 * @date 2023-05-14 19:51
 */
@Slf4j
@Component
public class Fzzy35Sync1404 {
 
    @Autowired
    private Fzzy35Sync1403Rep fzzy35Sync1403Rep;
    @Autowired
    private Fzzy35Sync1404Rep fzzy35Sync1404Rep;
    @Autowired
    private ApiCommonService commonService;
    @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<Fz35Plan> list = fzzy35Sync1403Rep.findDate("3", start, end);
 
            if (null == list || list.isEmpty()) {
                return;
            }
 
            Api1404 api1404;
            List<Fz35PlanDetail> fz35PlanDetails;
            Api1105 api1105;
            List<Api1404> api1404List;
            for (Fz35Plan fz35Plan : list) {
 
                fz35PlanDetails = fzzy35Sync1404Rep.findDate(fz35Plan.getId());
                if (null == fz35PlanDetails || fz35PlanDetails.isEmpty()) {
                    continue;
                }
                int index = 10001;
                for (Fz35PlanDetail fz35PlanDetail : fz35PlanDetails) {
                    api1105 = commonService.getApi1105Cache(fz35PlanDetail.getDepotId());
                    if (null == api1105) {
                        continue;
                    }
                    api1404 = new Api1404();
                    api1404.setLhjhdh(kqdm.substring(0, 18) + fz35PlanDetail.getPlanId().split("_")[1] + fz35PlanDetail.getPlanId().split("_")[2]);
                    api1404.setJhmxdh(api1404.getLhjhdh() + kqdm + String.valueOf(index).substring(1));
                    api1404.setLspzdm(fz35PlanDetail.getFoodVariety());
                    api1404.setLsdjdm(fz35PlanDetail.getFoodLevel());
                    api1404.setLsxzdm(fz35PlanDetail.getFoodType());
                    api1404.setShnd(StringUtils.isEmpty(fz35PlanDetail.getYear())?fz35Plan.getYear():fz35PlanDetail.getYear());
                    api1404.setLhhwdm(fz35PlanDetail.getDepotId());
                    api1404.setLhsl(fz35PlanDetail.getPlanNum());
                    api1404.setLhlx(fz35PlanDetail.getType());
                    api1404.setZhgxsj(new Date());
                    api1404.setKqdm(kqdm);
                    api1404.setBizId(fz35PlanDetail.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);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
 
}