|
@@ -6,20 +6,34 @@ import cn.hutool.core.util.StrUtil;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialPageReqVO;
|
|
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.iotdevicematerial.vo.IotDeviceMaterialSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotlockstock.vo.IotLockStockPageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmaterial.vo.IotMaterialPageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotsapstock.vo.IotSapStockPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicematerial.IotDeviceMaterialDO;
|
|
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.iotmaterial.IotMaterialDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotsapstock.IotSapStockDO;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicematerial.IotDeviceMaterialMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicematerial.IotDeviceMaterialMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotlockstock.IotLockStockMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotmaterial.IotMaterialMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock.IotSapStockMapper;
|
|
import cn.iocoder.yudao.module.pms.service.iotbom.IotBomService;
|
|
import cn.iocoder.yudao.module.pms.service.iotbom.IotBomService;
|
|
|
|
+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 com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -41,6 +55,18 @@ public class IotDeviceMaterialServiceImpl implements IotDeviceMaterialService {
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
@Resource
|
|
@Resource
|
|
private IotBomService iotBomService;
|
|
private IotBomService iotBomService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeptService deptService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeptSapOrgApi deptSapOrgApi;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SapOrgApi sapOrgApi;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IotLockStockMapper iotLockStockMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IotSapStockMapper iotSapStockMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IotMaterialMapper iotMaterialMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Long createIotDeviceMaterial(IotDeviceMaterialSaveReqVO createReqVO) {
|
|
public Long createIotDeviceMaterial(IotDeviceMaterialSaveReqVO createReqVO) {
|
|
@@ -169,4 +195,206 @@ public class IotDeviceMaterialServiceImpl implements IotDeviceMaterialService {
|
|
return resultCount;
|
|
return resultCount;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, List<IotDeviceMaterialRespVO>> bomMaterials(Set<Long> deptIds, Set<Long> deviceIds, Set<Long> bomNodeIds) {
|
|
|
|
+ // key设备id-bomid value保养项关联的物料列表
|
|
|
|
+ Map<String, List<IotDeviceMaterialRespVO>> deviceBomMaterialPair = new HashMap<>();
|
|
|
|
+ // 查询每个 维修/保养 项绑定的物料
|
|
|
|
+ IotDeviceMaterialPageReqVO reqVO = new IotDeviceMaterialPageReqVO();
|
|
|
|
+ reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
|
+ reqVO.setBomNodeIds(new ArrayList<>(bomNodeIds));
|
|
|
|
+ List<IotDeviceMaterialDO> deviceBomMaterials = iotDeviceMaterialMapper.selectList(reqVO);
|
|
|
|
+ Set<String> materialCodes = new HashSet<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceBomMaterials)) {
|
|
|
|
+ deviceBomMaterials.forEach(material -> {
|
|
|
|
+ // 设置物料编码组合
|
|
|
|
+ materialCodes.add(material.getCode());
|
|
|
|
+ });
|
|
|
|
+ // 查询每个保养项上 关联的物料数量 关联查询并直接绑定 设备所属部门的SAP组织成本中心的库存物料 与 保养项关联的物料 匹配
|
|
|
|
+ // 物料按照优化级绑定 本地库存 > sap库存 > sap主数据
|
|
|
|
+ /// Set<Long> deptIds = new HashSet<>();
|
|
|
|
+ Set<Long> allDeptIds = new HashSet<>();
|
|
|
|
+ List<IotLockStockDO> lockStocks = new ArrayList<>();
|
|
|
|
+ List<IotSapStockDO> sapStocks = new ArrayList<>();
|
|
|
|
+ // key物料编码 value:本地库存对象
|
|
|
|
+ Map<String, IotLockStockDO> lockStockPair = new HashMap<>();
|
|
|
|
+ // key物料编码 value:sap库存对象
|
|
|
|
+ Map<String, IotSapStockDO> sapStockPair = new HashMap<>();
|
|
|
|
+ // key物料编码 value:sap主数据对象
|
|
|
|
+ Map<String, IotMaterialDO> sapMasterDataPair = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ Map<Long, String> factoryPair = new HashMap<>();
|
|
|
|
+ // key成本中心id value成本中心名称
|
|
|
|
+ Map<Long, String> costCenterPair = new HashMap<>();
|
|
|
|
+ // key库存地点id value库存地点名称
|
|
|
|
+ Map<Long, String> storageLocationPair = new HashMap<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(deptIds)) {
|
|
|
|
+ // 查询每个部门下的所有子部门 将所有 部门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<>(); // 工厂 id 集合
|
|
|
|
+ Set<Long> costCenterIds = new HashSet<>(); // 成本中心id集合
|
|
|
|
+ Set<Long> storageLocationIds = new HashSet<>(); // 库存地点id集合
|
|
|
|
+ Set<Long> sapOrgIds = new HashSet<>(); // 查询本地库存 工厂id-成本中心id
|
|
|
|
+ Set<Long> factoryStorageIds = new HashSet<>(); // 查询sap库存 工厂id-库存地点id
|
|
|
|
+ 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 (ObjUtil.isNotEmpty(org.getStockLocationId())) {
|
|
|
|
+ storageLocationIds.add(org.getStockLocationId());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (CollUtil.isNotEmpty(factoryIds)) {
|
|
|
|
+ sapOrgIds.addAll(factoryIds);
|
|
|
|
+ factoryStorageIds.addAll(factoryIds);
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(costCenterIds)) {
|
|
|
|
+ sapOrgIds.addAll(costCenterIds);
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(storageLocationIds)) {
|
|
|
|
+ factoryStorageIds.addAll(storageLocationIds);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询所有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 = iotLockStockMapper.selectList(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);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询SAP库存
|
|
|
|
+ if (CollUtil.isNotEmpty(factoryIds) && CollUtil.isNotEmpty(storageLocationIds) && CollUtil.isNotEmpty(materialCodes)) {
|
|
|
|
+ IotSapStockPageReqVO sapStockReqVO = new IotSapStockPageReqVO();
|
|
|
|
+ sapStockReqVO.setFactoryIds(factoryIds);
|
|
|
|
+ sapStockReqVO.setStorageLocationIds(storageLocationIds);
|
|
|
|
+ sapStockReqVO.setMaterialCodes(materialCodes);
|
|
|
|
+ sapStocks = iotSapStockMapper.selectList(sapStockReqVO);
|
|
|
|
+ // 查询各工厂 库存地点的名称
|
|
|
|
+ List<SapOrgRespDTO> sapOrganizations = sapOrgApi.getSapOrgList(factoryStorageIds);
|
|
|
|
+ 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()) && 3==org.getType()) {
|
|
|
|
+ storageLocationPair.put(org.getId(), org.getStorageLocationName());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(sapStocks)) {
|
|
|
|
+ sapStocks.forEach(stock -> {
|
|
|
|
+ sapStockPair.put(stock.getMaterialCode(), stock);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询SAP主数据
|
|
|
|
+ if (CollUtil.isNotEmpty(materialCodes)) {
|
|
|
|
+ IotMaterialPageReqVO materialReqVO = new IotMaterialPageReqVO();
|
|
|
|
+ materialReqVO.setCodes(new ArrayList<>(materialCodes));
|
|
|
|
+ List<IotMaterialDO> materials = iotMaterialMapper.selectList(materialReqVO, null);
|
|
|
|
+ if (CollUtil.isNotEmpty(materials)) {
|
|
|
|
+ materials.forEach(material -> {
|
|
|
|
+ sapMasterDataPair.put(material.getCode(), material);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 设置保养项关联的物料列表
|
|
|
|
+ List<IotDeviceMaterialRespVO> deviceMaterials = BeanUtils.toBean(deviceBomMaterials, IotDeviceMaterialRespVO.class);
|
|
|
|
+ // 绑定保养项关联的物料 优先级 本地库存 > sap库存 > sap主数据
|
|
|
|
+ deviceMaterials.forEach(material -> {
|
|
|
|
+ if (lockStockPair.containsKey(material.getCode())) {
|
|
|
|
+ // 本地库存物料
|
|
|
|
+ IotLockStockDO tempLockStock = lockStockPair.get(material.getCode());
|
|
|
|
+ material.setStockQuantity(tempLockStock.getQuantity());
|
|
|
|
+ material.setUnit(tempLockStock.getUnit());
|
|
|
|
+ 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()));
|
|
|
|
+ }
|
|
|
|
+ } else if (sapStockPair.containsKey(material.getCode())) {
|
|
|
|
+ // sap库存物料
|
|
|
|
+ IotSapStockDO tempSapStock = sapStockPair.get(material.getCode());
|
|
|
|
+ material.setStockQuantity(tempSapStock.getQuantity());
|
|
|
|
+ material.setUnit(tempSapStock.getUnit());
|
|
|
|
+ material.setUnitPrice(tempSapStock.getUnitPrice());
|
|
|
|
+ material.setFactoryId(tempSapStock.getFactoryId());
|
|
|
|
+ material.setStorageLocationId(tempSapStock.getStorageLocationId());
|
|
|
|
+ if (factoryPair.containsKey(tempSapStock.getFactoryId())) {
|
|
|
|
+ material.setFactory(factoryPair.get(tempSapStock.getFactoryId()));
|
|
|
|
+ }
|
|
|
|
+ if (storageLocationPair.containsKey(tempSapStock.getStorageLocationId())) {
|
|
|
|
+ material.setStorageLocation(storageLocationPair.get(tempSapStock.getStorageLocationId()));
|
|
|
|
+ }
|
|
|
|
+ } else if (sapMasterDataPair.containsKey(material.getCode())) {
|
|
|
|
+ // sap主数据
|
|
|
|
+ IotMaterialDO tempMaterial = sapMasterDataPair.get(material.getCode());
|
|
|
|
+ material.setStockQuantity(BigDecimal.ZERO);
|
|
|
|
+ material.setUnit(tempMaterial.getUnit());
|
|
|
|
+ material.setUnitPrice(BigDecimal.ZERO);
|
|
|
|
+ material.setFactoryId(null);
|
|
|
|
+ material.setStorageLocationId(null);
|
|
|
|
+ material.setCostCenterId(null);
|
|
|
|
+ material.setFactory(StrUtil.EMPTY);
|
|
|
|
+ material.setStorageLocation(StrUtil.EMPTY);
|
|
|
|
+ material.setCostCenter(StrUtil.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ deviceMaterials.forEach(bomMaterial -> {
|
|
|
|
+ String uniqueKey = StrUtil.join("-", bomMaterial.getDeviceId(), bomMaterial.getBomNodeId());
|
|
|
|
+ if (deviceBomMaterialPair.containsKey(uniqueKey)) {
|
|
|
|
+ List<IotDeviceMaterialRespVO> tempBomMaterials = deviceBomMaterialPair.get(uniqueKey);
|
|
|
|
+ tempBomMaterials.add(bomMaterial);
|
|
|
|
+ deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
|
+ } else {
|
|
|
|
+ List<IotDeviceMaterialRespVO> tempBomMaterials = new ArrayList<>();
|
|
|
|
+ tempBomMaterials.add(bomMaterial);
|
|
|
|
+ deviceBomMaterialPair.put(uniqueKey, tempBomMaterials);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return deviceBomMaterialPair;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|