From f639d3be4549a1175b0c3ec07c902b28c4b768c2 Mon Sep 17 00:00:00 2001 From: wangwei <1610949092@qq.com> Date: Fri, 14 Mar 2025 18:18:19 +0800 Subject: [PATCH] =?UTF-8?q?3/14=20=E4=BC=98=E5=8C=961.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/glxp/api/http/ErpBasicClient.java | 2 - .../thrsys/impl/ThrDeptServiceImpl.java | 95 ++++++++++++++----- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/glxp/api/http/ErpBasicClient.java b/src/main/java/com/glxp/api/http/ErpBasicClient.java index 736777415..dbb57956e 100644 --- a/src/main/java/com/glxp/api/http/ErpBasicClient.java +++ b/src/main/java/com/glxp/api/http/ErpBasicClient.java @@ -131,11 +131,9 @@ public class ErpBasicClient { String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/getWarehouse"; try { String response = httpOkClient.uCloudPost(url, udiwmsWarehouseRequest); - log.error("获取当前部门数据" + response); BaseResponse> listBaseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); - return listBaseResponse; } catch (Exception e) { log.error("获取第三方系统的仓库货位码异常", e); diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrDeptServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrDeptServiceImpl.java index 6a0d2d4d3..afa430e61 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrDeptServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrDeptServiceImpl.java @@ -1,7 +1,11 @@ package com.glxp.api.service.thrsys.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.glxp.api.common.res.BaseResponse; @@ -20,10 +24,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; @Service @Transactional(rollbackFor = Exception.class) @@ -126,7 +130,7 @@ public class ThrDeptServiceImpl extends ServiceImpl i @Override public BaseResponse downloadThirdWarehouse(String thirdSysFk) { int page = 1; - int limit = 100; + int limit = 1000; while (true) { UdiwmsWarehouseRequest udiwmsWarehouseRequest = new UdiwmsWarehouseRequest(); udiwmsWarehouseRequest.setThirdSys(thirdSysFk); @@ -135,42 +139,89 @@ public class ThrDeptServiceImpl extends ServiceImpl i BaseResponse> baseResponse = erpBasicClient.getWarehouse(udiwmsWarehouseRequest); if (baseResponse.getCode() == 20000) { List responseList = baseResponse.getData().getList(); - List list = new ArrayList<>(); - List warehouseList = new ArrayList<>(); - for (UdiwmsWarehouseDetail response : responseList) { - ThrDeptEntity thrDeptEntity = new ThrDeptEntity(); - thrDeptEntity.setPid(0); - thrDeptEntity.setName(response.getName()); - thrDeptEntity.setCode(response.getCode()); + if (CollUtil.isNotEmpty(responseList)) { + AtomicInteger count = new AtomicInteger(); // 计数器 + responseList.forEach(item -> { + ThrDeptEntity thrDeptEntity = new ThrDeptEntity(); + ThrInvWarehouseEntity thrInvWarehouseEntity = new ThrInvWarehouseEntity(); + BeanUtil.copyProperties(item, thrDeptEntity); + BeanUtil.copyProperties(item, thrInvWarehouseEntity); + + thrDeptEntity.setPid(0); + thrDeptEntity.setName(item.getName()); + thrDeptEntity.setCode(item.getCode()); thrDeptEntity.setThirdSysFk(thirdSysFk); thrDeptEntity.setAdvanceType(false); //默认是仓库 thrDeptEntity.setStatus(1);//默认启用 thrDeptEntity.setUpdateTime(new Date()); thrDeptEntity.setId(IdUtil.getSnowflake(6, 1).nextId()); - list.add(thrDeptEntity); - ThrInvWarehouseEntity thrInvWarehouseEntity = new ThrInvWarehouseEntity(); - thrInvWarehouseEntity.setCode(response.getCode()); - thrInvWarehouseEntity.setName(response.getName()); - thrInvWarehouseEntity.setRemark(response.getRemark()); + + thrInvWarehouseEntity.setCode(item.getCode()); + thrInvWarehouseEntity.setName(item.getName()); + thrInvWarehouseEntity.setRemark(item.getRemark()); thrInvWarehouseEntity.setThirdSysFk(thirdSysFk); - thrInvWarehouseEntity.setParentId(response.getCode()); + thrInvWarehouseEntity.setParentId(item.getCode()); thrInvWarehouseEntity.setId(IdUtil.getSnowflake(6, 1).nextId() + ""); thrInvWarehouseEntity.setUpdateTime(new Date()); - warehouseList.add(thrInvWarehouseEntity); - + boolean b = thrDeptDao.exists(new LambdaQueryWrapper().eq(ThrDeptEntity::getCode, thrDeptEntity.getCode())); + if (b) { + thrDeptDao.update(thrDeptEntity, new LambdaUpdateWrapper().eq(ThrDeptEntity::getCode, thrDeptEntity.getCode())); + } else { + thrDeptDao.insert(thrDeptEntity); + } + boolean b1 = thrInvWarehouseDao.exists(new LambdaQueryWrapper().eq(ThrInvWarehouseEntity::getCode, thrInvWarehouseEntity.getCode())); + if (b1) { + thrInvWarehouseDao.update(thrInvWarehouseEntity, new LambdaUpdateWrapper().eq(ThrInvWarehouseEntity::getCode, thrInvWarehouseEntity.getCode())); + } else { + thrInvWarehouseDao.insert(thrInvWarehouseEntity); + } + + }); } - //插入数据 - thrDeptDao.insertThrDeptList(list); - thrInvWarehouseDao.insertThrInvWarehouses(warehouseList); - if (list.size() >= limit) { + if (responseList.size() >= limit) { page++; } else { break; } +// List list = new ArrayList<>(); +// List warehouseList = new ArrayList<>(); +// for (UdiwmsWarehouseDetail response : responseList) { +// ThrDeptEntity thrDeptEntity = new ThrDeptEntity(); +// thrDeptEntity.setPid(0); +// thrDeptEntity.setName(response.getName()); +// thrDeptEntity.setCode(response.getCode()); +// thrDeptEntity.setThirdSysFk(thirdSysFk); +// thrDeptEntity.setAdvanceType(false); //默认是仓库 +// thrDeptEntity.setStatus(1);//默认启用 +// thrDeptEntity.setUpdateTime(new Date()); +// thrDeptEntity.setId(IdUtil.getSnowflake(6, 1).nextId()); +// list.add(thrDeptEntity); +// +// ThrInvWarehouseEntity thrInvWarehouseEntity = new ThrInvWarehouseEntity(); +// thrInvWarehouseEntity.setCode(response.getCode()); +// thrInvWarehouseEntity.setName(response.getName()); +// thrInvWarehouseEntity.setRemark(response.getRemark()); +// thrInvWarehouseEntity.setThirdSysFk(thirdSysFk); +// thrInvWarehouseEntity.setParentId(response.getCode()); +// thrInvWarehouseEntity.setId(IdUtil.getSnowflake(6, 1).nextId() + ""); +// thrInvWarehouseEntity.setUpdateTime(new Date()); +// warehouseList.add(thrInvWarehouseEntity); +// +// +// } +// //插入数据 +// thrDeptDao.insertThrDeptList(list); +// thrInvWarehouseDao.insertThrInvWarehouses(warehouseList); +// if (list.size() >= limit) { +// page++; +// } else { +// break; +// } + } else { - return baseResponse; + return ResultVOUtils.error(500, "下载异常中断"); } }