| package com.fzzy.async.fzzy40.impl; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1102; | 
| 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.service.ApiTriggerService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.view.repository.Api1102Rep; | 
| import com.fzzy.api.view.repository.ApiInfoDataRep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy40.entity.Fz40InoutRecord; | 
| import com.fzzy.async.fzzy40.repository.Fzzy40Sync1202Rep; | 
| import com.fzzy.push.sh2023.SH2023Constant; | 
| import com.fzzy.push.sh2023.dto.SH2023Api2101; | 
| import com.fzzy.push.sh2023.dto.ShAreaBjw; | 
| 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:YAN | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy40Sync2101 { | 
|   | 
|     @Autowired | 
|     private Fzzy40Sync1202Rep fzzy40Sync1202Rep; | 
|     @Autowired | 
|     private Api1102Rep api1102Rep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|     @Autowired | 
|     private ApiInfoDataRep apiInfoDataRep; | 
|     @Autowired | 
|     private ApiTriggerService apiTriggerService; | 
|   | 
|     /** | 
|      * 同步市储检斤单 | 
|      * | 
|      * @param deptId | 
|      * @param start | 
|      * @param end | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|   | 
|         log.info("-------------2101接口数据开始同步------------------"); | 
|   | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(SH2023Constant.SH_2023_API_CODE_2101); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             List<Fz40InoutRecord> list = fzzy40Sync1202Rep.listInoutRecord(deptId, start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 log.debug("-------------没有获取到市储检斤单------------------"); | 
|                 return; | 
|             } | 
|   | 
|             SH2023Api2101 sh2023Api2101; | 
|             Api1105 api1105; | 
|             List<ApiInfoData> apiInfoDataList; | 
|             List<Api1102> api1102List = api1102Rep.findPushData(kqdm); | 
|             String bjw = ""; | 
|             if (null != api1102List && api1102List.size() > 0) { | 
|                 bjw = ShAreaBjw.getBjw(api1102List.get(0).getXzqhdm()); | 
|             } | 
|             for (Fz40InoutRecord sysData : list) { | 
|                 sh2023Api2101 = new SH2023Api2101(); | 
|                 sh2023Api2101.setJjdh(sysData.getCheckId()); | 
|                 sh2023Api2101.setKqdm(kqdm); | 
|                 sh2023Api2101.setJjrq(sysData.getCompleteTime()); | 
|                 sh2023Api2101.setJzrq(sysData.getCompleteTime()); | 
|                 sh2023Api2101.setInbillno(sysData.getId().substring(2)); | 
|                 sh2023Api2101.setZydh(sysData.getId()); | 
|                 sh2023Api2101.setZylx("IN".equals(sysData.getType()) ? "1" : "4"); | 
|   | 
|                 sh2023Api2101.setCch(sysData.getPlateNum()); | 
|                 String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSXZ, sysData.getFoodType()); | 
|                 sh2023Api2101.setLsxzdm(mappingCode); | 
|                 mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, sysData.getFoodVariety()); | 
|                 sh2023Api2101.setLspzdmdl(mappingCode); | 
|   | 
|                 sh2023Api2101.setLldm(kqdm); | 
|   | 
|   | 
|                 sh2023Api2101.setJz(sysData.getNetWeight()); | 
|                 sh2023Api2101.setMz(sysData.getNetWeight()); | 
|                 sh2023Api2101.setBzwzkl(sysData.getDePackage()); | 
|                 sh2023Api2101.setZhgxsj(sysData.getUpdateTime()); | 
|   | 
|                 //获取货位信息 | 
|                 api1105 = commonService.getApi1105Cache(sysData.getDepotId()); | 
|                 sh2023Api2101.setAjdm(api1105.getAjdm()); | 
|                 sh2023Api2101.setHwdm(api1105.getHwdm()); | 
|                 sh2023Api2101.setPch(api1105.getHwdm() + sysData.getFoodYear()); | 
|                 sh2023Api2101.setBjw(bjw); | 
|   | 
|                 //持久化保存,单独存入非国标接口表 | 
|                 ApiInfoData infoData = new ApiInfoData(); | 
|                 infoData.setId(ContextUtil.getUUID()); | 
|                 infoData.setKqdm(kqdm); | 
|                 infoData.setInteType(Constant.API_CATEGORY_12); | 
|                 infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2101); | 
|                 infoData.setUpdateTime(new Date()); | 
|                 infoData.setDataId(sh2023Api2101.getJjdh()); | 
|                 infoData.setRemarks("市储检斤单"); | 
|   | 
|                 //设置操作标志 | 
|                 apiInfoDataList = apiInfoDataRep.getDataByInteAndData(SH2023Constant.SH_2023_API_CODE_2101, infoData.getDataId(), kqdm); | 
|                 if (null == apiInfoDataList || apiInfoDataList.isEmpty()) { | 
|                     infoData.setCzbz(Constant.CZBZ_I); | 
|                     sh2023Api2101.setCzbz(Constant.CZBZ_I); | 
|                 } else { | 
|                     infoData.setCzbz(apiInfoDataList.get(0).getCzbz()); | 
|                     sh2023Api2101.setCzbz(apiInfoDataList.get(0).getCzbz()); | 
|                 } | 
|   | 
|                 infoData.setData(JSON.toJSONString(sh2023Api2101)); | 
|                 apiInfoDataRep.save(infoData); | 
|   | 
|                 log.info("2101---市储检斤单-同步数据:{}", sh2023Api2101); | 
|   | 
|             } | 
|   | 
|         } catch (Exception e) { | 
|             log.error("---市储检斤单同步执行失败----{}", e); | 
|             apiLog.setResult("同步市储检斤单失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
| } |