| package com.fzzy.async.fzzy61.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1202; | 
| import com.fzzy.api.entity.Api1203; | 
| import com.fzzy.api.entity.ApiLog; | 
| import com.fzzy.api.entity.GbCheckItem; | 
| import com.fzzy.api.service.ApiTriggerService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.utils.DateUtil; | 
| import com.fzzy.api.view.repository.Api1202Rep; | 
| import com.fzzy.api.view.repository.Api1203Rep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.api.view.repository.GbCheckItemRep; | 
| import com.fzzy.async.fzzy61.entity.Fz61CheckItem; | 
| import com.fzzy.async.fzzy61.entity.Fz61InoutRecord; | 
| import com.fzzy.async.fzzy61.entity.Fz61InoutRecordItem; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61Sync1202Rep; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61Sync1203Rep; | 
| import com.fzzy.async.fzzy61.repository.Fzzy61SyncInoutRecordItemRep; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.lang.StringUtils; | 
| import org.apache.commons.lang.time.DateFormatUtils; | 
| import org.apache.commons.lang.time.DateUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 粮食入库检验信息 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy61Sync1203 { | 
|   | 
|     /** | 
|      * 入库类型 | 
|      */ | 
|     private final static String INOUT_TYPE_IN = "IN"; | 
|   | 
|     @Autowired | 
|     private Fzzy61Sync1202Rep fzzySync1202Rep; | 
|     @Autowired | 
|     private Fzzy61SyncInoutRecordItemRep fzzy61SyncInoutRecordItemRep; | 
|     @Autowired | 
|     private Fzzy61Sync1203Rep fzzySync1203Rep; | 
|     @Autowired | 
|     private ApiTriggerService apiTriggerService; | 
|     @Autowired | 
|     private Api1202Rep api1202Rep; | 
|     @Autowired | 
|     private Api1203Rep api1203Rep; | 
|     @Autowired | 
|     private GbCheckItemRep gbCheckItemRep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|   | 
|     /** | 
|      * 粮食入库检验信息 | 
|      * | 
|      * @param deptId | 
|      * @param start | 
|      * @param end | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|   | 
|         log.info("-------------1203入库检验接口数据开始同步------------------"); | 
|   | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(Constant.API_CODE_1203); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             //获取粮食入库记录信息 | 
|             List<Fz61InoutRecord> list = fzzySync1202Rep.listInoutRecord(deptId, INOUT_TYPE_IN, start, end); | 
|   | 
|             if (null == list || list.isEmpty()) { | 
|                 log.info("-------------没有获取到粮食入库信息------------------"); | 
|                 return; | 
|             } | 
|   | 
|             Api1203 apiData; | 
|             List<Fz61CheckItem> fz61CheckItems; | 
|             List<GbCheckItem> gbCheckList; | 
|             String jyxm; | 
|             String jyz; | 
|             String zkj; | 
|             String zkl; | 
|             List<Api1203> api1203List; | 
|             List<Api1202> api1102List; | 
|             List<Fz61InoutRecordItem> listInoutRecordItem; | 
|             List<String> listIds; | 
|             for (Fz61InoutRecord sysData : list) { | 
|                 listIds = new ArrayList<>(); | 
|                 //判断是否为船运 | 
|                 if (StringUtils.isNotEmpty(sysData.getTransType()) && sysData.getTransType().equals("3")) { | 
|                     listInoutRecordItem = fzzy61SyncInoutRecordItemRep.findDataByRecordId(sysData.getId()); | 
|                     if (null != listInoutRecordItem && listInoutRecordItem.size() > 0) { | 
|                         int idNum = Integer.valueOf(sysData.getId().substring(12)) * 100 + 10001; | 
|   | 
|                         for (Fz61InoutRecordItem fz61InoutRecordItem : listInoutRecordItem) { | 
|                             if ("DEL".equals(fz61InoutRecordItem.getRecordStatus())) { | 
|                                 continue; | 
|                             } | 
|                             listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4, 10) + String.valueOf(idNum).substring(1)); | 
|                             idNum++; | 
|                         } | 
|                     } else { | 
|                         listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4)); | 
|                     } | 
|                 } else { | 
|                     listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4)); | 
|                 } | 
|   | 
|                 //获取入库质检信息 | 
|                 fz61CheckItems = fzzySync1203Rep.listInoutCheckItem(sysData.getCheckId(), deptId.substring(0, 4)); | 
|                 if (null == fz61CheckItems || fz61CheckItems.isEmpty()) { | 
|                     log.info("-------------没有获取到当前入库质检信息--------------"); | 
|                     continue; | 
|                 } | 
|   | 
|                 for (String listId : listIds) { | 
|                     //查询粮食入库信息,若为空则不进行同步上传 | 
|                     api1102List = api1202Rep.getDataById(listId); | 
|                     if (null == api1102List || api1102List.isEmpty()) { | 
|                         continue; | 
|                     } | 
|   | 
|                     apiData = new Api1203(); | 
|   | 
|                     apiData.setRkjydh(api1102List.get(0).getRkywdh()); | 
|                     //货位代码 | 
|                     apiData.setHwdm(api1102List.get(0).getHwdm()); | 
|                     apiData.setRkywdh(api1102List.get(0).getRkywdh()); | 
|                     if (null == sysData.getFullWeightTime()) { | 
|                         sysData.setFullWeightTime(DateUtils.addMinutes(sysData.getRegisterTime(), 5)); | 
|                     } | 
|   | 
|                     //判断业务时间与单据号是否匹配,若不匹配,则更改业务时间为单据号所在的时间 | 
|                     String time = apiData.getRkjydh().substring(2, 8); | 
|                     if (sysData.getCheckTime() != null) { | 
|                         String isCheckTime = DateFormatUtils.format(sysData.getCheckTime(), "yyMMdd"); | 
|                         if (!isCheckTime.equals(time)) { | 
|                             int difDay = DateUtil.difDay1(sysData.getRegisterTime(), sysData.getCheckTime()); | 
|                             if (difDay == 0) { | 
|                                 apiData.setRkjydh("14" + isCheckTime + "01" + api1102List.get(0).getRkywdh().substring(10)); | 
|                             } else { | 
|                                 apiData.setRkjydh("14" + isCheckTime + String.format("%02d", difDay) + api1102List.get(0).getRkywdh().substring(10)); | 
|                             } | 
|                         } | 
|                     } | 
|   | 
|                     //船运使用入库单据号做质检单号 | 
|                     if (StringUtils.isNotEmpty(sysData.getTransType()) && sysData.getTransType().equals("3")) { | 
|                         apiData.setRkjydh(api1102List.get(0).getRkywdh()); | 
|                     } | 
|   | 
|                     apiData.setQyrxm(sysData.getCheckUser()); | 
|                     //扦样方式 2-智能随机 | 
|                     apiData.setQyfs("2"); | 
|   | 
|                     //检测项,检测值,增扣价及增扣量 | 
|                     jyxm = ""; | 
|                     jyz = ""; | 
|                     zkj = ""; | 
|                     zkl = ""; | 
|                     for (Fz61CheckItem fz61CheckItem : fz61CheckItems) { | 
|                         gbCheckList = gbCheckItemRep.findByBizCode(fz61CheckItem.getStandardId()); | 
|   | 
|                         if (gbCheckList == null || gbCheckList.isEmpty()) { | 
|                             continue; | 
|                         } | 
|                         if (StringUtils.isEmpty(fz61CheckItem.getValue())) { | 
|                             continue; | 
|                         } | 
|                         jyxm += "," + gbCheckList.get(0).getCode(); | 
|                         jyz += "," + fz61CheckItem.getValue(); | 
|                         zkj += ",0.0"; | 
|                         zkl += ",0.0"; | 
|                     } | 
|                     if (jyxm.length() > 0) { | 
|                         jyxm = jyxm.substring(1); | 
|                     } | 
|                     if (jyz.length() > 0) { | 
|                         jyz = jyz.substring(1); | 
|                     } | 
|                     apiData.setJyxm(jyxm); | 
|                     apiData.setJyz(jyz); | 
|                     apiData.setZkj(StringUtils.isEmpty(zkj) ? "" : zkj.substring(1)); | 
|                     apiData.setZkl(StringUtils.isEmpty(zkl) ? "" : zkl.substring(1)); | 
|                     if ("UNPASS".equals(sysData.getCheckStatus())) { | 
|                         apiData.setJyjg("0"); | 
|                     } else { | 
|                         apiData.setJyjg("1"); | 
|                     } | 
|                     apiData.setJyrxm(sysData.getCheckUser()); | 
|                     if (null == sysData.getCheckTime()) { | 
|                         sysData.setCheckTime(DateUtils.addMinutes(sysData.getFullWeightTime(), -5)); | 
|                     } | 
|                     if (sysData.getCheckTime().after(sysData.getEmptyWeightTime())) { | 
|                         sysData.setCheckTime(DateUtils.addMinutes(sysData.getFullWeightTime(), -5)); | 
|                     } | 
|                     apiData.setJysj(sysData.getCheckTime()); | 
|                     if (null == sysData.getSampleTime()) { | 
|                         sysData.setSampleTime(DateUtils.addMinutes(sysData.getCheckTime(), -1)); | 
|                     } | 
|                     if (sysData.getSampleTime().after(sysData.getCheckTime())) { | 
|                         sysData.setSampleTime(DateUtils.addMinutes(sysData.getCheckTime(), -1)); | 
|                     } | 
|                     apiData.setQysj(sysData.getSampleTime()); | 
|   | 
|                     //粮食品种 | 
|                     String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, sysData.getFoodVariety()); | 
|                     apiData.setLspzdm(mappingCode); | 
|   | 
|                     //保管员复核 | 
|                     apiData.setBgyfh(apiData.getJyjg()); | 
|                     apiData.setSpaqzbsfhg("1"); | 
|   | 
|                     //粮食等级 | 
|                     mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSDJ, sysData.getFoodLevel()); | 
|                     apiData.setLsdd(mappingCode); | 
|   | 
|                     //操作标志及最后更新时间 | 
|                     apiData.setZhgxsj(sysData.getCompleteTime()); | 
|   | 
|                     //业务id、库区编码、同步时间 | 
|                     apiData.setBizId(sysData.getId()); | 
|                     apiData.setKqdm(kqdm); | 
|                     apiData.setSyncTime(new Date()); | 
|   | 
|                     api1203List = api1203Rep.getDataById(apiData.getRkjydh()); | 
|                     if (null == api1203List || api1203List.isEmpty()) { | 
|                         apiData.setCzbz(Constant.CZBZ_I); | 
|                     } else { | 
|                         apiData.setCzbz(api1203List.get(0).getCzbz()); | 
|                     } | 
|   | 
|                     api1203Rep.save(apiData); | 
|                     log.info("1203入库检验---同步数据:{}", apiData.toString()); | 
|                 } | 
|             } | 
|         } catch (Exception e) { | 
|             log.error("---1203入库检验数据同步失败----{}", e.toString()); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
|   | 
|     public static void main(String[] args) { | 
|         //判断业务时间与单据号是否匹配,若不匹配,则更改业务时间为单据号所在的时间 | 
|         String id = "142508200001"; | 
|         String time = id.substring(2, 8); | 
|   | 
|         String isCheckTime = "250821"; | 
|         if (!isCheckTime.equals(time)) { | 
|             int difDay = 2; | 
|             String idd = "14" + isCheckTime + difDay + id.substring(9); | 
|             System.out.println(idd); | 
|         } | 
|   | 
|     } | 
| } |