From 02f1ce16c6a272d10f8f8a3e477865e2eb40a7d4 Mon Sep 17 00:00:00 2001 From: x_z Date: Fri, 21 Apr 2023 14:51:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/glxp/api/dao/inout/IoOrderDao.java | 7 ++ .../glxp/api/dao/thrsys/ThrProductsDao.java | 12 +++ .../api/service/inout/IoOrderService.java | 9 +++ .../inout/impl/IoOrderServiceImpl.java | 15 ++++ .../impl/ThrBusTypeOriginServiceImpl.java | 20 ++--- .../thrsys/impl/ThrCorpServiceImpl.java | 40 +++------ .../impl/ThrInvWarehouseServiceImpl.java | 15 ++-- .../thrsys/impl/ThrProductsServiceImpl.java | 81 ++++++++++++++++++- .../glxp/api/task/ThirdSysInterfaceTask.java | 10 ++- .../mybatis/mapper/inout/IoOrderDao.xml | 4 + .../mybatis/mapper/thrsys/ThrProductsDao.xml | 74 +++++++++++++++++ 12 files changed, 233 insertions(+), 56 deletions(-) diff --git a/pom.xml b/pom.xml index e06eef846..b0139781f 100644 --- a/pom.xml +++ b/pom.xml @@ -220,7 +220,7 @@ cn.hutool hutool-all - 5.7.9 + 5.8.18 com.belerweb diff --git a/src/main/java/com/glxp/api/dao/inout/IoOrderDao.java b/src/main/java/com/glxp/api/dao/inout/IoOrderDao.java index 46a59feb3..214169688 100644 --- a/src/main/java/com/glxp/api/dao/inout/IoOrderDao.java +++ b/src/main/java/com/glxp/api/dao/inout/IoOrderDao.java @@ -59,4 +59,11 @@ public interface IoOrderDao extends BaseMapperPlus selectWaitSubmitOrder(String thirdSys); } \ No newline at end of file diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java index 069211918..b7939422a 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java @@ -20,6 +20,7 @@ public interface ThrProductsDao { List filterThrProducts(FilterThrProductsRequest filterThrProductsRequest); + List filterThrProducts1(FilterThrProductsRequest filterThrProductsRequest); List filterJoinThrProducts(FilterThrProductsRequest filterThrProductsRequest); @@ -33,4 +34,15 @@ public interface ThrProductsDao { boolean insertThrProductsList(List list); List selectByLastTime(@Param("lastUpdateTime") Date lastUpdateTime); + + /** + * 查询下载第三方产品校验字段 + * + * @param code + * @param thirdSysFk + * @return + */ + ThrProductsEntity selectByCodeAndThird(@Param("code") String code, @Param("thirdSysFk") String thirdSysFk); + + boolean updateById(ThrProductsEntity thrProductsEntity); } diff --git a/src/main/java/com/glxp/api/service/inout/IoOrderService.java b/src/main/java/com/glxp/api/service/inout/IoOrderService.java index 4db6ed140..7eb96125a 100644 --- a/src/main/java/com/glxp/api/service/inout/IoOrderService.java +++ b/src/main/java/com/glxp/api/service/inout/IoOrderService.java @@ -2,6 +2,7 @@ package com.glxp.api.service.inout; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.inout.IoOrderEntity; +import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.inout.FilterOrderRequest; import com.glxp.api.req.inout.FilterUploadOrderRequest; import com.glxp.api.req.inout.OrderEditRequest; @@ -124,4 +125,12 @@ public interface IoOrderService { boolean isExitByAction(String action); + + /** + * 定时任务自动提交单据到第三方系统 + * + * @param thrSystemDetailEntity + * @return + */ + BaseResponse submitOrderToThrSys(ThrSystemDetailEntity thrSystemDetailEntity); } diff --git a/src/main/java/com/glxp/api/service/inout/impl/IoOrderServiceImpl.java b/src/main/java/com/glxp/api/service/inout/impl/IoOrderServiceImpl.java index 5c8c27d72..299ab7222 100644 --- a/src/main/java/com/glxp/api/service/inout/impl/IoOrderServiceImpl.java +++ b/src/main/java/com/glxp/api/service/inout/impl/IoOrderServiceImpl.java @@ -26,6 +26,7 @@ import com.glxp.api.entity.inout.*; import com.glxp.api.entity.inv.*; import com.glxp.api.entity.system.SyncDataBustypeEntity; import com.glxp.api.entity.thrsys.ThrSystemBusApiEntity; +import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.entity.thrsys.ThrSystemEntity; import com.glxp.api.http.HttpOkClient; import com.glxp.api.req.inout.FilterOrderRequest; @@ -745,6 +746,20 @@ public class IoOrderServiceImpl implements IoOrderService { return orderDao.exists(new QueryWrapper().eq("action", action)); } + @Override + public BaseResponse submitOrderToThrSys(ThrSystemDetailEntity thrSystemDetailEntity) { + //查询可以提交到第三方系统的单据 + List billNos = orderDao.selectWaitSubmitOrder(thrSystemDetailEntity.getThirdSysFk()); + if (CollUtil.isNotEmpty(billNos)) { + log.info("开始提交单据到第三方系统,本次提交单据数量:{}", billNos.size()); + for (String billNo : billNos) { + submitToThrSys(billNo); + } + log.info("单据提交完成"); + } + return ResultVOUtils.success("单据提交完成"); + } + /** * 查询此单据关联的所有单据 * diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java index a3b533396..c784d7317 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java @@ -28,7 +28,6 @@ import javax.annotation.Resource; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Objects; @Slf4j @Service @@ -215,18 +214,11 @@ public class ThrBusTypeOriginServiceImpl implements IThrBusTypeOriginService { * @return */ private boolean verifyDataChange(ThrBusTypeOriginEntity thrBusTypeOriginEntity, ThrSystemBusApiEntity thrSystemBusApi) { - if (!StrUtil.equals(thrBusTypeOriginEntity.getName(), thrSystemBusApi.getName())) { - thrBusTypeOriginEntity.setName(thrSystemBusApi.getName()); - return true; - } - if (!Objects.equals(thrBusTypeOriginEntity.getInoutType(), thrSystemBusApi.getInoutType())) { - thrBusTypeOriginEntity.setInoutType(thrSystemBusApi.getInoutType()); - return true; - } - if (!StrUtil.equals(thrBusTypeOriginEntity.getRemark(), thrSystemBusApi.getRemark())) { - thrBusTypeOriginEntity.setRemark(thrSystemBusApi.getRemark()); - return true; - } - return false; + ThrBusTypeOriginEntity oldData = new ThrBusTypeOriginEntity(); + BeanUtil.copyProperties(thrBusTypeOriginEntity, oldData); + thrBusTypeOriginEntity.setName(thrSystemBusApi.getName()); + thrBusTypeOriginEntity.setInoutType(thrSystemBusApi.getInoutType()); + thrBusTypeOriginEntity.setRemark(thrSystemBusApi.getRemark()); + return !thrBusTypeOriginEntity.equals(oldData); } } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java index 845fade20..fc2a50a41 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java @@ -1,7 +1,6 @@ package com.glxp.api.service.thrsys.impl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; @@ -157,35 +156,16 @@ public class ThrCorpServiceImpl implements ThrCorpService { * @return */ private boolean verifyDataChange(ThrCorpEntity thrCorpEntity, ThrCorpsResponse thrCorpsResponse) { - if (!StrUtil.equals(thrCorpEntity.getSpell(), thrCorpsResponse.getSpell())) { - thrCorpEntity.setSpell(thrCorpsResponse.getSpell()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getAddr(), thrCorpsResponse.getAddr())) { - thrCorpEntity.setAddr(thrCorpsResponse.getAddr()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getCreditNo(), thrCorpsResponse.getCreditNo())) { - thrCorpEntity.setContact(thrCorpsResponse.getCreditNo()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getContact(), thrCorpsResponse.getContact())) { - thrCorpEntity.setContact(thrCorpsResponse.getContact()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getMobile(), thrCorpsResponse.getMobile())) { - thrCorpEntity.setMobile(thrCorpsResponse.getMobile()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getName(), thrCorpsResponse.getName())) { - thrCorpEntity.setName(thrCorpsResponse.getName()); - return true; - } - if (!StrUtil.equals(thrCorpEntity.getRemark(), thrCorpsResponse.getRemark())) { - thrCorpEntity.setRemark(thrCorpsResponse.getRemark()); - return true; - } - return false; + ThrCorpEntity oldData = new ThrCorpEntity(); + BeanUtil.copyProperties(thrCorpEntity, oldData); + thrCorpEntity.setSpell(thrCorpsResponse.getSpell()); + thrCorpEntity.setAddr(thrCorpsResponse.getAddr()); + thrCorpEntity.setContact(thrCorpsResponse.getCreditNo()); + thrCorpEntity.setContact(thrCorpsResponse.getContact()); + thrCorpEntity.setMobile(thrCorpsResponse.getMobile()); + thrCorpEntity.setName(thrCorpsResponse.getName()); + thrCorpEntity.setRemark(thrCorpsResponse.getRemark()); + return !thrCorpEntity.equals(oldData); } } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java index b32e30b7e..29a84e44f 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java @@ -1,5 +1,6 @@ package com.glxp.api.service.thrsys.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; @@ -184,15 +185,11 @@ public class ThrInvWarehouseServiceImpl implements ThrInvWarehouseService { * @return */ private boolean verifyDataChange(ThrInvWarehouseEntity thrInvWarehouseEntity, UdiwmsWarehouseDetail udiwmsWarehouseDetail) { - if (!StrUtil.equals(thrInvWarehouseEntity.getName(), udiwmsWarehouseDetail.getName())) { - thrInvWarehouseEntity.setName(udiwmsWarehouseDetail.getName()); - return true; - } - if (!StrUtil.equals(thrInvWarehouseEntity.getRemark(), udiwmsWarehouseDetail.getRemark())) { - thrInvWarehouseEntity.setRemark(udiwmsWarehouseDetail.getRemark()); - return true; - } - return false; + ThrInvWarehouseEntity oldData = new ThrInvWarehouseEntity(); + BeanUtil.copyProperties(thrInvWarehouseEntity, oldData); + thrInvWarehouseEntity.setName(udiwmsWarehouseDetail.getName()); + thrInvWarehouseEntity.setRemark(udiwmsWarehouseDetail.getRemark()); + return !thrInvWarehouseEntity.equals(oldData); } } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java index b2ec40905..b457d84a2 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java @@ -13,6 +13,7 @@ import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrProductsRequest; import com.glxp.api.req.thrsys.PostThrProductsRequest; +import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.service.thrsys.ThrProductsService; import lombok.extern.slf4j.Slf4j; @@ -160,8 +161,86 @@ public class ThrProductsServiceImpl implements ThrProductsService { @Override public BaseResponse downloadThrPi(ThrSystemDetailEntity thrSystemDetailEntity) { + int page = 1; + int limit = 200; + FilterThrProductsRequest request = new FilterThrProductsRequest(); + request.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk()); + request.setLimit(limit); + while (true) { + request.setPage(page); + + BaseResponse> baseResponse = erpBasicClient.getErpProducts(request); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.forEach(item -> { + ThrProductsEntity thrProductsEntity = thrProductsDao.selectByCodeAndThird(item.getCode(), item.getThirdSys()); + if (null == thrProductsEntity) { + thrProductsEntity = new ThrProductsEntity(); + BeanUtil.copyProperties(item, thrProductsEntity); + thrProductsEntity.setCreateTime(new Date()); + thrProductsEntity.setUpdateTime(new Date()); + } else { + boolean isChange = verifyDataChange(thrProductsEntity, item); + if (isChange) { + thrProductsEntity.setUpdateTime(new Date()); + thrProductsDao.updateById(thrProductsEntity); + } + } + }); + + + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return ResultVOUtils.error(500, "下载第三方系统产品信息异常"); + } + } + return ResultVOUtils.success("下载成功"); + } - return null; + /** + * 校验拉取的第三方数据是否有更新 + * + * @param thrProductsEntity + * @param thrProductsResponse + * @return + */ + private boolean verifyDataChange(ThrProductsEntity thrProductsEntity, ThrProductsResponse thrProductsResponse) { + ThrProductsEntity oldData = new ThrProductsEntity(); + BeanUtil.copyProperties(thrProductsEntity, oldData); + + //将关键字段的值设置为新数据的值 + thrProductsEntity.setName(thrProductsResponse.getName()); + thrProductsEntity.setMeasname(thrProductsResponse.getMeasname()); + thrProductsEntity.setSpec(thrProductsResponse.getSpec()); + thrProductsEntity.setRegisterNo(thrProductsResponse.getRegisterNo()); + thrProductsEntity.setManufactory(thrProductsResponse.getManufactory()); + thrProductsEntity.setCplb(thrProductsResponse.getCplb()); + thrProductsEntity.setFlbm(thrProductsResponse.getFlbm()); + thrProductsEntity.setQtbm(thrProductsResponse.getQtbm()); + thrProductsEntity.setSptm(thrProductsResponse.getSptm()); + thrProductsEntity.setYbbm(thrProductsResponse.getYbbm()); + thrProductsEntity.setTyshxydm(thrProductsResponse.getTyshxydm()); + thrProductsEntity.setZczbhhzbapzbh(thrProductsResponse.getZczbhhzbapzbh()); + thrProductsEntity.setYlqxzcrbarmc(thrProductsResponse.getYlqxzcrbarmc()); + thrProductsEntity.setYlqxzcrbarywmc(thrProductsResponse.getYlqxzcrbarywmc()); + thrProductsEntity.setCpms(thrProductsResponse.getCpms()); + thrProductsEntity.setSupName(thrProductsResponse.getSupName()); + thrProductsEntity.setModel(thrProductsResponse.getModel()); + thrProductsEntity.setStandard(thrProductsResponse.getStandard()); + thrProductsEntity.setQtbm(thrProductsResponse.getQtbm()); + thrProductsEntity.setZczyxqz(thrProductsResponse.getZczyxqz()); + thrProductsEntity.setRemark(thrProductsResponse.getRemark()); + thrProductsEntity.setRemark1(thrProductsResponse.getRemark1()); + thrProductsEntity.setRemark2(thrProductsResponse.getRemark2()); + thrProductsEntity.setRemark3(thrProductsResponse.getRemark3()); + thrProductsEntity.setPrice(thrProductsResponse.getPrice()); + + //比对更新完的对象和原对象是否发生变化,若有变化则说明书有更新 + return !thrProductsEntity.equals(oldData); } } diff --git a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java index ff921b2cb..5cb05089d 100644 --- a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java +++ b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java @@ -114,7 +114,15 @@ public class ThirdSysInterfaceTask { * @param thrSystemDetailEntity */ private void submitOrder(ThrSystemDetailEntity thrSystemDetailEntity) { - + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始提交单据到第三方系统"); + orderService.submitOrderToThrSys(thrSystemDetailEntity); + updateTask(getTaskKey(thrSystemDetailEntity)); + log.info("提交单据到第三方系统完成"); + }); + } } /** diff --git a/src/main/resources/mybatis/mapper/inout/IoOrderDao.xml b/src/main/resources/mybatis/mapper/inout/IoOrderDao.xml index e23840d48..4922ca64a 100644 --- a/src/main/resources/mybatis/mapper/inout/IoOrderDao.xml +++ b/src/main/resources/mybatis/mapper/inout/IoOrderDao.xml @@ -264,4 +264,8 @@ from io_order where billNo = #{billNo} + + diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml index c3b2d59bd..18452a296 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml @@ -238,4 +238,78 @@ #{item.updateUser} + + + + + update thr_products + + code = #{code,jdbcType=VARCHAR}, + name = #{name,jdbcType=VARCHAR}, + measname = #{measname,jdbcType=VARCHAR}, + spec = #{spec,jdbcType=VARCHAR}, + registerNo = #{registerNo,jdbcType=VARCHAR}, + manufactory = #{manufactory,jdbcType=VARCHAR}, + cplb = #{cplb,jdbcType=VARCHAR}, + flbm = #{flbm,jdbcType=VARCHAR}, + qxlb = #{qxlb,jdbcType=VARCHAR}, + ybbm = #{ybbm,jdbcType=VARCHAR}, + sptm = #{sptm,jdbcType=VARCHAR}, + tyshxydm = #{tyshxydm,jdbcType=VARCHAR}, + zczbhhzbapzbh = #{zczbhhzbapzbh,jdbcType=VARCHAR}, + ylqxzcrbarmc = #{ylqxzcrbarmc,jdbcType=VARCHAR}, + ylqxzcrbarywmc = #{ylqxzcrbarywmc,jdbcType=VARCHAR}, + cpms = #{cpms,jdbcType=LONGVARCHAR}, + updateTime = #{updateTime,jdbcType=TIMESTAMP}, + supName = #{supName,jdbcType=VARCHAR}, + model = #{model,jdbcType=VARCHAR}, + standard = #{standard,jdbcType=VARCHAR}, + qtbm = #{qtbm,jdbcType=VARCHAR}, + zczyxqz = #{zczyxqz,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR}, + remark1 = #{remark1,jdbcType=VARCHAR}, + remark2 = #{remark2,jdbcType=VARCHAR}, + remark3 = #{remark3,jdbcType=VARCHAR}, + price = #{price,jdbcType=VARCHAR} + + where id = #{id,jdbcType=INTEGER} +