| package com.fzzy.async.fzzy35.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.*; | 
| import com.fzzy.api.service.ApiCommonService; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.view.repository.Api1310Rep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.api.view.repository.GbCheckItemRep; | 
| import com.fzzy.async.fzzy35.entity.Fz35CheckItem; | 
| import com.fzzy.async.fzzy35.entity.Fz35Quality; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35Sync1203Rep; | 
| import com.fzzy.async.fzzy35.repository.Fzzy35Sync1310Rep; | 
| 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.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 质检同步 | 
|  * | 
|  * @author czt | 
|  * @date 2023-05-14 19:51 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy35Sync1310 { | 
|   | 
|     @Autowired | 
|     private Fzzy35Sync1310Rep fzzySync1310Rep; | 
|     @Autowired | 
|     private Fzzy35Sync1203Rep fzzySync1203Rep; | 
|     @Autowired | 
|     private GbCheckItemRep gbCheckItemRep; | 
|     @Autowired | 
|     private ApiCommonService commonService; | 
|     @Autowired | 
|     private Api1310Rep api1310Rep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|   | 
|     /** | 
|      * 同步并封装保存质检数据 | 
|      * | 
|      * @param deptId 系统对应库区编码 | 
|      * @param start  起始时间 | 
|      * @param end    截止时间 | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|         log.info("-------------1310接口数据开始同步------------------"); | 
|         //同步数据,只记录失败的信息 | 
|         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<Fz35Quality> list = fzzySync1310Rep.findDateByTime(start, end); | 
|             if (null == list || list.isEmpty()) { | 
|                 return; | 
|             } | 
|   | 
|             Api1310 api1310; | 
|             Api1105 api1105; | 
|             List<Fz35CheckItem> fz35CheckItems; | 
|             List<GbCheckItem> gbCheckList; | 
|             StringBuilder jyxm; | 
|             StringBuilder jyxmz; | 
|             List<Api1310> api1310List; | 
|             int index = 10001; | 
|             for (Fz35Quality fz35Quality : list) { | 
|                 api1105 = commonService.getApi1105Cache(fz35Quality.getDepotId()); | 
|                 if (null == api1105) { | 
|                     continue; | 
|                 } | 
|                 api1310 = new Api1310(); | 
|                 api1310.setZjbgdh(fz35Quality.getType() + DateFormatUtils.format(fz35Quality.getTime(), "yyyyMMdd") + String.valueOf(index).substring(1)); | 
|                 api1310.setHwdm(api1105.getHwdm()); | 
|                 api1310.setKqdm(kqdm); | 
|                 api1310.setLspzdm(fz35Quality.getFoodVariety()); | 
|                 api1310.setLsdjdm(fz35Quality.getFoodLevel()); | 
|                 api1310.setRkrq(DateUtils.addDays(fz35Quality.getTime(), -30)); | 
|                 api1310.setJylb(fz35Quality.getType()); | 
|                 api1310.setJysj(fz35Quality.getTime()); | 
|                 api1310.setJydw(fz35Quality.getUser()); | 
|                 api1310.setJyr(fz35Quality.getUser()); | 
|                 api1310.setJyyj(fz35Quality.getStandard()); | 
|                 api1310.setZblb("2"); | 
|                 //检测项,检测值 | 
|                 jyxm = new StringBuilder(); | 
|                 jyxmz = new StringBuilder(); | 
|                 fz35CheckItems = fzzySync1203Rep.listInoutCheckItem(fz35Quality.getId(), deptId.substring(0, 4)); | 
|                 if (null != fz35CheckItems && fz35CheckItems.size() > 0) { | 
|   | 
|                     for (Fz35CheckItem fz35CheckItem : fz35CheckItems) { | 
|                         if(StringUtils.isEmpty(fz35CheckItem.getValue())){ | 
|                             continue; | 
|                         } | 
|                         gbCheckList = gbCheckItemRep.findByBizCode(fz35CheckItem.getStandardId()); | 
|                         if (gbCheckList == null || gbCheckList.isEmpty()) { | 
|                             continue; | 
|                         } | 
|                         jyxm.append(",").append(gbCheckList.get(0).getCode()); | 
|                         jyxmz.append(",").append(fz35CheckItem.getValue()); | 
|                     } | 
|                 } | 
|                 api1310.setJyxm(jyxm.toString().substring(1)); | 
|                 api1310.setJyxmz(jyxmz.toString().substring(1)); | 
|   | 
|                 api1310.setZbjgpd(fz35Quality.getResult()); | 
|                 api1310.setQfrq(fz35Quality.getTime()); | 
|                 api1310.setBgcjsj(fz35Quality.getTime()); | 
|                 api1310.setShrxm(fz35Quality.getCheckUser()); | 
|                 api1310.setQysj(fz35Quality.getCheckTime()); | 
|                 api1310.setQyqy(fz35Quality.getCheckArea()); | 
|                 api1310.setQyrxm(fz35Quality.getCheckUser()); | 
|                 api1310.setJdrxm(fz35Quality.getCheckUser()); | 
|   | 
|                 api1310.setYpsl(fz35Quality.getCheckNum()==null?0.0:(fz35Quality.getCheckNum())); | 
|                 api1310.setDbsl(StringUtils.isEmpty(fz35Quality.getCheckRepresent())? 0.0:Double.valueOf(fz35Quality.getCheckRepresent())); | 
|                 api1310.setYpdj(StringUtils.isEmpty(fz35Quality.getCheckLevel())?"0": fz35Quality.getCheckLevel()); | 
|                 api1310.setSfzcccnx(StringUtils.isEmpty(fz35Quality.getNormalYear())?"0": fz35Quality.getNormalYear()); | 
|                 api1310.setBz(fz35Quality.getRemark()); | 
|                 api1310.setZhgxsj(new Date()); | 
|   | 
|                 api1310List = api1310Rep.getDataByZjbgdh(api1310.getZjbgdh()); | 
|                 if(null == api1310List || api1310List.isEmpty()){ | 
|                     api1310.setCzbz(Constant.CZBZ_I); | 
|                 }else { | 
|                     api1310.setCzbz(api1310List.get(0).getCzbz()); | 
|                 } | 
|   | 
|                 api1310Rep.save(api1310); | 
|                 index ++; | 
|             } | 
|         } catch (Exception e) { | 
|             log.error("---同步失败----{}", e); | 
|             apiLog.setResult("同步失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
|   | 
| } |