|  |  |  | 
|---|
|  |  |  | import com.fzzy.api.Constant; | 
|---|
|  |  |  | import com.fzzy.api.data.PushProtocol; | 
|---|
|  |  |  | import com.fzzy.api.entity.*; | 
|---|
|  |  |  | import com.fzzy.api.service.ApiCommonService; | 
|---|
|  |  |  | import com.fzzy.api.service.ApiTriggerService; | 
|---|
|  |  |  | import com.fzzy.api.utils.ContextUtil; | 
|---|
|  |  |  | import com.fzzy.api.view.repository.*; | 
|---|
|  |  |  | import com.fzzy.async.fzzy40.entity.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.fzzy.async.fzzy40.repository.Fzzy40SyncDrugLogDtlRep; | 
|---|
|  |  |  | import com.fzzy.async.fzzy40.repository.Fzzy40SyncDrugLogPeopleRep; | 
|---|
|  |  |  | import com.fzzy.async.fzzy40.repository.Fzzy40SyncDrugLogWayRep; | 
|---|
|  |  |  | import com.fzzy.otherview.gd2022.dto.GdApi1023; | 
|---|
|  |  |  | import com.fzzy.otherview.gd2022.dto.GdApi1023Dtl; | 
|---|
|  |  |  | import com.fzzy.otherview.gd2022.dto.GdApi1023People; | 
|---|
|  |  |  | import com.fzzy.otherview.gd2022.dto.GdApi1023Way; | 
|---|
|  |  |  | import com.fzzy.push.gd2022.dto.Gd2022Api1023; | 
|---|
|  |  |  | import com.fzzy.push.gd2022.dto.Gd2022Api1023Dtl; | 
|---|
|  |  |  | import com.fzzy.push.gd2022.dto.Gd2022Api1023People; | 
|---|
|  |  |  | import com.fzzy.push.gd2022.dto.Gd2022Api1023Way; | 
|---|
|  |  |  | import com.fzzy.push.gd2022.ApiCodeConstant; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang.time.DateFormatUtils; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class Fzzy40Sync1023 { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private Api1101Rep api1101Rep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private Api1102Rep api1102Rep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private Api1105Rep api1105Rep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private Fzzy40Sync1023Rep fzzy40Sync1023Rep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private Fzzy40SyncDrugLogPeopleRep drugLogPeopleRep; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogRep apiLogRep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiCommonService commonService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiInfoDataRep apiInfoDataRep; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiTriggerService apiTriggerService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param end | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|---|
|  |  |  | log.info("-------------1023接口设备信息开始同步------------------"); | 
|---|
|  |  |  | log.info("-------------1023接口熏蒸备案信息开始同步------------------"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //同步数据,只记录失败的信息 | 
|---|
|  |  |  | ApiLog apiLog = new ApiLog(); | 
|---|
|  |  |  | apiLog.setType(ApiLog.TYPE_SYNC); | 
|---|
|  |  |  | apiLog.setKqdm(deptId); | 
|---|
|  |  |  | apiLog.setUploadTime(new Date()); | 
|---|
|  |  |  | apiLog.setInteId(ApiCodeConstant.API_1023); | 
|---|
|  |  |  | apiLog.setInteId(ApiCodeConstant.API_9201); | 
|---|
|  |  |  | apiLog.setStatus(99); | 
|---|
|  |  |  | apiLog.setId(ContextUtil.getUUID()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<Fz40DrugLogApply> list = fzzy40Sync1023Rep.listDrugLogApply(deptId); | 
|---|
|  |  |  | List<Fz40DrugLogApply> list = fzzy40Sync1023Rep.listDrugLogApply(deptId, start, end); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null == list || list.isEmpty()) { | 
|---|
|  |  |  | log.info("-------------没有获取到熏蒸备案信息------------------"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<GdApi1023Dtl> dtlList; | 
|---|
|  |  |  | List<GdApi1023Way> wayList; | 
|---|
|  |  |  | List<GdApi1023People> peopleList; | 
|---|
|  |  |  | List<Gd2022Api1023Dtl> dtlList; | 
|---|
|  |  |  | List<Gd2022Api1023Way> wayList; | 
|---|
|  |  |  | List<Gd2022Api1023People> peopleList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GdApi1023 gdApi1023; | 
|---|
|  |  |  | GdApi1023Dtl gdApi1023Dtl; | 
|---|
|  |  |  | GdApi1023Way gdApi1023Way; | 
|---|
|  |  |  | GdApi1023People gdApi1023People; | 
|---|
|  |  |  | Gd2022Api1023 GD2022Api1023; | 
|---|
|  |  |  | Gd2022Api1023Dtl gd2022Api1023Dtl; | 
|---|
|  |  |  | Gd2022Api1023Way gd2022Api1023Way; | 
|---|
|  |  |  | Gd2022Api1023People gd2022Api1023People; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ApiInfoData> apiInfoList; | 
|---|
|  |  |  | ApiInfoData infoData; | 
|---|
|  |  |  | for (Fz40DrugLogApply data : list) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | gdApi1023 = new GdApi1023(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data, gdApi1023); | 
|---|
|  |  |  | gdApi1023.setXzbm(data.getXzbm().substring(8)); | 
|---|
|  |  |  | gdApi1023.setKqdm(kqdm); | 
|---|
|  |  |  | gdApi1023.setDwdm(kqdm.substring(0, 18)); | 
|---|
|  |  |  | gdApi1023.setYjmc(data.getDrugName()); | 
|---|
|  |  |  | gdApi1023.setYjlx(data.getDrugType()); | 
|---|
|  |  |  | gdApi1023.setLqrq(data.getLqsj()); | 
|---|
|  |  |  | gdApi1023.setZhgxsj(data.getUpdateTime()); | 
|---|
|  |  |  | GD2022Api1023 = new Gd2022Api1023(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data, GD2022Api1023); | 
|---|
|  |  |  | GD2022Api1023.setXzbm(data.getXzbm().substring(8)); | 
|---|
|  |  |  | GD2022Api1023.setKqdm(kqdm); | 
|---|
|  |  |  | List<Api1102> api1102List = api1102Rep.findPushData(kqdm); | 
|---|
|  |  |  | if (null != api1102List && api1102List.size() > 0) { | 
|---|
|  |  |  | GD2022Api1023.setKqmc(api1102List.get(0).getKqmc()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GD2022Api1023.setDwdm(kqdm.substring(0, 18)); | 
|---|
|  |  |  | List<Api1101> api1101List = api1101Rep.findPushData(kqdm); | 
|---|
|  |  |  | if (null != api1101List && api1101List.size() > 0) { | 
|---|
|  |  |  | GD2022Api1023.setDwmc(api1101List.get(0).getDwmc()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | GD2022Api1023.setYjmc(data.getDrugName()); | 
|---|
|  |  |  | GD2022Api1023.setYjlx(data.getDrugType()); | 
|---|
|  |  |  | GD2022Api1023.setLqrq(data.getLqsj()); | 
|---|
|  |  |  | GD2022Api1023.setZhgxsj(data.getUpdateTime()); | 
|---|
|  |  |  | if (data.getLqr().contains("、")) { | 
|---|
|  |  |  | GD2022Api1023.setLqr(data.getLqr().replace('、', '|')); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //储粮粮情明细表 | 
|---|
|  |  |  | List<Fz40DrugLogDtl> dtls = drugLogDtlRep.listDrugLogDtl(data.getXzbm()); | 
|---|
|  |  |  | if (null != dtls && dtls.size() > 0) { | 
|---|
|  |  |  | dtlList = new ArrayList<>(); | 
|---|
|  |  |  | for (Fz40DrugLogDtl dtl : dtls) { | 
|---|
|  |  |  | gdApi1023Dtl = new GdApi1023Dtl(); | 
|---|
|  |  |  | BeanUtils.copyProperties(dtl, gdApi1023Dtl); | 
|---|
|  |  |  | gdApi1023Dtl.setCfdm(dtl.getDepotId()); | 
|---|
|  |  |  | gdApi1023Dtl.setLspzdm(dtl.getFoodVariety()); | 
|---|
|  |  |  | gdApi1023Dtl.setLsxzdm(dtl.getFoodType()); | 
|---|
|  |  |  | gdApi1023Dtl.setLsdjdm(dtl.getFoodLevel()); | 
|---|
|  |  |  | gdApi1023Dtl.setLssl(dtl.getNumber()); | 
|---|
|  |  |  | gdApi1023Dtl.setSf(dtl.getPerWet()); | 
|---|
|  |  |  | gdApi1023Dtl.setZz(dtl.getPerImpurity()); | 
|---|
|  |  |  | dtlList.add(gdApi1023Dtl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | gdApi1023.setDtls(dtlList); | 
|---|
|  |  |  | Api1105 api1105 = commonService.getApi1105Cache(data.getDepotId()); | 
|---|
|  |  |  | gd2022Api1023Dtl = new Gd2022Api1023Dtl(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data, gd2022Api1023Dtl); | 
|---|
|  |  |  | if (null != api1105) { | 
|---|
|  |  |  | gd2022Api1023Dtl.setCfmc(api1105.getHwmc()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setCfdm(api1105.getHwdm().substring(0, 25)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Fz40DrugLogWay> ways = drugLogWayRep.listDrugLogWay(data.getXzbm()); | 
|---|
|  |  |  | if (null != ways && ways.size() > 0) { | 
|---|
|  |  |  | wayList = new ArrayList<>(); | 
|---|
|  |  |  | for (Fz40DrugLogWay way : ways) { | 
|---|
|  |  |  | gdApi1023Way = new GdApi1023Way(); | 
|---|
|  |  |  | BeanUtils.copyProperties(way, gdApi1023Way); | 
|---|
|  |  |  | wayList.add(gdApi1023Way); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | gdApi1023.setWays(wayList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //粮食品种 | 
|---|
|  |  |  | String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, data.getFoodVariety()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setLspzdm(mappingCode); | 
|---|
|  |  |  | gd2022Api1023Dtl.setLsxzdm(data.getFoodType()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setLsdjdm(data.getFoodLevel()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setLssl(data.getNumber()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setSf(data.getPerWet()); | 
|---|
|  |  |  | gd2022Api1023Dtl.setZz(data.getPerImpurity()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dtlList = new ArrayList<>(); | 
|---|
|  |  |  | dtlList.add(gd2022Api1023Dtl); | 
|---|
|  |  |  | GD2022Api1023.setDtls(dtlList); | 
|---|
|  |  |  | //                if (null != dtls && dtls.size() > 0) { | 
|---|
|  |  |  | //                    dtlList = new ArrayList<>(); | 
|---|
|  |  |  | //                    for (Fz40DrugLogDtl dtl : dtls) { | 
|---|
|  |  |  | //                        gdApi1023Dtl = new GdApi1023Dtl(); | 
|---|
|  |  |  | //                        BeanUtils.copyProperties(dtl, gdApi1023Dtl); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setCfdm(dtl.getDepotId()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setLspzdm(dtl.getFoodVariety()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setLsxzdm(dtl.getFoodType()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setLsdjdm(dtl.getFoodLevel()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setLssl(dtl.getNumber()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setSf(dtl.getPerWet()); | 
|---|
|  |  |  | //                        gdApi1023Dtl.setZz(dtl.getPerImpurity()); | 
|---|
|  |  |  | //                        dtlList.add(gdApi1023Dtl); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    gdApi1023.setDtls(dtlList); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | gd2022Api1023Way = new Gd2022Api1023Way(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data, gd2022Api1023Way); | 
|---|
|  |  |  | wayList = new ArrayList<>(); | 
|---|
|  |  |  | wayList.add(gd2022Api1023Way); | 
|---|
|  |  |  | GD2022Api1023.setWays(wayList); | 
|---|
|  |  |  | //                List<Fz40DrugLogWay> ways = drugLogWayRep.listDrugLogWay(data.getXzbm()); | 
|---|
|  |  |  | //                if (null != ways && ways.size() > 0) { | 
|---|
|  |  |  | //                    wayList = new ArrayList<>(); | 
|---|
|  |  |  | //                    for (Fz40DrugLogWay way : ways) { | 
|---|
|  |  |  | //                        gdApi1023Way = new GdApi1023Way(); | 
|---|
|  |  |  | //                        BeanUtils.copyProperties(way, gdApi1023Way); | 
|---|
|  |  |  | //                        wayList.add(gdApi1023Way); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    gdApi1023.setWays(wayList); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Fz40DrugLogPeople> peoples = drugLogPeopleRep.listDrugLogPeople(data.getXzbm()); | 
|---|
|  |  |  | if (null != peoples && peoples.size() > 0) { | 
|---|
|  |  |  | peopleList = new ArrayList<>(); | 
|---|
|  |  |  | for (Fz40DrugLogPeople people : peoples) { | 
|---|
|  |  |  | gdApi1023People = new GdApi1023People(); | 
|---|
|  |  |  | BeanUtils.copyProperties(people, gdApi1023People); | 
|---|
|  |  |  | gdApi1023People.setXm(people.getMx()); | 
|---|
|  |  |  | peopleList.add(gdApi1023People); | 
|---|
|  |  |  | gd2022Api1023People = new Gd2022Api1023People(); | 
|---|
|  |  |  | BeanUtils.copyProperties(people, gd2022Api1023People); | 
|---|
|  |  |  | gd2022Api1023People.setXm(people.getMx()); | 
|---|
|  |  |  | if (StringUtils.isEmpty(people.getZyzg())) { | 
|---|
|  |  |  | gd2022Api1023People.setZyzg("中级"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | peopleList.add(gd2022Api1023People); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | gdApi1023.setPeoples(peopleList); | 
|---|
|  |  |  | GD2022Api1023.setPeoples(peopleList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //持久化保存,单独存入非国标接口表 | 
|---|
|  |  |  | infoData = new ApiInfoData(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | infoData.setKqdm(kqdm); | 
|---|
|  |  |  | infoData.setInteType(Constant.API_CATEGORY_13); | 
|---|
|  |  |  | infoData.setInteId(ApiCodeConstant.API_1023); | 
|---|
|  |  |  | infoData.setBizType(PushProtocol.SB_GD_2022.getCode()); | 
|---|
|  |  |  | infoData.setInteId(ApiCodeConstant.API_9201); | 
|---|
|  |  |  | infoData.setBizType(PushProtocol.SB_GD_2023.getCode()); | 
|---|
|  |  |  | infoData.setUpdateTime(new Date()); | 
|---|
|  |  |  | infoData.setDataId(data.getXzbm()); | 
|---|
|  |  |  | apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_1023, data.getXzbm(), kqdm); | 
|---|
|  |  |  | apiInfoList = apiInfoDataRep.getDataByInteAndData(ApiCodeConstant.API_9201, data.getXzbm(), kqdm); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null == apiInfoList || apiInfoList.isEmpty()) { | 
|---|
|  |  |  | gdApi1023.setCzbz(Constant.CZBZ_I); | 
|---|
|  |  |  | GD2022Api1023.setCzbz(Constant.CZBZ_I); | 
|---|
|  |  |  | infoData.setCzbz(Constant.CZBZ_I); | 
|---|
|  |  |  | infoData.setId(ContextUtil.getUUID()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | gdApi1023.setCzbz(apiInfoList.get(0).getCzbz()); | 
|---|
|  |  |  | GD2022Api1023.setCzbz(apiInfoList.get(0).getCzbz()); | 
|---|
|  |  |  | infoData.setCzbz(apiInfoList.get(0).getCzbz()); | 
|---|
|  |  |  | infoData.setId(apiInfoList.get(0).getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | infoData.setData(JSON.toJSONString(gdApi1023)); | 
|---|
|  |  |  | infoData.setData(JSON.toJSONString(GD2022Api1023)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //保存数据 | 
|---|
|  |  |  | apiInfoDataRep.save(infoData); | 
|---|
|  |  |  | log.info("1023---同步数据:{}", gdApi1023.toString()); | 
|---|
|  |  |  | log.info("1023---同步数据:{}", GD2022Api1023.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("---设备信息同步执行失败----{}", e.toString()); | 
|---|
|  |  |  | apiLog.setResult("设备信息同步执行失败:" + e.getMessage()); | 
|---|
|  |  |  | log.error("---熏蒸备案同步执行失败----{}", e.toString()); | 
|---|
|  |  |  | apiLog.setResult("熏蒸备案信息同步执行失败:" + e.getMessage()); | 
|---|
|  |  |  | apiLogRep.save(apiLog); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|