| package com.fzzy.async.fzzy35.impl; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.data.PushProtocol; | 
| import com.fzzy.api.entity.Api1105; | 
| import com.fzzy.api.entity.ApiInfoData; | 
| import com.fzzy.api.entity.ApiLog; | 
| import com.fzzy.api.service.ApiCommonService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.view.repository.ApiInfoDataRep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy35.entity.Fz35DrugLogApply; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35Sync1023Rep; | 
| import com.fzzy.async.fzzy35.entity.Fz35DrugLogDtl; | 
| import com.fzzy.async.fzzy35.entity.Fz35DrugLogPeople; | 
| import com.fzzy.async.fzzy35.entity.Fz35DrugLogWay; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35SyncDrugLogDtlRep; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35SyncDrugLogPeopleRep; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35SyncDrugLogWayRep; | 
| import com.fzzy.push.gd2022.dto.Gd2022Api1023; | 
| import com.fzzy.push.gd2022.dto.Gd2022Api1023Dtl; | 
| import com.fzzy.push.gd2022.dto.Gd2022Api1023People; | 
| import com.fzzy.push.gd2022.dto.Gd2022Api1023Way; | 
| import com.fzzy.push.gd2022.ApiCodeConstant; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Component; | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 熏蒸备案信息 | 
|  * | 
|  * @author czt | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy35Sync1023 { | 
|     @Autowired | 
|     private Fzzy35Sync1023Rep fzzy35Sync1023Rep; | 
|     @Autowired | 
|     private Fzzy35SyncDrugLogPeopleRep drugLogPeopleRep; | 
|     @Autowired | 
|     private Fzzy35SyncDrugLogWayRep drugLogWayRep; | 
|     @Autowired | 
|     private Fzzy35SyncDrugLogDtlRep drugLogDtlRep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|     @Autowired | 
|     private ApiInfoDataRep apiInfoDataRep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|   | 
|     /** | 
|      * 同步熏蒸备案信息 | 
|      * | 
|      * @param deptId | 
|      * @param start | 
|      * @param end | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|         log.info("-------------1023接口设备信息开始同步------------------"); | 
|   | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(ApiCodeConstant.API_1023); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             List<Fz35DrugLogApply> list = fzzy35Sync1023Rep.listDrugLogApply(deptId, start, end); | 
|   | 
|             if (null == list || list.isEmpty()) { | 
|                 log.info("-------------没有获取到熏蒸备案信息------------------"); | 
|                 return; | 
|             } | 
|   | 
|             Gd2022Api1023 GD2022Api1023; | 
|             Gd2022Api1023Way gd2022Api1023Way; | 
|             Gd2022Api1023People gd2022Api1023People; | 
|             Gd2022Api1023Dtl gd2022Api1023Dtl; | 
|   | 
|             List<Gd2022Api1023Dtl> dtlList; | 
|             List<Gd2022Api1023Way> wayList; | 
|             List<Gd2022Api1023People> peopleList; | 
|   | 
|             List<ApiInfoData> apiInfoList; | 
|             ApiInfoData infoData; | 
|             Api1105 api1105; | 
|   | 
|             for (Fz35DrugLogApply data : list) { | 
|                 GD2022Api1023 = new Gd2022Api1023(); | 
|                 BeanUtils.copyProperties(data, GD2022Api1023); | 
|                 GD2022Api1023.setXzbm(data.getXzbm().substring(7)); | 
|                 GD2022Api1023.setKqdm(kqdm); | 
|                 GD2022Api1023.setDwdm(kqdm.substring(0, 18)); | 
|                 GD2022Api1023.setYjmc(data.getDrugName()); | 
|                 GD2022Api1023.setYjlx(data.getDrugType()); | 
|                 GD2022Api1023.setZhgxsj(data.getUpdateTime()); | 
|   | 
|                 //储粮粮情明细表 | 
|                 List<Fz35DrugLogDtl> dtls = drugLogDtlRep.listDrugLogDtl(data.getXzbm()); | 
|                 if (null != dtls && dtls.size() > 0) { | 
|                     dtlList = new ArrayList<>(); | 
|                     for (Fz35DrugLogDtl dtl : dtls) { | 
|                         gd2022Api1023Dtl = new Gd2022Api1023Dtl(); | 
|                         BeanUtils.copyProperties(dtl, gd2022Api1023Dtl); | 
|                         //获取货位信息 | 
|                         api1105 = commonService.getApi1105Cache(dtl.getDepotId()); | 
|                         if (null == api1105) { | 
|                             continue; | 
|                         } | 
|                         gd2022Api1023Dtl.setCfdm(api1105.getHwdm().substring(0, 25)); | 
|                         gd2022Api1023Dtl.setLspzdm(dtl.getFoodVariety()); | 
|                         gd2022Api1023Dtl.setLsxzdm(dtl.getFoodType()); | 
|                         gd2022Api1023Dtl.setLsdjdm(dtl.getFoodLevel()); | 
|                         gd2022Api1023Dtl.setLssl(dtl.getNumber()); | 
|                         gd2022Api1023Dtl.setSf(dtl.getPerWet()); | 
|                         gd2022Api1023Dtl.setZz(dtl.getPerImpurity()); | 
|                         dtlList.add(gd2022Api1023Dtl); | 
|                     } | 
|                     GD2022Api1023.setDtls(dtlList); | 
|                 } | 
|   | 
|                 List<Fz35DrugLogWay> ways = drugLogWayRep.listDrugLogWay(data.getXzbm()); | 
|                 if (null != ways && ways.size() > 0) { | 
|                     wayList = new ArrayList<>(); | 
|                     for (Fz35DrugLogWay way : ways) { | 
|                         gd2022Api1023Way = new Gd2022Api1023Way(); | 
|                         BeanUtils.copyProperties(way, gd2022Api1023Way); | 
|                         wayList.add(gd2022Api1023Way); | 
|                     } | 
|   | 
|                     GD2022Api1023.setWays(wayList); | 
|                 } | 
|   | 
|                 List<Fz35DrugLogPeople> peoples = drugLogPeopleRep.listDrugLogPeople(data.getXzbm()); | 
|                 if (null != peoples && peoples.size() > 0) { | 
|                     peopleList = new ArrayList<>(); | 
|                     for (Fz35DrugLogPeople people : peoples) { | 
|                         gd2022Api1023People = new Gd2022Api1023People(); | 
|                         BeanUtils.copyProperties(people, gd2022Api1023People); | 
|                         peopleList.add(gd2022Api1023People); | 
|   | 
|                     } | 
|                     GD2022Api1023.setPeoples(peopleList); | 
|                 } | 
|   | 
|                 //持久化保存,单独存入非国标接口表 | 
|                 infoData = new ApiInfoData(); | 
|                 infoData.setId(ContextUtil.getUUID()); | 
|                 infoData.setKqdm(kqdm); | 
|                 infoData.setInteType(Constant.API_CATEGORY_13); | 
|                 infoData.setInteId(ApiCodeConstant.API_1023); | 
|                 infoData.setBizType(PushProtocol.SB_GD_2022.getCode()); | 
|                 infoData.setUpdateTime(new Date()); | 
|                 infoData.setDataId(data.getXzbm()); | 
|   | 
|                 apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), kqdm); | 
|                 if (null == apiInfoList || apiInfoList.isEmpty()) { | 
|                     GD2022Api1023.setCzbz(Constant.CZBZ_I); | 
|                     infoData.setCzbz(Constant.CZBZ_I); | 
|                 } else { | 
|                     GD2022Api1023.setCzbz(apiInfoList.get(0).getCzbz()); | 
|                     infoData.setCzbz(apiInfoList.get(0).getCzbz()); | 
|                 } | 
|   | 
|                 infoData.setData(JSON.toJSONString(GD2022Api1023)); | 
|   | 
|                 //保存数据 | 
|                 apiInfoDataRep.save(infoData); | 
|                 log.info("1023---同步数据:{}", GD2022Api1023.toString()); | 
|             } | 
|              | 
|         } catch (Exception e) { | 
|             log.error("---熏蒸备案信息同步执行失败----{}", e.toString()); | 
|             apiLog.setResult("熏蒸备案信息同步执行失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
| } |