Przeglądaj źródła

pms 同步SAP库存功能优化

zhangcl 9 godzin temu
rodzic
commit
7d3da273bd

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotsapstock/IotSapStockMapper.java

@@ -3,10 +3,12 @@ package cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.controller.admin.iotsapstock.vo.IotSapStockPageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotsapstock.IotSapStockDO;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -96,4 +98,8 @@ public interface IotSapStockMapper extends BaseMapperX<IotSapStockDO> {
                 .gt(IotSapStockDO::getSafetyStock, 0));
     }
 
+    @Select("SELECT * FROM rq_iot_sap_stock WHERE deleted = 0 AND tenant_id = 1")
+    @TenantIgnore
+    List<IotSapStockDO> allSapStocks();
+
 }

+ 6 - 76
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/sap/SyncSapStockJob.java

@@ -3,9 +3,7 @@ package cn.iocoder.yudao.module.pms.job.sap;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
-import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
-import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
-import cn.iocoder.yudao.module.pms.controller.admin.iotsapstock.vo.IotSapStockPageReqVO;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock.IotSapStockMapper;
 import cn.iocoder.yudao.module.pms.sap.SapConnector;
 import cn.iocoder.yudao.module.pms.sap.service.IotSapService;
@@ -50,7 +48,7 @@ public class SyncSapStockJob implements JobHandler {
     private DeptApi deptApi;
 
     @Override
-    @TenantJob
+    @TenantIgnore
     public String execute(String param) throws Exception {
         // 查询所有工厂 根据工厂 多线程处理 SAP 库存
         List<String> factoryCodes = factoryCodes();
@@ -65,18 +63,6 @@ public class SyncSapStockJob implements JobHandler {
             return "基础数据加载失败,无法继续同步";
         }
 
-        // 提前获取SAP连接,避免每个线程重复创建
-        /* JCoDestination destination;
-        try {
-            destination = sapConnector.getDestination();
-            // 测试连接是否有效
-            destination.ping();
-            log.info("SAP连接建立成功");
-        } catch (JCoException e) {
-            log.error("SAP连接建立失败", e);
-            return "SAP连接失败: " + e.getMessage();
-        } */
-
         long startTime = System.currentTimeMillis();
 
         // 使用单线程循环处理每个工厂(移除了多线程)
@@ -97,57 +83,6 @@ public class SyncSapStockJob implements JobHandler {
         List<String> failedFactories = new ArrayList<>();
         List<String> successFactories = new ArrayList<>();
 
-        // 一次性查询出所有已经存在的SAP库存 避免重复查询
-        /* IotSapStockPageReqVO reqVO = new IotSapStockPageReqVO();
-        List<IotSapStockDO> existStocks = TenantUtils.execute(1L, () -> iotSapStockMapper.selectList(reqVO));
-
-        // 查询出所有库存地点 对应的 deptId 工厂+库存地点 确定唯一值 因为 不同工厂的库存地点code可能重复
-        List<SapOrgRespDTO> storageLocations = TenantUtils.execute(1L, () -> sapOrgApi.getSapOrgByType(3));
-        // 查询所有工厂
-        List<SapOrgRespDTO> factories = TenantUtils.execute(1L, () -> sapOrgApi.getSapOrgByType(1));
-        // key工厂code    value工厂id
-        Map<String, Long> factoryIdPair = new HashMap<>();
-        // key工厂code    value工厂名称
-        Map<String, String> factoryNamePair = new HashMap<>();
-        // key工厂code-库存地点code    value库存地点id
-        Map<String, Long> storageLocationIdPair = new HashMap<>();
-        // key库存地点id    value工厂code-库存地点code
-        Map<Long, String> stockLocationCodeIdPair = new HashMap<>();
-        // key库存地点code  value部门id
-        Map<String, Long> locationCodeDeptIdPair = new HashMap<>();
-        // key工厂code-库存地点code    value库存地点名称描述
-        Map<String, String> stockLocationNamePair = new HashMap<>();
-        // 工厂集合
-        factories.forEach(factory -> {
-            factoryIdPair.put(factory.getFactoryCode(), factory.getId());
-            factoryNamePair.put(factory.getFactoryCode(), factory.getFactoryName());
-        });
-        // pms已经维护的 库存地点 集合
-        storageLocations.forEach(location -> {
-            System.out.println("当前库存地点信息:" + location.getFactoryCode() + " - " + location.getStorageLocationCode());
-            String uniqueKey = StrUtil.join("-", location.getFactoryCode(), location.getStorageLocationCode());
-            stockLocationCodeIdPair.put(location.getId(), uniqueKey);
-            storageLocationIdPair.put(uniqueKey, location.getId());
-            stockLocationNamePair.put(uniqueKey, location.getStorageLocationName());
-        });
-        // todo 筛选出pms系统中未维护的 库存地点 信息(工厂-库存地点编码)
-        // 查询所有部门
-        List<DeptRespDTO> depts = TenantUtils.execute(1L, () -> deptApi.getDeptList());
-        // 筛选出所有设置了 库存地点 的部门
-        depts.forEach(dept -> {
-            Set<Long> stockLocationIds = dept.getStockLocationIds();
-            // 循环遍历 stockLocationIds
-            if (CollUtil.isNotEmpty(stockLocationIds)) {
-                stockLocationIds.forEach(locationId -> {
-                    if (stockLocationCodeIdPair.containsKey(locationId)) {
-                        // 当前部门设置的 库存地点 uniqueKey = 工厂编码+库存地点编码
-                        String uniqueKey = stockLocationCodeIdPair.get(locationId);
-                        locationCodeDeptIdPair.put(uniqueKey, dept.getId());
-                    }
-                });
-            }
-        }); */
-
         for (FactorySyncResult result : results) {
             if (result.success) {
                 if (CollUtil.isNotEmpty(result.stockData)) {
@@ -319,15 +254,10 @@ public class SyncSapStockJob implements JobHandler {
             context.destination = sapConnector.getDestination();
             context.destination.ping(); // 测试连接
 
-            // 查询基础数据
-            context.existStocks = TenantUtils.executeIgnore(() ->
-                    iotSapStockMapper.selectList());
-            context.storageLocations = TenantUtils.executeIgnore(() ->
-                    sapOrgApi.getSapOrgByType(3));
-            context.factories = TenantUtils.executeIgnore(() ->
-                    sapOrgApi.getSapOrgByType(1));
-            context.depts = TenantUtils.executeIgnore(() ->
-                    deptApi.getDeptList());
+            context.existStocks = iotSapStockMapper.allSapStocks();
+            context.depts = deptApi.ignoredTenantDepts();
+            context.storageLocations = sapOrgApi.getSapOrgByType(3);
+            context.factories = sapOrgApi.getSapOrgByType(1);
 
             // 构建映射关系
             context.buildMappings();

+ 7 - 0
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java

@@ -37,6 +37,13 @@ public interface DeptApi {
      */
     List<DeptRespDTO> getDeptList();
 
+    /**
+     * 忽略租户 查询所有部门集合
+     *
+     * @return 所有部门
+     */
+    List<DeptRespDTO> ignoredTenantDepts();
+
     /**
      * 校验部门们是否有效。如下情况,视为无效:
      * 1. 部门编号不存在

+ 7 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java

@@ -47,6 +47,13 @@ public class DeptApiImpl implements DeptApi {
         return BeanUtils.toBean(depts, DeptRespDTO.class);
     }
 
+    @Override
+    public List<DeptRespDTO> ignoredTenantDepts() {
+        DeptListReqVO reqVO = new DeptListReqVO();
+        List<DeptDO> depts = deptService.ignoredTenantDepts(reqVO);
+        return BeanUtils.toBean(depts, DeptRespDTO.class);
+    }
+
     @Override
     public void validateDeptList(Collection<Long> ids) {
         deptService.validateDeptList(ids);

+ 5 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java

@@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept;
 
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.Collection;
 import java.util.List;
@@ -39,4 +41,7 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
         return selectList(DeptDO::getLeaderUserId, id);
     }
 
+    @Select("SELECT * FROM system_dept WHERE deleted = 0 AND tenant_id = 1")
+    @TenantIgnore
+    List<DeptDO> allDepts();
 }

+ 8 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java

@@ -60,6 +60,14 @@ public interface DeptService {
      */
     List<DeptDO> getDeptList(DeptListReqVO reqVO);
 
+    /**
+     * 忽略租户 查询所有部门列表
+     *
+     * @param reqVO 筛选条件请求 VO
+     * @return 部门列表
+     */
+    List<DeptDO> ignoredTenantDepts(DeptListReqVO reqVO);
+
     /**
      * 筛选公司层级的部门列表
      *

+ 5 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java

@@ -258,6 +258,11 @@ public class DeptServiceImpl implements DeptService {
         return list;
     }
 
+    @Override
+    public List<DeptDO> ignoredTenantDepts(DeptListReqVO reqVO) {
+        return deptMapper.allDepts();
+    }
+
     @Override
     public List<DeptDO> companyLevelDepts(DeptListReqVO reqVO) {
         Set<Long> parentIds = new HashSet<>();