From 598b58d8d4a3cd237f108f33c99b942baca1814a Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Wed, 24 May 2023 10:28:14 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E4=BA=A7=E5=93=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thrsys/ThrProductsController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java index 97310b3e4..15d2e4e70 100644 --- a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java @@ -16,6 +16,7 @@ import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.req.thrsys.FilterThrProductsRequest; import com.glxp.api.req.thrsys.PostThrProductsRequest; +import com.glxp.api.req.thrsys.ThrOnhandRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.service.auth.CustomerService; @@ -237,4 +238,21 @@ public class ThrProductsController { return ResultVOUtils.success(); } + /** + * 下载第三方产品信息 + * + * @param filterThrProductsRequest + * @return + */ + @PostMapping("/udiwms/thrsys/products/productsDlAll") + public BaseResponse productsDlAll(@RequestBody FilterThrProductsRequest filterThrProductsRequest) { + if (null == filterThrProductsRequest) { + return ResultVOUtils.error(500, "参数不能为空"); + } + ThreadUtil.execAsync(() -> { + erpBasicClient.getErpProducts(filterThrProductsRequest); + }); + return ResultVOUtils.success(); + } + } \ No newline at end of file From f7d09c1ec4287579ac35e044d4d6ac67f23fbc70 Mon Sep 17 00:00:00 2001 From: anthonywj Date: Wed, 24 May 2023 17:52:33 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thrsys/ThrProductsController.java | 10 +- .../com/glxp/api/http/ErpBasicClient.java | 5 +- .../req/thrsys/FilterThrProductsRequest.java | 16 + .../service/thrsys/ThrProductsService.java | 8 + .../impl/ThrBusTypeOriginServiceImpl.java | 4 +- .../impl/ThrInvWarehouseServiceImpl.java | 2 +- .../thrsys/impl/ThrProductsServiceImpl.java | 44 ++- .../com/glxp/api/task/SyncThirdSysTask.java | 331 ++++++++++++++++++ .../glxp/api/task/ThirdSysInterfaceTask.java | 4 +- .../mapper/thrsys/ThrInvWarehouseDao.xml | 92 +++-- src/main/resources/schemas/schema_v2.1.sql | 34 +- 11 files changed, 494 insertions(+), 56 deletions(-) create mode 100644 src/main/java/com/glxp/api/task/SyncThirdSysTask.java diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java index 15d2e4e70..97066c999 100644 --- a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java @@ -1,6 +1,8 @@ package com.glxp.api.controller.thrsys; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.IdUtil; @@ -249,10 +251,12 @@ public class ThrProductsController { if (null == filterThrProductsRequest) { return ResultVOUtils.error(500, "参数不能为空"); } + + ThreadUtil.execAsync(() -> { - erpBasicClient.getErpProducts(filterThrProductsRequest); + thrProductsService.downloadByRequest(filterThrProductsRequest); }); - return ResultVOUtils.success(); + return ResultVOUtils.success("后台正在下载,请稍后刷新查看!"); } -} \ No newline at end of file +} diff --git a/src/main/java/com/glxp/api/http/ErpBasicClient.java b/src/main/java/com/glxp/api/http/ErpBasicClient.java index b06b8a211..436d5ec0c 100644 --- a/src/main/java/com/glxp/api/http/ErpBasicClient.java +++ b/src/main/java/com/glxp/api/http/ErpBasicClient.java @@ -43,7 +43,7 @@ public class ErpBasicClient { UdiwmsUnitRequest udiwmsUnitRequest = new UdiwmsUnitRequest(); BeanUtils.copyProperties(thrUnitMaintainFilterRequest, udiwmsUnitRequest); udiwmsUnitRequest.setUnitId(thrUnitMaintainFilterRequest.getErpId()); - ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thrUnitMaintainFilterRequest.getThirdSys()); + ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thrUnitMaintainFilterRequest.getThirdSysFk()); try { String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/getUnits"; @@ -64,9 +64,8 @@ public class ErpBasicClient { //获取产品信息 public BaseResponse> getErpProducts(FilterThrProductsRequest filterThrProductsRequest) { - ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(filterThrProductsRequest.getThirdSys()); + ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(filterThrProductsRequest.getThirdSysFk()); String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/getProducts"; - try { String response = httpOkClient.uCloudPost(url, filterThrProductsRequest, basicThirdSysEntity); if (StrUtil.isBlank(response)) { diff --git a/src/main/java/com/glxp/api/req/thrsys/FilterThrProductsRequest.java b/src/main/java/com/glxp/api/req/thrsys/FilterThrProductsRequest.java index 70ddf3fab..f8a1ca559 100644 --- a/src/main/java/com/glxp/api/req/thrsys/FilterThrProductsRequest.java +++ b/src/main/java/com/glxp/api/req/thrsys/FilterThrProductsRequest.java @@ -1,6 +1,7 @@ package com.glxp.api.req.thrsys; +import cn.hutool.core.util.StrUtil; import com.glxp.api.entity.thrsys.ThrProductsEntity; import com.glxp.api.util.page.ListPageRequest; import lombok.Data; @@ -34,5 +35,20 @@ public class FilterThrProductsRequest extends ListPageRequest { private String uuid; private Integer diType; + public List getThrProductsEntities() { + return thrProductsEntities; + } + public String getThirdSys() { + if (StrUtil.isEmpty(thirdSys)) + return thirdSysFk; + return thirdSys; + } + + public String getThirdSysFk() { + + if (StrUtil.isEmpty(thirdSysFk)) + return thirdSys; + return thirdSysFk; + } } diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java index 593052c2d..f9ac1ad55 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java @@ -66,4 +66,12 @@ public interface ThrProductsService extends IService { * @return */ BaseResponse downloadThrPi(ThrSystemDetailEntity thrSystemDetailEntity); + + /** + * 下载第三方产品信息 + * + * @param filterThrProductsRequest + * @return + */ + BaseResponse downloadByRequest(FilterThrProductsRequest filterThrProductsRequest); } 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 3842bf90e..6ab0a2ab9 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 @@ -34,7 +34,7 @@ import java.util.List; @Slf4j @Service @Transactional(rollbackFor = Exception.class) -public class ThrBusTypeOriginServiceImpl extends ServiceImpl implements IThrBusTypeOriginService { +public class ThrBusTypeOriginServiceImpl extends ServiceImpl implements IThrBusTypeOriginService { @Resource private CustomerService customerService; @@ -180,7 +180,7 @@ public class ThrBusTypeOriginServiceImpl extends ServiceImpl list = baseResponse.getData().getList(); list.forEach(item -> { - ThrBusTypeOriginEntity thrBusTypeOriginEntity = thrBusTypeOriginDao.selectOne(new QueryWrapper().eq("code", item.getCode()).eq("thirdSys", thrSystemDetailEntity.getThirdSysFk())); + ThrBusTypeOriginEntity thrBusTypeOriginEntity = thrBusTypeOriginDao.selectOne(new QueryWrapper().eq("action", item.getCode()).eq("thirdSys", thrSystemDetailEntity.getThirdSysFk())); if (null == thrBusTypeOriginEntity) { thrBusTypeOriginEntity = new ThrBusTypeOriginEntity(); BeanUtil.copyProperties(item, thrBusTypeOriginEntity); 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 24970bcb4..c9bb116db 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 @@ -29,7 +29,7 @@ import java.util.List; @Slf4j @Service @Transactional(rollbackFor = Exception.class) -public class ThrInvWarehouseServiceImpl extends ServiceImpl implements ThrInvWarehouseService { +public class ThrInvWarehouseServiceImpl extends ServiceImpl implements ThrInvWarehouseService { @Resource private ThrInvWarehouseDao thrInvWarehouseDao; 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 c6eac8d44..45e4bd45f 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 @@ -176,7 +176,6 @@ public class ThrProductsServiceImpl extends ServiceImpl> baseResponse = erpBasicClient.getErpProducts(request); if (baseResponse.getCode() == 20000) { List list = baseResponse.getData().getList(); @@ -192,7 +191,7 @@ public class ThrProductsServiceImpl extends ServiceImpl> baseResponse = erpBasicClient.getErpProducts(filterThrProductsRequest); + 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()); + thrProductsEntity.setId(IdUtil.getSnowflakeNextId()); + thrProductsDao.insertThrProducts(thrProductsEntity); + } else { + boolean isChange = verifyDataChange(thrProductsEntity, item); + if (isChange) { + BeanUtil.copyProperties(item, thrProductsEntity, new CopyOptions().setIgnoreNullValue(true)); + thrProductsEntity.setUpdateTime(new Date()); + thrProductsDao.updateEntityById(thrProductsEntity); + } + } + }); + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return ResultVOUtils.error(500, "下载第三方系统产品信息异常"); + } + } + return ResultVOUtils.success("下载成功"); + } + /** * 校验拉取的第三方数据是否有更新 * diff --git a/src/main/java/com/glxp/api/task/SyncThirdSysTask.java b/src/main/java/com/glxp/api/task/SyncThirdSysTask.java new file mode 100644 index 000000000..d10c44f95 --- /dev/null +++ b/src/main/java/com/glxp/api/task/SyncThirdSysTask.java @@ -0,0 +1,331 @@ +package com.glxp.api.task; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.thread.ThreadUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.glxp.api.constant.ThirdSysConstant; +import com.glxp.api.dao.schedule.ScheduledDao; +import com.glxp.api.dao.system.SyncDataSetDao; +import com.glxp.api.dao.thrsys.ThrSystemDetailDao; +import com.glxp.api.entity.system.ScheduledEntity; +import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; +import com.glxp.api.req.system.ScheduledRequest; +import com.glxp.api.res.thrsys.ThirdSysInterfaceExecuteVo; +import com.glxp.api.service.inout.IoOrderService; +import com.glxp.api.service.thrsys.IThrBusTypeOriginService; +import com.glxp.api.service.thrsys.ThrCorpService; +import com.glxp.api.service.thrsys.ThrInvWarehouseService; +import com.glxp.api.service.thrsys.ThrProductsService; +import com.glxp.api.util.RedisUtil; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; + +@Component +@EnableScheduling +@Slf4j +public class SyncThirdSysTask implements SchedulingConfigurer { + + /** + * redis key 前缀 + */ + private static final Map> keyMap = new ConcurrentHashMap<>(5); + + private volatile ExecutorService executor; + + @Resource + private RedisUtil redisUtil; + @Resource + private ThrSystemDetailDao thrSystemDetailDao; + @Resource + private ThrInvWarehouseService thrInvWarehouseService; + @Resource + private ThrCorpService thrCorpService; + @Resource + private ThrProductsService thrProductsService; + @Resource + private IThrBusTypeOriginService thrBusTypeOriginService; + @Resource + private IoOrderService orderService; + + + final Logger logger = LoggerFactory.getLogger(SyncHeartTask.class); + @Resource + protected ScheduledDao scheduledDao; + @Resource + private SyncDataSetDao syncDataSetDao; + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + + scheduledTaskRegistrar.addTriggerTask(() -> process(), + triggerContext -> { + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("dlThrSysHeartTask"); + ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); + if (scheduledEntity != null) { + String cron = scheduledEntity.getCron(); + if (cron.isEmpty()) { + logger.error("cron is null"); + } + return new CronTrigger(cron).nextExecutionTime(triggerContext); + } else + return null; + + }); + } + + private ExecutorService getExecutor() { + if (null == executor) { + synchronized (this) { + log.info("初始化第三方系统接口执行线程池"); + executor = ThreadUtil.newExecutor(10, 100, Integer.MAX_VALUE); + } + } + return executor; + } + + + private void process() { + + log.info("开始扫描自动执行的第三方接口列表"); + List list = thrSystemDetailDao.selectAutoExecuteList(); + if (CollUtil.isNotEmpty(list)) { + log.info("本次查询到的接口列表数量:{}", list.size()); + list.parallelStream().forEach(thrSystemDetailEntity -> { + switch (thrSystemDetailEntity.getKey()) { + case ThirdSysConstant.WAREHOUSE_QUERY_URL: + //下载第三方仓库信息 + downloadThrInv(thrSystemDetailEntity); + break; + case ThirdSysConstant.CORP_URL: + //下载往来单位信息 + downloadThrCorp(thrSystemDetailEntity); + break; + case ThirdSysConstant.PI_QUERY_URL: + //下载第三方产品信息 + downloadThrPi(thrSystemDetailEntity); + break; + case ThirdSysConstant.BUS_TYPE_QUERY_URL: + //下载第三方单据类型 + downloadThrBusType(thrSystemDetailEntity); + break; + case ThirdSysConstant.ORDER_SUBMIT_URL: + //提交单据 + submitOrder(thrSystemDetailEntity); + break; + default: + //其他接口暂不处理 + break; + } + }); + } else { + log.info("未配置自动执行的第三方接口列表"); + } + } + + + /** + * 提交单据到第三方系统 + * + * @param thrSystemDetailEntity + */ + private void submitOrder(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始提交单据到第三方系统"); + try { + orderService.submitOrderToThrSys(thrSystemDetailEntity); + } catch (Exception e) { + log.error("提交单据到第三方系统异常", e); + } finally { + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("提交单据到第三方系统完成"); + }); + } + } + + /** + * 下载第三方单据类型 + * + * @param thrSystemDetailEntity + */ + private void downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方单据类型"); + try { + thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity); + } catch (Exception e) { + log.error("下载第三方单据类型异常", e); + } finally { + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("第三方单据类型下载完成"); + }); + } + } + + /** + * 下载第三方产品信息 + * + * @param thrSystemDetailEntity + */ + private void downloadThrPi(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方产品信息"); + try { + thrProductsService.downloadThrPi(thrSystemDetailEntity); + } catch (Exception e) { + log.error("下载第三方产品信息异常", e); + } finally { + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("第三方产品信息下载完成"); + }); + } + } + + /** + * 下载第三方往来单位 + * + * @param thrSystemDetailEntity + */ + private void downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方往来单位信息"); + try { + thrCorpService.downloadThrCorp(thrSystemDetailEntity); + } catch (Exception e) { + log.error("下载第三方往来单位异常", e); + } finally { + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("第三方往来单位信息下载完成"); + }); + } + } + + /** + * 下载第三方系统仓库 + * + * @param thrSystemDetailEntity + */ + private void downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方仓库信息"); + try { + thrInvWarehouseService.downloadThrInv(thrSystemDetailEntity); + } catch (Exception e) { + log.error("下载第三方仓库信息异常", e); + } finally { + //保证任务标识一定会被修改回去 + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("第三方仓库信息下载完成"); + }); + } + } + + /** + * 更新任务状态为已完成 + * + * @param taskKey + */ + private void updateTask(String taskKey) { + ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey); + vo.setFinished(true); + redisUtil.set(taskKey, vo); + } + + /** + * 校验当前任务是否可以执行 + * + * @param thrSystemDetailEntity + * @return + */ + private boolean verifyTask(ThrSystemDetailEntity thrSystemDetailEntity) { + String taskKey = getTaskKey(thrSystemDetailEntity); + ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey); + if (null != vo && !vo.isFinished()) { + log.info("有任务尚未执行完成,当前任务key:{}", taskKey); + return false; + } + long nextTime = DateUtil.offsetMonth(new Date(), thrSystemDetailEntity.getTime()).getTime(); + if (vo != null) { + if (vo.getNextTime() - new Date().getTime() > thrSystemDetailEntity.getTime() * 1000 * 60) { + log.info("定时任务时间未到", taskKey); + return false; + } else { + return true; + } + } else { + vo = Optional.ofNullable(vo).orElse(new ThirdSysInterfaceExecuteVo()); + vo.setKey(taskKey); + vo.setNextTime(nextTime); + vo.setFinished(false); + redisUtil.set(taskKey, vo); + } + return true; + } + + /** + * 获取上一次执行结果 + * + * @param taskKey + * @return + */ + private ThirdSysInterfaceExecuteVo getLastResult(String taskKey) { + String json = redisUtil.getJSON(taskKey); + return StrUtil.isBlank(json) ? null : JSONUtil.toBean(json, ThirdSysInterfaceExecuteVo.class); + } + + /** + * 拼接redis Key + * + * @param thrSystemDetailEntity + * @return + */ + private String getTaskKey(ThrSystemDetailEntity thrSystemDetailEntity) { + String key = ""; + Map keys = keyMap.get(thrSystemDetailEntity.getThirdSysFk()); + if (CollUtil.isEmpty(keys)) { + Map map = new HashMap<>(1); + key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey(); + map.put(thrSystemDetailEntity.getKey(), key); + keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map); + } else { + key = keys.get(thrSystemDetailEntity.getKey()); + if (StrUtil.isBlank(key)) { + key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey(); + Map map = new HashMap<>(1); + map.put(thrSystemDetailEntity.getKey(), key); + keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map); + } + } + return key; + } + + +} diff --git a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java index a190b23d6..803760533 100644 --- a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java +++ b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java @@ -29,7 +29,7 @@ import java.util.concurrent.ExecutorService; * 此任务负责校验第三方接口设置里的所有接口列表,并生成任务到线程池中异步执行 */ @Slf4j -@Component +//@Component public class ThirdSysInterfaceTask { /** @@ -69,7 +69,7 @@ public class ThirdSysInterfaceTask { @Resource private IoOrderService orderService; - @Scheduled(fixedRate = 20 * 1000, initialDelay = 60 * 1000) + @Scheduled(fixedRate = 1 * 1000, initialDelay = 60 * 1000) public void scanInterface() { log.info("开始扫描自动执行的第三方接口列表"); List list = thrSystemDetailDao.selectAutoExecuteList(); diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml index 2b0f0b502..6172d3bd8 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml @@ -41,27 +41,33 @@ - select * from thr_inv_warehouse where updateTime >= #{lastUpdateTime} + select * + from thr_inv_warehouse + where updateTime >= #{lastUpdateTime} diff --git a/src/main/resources/schemas/schema_v2.1.sql b/src/main/resources/schemas/schema_v2.1.sql index 4de510174..61a3a9b51 100644 --- a/src/main/resources/schemas/schema_v2.1.sql +++ b/src/main/resources/schemas/schema_v2.1.sql @@ -444,9 +444,31 @@ CALL Pro_Temp_ColumnWork('io_code', 'preInSpaceCode', 'varchar(255)', 1); CALL Pro_Temp_ColumnWork('pur_order_detail', 'price', 'decimal(10, 2)', 1); -INSERT ignore INTO `sys_pdf_template_relevance_label`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (1, 30, 110, 0, 9, '内部码打印', NULL, NULL, NULL, NULL, 'lable'); -INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (1, 31, 110, 0, NULL, '配送企业资质打印', NULL, NULL, NULL, NULL, 'reportForms'); -INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (2, 32, 110, 0, NULL, '生产企业资质打印', NULL, NULL, NULL, NULL, 'reportForms'); -INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (3, 33, 110, 0, NULL, '配送产品资质打印', NULL, NULL, NULL, NULL, 'reportForms'); -INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (4, 33, 110, 0, NULL, '库存报表打印', NULL, NULL, NULL, NULL, 'reportForms'); -INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, `localAction`, `remark1`, `remark2`, `remark3`, `printType`, `modelKey`) VALUES (5, 33, 110, 0, NULL, '内部码报表打印', NULL, NULL, NULL, NULL, 'reportForms'); +INSERT ignore INTO `sys_pdf_template_relevance_label`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (1, 30, 110, 0, 9, '内部码打印', NULL, NULL, NULL, NULL, 'lable'); +INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (1, 31, 110, 0, NULL, '配送企业资质打印', NULL, NULL, NULL, NULL, 'reportForms'); +INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (2, 32, 110, 0, NULL, '生产企业资质打印', NULL, NULL, NULL, NULL, 'reportForms'); +INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (3, 33, 110, 0, NULL, '配送产品资质打印', NULL, NULL, NULL, NULL, 'reportForms'); +INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (4, 33, 110, 0, NULL, '库存报表打印', NULL, NULL, NULL, NULL, 'reportForms'); +INSERT ignore INTO `sys_pdf_template_relevance_statemen`(`id`, `templateId`, `customerId`, `adminId`, `moduleId`, + `localAction`, `remark1`, `remark2`, `remark3`, `printType`, + `modelKey`) +VALUES (5, 33, 110, 0, NULL, '内部码报表打印', NULL, NULL, NULL, NULL, 'reportForms'); + + +INSERT ignore INTO `sys_scheduled`(`id`, `cronName`, `cron`, `customerId`, `remark`) +VALUES (140, 'dlThrSysHeartTask', '0 0/1 * * * ?', NULL, '第三方接口同步心跳'); From 6111d7c580729a472a867167f283110aea95b2dd Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Wed, 24 May 2023 19:27:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?insertIgnoreBatch/replaceBatch=E6=94=B9?= =?UTF-8?q?=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/glxp/api/dao/BaseMapperPlus.java | 67 +++++++++++++++++-- .../com/glxp/api/service/CustomService.java | 4 +- .../glxp/api/service/CustomServiceImpl.java | 8 +-- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/glxp/api/dao/BaseMapperPlus.java b/src/main/java/com/glxp/api/dao/BaseMapperPlus.java index 59eb52bd1..3d3a64bce 100644 --- a/src/main/java/com/glxp/api/dao/BaseMapperPlus.java +++ b/src/main/java/com/glxp/api/dao/BaseMapperPlus.java @@ -18,10 +18,7 @@ import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; import java.io.Serializable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** * 自定义 Mapper 接口, 实现 自定义扩展 @@ -242,8 +239,39 @@ public interface BaseMapperPlus extends BaseMapper { * @param entityList 实体类列表 * @return 影响条数 */ + default boolean insertIgnoreBatchs(List entityList) { + return insertIgnoreBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean insertIgnoreBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator var7 = entityList.iterator(); var7.hasNext(); ++i) { + T element = var7.next(); + oneBatchList.add(element); + if (i == idxLimit) { + + this.insertIgnoreBatch(oneBatchList); + //每次提交后需要清空集合数据 + oneBatchList.clear(); + idxLimit = Math.min(idxLimit + batchSize, size); + } + } + } catch (Exception e) { + log.error("insertIgnoreBatch fail", e); + return false; + } + return true; + } + int insertIgnoreBatch(List entityList); + /** * 替换数据 * replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样; @@ -262,5 +290,36 @@ public interface BaseMapperPlus extends BaseMapper { * @param entityList 实体类列表 * @return 影响条数 */ + default boolean replaceBatchs(List entityList) { + return this.replaceBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean replaceBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator var7 = entityList.iterator(); var7.hasNext(); ++i) { + T element = var7.next(); + oneBatchList.add(element); + if (i == idxLimit) { + + this.replaceBatch(oneBatchList); + //每次提交后需要清空集合数据 + oneBatchList.clear(); + idxLimit = Math.min(idxLimit + batchSize, size); + } + } + } catch (Exception e) { + log.error("insertIgnoreBatch fail", e); + return false; + } + return true; + } + int replaceBatch(List entityList); + } diff --git a/src/main/java/com/glxp/api/service/CustomService.java b/src/main/java/com/glxp/api/service/CustomService.java index 6f5771cab..f7e0cfe2f 100644 --- a/src/main/java/com/glxp/api/service/CustomService.java +++ b/src/main/java/com/glxp/api/service/CustomService.java @@ -6,7 +6,7 @@ import java.util.List; public interface CustomService extends IService { int insertIgnore(T entity); - int insertIgnoreBatch(List entityList); + boolean insertIgnoreBatch(List entityList); int replace(T entity); - int replaceBatch(List entityList); + boolean replaceBatch(List entityList); } diff --git a/src/main/java/com/glxp/api/service/CustomServiceImpl.java b/src/main/java/com/glxp/api/service/CustomServiceImpl.java index fbe971939..e180c9058 100644 --- a/src/main/java/com/glxp/api/service/CustomServiceImpl.java +++ b/src/main/java/com/glxp/api/service/CustomServiceImpl.java @@ -13,8 +13,8 @@ public class CustomServiceImpl, T> extends ServiceImpl entityList) { - return baseMapper.insertIgnoreBatch(entityList); + public boolean insertIgnoreBatch(List entityList) { + return baseMapper.insertIgnoreBatchs(entityList); } @Override @@ -23,7 +23,7 @@ public class CustomServiceImpl, T> extends ServiceImpl entityList) { - return baseMapper.replaceBatch(entityList); + public boolean replaceBatch(List entityList) { + return baseMapper.replaceBatchs(entityList); } } From 3e53fea186cb12a1f672635a22cc83fc10a8b50c Mon Sep 17 00:00:00 2001 From: anthonywj Date: Wed, 24 May 2023 20:21:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B8=8B=E8=BD=BDbug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/thrsys/ThrCorpsController.java | 41 +-- .../thrsys/ThrProductsController.java | 43 +-- .../com/glxp/api/http/ErpBasicClient.java | 8 +- .../thrsys/ThrUnitMaintainFilterRequest.java | 15 + .../glxp/api/service/sync/HeartService.java | 9 +- .../api/service/thrsys/ThrCorpService.java | 2 + .../api/service/thrsys/ThrCorpsDlService.java | 14 +- .../service/thrsys/ThrProductsService.java | 2 +- .../thrsys/impl/ThrCorpServiceImpl.java | 55 +++- .../thrsys/impl/ThrProductsServiceImpl.java | 12 +- .../glxp/api/task/ThirdSysInterfaceTask.java | 291 ------------------ .../mybatis/mapper/thrsys/ThrCorpDao.xml | 26 +- 12 files changed, 142 insertions(+), 376 deletions(-) delete mode 100644 src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrCorpsController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrCorpsController.java index e263cf2d0..ae7bc4d1f 100644 --- a/src/main/java/com/glxp/api/controller/thrsys/ThrCorpsController.java +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrCorpsController.java @@ -1,5 +1,6 @@ package com.glxp.api.controller.thrsys; +import cn.hutool.core.thread.ThreadUtil; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.enums.ResultEnum; @@ -23,6 +24,7 @@ import com.glxp.api.service.thrsys.ThrCorpsDlService; import com.glxp.api.service.thrsys.ThrSystemDetailService; import com.glxp.api.util.CustomUtil; import com.glxp.api.util.RedisUtil; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; @@ -32,6 +34,7 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +@Slf4j @RestController public class ThrCorpsController { @Resource @@ -137,7 +140,7 @@ public class ThrCorpsController { thrCorpImportLogEntity.setUpdateTime(new Date()); thrCorpImportLogEntity.setThirdSysFk(filterThrProductsRequest.getThirdSysFk()); thrCorpImportLogService.insertImportLog(thrCorpImportLogEntity); - thrCorpsDlService.importCorps(genKey,null, filterThrProductsRequest.getThirdSysFk()); + thrCorpsDlService.importCorps(genKey, null, filterThrProductsRequest.getThirdSysFk()); return ResultVOUtils.success("后台开始下载更新,请稍后刷新查看"); } } @@ -146,33 +149,19 @@ public class ThrCorpsController { @AuthRuleAnnotation("") @PostMapping("/udiwms/thrsys/corp/corpsDlAll") public BaseResponse corpsDlAll(@RequestBody ThrUnitMaintainFilterRequest thrUnitMaintainFilterRequest) { - thrUnitMaintainFilterRequest.setThirdSysFk(thrUnitMaintainFilterRequest.getThirdSys()); - String data = (String) redisUtil.get(Constant.dlThrProducts); - if (data != null && data.equals("true")) { - return ResultVOUtils.error(500, "当前任务正在下载更新产品信息,请稍后重试!"); - } else { - redisUtil.set(Constant.dlThrCorps, "true", 30); - if (thrUnitMaintainFilterRequest.getThirdSysFk() == null) { - return ResultVOUtils.error(500, "未选择第三方系统!"); - } - ThrCorpImportLogEntity thrCorpImportLogEntity = new ThrCorpImportLogEntity(); - String genKey = CustomUtil.getId(); - thrCorpImportLogEntity.setGenKey(genKey); - thrCorpImportLogEntity.setFromType("第三方系统获取"); - thrCorpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_PROCESS); - thrCorpImportLogEntity.setUpdateTime(new Date()); - thrCorpImportLogEntity.setThirdSysFk(thrUnitMaintainFilterRequest.getThirdSysFk()); - thrCorpImportLogService.insertImportLog(thrCorpImportLogEntity); - - if (thrUnitMaintainFilterRequest.getThrCorpEntities() != null && thrUnitMaintainFilterRequest.getThrCorpEntities().size() > 0) {//选中导出 - thrCorpsDlService.importSelectCorps(genKey, thrUnitMaintainFilterRequest.getThrCorpEntities(), thrUnitMaintainFilterRequest.getThirdSysFk()); - } else { //结果导出 - thrCorpsDlService.importCorps(genKey,thrUnitMaintainFilterRequest, thrUnitMaintainFilterRequest.getThirdSysFk()); + if (null == thrUnitMaintainFilterRequest) { + return ResultVOUtils.error(500, "参数不能为空"); + } + ThreadUtil.execAsync(() -> { + try { + thrCorpService.downloadByRequest(thrUnitMaintainFilterRequest); + } catch (Exception e) { + log.error("下载异常", e); + e.printStackTrace(); } -// thrCorpsDlService.importCorps(genKey, filterThrCorpRequest.getThirdSysFk()); - return ResultVOUtils.success("后台开始下载更新,请稍后刷新查看"); - } + }); + return ResultVOUtils.success("后台正在下载,请稍后刷新查看!"); } //查询ERP往来单位 diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java index 97066c999..31dc2c92e 100644 --- a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java @@ -24,12 +24,14 @@ import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.service.auth.CustomerService; import com.glxp.api.service.thrsys.ThrProductsService; import com.glxp.api.service.thrsys.ThrSystemDetailService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.IOException; import java.util.Date; import java.util.List; @@ -41,6 +43,7 @@ import java.util.List; * @author ${author} * @since 2023-01-10 */ +@Slf4j @RestController public class ThrProductsController { @@ -74,35 +77,9 @@ public class ThrProductsController { if (thrSystemDetailEntity.getEnabled()) { if (thrSystemDetailEntity.getFromType() == 0 || (filterThrProductsRequest.getIsDownThrSys() != null && filterThrProductsRequest.getIsDownThrSys())) { BaseResponse> udiDlDeviceResponse = erpBasicClient.getErpProducts(filterThrProductsRequest); - if (udiDlDeviceResponse.getCode() == 20000) { - List invmandocResponses = udiDlDeviceResponse.getData().getList(); - //todo 耗材字典未确认数据库 -// if (invmandocResponses != null) { -// for (ThrProductsResponse invmandocResponse : invmandocResponses) { -// UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectByThirdId(invmandocResponse.getCode(), filterErpGoodsRequest.getThirdSys()); -// invmandocResponse.setThirdSys(thrProductsRequest.getThirdSys()); -// if (udiRelevanceEntity != null) { -// invmandocResponse.setChecked(true); -// } else { -// invmandocResponse.setChecked(false); -// } -// } -// } - - } return udiDlDeviceResponse; } else { - List thrCorpEntities = thrProductsService.filterJoinThrProducts(filterThrProductsRequest); - //todo 耗材字典未确认数据库 -// for (ThrProductsEntity thrProductsEntity : thrCorpEntities) { -// UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectByThirdId(thrProductsEntity.getCode(), thrProductsEntity.getThirdSysFk()); -// if (udiRelevanceEntity != null) { -// thrProductsEntity.setChecked(true); -// } else { -// thrProductsEntity.setChecked(false); -// } -// } PageInfo pageInfo; pageInfo = new PageInfo<>(thrCorpEntities); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); @@ -218,7 +195,11 @@ public class ThrProductsController { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "每次只能上传一个文件!"); } ThreadUtil.execAsync(() -> { - thrProductsService.uploadPi(files, thirdSys); + try { + thrProductsService.uploadPi(files.get(0).getBytes(), files.get(0).getName(), thirdSys); + } catch (IOException e) { + e.printStackTrace(); + } }); return ResultVOUtils.success("正在导入中,稍后请刷新页面查看"); } @@ -254,7 +235,13 @@ public class ThrProductsController { ThreadUtil.execAsync(() -> { - thrProductsService.downloadByRequest(filterThrProductsRequest); + try { + thrProductsService.downloadByRequest(filterThrProductsRequest); + } catch (Exception e) { + log.error("下载异常", e); + e.printStackTrace(); + } + }); return ResultVOUtils.success("后台正在下载,请稍后刷新查看!"); } diff --git a/src/main/java/com/glxp/api/http/ErpBasicClient.java b/src/main/java/com/glxp/api/http/ErpBasicClient.java index 436d5ec0c..bbd0a1c27 100644 --- a/src/main/java/com/glxp/api/http/ErpBasicClient.java +++ b/src/main/java/com/glxp/api/http/ErpBasicClient.java @@ -22,6 +22,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.File; import java.util.List; /** @@ -44,7 +45,6 @@ public class ErpBasicClient { BeanUtils.copyProperties(thrUnitMaintainFilterRequest, udiwmsUnitRequest); udiwmsUnitRequest.setUnitId(thrUnitMaintainFilterRequest.getErpId()); ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thrUnitMaintainFilterRequest.getThirdSysFk()); - try { String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/getUnits"; String response = httpOkClient.uCloudPost(url, udiwmsUnitRequest, thrSystemEntity); @@ -158,16 +158,14 @@ public class ErpBasicClient { * @param thirdSys * @return */ - public BaseResponse uploadPi(List files, String thirdSys) { + public BaseResponse uploadPi(byte[] bytes, String fileName, String thirdSys) { ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thirdSys); String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/pi/upload"; try { MultipartBody.Builder builder = new MultipartBody.Builder() .setType(MultipartBody.FORM); - for (MultipartFile file : files) { - builder.addFormDataPart("file", file.getOriginalFilename(), RequestBody.create(MediaType.parse("application/vnd.ms-excel"), file.getBytes())); - } + builder.addFormDataPart("file", fileName, RequestBody.create(MediaType.parse("application/vnd.ms-excel"), bytes)); builder.addFormDataPart("thirdSys", thirdSys); MultipartBody multipartBody = builder.build(); diff --git a/src/main/java/com/glxp/api/req/thrsys/ThrUnitMaintainFilterRequest.java b/src/main/java/com/glxp/api/req/thrsys/ThrUnitMaintainFilterRequest.java index 7c950df79..24a55904b 100644 --- a/src/main/java/com/glxp/api/req/thrsys/ThrUnitMaintainFilterRequest.java +++ b/src/main/java/com/glxp/api/req/thrsys/ThrUnitMaintainFilterRequest.java @@ -1,6 +1,7 @@ package com.glxp.api.req.thrsys; +import cn.hutool.core.util.StrUtil; import com.glxp.api.util.page.ListPageRequest; import com.glxp.api.res.thrsys.ThrCorpsResponse; import lombok.Data; @@ -28,4 +29,18 @@ public class ThrUnitMaintainFilterRequest extends ListPageRequest { private Boolean isDownThrSys; private String lastUpdateTime; List thrCorpEntities; + + + public String getThirdSys() { + if (StrUtil.isEmpty(thirdSys)) + return thirdSysFk; + return thirdSys; + } + + public String getThirdSysFk() { + + if (StrUtil.isEmpty(thirdSysFk)) + return thirdSys; + return thirdSysFk; + } } diff --git a/src/main/java/com/glxp/api/service/sync/HeartService.java b/src/main/java/com/glxp/api/service/sync/HeartService.java index 9164be85d..1572fff76 100644 --- a/src/main/java/com/glxp/api/service/sync/HeartService.java +++ b/src/main/java/com/glxp/api/service/sync/HeartService.java @@ -31,6 +31,7 @@ import com.glxp.api.http.sync.SpGetHttpClient; import com.glxp.api.idc.service.FileService; import com.glxp.api.idc.service.IdcService; import com.glxp.api.req.sync.SpsSyncDataRequest; +import com.glxp.api.res.inv.InnerOrderPrintResponse; import com.glxp.api.res.sync.*; import com.glxp.api.service.auth.*; import com.glxp.api.service.basic.EntrustReceService; @@ -1614,7 +1615,13 @@ public class HeartService { supManufacturerDao.replaceBatch(supManufacturerList); } if (CollectionUtil.isNotEmpty(supProductList)) { - supProductDao.replaceBatch(supProductList); + List> splits = CustomUtil.splitList(supProductList, 100); + if (CollUtil.isNotEmpty(splits)) { + for (List items : splits) { + supProductDao.replaceBatch(items); + } + } + } if (CollUtil.isNotEmpty(syncFiles)) { // fileService.download(syncFiles); diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java b/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java index c6ff97012..40f445e35 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java @@ -6,6 +6,7 @@ import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.thrsys.ThrCorpEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.thrsys.FilterThrCorpRequest; +import com.glxp.api.req.thrsys.ThrUnitMaintainFilterRequest; import com.glxp.api.res.thrsys.ThrCorpsResponse; import com.glxp.api.res.thrsys.ThrUnitMaintainResponse; @@ -42,4 +43,5 @@ public interface ThrCorpService extends IService { */ BaseResponse downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity); + public BaseResponse downloadByRequest(ThrUnitMaintainFilterRequest request); } diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrCorpsDlService.java b/src/main/java/com/glxp/api/service/thrsys/ThrCorpsDlService.java index aee1de9c1..2f5909e5e 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrCorpsDlService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrCorpsDlService.java @@ -45,7 +45,7 @@ public class ThrCorpsDlService { ThrCorpExportLogService thrCorpExportLogService; @Resource private ThrCorpImportDetailService thrCorpImportDetailService; -// @Value("${SPSYNC_IP}") + // @Value("${SPSYNC_IP}") // private String spsSyncUrl; @Resource ErpBasicClient erpBasicClient; @@ -353,9 +353,9 @@ public class ThrCorpsDlService { public List> genExcelData(FilterThrCorpRequest filterThrOrderRequest) { List> excelData = new ArrayList<>(); - List thrCorpEntityList=new ArrayList<>(); + List thrCorpEntityList = new ArrayList<>(); List thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrOrderRequest); - if(thrCorpsResponseList.size()>0){ + if (thrCorpsResponseList.size() > 0) { thrCorpEntityList = thrCorpsResponseList.stream().map( item -> { ThrCorpEntity thrCorpEntity = new ThrCorpEntity(); @@ -419,12 +419,12 @@ public class ThrCorpsDlService { exportData.addAll(thrCorpEntities); } else { //根据查询条件一键导出数据库往来单位 - List thrCorpEntityList=new ArrayList<>(); + List thrCorpEntityList = new ArrayList<>(); FilterThrCorpRequest filterThrCorpRequest = new FilterThrCorpRequest(); BeanUtils.copyProperties(thrCorpExportRequest, filterThrCorpRequest); filterThrCorpRequest.setPage(null); List thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrCorpRequest); - if(thrCorpsResponseList.size()>0){ + if (thrCorpsResponseList.size() > 0) { thrCorpEntityList = thrCorpsResponseList.stream().map( item -> { ThrCorpEntity thrCorpEntity = new ThrCorpEntity(); @@ -476,12 +476,12 @@ public class ThrCorpsDlService { exportData.addAll(thrCorpEntities); } else { //根据查询条件一键导出数据库往来单位 - List thrCorpEntityList=new ArrayList<>(); + List thrCorpEntityList = new ArrayList<>(); FilterThrCorpRequest filterThrCorpRequest = new FilterThrCorpRequest(); BeanUtils.copyProperties(thrCorpExportRequest, filterThrCorpRequest); filterThrCorpRequest.setPage(null); List thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrCorpRequest); - if(thrCorpsResponseList.size()>0){ + if (thrCorpsResponseList.size() > 0) { thrCorpEntityList = thrCorpsResponseList.stream().map( item -> { ThrCorpEntity thrCorpEntity = new ThrCorpEntity(); diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java index f9ac1ad55..c59b4e693 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java @@ -49,7 +49,7 @@ public interface ThrProductsService extends IService { * @param thirdSys * @return */ - BaseResponse uploadPi(List files, String thirdSys); + BaseResponse uploadPi(byte[] bytes, String fileName, String thirdSys); /** * 将上传的第三方系统的数据插入到数据库 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 00f65773b..f179f6269 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,6 +1,7 @@ package com.glxp.api.service.thrsys.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.glxp.api.common.res.BaseResponse; @@ -47,11 +48,19 @@ public class ThrCorpServiceImpl extends ServiceImpl i @Override public boolean insertThrCorps(ThrCorpEntity thrCorpEntity) { + if (thrCorpEntity.getId() == null) { + thrCorpEntity.setId(IdUtil.getSnowflakeNextId()); + } return thrCorpDao.insertThrCorps(thrCorpEntity); } @Override public boolean insertThrCorpss(List thrCorpEntitys) { + for (ThrCorpEntity thrCorpEntity : thrCorpEntitys) { + if (thrCorpEntity.getId() == null) { + thrCorpEntity.setId(IdUtil.getSnowflakeNextId()); + } + } return thrCorpDao.insertThrCorpss(thrCorpEntitys); } @@ -125,7 +134,51 @@ public class ThrCorpServiceImpl extends ServiceImpl i BeanUtil.copyProperties(thrCorpsResponse, thrCorpEntity); thrCorpEntity.setCreateTime(new Date()); thrCorpEntity.setUpdateTime(new Date()); - thrCorpEntity.setId(null); + thrCorpEntity.setId(IdUtil.getSnowflakeNextId()); + thrCorpEntity.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk()); + thrCorpDao.insertThrCorps(thrCorpEntity); + } else { + boolean isChange = verifyDataChange(thrCorpEntity, thrCorpsResponse); + if (isChange) { + thrCorpEntity.setUpdateTime(new Date()); + thrCorpDao.updateThrCorps(thrCorpEntity); + } + } + }); + + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return baseResponse; + } + } + + return ResultVOUtils.success("下载完成"); + } + + @Override + public BaseResponse downloadByRequest(ThrUnitMaintainFilterRequest request) { + int page = 1; + int limit = 100; + while (true) { + request.setPage(page); + request.setLimit(limit); + request.setThirdSysFk(request.getThirdSys()); + BaseResponse> baseResponse = erpBasicClient.getErpCrop(request); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.forEach(thrCorpsResponse -> { + ThrCorpEntity thrCorpEntity = thrCorpDao.selectByUnitIdAndThirdId(thrCorpsResponse.getUnitId(), request.getThirdSys()); + if (null == thrCorpEntity) { + thrCorpEntity = new ThrCorpEntity(); + BeanUtil.copyProperties(thrCorpsResponse, thrCorpEntity); + thrCorpEntity.setCreateTime(new Date()); + thrCorpEntity.setUpdateTime(new Date()); + thrCorpEntity.setThirdSysFk(request.getThirdSys()); + thrCorpEntity.setId(IdUtil.getSnowflakeNextId()); thrCorpDao.insertThrCorps(thrCorpEntity); } else { boolean isChange = verifyDataChange(thrCorpEntity, thrCorpsResponse); 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 45e4bd45f..4bd4fcc4a 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 @@ -130,8 +130,8 @@ public class ThrProductsServiceImpl extends ServiceImpl files, String thirdSys) { - BaseResponse baseResponse = erpBasicClient.uploadPi(files, thirdSys); + public BaseResponse uploadPi(byte[] bytes, String fileName, String thirdSys) { + BaseResponse baseResponse = erpBasicClient.uploadPi(bytes, fileName, thirdSys); if (baseResponse.getCode() == 20000) { return ResultVOUtils.success("导入成功"); } else { @@ -153,10 +153,11 @@ public class ThrProductsServiceImpl extends ServiceImpl> baseResponse = erpBasicClient.getErpProducts(filterThrProductsRequest); if (baseResponse.getCode() == 20000) { @@ -230,6 +234,7 @@ public class ThrProductsServiceImpl extends ServiceImpl> keyMap = new ConcurrentHashMap<>(5); - - private volatile ExecutorService executor; - - /** - * 获取执行任务的线程池 - * - * @return - */ - private ExecutorService getExecutor() { - if (null == executor) { - synchronized (this) { - log.info("初始化第三方系统接口执行线程池"); - executor = ThreadUtil.newExecutor(10, 100, Integer.MAX_VALUE); - } - } - return executor; - } - - @Resource - private RedisUtil redisUtil; - @Resource - private ThrSystemDetailDao thrSystemDetailDao; - @Resource - private ThrInvWarehouseService thrInvWarehouseService; - @Resource - private ThrCorpService thrCorpService; - @Resource - private ThrProductsService thrProductsService; - @Resource - private IThrBusTypeOriginService thrBusTypeOriginService; - @Resource - private IoOrderService orderService; - - @Scheduled(fixedRate = 1 * 1000, initialDelay = 60 * 1000) - public void scanInterface() { - log.info("开始扫描自动执行的第三方接口列表"); - List list = thrSystemDetailDao.selectAutoExecuteList(); - if (CollUtil.isNotEmpty(list)) { - log.info("本次查询到的接口列表数量:{}", list.size()); - list.parallelStream().forEach(thrSystemDetailEntity -> { - switch (thrSystemDetailEntity.getKey()) { - case ThirdSysConstant.WAREHOUSE_QUERY_URL: - //下载第三方仓库信息 - downloadThrInv(thrSystemDetailEntity); - break; - case ThirdSysConstant.CORP_URL: - //下载往来单位信息 - downloadThrCorp(thrSystemDetailEntity); - break; - case ThirdSysConstant.PI_QUERY_URL: - //下载第三方产品信息 - downloadThrPi(thrSystemDetailEntity); - break; - case ThirdSysConstant.BUS_TYPE_QUERY_URL: - //下载第三方单据类型 - downloadThrBusType(thrSystemDetailEntity); - break; - case ThirdSysConstant.ORDER_SUBMIT_URL: - //提交单据 - submitOrder(thrSystemDetailEntity); - break; - default: - //其他接口暂不处理 - break; - } - }); - } else { - log.info("未配置自动执行的第三方接口列表"); - } - } - - /** - * 提交单据到第三方系统 - * - * @param thrSystemDetailEntity - */ - private void submitOrder(ThrSystemDetailEntity thrSystemDetailEntity) { - //校验任务并更新redis数据执行标识 - if (verifyTask(thrSystemDetailEntity)) { - getExecutor().submit(() -> { - log.info("开始提交单据到第三方系统"); - try { - orderService.submitOrderToThrSys(thrSystemDetailEntity); - } catch (Exception e) { - log.error("提交单据到第三方系统异常", e); - } finally { - updateTask(getTaskKey(thrSystemDetailEntity)); - } - log.info("提交单据到第三方系统完成"); - }); - } - } - - /** - * 下载第三方单据类型 - * - * @param thrSystemDetailEntity - */ - private void downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity) { - //校验任务并更新redis数据执行标识 - if (verifyTask(thrSystemDetailEntity)) { - getExecutor().submit(() -> { - log.info("开始下载第三方单据类型"); - try { - thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity); - } catch (Exception e) { - log.error("下载第三方单据类型异常", e); - } finally { - updateTask(getTaskKey(thrSystemDetailEntity)); - } - log.info("第三方单据类型下载完成"); - }); - } - } - - /** - * 下载第三方产品信息 - * - * @param thrSystemDetailEntity - */ - private void downloadThrPi(ThrSystemDetailEntity thrSystemDetailEntity) { - //校验任务并更新redis数据执行标识 - if (verifyTask(thrSystemDetailEntity)) { - getExecutor().submit(() -> { - log.info("开始下载第三方产品信息"); - try { - thrProductsService.downloadThrPi(thrSystemDetailEntity); - } catch (Exception e) { - log.error("下载第三方产品信息异常", e); - } finally { - updateTask(getTaskKey(thrSystemDetailEntity)); - } - log.info("第三方产品信息下载完成"); - }); - } - } - - /** - * 下载第三方往来单位 - * - * @param thrSystemDetailEntity - */ - private void downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity) { - //校验任务并更新redis数据执行标识 - if (verifyTask(thrSystemDetailEntity)) { - getExecutor().submit(() -> { - log.info("开始下载第三方往来单位信息"); - try { - thrCorpService.downloadThrCorp(thrSystemDetailEntity); - } catch (Exception e) { - log.error("下载第三方往来单位异常", e); - } finally { - updateTask(getTaskKey(thrSystemDetailEntity)); - } - log.info("第三方往来单位信息下载完成"); - }); - } - } - - /** - * 下载第三方系统仓库 - * - * @param thrSystemDetailEntity - */ - private void downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity) { - //校验任务并更新redis数据执行标识 - if (verifyTask(thrSystemDetailEntity)) { - getExecutor().submit(() -> { - log.info("开始下载第三方仓库信息"); - try { - thrInvWarehouseService.downloadThrInv(thrSystemDetailEntity); - } catch (Exception e) { - log.error("下载第三方仓库信息异常", e); - } finally { - //保证任务标识一定会被修改回去 - updateTask(getTaskKey(thrSystemDetailEntity)); - } - log.info("第三方仓库信息下载完成"); - }); - } - } - - /** - * 更新任务状态为已完成 - * - * @param taskKey - */ - private void updateTask(String taskKey) { - ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey); - vo.setFinished(true); - redisUtil.set(taskKey, vo); - } - - /** - * 校验当前任务是否可以执行 - * - * @param thrSystemDetailEntity - * @return - */ - private boolean verifyTask(ThrSystemDetailEntity thrSystemDetailEntity) { - String taskKey = getTaskKey(thrSystemDetailEntity); - ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey); - if (null != vo && !vo.isFinished()) { - log.info("有任务尚未执行完成,当前任务key:{}", taskKey); - return false; - } - long nextTime = DateUtil.offsetMonth(new Date(), thrSystemDetailEntity.getTime()).getTime(); - vo = Optional.ofNullable(vo).orElse(new ThirdSysInterfaceExecuteVo()); - vo.setKey(taskKey); - vo.setNextTime(nextTime); - vo.setFinished(false); - redisUtil.set(taskKey, vo); - return true; - } - - /** - * 获取上一次执行结果 - * - * @param taskKey - * @return - */ - private ThirdSysInterfaceExecuteVo getLastResult(String taskKey) { - String json = redisUtil.getJSON(taskKey); - return StrUtil.isBlank(json) ? null : JSONUtil.toBean(json, ThirdSysInterfaceExecuteVo.class); - } - - /** - * 拼接redis Key - * - * @param thrSystemDetailEntity - * @return - */ - private String getTaskKey(ThrSystemDetailEntity thrSystemDetailEntity) { - String key = ""; - Map keys = keyMap.get(thrSystemDetailEntity.getThirdSysFk()); - if (CollUtil.isEmpty(keys)) { - Map map = new HashMap<>(1); - key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey(); - map.put(thrSystemDetailEntity.getKey(), key); - keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map); - } else { - key = keys.get(thrSystemDetailEntity.getKey()); - if (StrUtil.isBlank(key)) { - key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey(); - Map map = new HashMap<>(1); - map.put(thrSystemDetailEntity.getKey(), key); - keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map); - } - } - return key; - } - -} diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml index d767b3ff2..0a184c924 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml @@ -26,12 +26,12 @@ - + replace - INTO thr_corp - (unitId, name, spell, addr, creditNo, - contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark) - values (#{unitId}, + INTO thr_corp + (id, unitId, name, spell, addr, creditNo, + contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark) + values (#{id}, #{unitId}, #{name}, #{spell}, #{addr}, @@ -48,13 +48,13 @@ replace INTO thr_corp - (unitId, name, spell, addr, creditNo, - contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark) - values + (id, unitId, name, spell, addr, creditNo, + contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark) + values - (#{item.unitId}, + (#{item.id}, #{item.unitId}, #{item.name}, #{item.spell}, #{item.addr}, @@ -134,8 +134,8 @@ replace - into thr_corp (unitId, spell, addr, creditNo, contact, mobile, thirdSysFk, name, updateTime, createUser, - createTime, updateUser, remark) + into thr_corp (unitId, spell, addr, creditNo, contact, mobile, thirdSysFk, name, updateTime, createUser, + createTime, updateUser, remark) values (#{unitId}, #{spell}, #{addr}, @@ -183,7 +183,7 @@ resultType="com.glxp.api.entity.thrsys.ThrSystemDetailEntity"> select basic_third_sys_detail.*, basic_third_sys.thridUrl FROM basic_third_sys_detail - inner join basic_third_sys on basic_third_sys_detail.thirdSysFk = basic_third_sys.thirdId + inner join basic_third_sys on basic_third_sys_detail.thirdSysFk = basic_third_sys.thirdId WHERE basic_third_sys_detail.key = #{key} and basic_third_sys_detail.thirdSysFk = #{thirdSys} and basic_third_sys.enabled = 1 @@ -214,4 +214,4 @@ - \ No newline at end of file +