|
@@ -11,21 +11,34 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotlockstock.vo.IotLockStockPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmaterial.vo.IotMaterialPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicematerial.IotDeviceMaterialDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotlockstock.IotLockStockDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaterial.IotMaterialDO;
|
|
|
import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicematerial.IotDeviceMaterialService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotlockstock.IotLockStockService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotmainworkorder.IotMainWorkOrderService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotmainworkorderbom.IotMainWorkOrderBomService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotmaterial.IotMaterialService;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptSapOrgApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptSapOrgRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.saporg.SapOrgApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.saporg.dto.SapOrgRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -59,6 +72,16 @@ public class IotMainWorkOrderBomController {
|
|
|
private IotMainWorkOrderService iotMainWorkOrderService;
|
|
|
@Resource
|
|
|
private IotDeviceMaterialService iotDeviceMaterialService;
|
|
|
+ @Resource
|
|
|
+ private IotMaterialService iotMaterialService;
|
|
|
+ @Autowired
|
|
|
+ private DeptService deptService;
|
|
|
+ @Autowired
|
|
|
+ private DeptSapOrgApi deptSapOrgApi;
|
|
|
+ @Autowired
|
|
|
+ private IotLockStockService iotLockStockService;
|
|
|
+ @Autowired
|
|
|
+ private SapOrgApi sapOrgApi;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建PMS 保养计划明细BOM")
|
|
@@ -186,23 +209,131 @@ public class IotMainWorkOrderBomController {
|
|
|
reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
reqVO.setBomNodeIds(new ArrayList<>(bomNodeIds));
|
|
|
List<IotDeviceMaterialDO> deviceBomMaterials = iotDeviceMaterialService.deviceBomMaterials(reqVO);
|
|
|
- Map<String, List<IotDeviceMaterialDO>> deviceBomMaterialPair = new HashMap<>();
|
|
|
+ // 将 deviceBomMaterials 集合中的对象类型转换成 IotDeviceMaterialRespVO
|
|
|
+ // key设备id-bomid value保养项关联的物料列表
|
|
|
+ Map<String, List<IotDeviceMaterialRespVO>> deviceBomMaterialPair = new HashMap<>();
|
|
|
+ Set<String> materialCodes = new HashSet<>();
|
|
|
if (CollUtil.isNotEmpty(deviceBomMaterials)) {
|
|
|
- deviceBomMaterials.forEach(bomMaterial -> {
|
|
|
+ deviceBomMaterials.forEach(material -> {
|
|
|
+ // 设置物料编码组合
|
|
|
+ materialCodes.add(material.getCode());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 查询每个保养项上 关联的物料数量 关联查询并直接绑定 设备所属部门的SAP组织成本中心的库存物料 与 保养项关联的物料 匹配
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
+ Set<Long> allDeptIds = new HashSet<>();
|
|
|
+ List<IotLockStockDO> lockStocks = new ArrayList<>();
|
|
|
+ Map<String, IotLockStockDO> lockStockPair = new HashMap<>();
|
|
|
+ Map<Long, String> factoryPair = new HashMap<>();
|
|
|
+ Map<Long, String> costCenterPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceMap)) {
|
|
|
+ deviceMap.forEach((k,v) -> {
|
|
|
+ // k设备id v设备对象
|
|
|
+ deptIds.add(v.getDeptId());
|
|
|
+ });
|
|
|
+ // 查询每个部门下的所有子部门 将所有 部门id设置到 相同集合
|
|
|
+ if (CollUtil.isNotEmpty(deptIds)) {
|
|
|
+ deptIds.forEach(deptId -> {
|
|
|
+ Set<Long> tempDeptIds = new HashSet<>();
|
|
|
+ tempDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ tempDeptIds.add(deptId);
|
|
|
+ allDeptIds.addAll(tempDeptIds);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 查询所有部门关联的SAP工厂 成本中心 列表
|
|
|
+ List<DeptSapOrgRespDTO> sapOrgS = deptSapOrgApi.getSapOrgListByDeptIds(allDeptIds);
|
|
|
+ Set<Long> factoryIds = new HashSet<>();
|
|
|
+ Set<Long> costCenterIds = new HashSet<>();
|
|
|
+ Set<Long> sapOrgIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(sapOrgS)) {
|
|
|
+ sapOrgS.forEach(org -> {
|
|
|
+ if (ObjUtil.isNotEmpty(org.getFactoryId())) {
|
|
|
+ factoryIds.add(org.getFactoryId());
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(org.getCostCenterId())) {
|
|
|
+ costCenterIds.add(org.getCostCenterId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollUtil.isNotEmpty(factoryIds)) {
|
|
|
+ sapOrgIds.addAll(factoryIds);
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(costCenterIds)) {
|
|
|
+ sapOrgIds.addAll(costCenterIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询所有sap 工厂 成本中心下的指定物料的库存信息
|
|
|
+ if (CollUtil.isNotEmpty(factoryIds) && CollUtil.isNotEmpty(costCenterIds) && CollUtil.isNotEmpty(materialCodes)) {
|
|
|
+ IotLockStockPageReqVO stockReqVO = new IotLockStockPageReqVO();
|
|
|
+ stockReqVO.setFactoryIds(factoryIds);
|
|
|
+ stockReqVO.setCostCenterIds(costCenterIds);
|
|
|
+ stockReqVO.setMaterialCodes(materialCodes);
|
|
|
+ lockStocks = iotLockStockService.getIotLockStocks(stockReqVO);
|
|
|
+ // 查询各工厂 成本中心的名称
|
|
|
+ List<SapOrgRespDTO> sapOrganizations = sapOrgApi.getSapOrgList(sapOrgIds);
|
|
|
+ if (CollUtil.isNotEmpty(sapOrganizations)) {
|
|
|
+ sapOrganizations.forEach(org -> {
|
|
|
+ // 工厂 名称集合
|
|
|
+ if (ObjUtil.isNotEmpty(org.getType()) && 1==org.getType()) {
|
|
|
+ factoryPair.put(org.getId(), org.getFactoryName());
|
|
|
+ }
|
|
|
+ // 成本中心名称集合
|
|
|
+ if (ObjUtil.isNotEmpty(org.getType()) && 2==org.getType()) {
|
|
|
+ costCenterPair.put(org.getId(), org.getCostCenterName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(lockStocks)) {
|
|
|
+ lockStocks.forEach(stock -> {
|
|
|
+ lockStockPair.put(stock.getMaterialCode(), stock);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询集合中所有物料的单位
|
|
|
+ IotMaterialPageReqVO materialReqVO = new IotMaterialPageReqVO();
|
|
|
+ materialReqVO.setCodes(new ArrayList<>(materialCodes));
|
|
|
+ List<IotMaterialDO> materials = iotMaterialService.getIotMaterials(materialReqVO);
|
|
|
+ Map<String, String> materialUnitPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(materials)) {
|
|
|
+ materials.forEach(material -> {
|
|
|
+ materialUnitPair.put(material.getCode(), material.getUnit());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 设置保养项关联的物料列表
|
|
|
+ List<IotDeviceMaterialRespVO> deviceMaterials = BeanUtils.toBean(deviceBomMaterials, IotDeviceMaterialRespVO.class);
|
|
|
+ // 设置保养项关联的物料的本地库存
|
|
|
+ deviceMaterials.forEach(material -> {
|
|
|
+ if (lockStockPair.containsKey(material.getCode())) {
|
|
|
+ IotLockStockDO tempLockStock = lockStockPair.get(material.getCode());
|
|
|
+ material.setStockQuantity(tempLockStock.getQuantity());
|
|
|
+ material.setUnitPrice(tempLockStock.getUnitPrice());
|
|
|
+ material.setFactoryId(tempLockStock.getFactoryId());
|
|
|
+ material.setCostCenterId(tempLockStock.getCostCenterId());
|
|
|
+ if (factoryPair.containsKey(tempLockStock.getFactoryId())) {
|
|
|
+ material.setFactory(factoryPair.get(tempLockStock.getFactoryId()));
|
|
|
+ }
|
|
|
+ if (costCenterPair.containsKey(tempLockStock.getCostCenterId())) {
|
|
|
+ material.setCostCenter(costCenterPair.get(tempLockStock.getCostCenterId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ deviceMaterials.forEach(bomMaterial -> {
|
|
|
+ if (materialUnitPair.containsKey(bomMaterial.getCode())) {
|
|
|
+ bomMaterial.setUnit(materialUnitPair.get(bomMaterial.getCode()));
|
|
|
+ }
|
|
|
String uniqueKey = StrUtil.join("-", bomMaterial.getDeviceId(), bomMaterial.getBomNodeId());
|
|
|
if (deviceBomMaterialPair.containsKey(uniqueKey)) {
|
|
|
- List<IotDeviceMaterialDO> tempBomMaterials = deviceBomMaterialPair.get(uniqueKey);
|
|
|
+ List<IotDeviceMaterialRespVO> tempBomMaterials = deviceBomMaterialPair.get(uniqueKey);
|
|
|
tempBomMaterials.add(bomMaterial);
|
|
|
deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
} else {
|
|
|
- List<IotDeviceMaterialDO> tempBomMaterials = new ArrayList<>();
|
|
|
+ List<IotDeviceMaterialRespVO> tempBomMaterials = new ArrayList<>();
|
|
|
tempBomMaterials.add(bomMaterial);
|
|
|
deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- // 2. 转换成 VO
|
|
|
return BeanUtils.toBean(BOMs, IotMainWorkOrderBomRespVO.class, bomVO -> {
|
|
|
// 设置设备相关信息
|
|
|
MapUtils.findAndThen(deviceMap, bomVO.getDeviceId(),
|