package com.glxp.api.task; import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.glxp.api.constant.AsyncDiDlHelper; import com.glxp.api.entity.basic.ProductInfoEntity; import com.glxp.api.entity.basic.UdiProductEntity; import com.glxp.api.service.basic.ProductInfoService; import com.glxp.api.service.basic.UdiProductService; import com.glxp.api.util.CustomUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; @Service public class AsyncDiDlService { @Value("${UDI_SERVER_URL}") private String udiUrl; @Resource ProductInfoService productInfoService; @Resource AsyncDiDlHelper asyncDiDlHelper; @Resource UdiProductService udiProductService; private static final Logger logger = LoggerFactory.getLogger(AsyncDiDlService.class); @Async public void asyncDiByTime(String updateTime) { int page = 1; int limit = 200; while (true) { logger.info("更新时间:" + updateTime + "----" + page + "----" + limit); List productInfoEntityList = asyncDiDlHelper.dlByTime(udiUrl, page, limit, updateTime); if (productInfoEntityList != null && productInfoEntityList.size() > 0) { try { for (ProductInfoEntity productInfoEntity : productInfoEntityList) { UdiProductEntity udiProductEntity = udiProductService.findByNameCode(productInfoEntity.getNameCode()); //更新物资字典基础信息 if (StrUtil.isNotEmpty(productInfoEntity.getPackRatio())) udiProductEntity.setPackRatio(productInfoEntity.getPackRatio()); if (StrUtil.isNotEmpty(productInfoEntity.getPackLevel())) udiProductEntity.setPackLevel(productInfoEntity.getPackLevel()); if (productInfoEntity.getBhxjsl() != null) udiProductEntity.setBhxjsl(productInfoEntity.getBhxjsl()); if (productInfoEntity.getBhzxxsbzsl() != null) udiProductEntity.setBhzxxsbzsl(productInfoEntity.getBhzxxsbzsl()); if (productInfoEntity.getZxxsbzbhsydysl() != null) udiProductEntity.setZxxsbzbhsydysl(productInfoEntity.getZxxsbzbhsydysl()); if (StrUtil.isNotEmpty(productInfoEntity.getBhxjcpbm())) udiProductEntity.setBhxjcpbm(productInfoEntity.getBhxjcpbm()); if (StrUtil.isNotEmpty(productInfoEntity.getSjcpbm())) udiProductEntity.setSjcpbm(productInfoEntity.getSjcpbm()); if (StrUtil.isNotEmpty(productInfoEntity.getBzcj())) udiProductEntity.setBzcj(productInfoEntity.getBzcj()); if (StrUtil.isNotEmpty(productInfoEntity.getCpmctymc())) udiProductEntity.setCpmctymc(productInfoEntity.getCpmctymc()); if (StrUtil.isNotEmpty(productInfoEntity.getCplb())) udiProductEntity.setCplb(productInfoEntity.getCplb()); if (StrUtil.isNotEmpty(productInfoEntity.getFlbm())) udiProductEntity.setFlbm(productInfoEntity.getFlbm()); if (StrUtil.isNotEmpty(productInfoEntity.getGgxh())) udiProductEntity.setGgxh(productInfoEntity.getGgxh()); if (StrUtil.isNotEmpty(productInfoEntity.getQxlb())) udiProductEntity.setQxlb(productInfoEntity.getQxlb()); if (StrUtil.isNotEmpty(productInfoEntity.getTyshxydm())) udiProductEntity.setTyshxydm(productInfoEntity.getTyshxydm()); if (StrUtil.isNotEmpty(productInfoEntity.getYlqxzcrbarmc())) udiProductEntity.setYlqxzcrbarmc(productInfoEntity.getYlqxzcrbarmc()); if (StrUtil.isNotEmpty(productInfoEntity.getYlqxzcrbarywmc())) udiProductEntity.setYlqxzcrbarywmc(productInfoEntity.getYlqxzcrbarywmc()); if (StrUtil.isNotEmpty(productInfoEntity.getSydycpbs())) udiProductEntity.setSydycpbs(productInfoEntity.getSydycpbs()); if (productInfoEntity.getVersionNumber() != null) udiProductEntity.setVersionNumber(productInfoEntity.getVersionNumber()); if (StrUtil.isNotEmpty(productInfoEntity.getScbssfbhph())) { udiProductEntity.setScbssfbhph(productInfoEntity.getScbssfbhph()); if (productInfoEntity.getScbssfbhph().equals("是")) { udiProductEntity.setAllowNoBatch(false); } else { udiProductEntity.setAllowNoBatch(true); } } if (StrUtil.isNotEmpty(productInfoEntity.getScbssfbhscrq())) { udiProductEntity.setScbssfbhscrq(productInfoEntity.getScbssfbhscrq()); if (productInfoEntity.getScbssfbhscrq().equals("是")) { udiProductEntity.setAllowNoProduct(false); } else { udiProductEntity.setAllowNoProduct(true); } } if (StrUtil.isNotEmpty(productInfoEntity.getScbssfbhsxrq())) { udiProductEntity.setScbssfbhsxrq(productInfoEntity.getScbssfbhsxrq()); if (productInfoEntity.getScbssfbhsxrq().equals("是")) { udiProductEntity.setAllowNoExpire(false); } else { udiProductEntity.setAllowNoExpire(true); } } if (StrUtil.isNotEmpty(productInfoEntity.getScbssfbhxlh())) { udiProductEntity.setScbssfbhxlh(productInfoEntity.getScbssfbhxlh()); if (productInfoEntity.getScbssfbhxlh().equals("是")) { udiProductEntity.setAllowNoSerial(false); } else { udiProductEntity.setAllowNoSerial(true); } } if (StrUtil.isNotEmpty(productInfoEntity.getYbbm())) udiProductEntity.setYbbm(productInfoEntity.getYbbm()); if (StrUtil.isNotEmpty(productInfoEntity.getCplx())) udiProductEntity.setCplx(productInfoEntity.getCplx()); if (StrUtil.isNotEmpty(productInfoEntity.getHchzsb())) udiProductEntity.setHchzsb(productInfoEntity.getHchzsb()); if (StrUtil.isNotEmpty(productInfoEntity.getSfwblztlcp())) udiProductEntity.setSfwblztlcp(productInfoEntity.getSfwblztlcp()); if (StrUtil.isNotEmpty(productInfoEntity.getCgzmraqxgxx())) udiProductEntity.setCgzmraqxgxx(productInfoEntity.getCgzmraqxgxx()); if (StrUtil.isNotEmpty(productInfoEntity.getSfbjwycxsy())) udiProductEntity.setSfbjwycxsy(productInfoEntity.getSfbjwycxsy()); if (StrUtil.isNotEmpty(productInfoEntity.getZdcfsycs())) udiProductEntity.setZdcfsycs(productInfoEntity.getZdcfsycs()); if (StrUtil.isNotEmpty(productInfoEntity.getSfwwjbz())) udiProductEntity.setSfwwjbz(productInfoEntity.getSfwwjbz()); if (StrUtil.isNotEmpty(productInfoEntity.getSyqsfxyjxmj())) udiProductEntity.setSyqsfxyjxmj(productInfoEntity.getSyqsfxyjxmj()); if (StrUtil.isNotEmpty(productInfoEntity.getMjfs())) udiProductEntity.setMjfs(productInfoEntity.getMjfs()); if (StrUtil.isNotEmpty(productInfoEntity.getCategoryName())) udiProductEntity.setCategoryName(productInfoEntity.getCategoryName()); udiProductService.updateUdiInfoById(udiProductEntity); } } catch (Exception e) { e.printStackTrace(); logger.error(ExceptionUtil.getMessage(e)); } productInfoService.insertProductInfos(productInfoEntityList); if (productInfoEntityList.size() < limit) { break; } else { page++; } } else { break; } } logger.info("更新时间:" + updateTime + "----" + "下载结束"); } }