czt
2024-11-01 dbef4eea6194ffba3bd25f978b33e09d65f5a6de
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
package com.fzzy.async.fzzy40.impl;
 
import com.fzzy.api.Constant;
import com.fzzy.api.entity.*;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.FileUtils;
import com.fzzy.api.view.repository.Api1101Rep;
import com.fzzy.api.view.repository.Api1403Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40InoutPlan;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1403Rep;
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 Fzzy40Sync1403 {
 
    @Autowired
    private Fzzy40Sync1403Rep fzzy40Sync1403Rep;
    @Autowired
    private FileUtils fileUtil;
    @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<Fz40InoutPlan> list = fzzy40Sync1403Rep.findDateByTime(deptId, start, end);
            if (null == list || list.isEmpty()) {
                return;
            }
 
            Api1403 api1403;
            List<Api1101> api1101List;
            List<Api1403> api1403List;
            for (Fz40InoutPlan 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.setManageWay("1"); //默认直储
                api1403.setRotationType("1"); //默认静态轮换
 
                //若附件id不为空,则判断是否为广东省平台协议,广东省平台协议时,需同时同步计划附件信息
                if (StringUtils.isNotEmpty(fz35Plan.getFileId())) {
                    //文件路径
                    api1403.setWjdz(fileUtil.getCommonFilePath(fz35Plan.getFileTime()) + fz35Plan.getFileId());
                    //文件名称
                    api1403.setFileName(fz35Plan.getFileName());
                }
 
                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);
        }
    }
 
}