| package com.fzzy.async.fzzy40.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.fzzy40.entity.Fz40InoutPlan; | 
| import com.fzzy.async.fzzy40.entity.Fz40InoutPlanDetail; | 
| import com.fzzy.async.fzzy40.repository.Fzzy40Sync1403Rep; | 
| import com.fzzy.async.fzzy40.repository.Fzzy40Sync1404Rep; | 
| 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 Fzzy40Sync1404 { | 
|   | 
|     @Autowired | 
|     private Fzzy40Sync1403Rep fzzy35Sync1403Rep; | 
|     @Autowired | 
|     private Fzzy40Sync1404Rep fzzy35Sync1404Rep; | 
|     @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<Fz40InoutPlan> list = fzzy35Sync1403Rep.findDateByTime(deptId, start, end); | 
|   | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Api1404 api1404; | 
|             List<Fz40InoutPlanDetail> fz35PlanDetails; | 
|             Api1105 api1105; | 
|             List<Api1404> api1404List; | 
|             for (Fz40InoutPlan fz35Plan : list) { | 
|   | 
|                 fz35PlanDetails = fzzy35Sync1404Rep.findDate(fz35Plan.getId()); | 
|                 if (null == fz35PlanDetails || fz35PlanDetails.isEmpty()) { | 
|                     continue; | 
|                 } | 
|                 int index = 10001; | 
|                 for (Fz40InoutPlanDetail 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)); | 
|   | 
|                     String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, fz35PlanDetail.getFoodVariety().substring(0,3)); | 
|                     api1404.setLspzdm(mappingCode); | 
|                     api1404.setLsdjdm(fz35PlanDetail.getFoodLevel()); | 
|                     mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSXZ, fz35PlanDetail.getFoodType()); | 
|                     api1404.setLsxzdm(mappingCode); | 
|                     api1404.setShnd(StringUtils.isEmpty(fz35PlanDetail.getYear())?fz35Plan.getYear():fz35PlanDetail.getYear()); | 
|                     api1404.setLhhwdm(api1105.getHwdm()); | 
|                     if(null == fz35PlanDetail.getPlanNum()){ | 
|                         fz35PlanDetail.setPlanNum(0.0); | 
|                     } | 
|                     api1404.setLhsl(fz35PlanDetail.getPlanNum()/1000); | 
|                     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); | 
|         } | 
|     } | 
|   | 
| } |