测试url,erp改为base
This commit is contained in:
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP资产卡片")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-asset")
|
||||
@RequestMapping("/base/erp-asset")
|
||||
@Validated
|
||||
public class ErpAssetController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP物料清单(BOM)")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-bom")
|
||||
@RequestMapping("/base/erp-bom")
|
||||
@Validated
|
||||
public class ErpBomController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP物料清单(BOM)明细")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-bom-detail")
|
||||
@RequestMapping("/base/erp-bom-detail")
|
||||
@Validated
|
||||
public class ErpBomDetailController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP公司")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-company")
|
||||
@RequestMapping("/base/erp-company")
|
||||
@Validated
|
||||
public class ErpCompanyController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP合同映射")
|
||||
@RestController
|
||||
@RequestMapping("/bse/erp-contract")
|
||||
@RequestMapping("/base/erp-contract")
|
||||
@Validated
|
||||
public class ErpContractController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP成本中心")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-costcenter")
|
||||
@RequestMapping("/base/erp-costcenter")
|
||||
@Validated
|
||||
public class ErpCostcenterController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP客商信息")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-customer")
|
||||
@RequestMapping("/base/erp-customer")
|
||||
@Validated
|
||||
public class ErpCustomerController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP工厂")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-factory")
|
||||
@RequestMapping("/base/erp-factory")
|
||||
@Validated
|
||||
public class ErpFactoryController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP内部订单")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-internal-order")
|
||||
@RequestMapping("/base/erp-internal-order")
|
||||
@Validated
|
||||
public class ErpInternalOrderController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP物料信息")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-material")
|
||||
@RequestMapping("/base/erp-material")
|
||||
@Validated
|
||||
public class ErpMaterialController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP工艺路线")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-process")
|
||||
@RequestMapping("/base/erp-process")
|
||||
@Validated
|
||||
public class ErpProcessController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP工艺路线明细")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-process-detail")
|
||||
@RequestMapping("/base/erp-process-detail")
|
||||
@Validated
|
||||
public class ErpProcessDetailController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP生产订单")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-productive-order")
|
||||
@RequestMapping("/base/erp-productive-order")
|
||||
@Validated
|
||||
public class ErpProductiveOrderController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP生产版本")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-productive-version")
|
||||
@RequestMapping("/base/erp-productive-version")
|
||||
@Validated
|
||||
public class ErpProductiveVersionController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP采购组织")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-purchase-organization")
|
||||
@RequestMapping("/base/erp-purchase-organization")
|
||||
@Validated
|
||||
public class ErpPurchaseOrganizationController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP销售组织")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-sales-organization")
|
||||
@RequestMapping("/base/erp-sales-organization")
|
||||
@Validated
|
||||
public class ErpSalesOrganizationController {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - ERP库位")
|
||||
@RestController
|
||||
@RequestMapping("/erp/erp-warehouse")
|
||||
@RequestMapping("/base/erp-warehouse")
|
||||
@Validated
|
||||
public class ErpWarehouseController {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.zt.plat.module.erp.service.erp;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
@@ -9,6 +11,7 @@ import com.zt.plat.module.erp.common.enums.OftenEnum;
|
||||
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpBomDetailPageReqVO;
|
||||
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpBomDetailRespVO;
|
||||
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpBomDetailSaveReqVO;
|
||||
import com.zt.plat.module.erp.dal.dataobject.erp.ErpAssetDO;
|
||||
import com.zt.plat.module.erp.dal.dataobject.erp.ErpBomDO;
|
||||
import com.zt.plat.module.erp.dal.dataobject.erp.ErpBomDetailDO;
|
||||
import com.zt.plat.module.erp.dal.mysql.erp.ErpBomDetailMapper;
|
||||
@@ -16,10 +19,12 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_BOM_DETAIL_NOT_EXISTS;
|
||||
@@ -97,25 +102,83 @@ public class ErpBomDetailServiceImpl implements ErpBomDetailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrUpdateErpBomDetail(List<ErpBomDetailDO> updateReqVO) {
|
||||
String key = "erpMap" + OftenEnum.FuncnrEnum.BOM清单.getFuncnr()+ "Detail";
|
||||
public void saveOrUpdateErpBomDetail(List<ErpBomDetailDO> updateReqVOS) {
|
||||
String key = "erpMap" + OftenEnum.FuncnrEnum.BOM清单.getFuncnr() + "Detail";
|
||||
// 1. 处理公司数据,区分新增和更新
|
||||
ProcessingResult result = processData(updateReqVOS, key);
|
||||
|
||||
// 2. 批量保存数据
|
||||
saveData(result);
|
||||
}
|
||||
|
||||
private ProcessingResult processData(List<ErpBomDetailDO> updateReqVOS, String key) {
|
||||
if (erpConfig.getRedisCacheMap(key).isEmpty()) {
|
||||
initializeMap(key);
|
||||
}
|
||||
List<ErpBomDetailDO> toUpdate = new ArrayList<>();
|
||||
List<ErpBomDetailDO> toInsert = new ArrayList<>();
|
||||
|
||||
List<String> dataArrayNumbers = new ArrayList<>();
|
||||
Map<String, Long> existingNumbers = erpConfig.getRedisCacheMap(key);
|
||||
// for (ErpBomDetailDO updateReqVO : updateReqVO){
|
||||
// String mapKey = updateReqVO.getBomId() + "-" + updateReqVO.getErpBomId();
|
||||
// if (existingNumbers.get(mapKey)!=null) {
|
||||
//
|
||||
// updateReqVO.setId(existingNumbers.get(mapKey));
|
||||
// }
|
||||
// }
|
||||
for (ErpBomDetailDO updateReqVO : updateReqVOS) {
|
||||
String mapKey = updateReqVO.getBomId() + "-" + updateReqVO.getErpBomId();
|
||||
if (updateReqVO.getId() == null) {
|
||||
toInsert.add(updateReqVO);
|
||||
} else {
|
||||
toUpdate.add(updateReqVO);
|
||||
}
|
||||
dataArrayNumbers.add(mapKey);
|
||||
}
|
||||
|
||||
Map<String, Long> deleteNumbers = new HashMap<>();
|
||||
for (Map.Entry<String, Long> entry : existingNumbers.entrySet()) {
|
||||
if (!dataArrayNumbers.contains(entry.getKey())) {
|
||||
deleteNumbers.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// erpBomDetailMapper.saveOrUpdateErpBomDetail(updateReqVO);
|
||||
return new ProcessingResult(toUpdate, toInsert, deleteNumbers, key);
|
||||
}
|
||||
|
||||
private void saveData(ProcessingResult result) {
|
||||
// 批量新增和更新
|
||||
if (!result.toInsert.isEmpty()) {
|
||||
erpBomDetailMapper.insertBatch(result.toInsert);
|
||||
// 批量查询刚插入数据的id,提升效率
|
||||
List<ErpBomDetailDO> insertedRecords = erpBomDetailMapper.selectList(
|
||||
new LambdaQueryWrapperX<ErpBomDetailDO>()
|
||||
.in(ErpBomDetailDO::getBomId, result.toInsert.stream().map(ErpBomDetailDO::getBomId).distinct().collect(Collectors.toList()))
|
||||
.in(ErpBomDetailDO::getErpBomId, result.toInsert.stream().map(ErpBomDetailDO::getErpBomId).distinct().collect(Collectors.toList()))
|
||||
);
|
||||
Map<String, Long> numberIdMap = insertedRecords.stream()
|
||||
.collect(Collectors.toMap(asset -> asset.getBomId() + "-" + asset.getErpBomId(), ErpBomDetailDO::getId));
|
||||
erpConfig.addRedisCacheMap(result.key, numberIdMap);
|
||||
}
|
||||
if (!result.toUpdate.isEmpty()) {
|
||||
erpBomDetailMapper.updateBatch(result.toUpdate);
|
||||
}
|
||||
if (!result.deleteNumbers.isEmpty()) {
|
||||
// 使用流式处理和批处理优化删除逻辑
|
||||
List<Long> idsToDelete = new ArrayList<>(result.deleteNumbers.values());
|
||||
if (!idsToDelete.isEmpty()) {
|
||||
erpBomDetailMapper.deleteByIds(idsToDelete);
|
||||
}
|
||||
erpConfig.deleteRedisCacheMap(result.key, new ArrayList<>(result.deleteNumbers.keySet()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class ProcessingResult {
|
||||
private final List<ErpBomDetailDO> toUpdate;
|
||||
private final List<ErpBomDetailDO> toInsert;
|
||||
private final Map<String, Long> deleteNumbers;
|
||||
private final String key;
|
||||
|
||||
public ProcessingResult(List<ErpBomDetailDO> toUpdate, List<ErpBomDetailDO> toInsert, Map<String, Long> deleteNumbers, String key) {
|
||||
this.toUpdate = toUpdate;
|
||||
this.toInsert = toInsert;
|
||||
this.deleteNumbers = deleteNumbers;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeMap(String key) {
|
||||
|
||||
@@ -160,6 +160,8 @@ public class ErpBomServiceImpl implements ErpBomService {
|
||||
|
||||
List<String> allnumbers = new ArrayList<>();
|
||||
List<ErpBomDetailDO> erpBomDetailDOList = new ArrayList<>();
|
||||
Map<String, Long> addnumbers = new HashMap<>();
|
||||
List<String> dataArrayNumbers = new ArrayList<>();
|
||||
for (int i = 0; i < dataArray.size(); i++) {
|
||||
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||
if (dataJson != null) {
|
||||
@@ -179,8 +181,9 @@ public class ErpBomServiceImpl implements ErpBomService {
|
||||
} else {
|
||||
// 为了避免数据重复,先将主表数据插入数据库,再获取主表ID,再插入子表数据
|
||||
erpBomMapper.insert(DO);
|
||||
numbers.put(number, DO.getId());
|
||||
addnumbers.put(number, DO.getId());
|
||||
}
|
||||
dataArrayNumbers.add(number);
|
||||
|
||||
JSONArray dataJsonItem = dataJson.getJSONArray("ITEM");
|
||||
if (dataJsonItem != null) {
|
||||
@@ -201,7 +204,15 @@ public class ErpBomServiceImpl implements ErpBomService {
|
||||
}
|
||||
}
|
||||
|
||||
return new ProcessingResult(toUpdate, erpBomDetailDOList,key, allnumbers);
|
||||
// 过滤出numbers中有,但dataArray中KOSTL没有的记录,即为需要删除的数据
|
||||
Map<String, Long> deleteNumbers = new HashMap<>();
|
||||
for (String number : numbers.keySet()) {
|
||||
if (!dataArrayNumbers.contains(number)) {
|
||||
deleteNumbers.put(number, numbers.get(number));
|
||||
}
|
||||
}
|
||||
|
||||
return new ProcessingResult(toUpdate, erpBomDetailDOList, key, allnumbers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user