| package com.fzzy.async.fzzy35.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1105; | 
| import com.fzzy.api.entity.Api1303; | 
| import com.fzzy.api.entity.ApiLog; | 
| import com.fzzy.api.service.ApiCommonService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.view.repository.Api1303Rep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy35.entity.Fz35Pest; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35Sync1303Rep; | 
| 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 chen | 
|  * @date 2022-09-08 09:51 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy35Sync1303 { | 
|   | 
|   | 
|     @Autowired | 
|     private Fzzy35Sync1303Rep fzzy35Sync1303Rep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|     @Autowired | 
|     private Api1303Rep api1303Rep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|   | 
|     /** | 
|      * 同步并封装保存虫害检测数据 | 
|      * | 
|      * @param deptId 系统对应库区编码 | 
|      * @param start  起始时间 | 
|      * @param end    截止时间 | 
|      */ | 
|     public void syncData(String deptId, Date start, Date end) { | 
|   | 
|         log.info("-------------1303接口数据开始同步------------------"); | 
|   | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(Constant.API_CODE_1303); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|   | 
|             List<Fz35Pest> list = fzzy35Sync1303Rep.findPestByReceiveDate(start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Date syncTime = new Date(); | 
|             Api1303 api1303; | 
|             Api1105 api1105; | 
|             List<Api1303> api1303List; | 
|             for (Fz35Pest fz35Pest : list) { | 
|                 //获取货位信息 | 
|                 api1105 = commonService.getApi1105Cache(fz35Pest.getDepotId()); | 
|                 if (null == api1105) { | 
|                     continue; | 
|                 } | 
|   | 
|                 api1303 = new Api1303(); | 
|                 api1303.setHcjcdh(api1105.getHwdm() + fz35Pest.getBatchId()); | 
|                 api1303.setJcsj(fz35Pest.getReceiveDate()); | 
|                 api1303.setHwdm(api1105.getHwdm()); | 
|   | 
|                 //检查害虫方法,0-远程、1-人工、2-其他 | 
|                 api1303.setJchcff("0"); | 
|                 //发生部位,坐标填写:x,y,z | 
|                 api1303.setFsbw(null);//非必填字段 | 
|   | 
|                 //害虫种类。多个用#隔开#TODO >> 待优化调整 | 
|                 api1303.setHczl("21212"); | 
|   | 
|                 //虫口密度值集合 | 
|                 String ckmdzjh = this.geeCkmdzjh(fz35Pest.getPestMax(), fz35Pest.getPoints()); | 
|                 api1303.setCkmdzjh(ckmdzjh); | 
|   | 
|                 //虫粮等级判定,531-基本无虫粮、532-一般虫粮、533严重虫粮、534危害虫粮 | 
|                 api1303.setCldjpd("531"); | 
|                 if (fz35Pest.getPestMax() > 5) { | 
|                     api1303.setCldjpd("532"); | 
|                 } | 
|                 if (fz35Pest.getPestMax() > 30) { | 
|                     api1303.setCldjpd("533"); | 
|                 } | 
|   | 
|                 api1303.setZhgxsj(syncTime); | 
|   | 
|                 api1303.setBizId(fz35Pest.getBatchId()); | 
|                 api1303.setKqdm(api1105.getKqdm()); | 
|                 api1303.setSyncTime(syncTime); | 
|                 api1303List = api1303Rep.getDataByHcjcdh(api1303.getHcjcdh()); | 
|                 if(null == api1303List || api1303List.isEmpty()){ | 
|                     api1303.setCzbz(Constant.CZBZ_I); | 
|                 }else { | 
|                     api1303.setCzbz(api1303List.get(0).getCzbz()); | 
|                 } | 
|                 api1303Rep.save(api1303); | 
|             } | 
|   | 
|         } catch (Exception e) { | 
|             log.error("---同步失败----{}", e); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|   | 
|     } | 
|   | 
|     /** | 
|      * 头/kg,指粮食害虫值集合,与 | 
|      * 害虫种类顺序对应,用“|”分 | 
|      * 隔,多个取样点用英文半角“,” | 
|      * 分隔,按照取样点示意图标识顺 | 
|      * 序排列。 | 
|      * | 
|      * @param pestMax | 
|      * @param points | 
|      * @return | 
|      */ | 
|     private String geeCkmdzjh(int pestMax, String points) { | 
|   | 
|         if (StringUtils.isEmpty(points)) return "0"; | 
|   | 
|         String[] attr = points.split(";"); | 
|   | 
|         String result = ""; | 
|         for (String str : attr) { | 
|             result += str.split(",")[1] + ","; | 
|         } | 
|         return result.substring(0, result.length() - 1); | 
|     } | 
|   | 
|   | 
| } |