|
@@ -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();
|