| package com.fzzy.async.fzzy61.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1105; | 
| import com.fzzy.api.entity.Api1304; | 
| import com.fzzy.api.entity.ApiLog; | 
| import com.fzzy.api.service.ApiCommonService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.view.repository.Api1304Rep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy61.entity.Fz61Gas; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61Sync1304Rep; | 
| 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 chen | 
|  * @date 2022-09-08 09:51 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy61Sync1304 { | 
|   | 
|     @Autowired | 
|     private Fzzy61Sync1304Rep fzzySync1304Rep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|     @Autowired | 
|     private Api1304Rep api1304Rep; | 
|   | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|   | 
|     /** | 
|      * 同步并封装保存气体检测数据 | 
|      * | 
|      * @param deptId 系统对应库区编码 | 
|      * @param start  起始时间 | 
|      * @param end    截止时间 | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|         log.info("-------------1304气体检测数据接口数据开始同步------------------"); | 
|         //同步数据,只记录失败的信息 | 
|         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<Fz61Gas> list = fzzySync1304Rep.findByReceiveDate(start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Api1304 api1304; | 
|             Api1105 api1105; | 
|             List<Api1304> api1304List; | 
|             for (Fz61Gas fz61Gas : list) { | 
|                 //获取货位信息 | 
|                 api1105 = commonService.getApi1105Cache(fz61Gas.getDepotId()); | 
|                 if (null == api1105) { | 
|                     continue; | 
|                 } | 
|   | 
|                 api1304 = new Api1304(); | 
|                 api1304.setQtndjcdh(api1105.getHwdm() + fz61Gas.getBatchId()); | 
|                 api1304.setJcsj(fz61Gas.getReceiveDate()); | 
|                 api1304.setHwdm(api1105.getHwdm()); | 
|                 api1304.setZylx("5"); | 
|   | 
|                 api1304 = updateGasInfo(api1304, fz61Gas.getPoints()); | 
|   | 
|                 api1304.setZhgxsj(new Date()); | 
|   | 
|                 api1304.setBizId(fz61Gas.getBatchId()); | 
|                 api1304.setKqdm(api1105.getKqdm()); | 
|                 api1304.setSyncTime(new Date()); | 
|                 api1304List = api1304Rep.getDataByQtndjcdh(api1304.getQtndjcdh()); | 
|                 if (null == api1304List || api1304List.isEmpty()) { | 
|                     api1304.setCzbz(Constant.CZBZ_I); | 
|                 } else { | 
|                     api1304.setCzbz(api1304List.get(0).getCzbz()); | 
|                 } | 
|                 api1304Rep.save(api1304); | 
|             } | 
|         } catch (Exception e) { | 
|             log.error("---1304气体检测数据同步失败----{}", e.toString()); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 获取对应气体浓度集合:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2; | 
|      * | 
|      * @param points | 
|      * @return | 
|      */ | 
|     private Api1304 updateGasInfo(Api1304 api1304, String points) { | 
|         String[] attr = points.split(";"); | 
|   | 
|         String[] arrt2; | 
|         String o2 = "", co2 = "", ph3 = "", n2 = ""; | 
|         for (String temp : attr) { | 
|             arrt2 = temp.split(","); | 
|             o2 +=  "," + arrt2[2]; | 
|             co2 += "," + arrt2[1]; | 
|             ph3 += "," + arrt2[3]; | 
|             n2 += "," + arrt2[4]; | 
|         } | 
|   | 
|         if(o2.length() > 0){ | 
|             o2 = o2.substring(1); | 
|         } | 
|         if(co2.length() > 0){ | 
|             co2 = co2.substring(1); | 
|         } | 
|         if(ph3.length() > 0){ | 
|             ph3 = ph3.substring(1); | 
|         } | 
|         if(n2.length() > 0){ | 
|             n2 = n2.substring(1); | 
|         } | 
|         co2 += "|ppm"; | 
|         ph3 += "|ppm"; | 
|         api1304.setYqhlzjh(o2); | 
|         api1304.setEyhthlzjh(co2); | 
|         api1304.setLhqndzjh(ph3); | 
|         api1304.setDqndzjh(n2); | 
|         return api1304; | 
|     } | 
|   | 
| } |