YYC
2023-08-17 9a29c498c851a412f5f64e6b0a293f27ed469702
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
package com.fzzy.async.fzzy35.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.*;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.*;
import com.fzzy.async.fzzy35.entity.Fz35Plan;
import com.fzzy.async.fzzy35.repository.Fzzy35Sync1403Rep;
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 czt
 * @date 2023-05-14 19:51
 */
@Slf4j
@Component
public class Fzzy35Sync1403 {
 
    @Autowired
    private Fzzy35Sync1403Rep fzzy35Sync1403Rep;
    @Autowired
    private Api1101Rep api1101Rep;
    @Autowired
    private Api1403Rep api1403Rep;
    @Autowired
    private ApiLogRep apiLogRep;
 
    /**
     * 同步并封装保存轮换计划数据
     *
     * @param deptId 系统对应库区编码
     * @param start  起始时间
     * @param end    截止时间
     */
    public void syncData(String kqdm, String deptId, Date start, Date end) {
        log.info("-------------1403接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        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;
            }
 
            Api1403 api1403;
            List<Api1101> api1101List;
            List<Api1403> api1403List;
            for (Fz35Plan fz35Plan : list) {
                api1403 = new Api1403();
                api1403.setLhjhdh(kqdm.substring(0, 18) + fz35Plan.getId().split("_")[1] + fz35Plan.getId().split("_")[2]);
                api1403.setJhwh(fz35Plan.getReferenceNumber());
                api1403.setJhmc(fz35Plan.getName());
                api1403.setJhnd(fz35Plan.getYear());
                api1403.setKszxrq(fz35Plan.getBeginTime());
                api1403.setJzzxrq(fz35Plan.getEndTime());
                api1101List = api1101Rep.findPushData(kqdm);
                if(null != api1101List && api1101List.size() > 0){
                    api1403.setJhxddw(api1101List.get(0).getDwdm());
                }
                api1403.setJhxdsj(fz35Plan.getCreateTime());
 
                api1403.setZhgxsj(new Date());
                api1403.setKqdm(kqdm);
                api1403.setBizId(fz35Plan.getId());
                api1403List = api1403Rep.getDataByLhjhdh(api1403.getLhjhdh());
                if(null == api1403List || api1403List.isEmpty()){
                    api1403.setCzbz(Constant.CZBZ_I);
                }else {
                    api1403.setCzbz(api1403List.get(0).getCzbz());
                }
                api1403Rep.save(api1403);
            }
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
 
}