| package com.fzzy.async.fzzy30.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.fzzy30.entity.Pest; | 
| import com.fzzy.async.fzzy30.repository.FzzySync1303Rep; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.lang.time.DateFormatUtils; | 
| 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 Fzzy30Sync1303 { | 
|   | 
|     @Autowired | 
|     private FzzySync1303Rep fzzySync1303Rep; | 
|     @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<Pest> list = fzzySync1303Rep.findByReceiveDate(start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Date syncTime = new Date(); | 
|             Api1303 api1303; | 
|             Api1105 api1105; | 
|             int index = 10001; | 
|             for (Pest pest : list) { | 
|                 //获取货位信息 | 
|                 api1105 = commonService.getApi1105Cache(pest.getDepotId()); | 
|                 if (null == api1105) { | 
|                     continue; | 
|                 } | 
|   | 
| //            //TODO 匹配库区代码 | 
| //            if(!deptId.equals(api1105.getKqdm())){ | 
| //                continue; | 
| //            } | 
|   | 
|                 api1303 = new Api1303(); | 
|                 api1303.setHcjcdh(api1105.getHwdm() + DateFormatUtils.format(pest.getReceiveDate(), "yyyyMMdd") + String.valueOf(index).substring(1)); | 
|                 api1303.setJcsj(pest.getReceiveDate()); | 
|                 api1303.setHwdm(api1105.getHwdm()); | 
|   | 
|                 //TODO 待调整格式 | 
|                 //检查害虫方法,0-远程、1-人工、2-其他 | 
|                 api1303.setJchcff("2"); | 
|                 //发生部位,坐标填写:x,y,z | 
|                 api1303.setFsbw("2,3,4"); | 
|                 //害虫种类。多个用#隔开 | 
|                 api1303.setHczl(""); | 
|                 //虫口密度值集合 | 
|                 api1303.setCkmdzjh(""); | 
|                 //虫粮等级判定,531-基本无虫粮、532-一般虫粮、533严重虫粮、534危害虫粮 | 
|                 api1303.setCldjpd(""); | 
|   | 
|                 api1303.setCzbz(Constant.CZBZ_I); | 
|                 api1303.setZhgxsj(syncTime); | 
|   | 
|                 api1303.setBizId(pest.getBatchId()); | 
|                 api1303.setKqdm(api1105.getKqdm()); | 
|                 api1303.setSyncTime(syncTime); | 
|                 api1303Rep.save(api1303); | 
|                 index++; | 
|             } | 
|   | 
|         } catch (Exception e) { | 
|             log.error("---同步失败----{}", e); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|   | 
|     } | 
|   | 
|   | 
| } |