| package com.fzzy.async.fzzy61.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1101; | 
| import com.fzzy.api.entity.Api1403; | 
| import com.fzzy.api.entity.ApiLog; | 
| 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.fzzy61.entity.Fz61InoutPlan; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61Sync1403Rep; | 
| 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 Fzzy61Sync1403 { | 
|   | 
|     @Autowired | 
|     private Fzzy61Sync1403Rep fzzy61Sync1403Rep; | 
|     @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_1403); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             List<Fz61InoutPlan> list = fzzy61Sync1403Rep.findDateByTime(deptId, start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Api1403 api1403; | 
|             List<Api1101> api1101List; | 
|             List<Api1403> api1403List; | 
|             for (Fz61InoutPlan fz61Plan : list) { | 
|                 api1403 = new Api1403(); | 
|                 api1403.setLhjhdh(kqdm.substring(0, 18) + fz61Plan.getId().split("_")[1] + fz61Plan.getId().split("_")[2]); | 
|                 api1403.setJhwh(fz61Plan.getReferenceNumber()); | 
|                 api1403.setJhmc(fz61Plan.getName()); | 
|                 api1403.setJhnd(fz61Plan.getYear()); | 
|                 api1403.setKszxrq(fz61Plan.getBeginTime()); | 
|                 api1403.setJzzxrq(fz61Plan.getEndTime()); | 
|                 api1101List = api1101Rep.findPushData(kqdm); | 
|                 if (null != api1101List && api1101List.size() > 0) { | 
|                     api1403.setJhxddw(api1101List.get(0).getDwdm()); | 
|                 } | 
|                 api1403.setJhxdsj(fz61Plan.getCreateTime()); | 
|                 api1403.setManageWay("1"); //默认直储 | 
|                 api1403.setRotationType("1"); //默认静态轮换 | 
|   | 
|                 //若附件id不为空,则判断是否为广东省平台协议,广东省平台协议时,需同时同步计划附件信息 | 
|                 if (StringUtils.isNotEmpty(fz61Plan.getFileId())) { | 
|                     //文件路径 | 
|                     api1403.setWjdz(fileUtil.getCommonFilePath(fz61Plan.getFileTime()) + fz61Plan.getFileId()); | 
|                     //文件名称 | 
|                     api1403.setFileName(fz61Plan.getFileName()); | 
|                 } | 
|   | 
|                 api1403.setZhgxsj(new Date()); | 
|                 api1403.setKqdm(kqdm); | 
|                 api1403.setBizId(fz61Plan.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("---1403轮换计划同步失败----{}", e.toString()); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
|   | 
| } |