| package com.fzzy.async.fzzy61.impl; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1105; | 
| import com.fzzy.api.entity.ApiConfs; | 
| 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.ApiConfsRep; | 
| import com.fzzy.api.view.repository.ApiInfoDataRep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy61.entity.Fz61Depot; | 
| import com.fzzy.async.fzzy61.entity.Fz61DepotConf; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61SyncDepotConfRep; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61SyncDepotRep; | 
| import com.fzzy.push.sh2023.SH2023Constant; | 
| import com.fzzy.push.sh2023.dto.SH2023Api2103; | 
| import com.fzzy.push.sh2023.dto.SH2023Api2103Item; | 
| 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.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 粮情检测设备信息同步 | 
|  * | 
|  * @author czt | 
|  * @date 2023-08-21 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy61Sync2103 { | 
|   | 
|     @Autowired | 
|     private Fzzy61SyncDepotRep fzzy61SyncDepotRep; | 
|     @Autowired | 
|     private Fzzy61SyncDepotConfRep fzzy61SyncDepotConfRep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|     @Autowired | 
|     private ApiConfsRep apiConfsRep; | 
|     @Autowired | 
|     private ApiInfoDataRep apiInfoDataRep; | 
|   | 
|   | 
|     /** | 
|      * 同步并封装保存温湿度检测数据 | 
|      * | 
|      * @param kqdm | 
|      * @param deptId 系统对应库区编码 | 
|      * @param start  起始时间 | 
|      * @param end    截止时间 | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|   | 
|         log.info("-------------1302接口数据开始同步------------------"); | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(Constant.API_CODE_1302); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             //由于depotConf表中没有库区编码,先查询仓库表 | 
|             List<Fz61Depot> list = fzzy61SyncDepotRep.listDepotList(deptId); | 
|   | 
|             if (null == list || list.isEmpty()) { | 
|                 log.info("2103---粮情设备配置同步数据:没有查询到仓库信息"); | 
|                 return; | 
|             } | 
|             List<ApiConfs> apiConf = apiConfsRep.getDataByKqdm(kqdm); | 
|             String bjw = ""; | 
|             if (null != apiConf && apiConf.size() > 0) { | 
|                 bjw = apiConf.get(0).getUserName(); | 
|             } | 
|   | 
|             SH2023Api2103 sh2023Api2103; | 
|             Api1105 api1105; | 
|             List<Fz61DepotConf> depotConfList; | 
|             Fz61DepotConf depotConf; | 
|   | 
|             List<ApiInfoData> apiInfoDataList; | 
|             SH2023Api2103Item sh2023Api2103Item; | 
|             List<SH2023Api2103Item> listItem; | 
|             for (Fz61Depot fz61Depot : list) { | 
|                 //根据仓库编码获取配置信息 | 
|                 depotConfList = fzzy61SyncDepotConfRep.findDataByDepotId(fz61Depot.getId()); | 
|                 if (null == depotConfList || depotConfList.isEmpty()) { | 
|                     continue; | 
|                 } | 
|                 //获取货位信息 | 
|                 api1105 = commonService.getApi1105Cache(fz61Depot.getId()); | 
|                 if (null == api1105) { | 
|                     continue; | 
|                 } | 
|   | 
|                 sh2023Api2103 = new SH2023Api2103(); | 
|                 sh2023Api2103.setHwdm(api1105.getHwdm()); | 
|                 depotConf = depotConfList.get(0); | 
|                 String[] strs = depotConf.getCableRule().split("-"); | 
|   | 
|                 sh2023Api2103.setDlcs(strs[0]); | 
|                 sh2023Api2103.setDlhs(strs[1]); | 
|                 sh2023Api2103.setDlls(strs[2]); | 
|   | 
|                 //判断是否有层行转换 | 
|                 if(null != depotConf.getStartConvert() && !"default".equals(depotConf.getStartConvert())){ | 
|                     sh2023Api2103.setDlcs(strs[1]); | 
|                     sh2023Api2103.setDlhs(strs[0]); | 
|                 } | 
|   | 
|                 // 1-3-5 | 
|                 // 8-8-8 | 
|                 //筒仓规则 | 
|                 sh2023Api2103.setDlqs("0"); | 
|                 if (StringUtils.isNotEmpty(depotConf.getCableCir())) { | 
|                     sh2023Api2103.setDlqs(String.valueOf(strs.length)); | 
|                     sh2023Api2103.setDlhs("0"); | 
|                     sh2023Api2103.setDlls("0"); | 
|   | 
|                     //电缆圈排列详情 | 
|                     listItem = new ArrayList<>(); | 
|                     String[] cableCir = depotConf.getCableCir().split("-"); | 
|                     int num1 = 0;  //起始根 | 
|                     int num2 = 0;  //截止根 | 
|                     for (int i = 0; i < cableCir.length; i++) { | 
|                         sh2023Api2103.setDlcs(cableCir[i]); | 
|   | 
|                         sh2023Api2103Item = new SH2023Api2103Item(); | 
|                         sh2023Api2103Item.setQh(i + 1 + ""); | 
|                         if (i == 0) { | 
|                             num1 += 1; | 
|                         } else { | 
|                             num1 = num2 + 1; | 
|                         } | 
|                         num2 += Integer.valueOf(strs[i]); | 
|                         sh2023Api2103Item.setQsdlbh(num1 + ""); | 
|                         sh2023Api2103Item.setJsdlbh(num2 + ""); | 
|                         sh2023Api2103Item.setCs(cableCir[i]); | 
|                         sh2023Api2103Item.setYbj((i + 1) * 4 + ""); | 
|                         sh2023Api2103Item.setRowId(i + ""); | 
|                         listItem.add(sh2023Api2103Item); | 
|                     } | 
|                     sh2023Api2103.setDlqplxq(JSON.toJSONString(listItem)); | 
|                 } | 
|   | 
|                 sh2023Api2103.setScqd("1"); | 
|                 sh2023Api2103.setSczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + ""); | 
|   | 
|                 sh2023Api2103.setZcqd("1"); | 
|                 sh2023Api2103.setZczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + ""); | 
|   | 
|                 sh2023Api2103.setXcqd("1"); | 
|                 sh2023Api2103.setXczd(Integer.valueOf(strs[1]) * Integer.valueOf(strs[2]) + ""); | 
|   | 
|                 sh2023Api2103.setYxfwqsc("1"); | 
|                 sh2023Api2103.setYxfwjsc(sh2023Api2103.getDlcs()); | 
|   | 
|                 sh2023Api2103.setBjw(bjw); | 
|                 sh2023Api2103.setZhgxsj(new Date()); | 
|   | 
|                 //持久化保存,单独存入非国标接口表 | 
|                 ApiInfoData infoData = new ApiInfoData(); | 
|                 infoData.setId(sh2023Api2103.getHwdm()); | 
|                 infoData.setKqdm(kqdm); | 
|                 infoData.setInteType(Constant.API_CATEGORY_13); | 
|                 infoData.setInteId(SH2023Constant.SH_2023_API_CODE_2103); | 
|                 infoData.setUpdateTime(new Date()); | 
|                 infoData.setDataId(sh2023Api2103.getHwdm()); | 
|                 infoData.setRemarks("粮情设备配置信息"); | 
|   | 
|                 //设置操作标志 | 
|                 apiInfoDataList = apiInfoDataRep.getDataByInteAndData(SH2023Constant.SH_2023_API_CODE_2103, infoData.getDataId(),kqdm); | 
|                 if (null == apiInfoDataList || apiInfoDataList.isEmpty()) { | 
|                     infoData.setCzbz(Constant.CZBZ_I); | 
|                     sh2023Api2103.setCzbz(Constant.CZBZ_I); | 
|                 } else { | 
|                     infoData.setCzbz(apiInfoDataList.get(0).getCzbz()); | 
|                     sh2023Api2103.setCzbz(apiInfoDataList.get(0).getCzbz()); | 
|                 } | 
|   | 
|                 infoData.setData(JSON.toJSONString(sh2023Api2103)); | 
|                 apiInfoDataRep.save(infoData); | 
|   | 
|                 log.info("2103---粮情设备配置-同步数据:{}", sh2023Api2103.toString()); | 
|             } | 
|   | 
|         } catch (Exception e) { | 
|             log.error("---同步失败----{}", e); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|   | 
|     } | 
| } |