|
@@ -1,6 +1,7 @@
|
|
package cn.iocoder.yudao.module.pms.service.iotmainworkorderbommaterial;
|
|
package cn.iocoder.yudao.module.pms.service.iotmainworkorderbommaterial;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
@@ -9,10 +10,15 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotC
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialDO;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
import cn.iocoder.yudao.module.pms.service.iotcommonbommaterial.IotCommonBomMaterialService;
|
|
import cn.iocoder.yudao.module.pms.service.iotcommonbommaterial.IotCommonBomMaterialService;
|
|
|
|
+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.dal.dataobject.dept.DeptDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -44,6 +50,12 @@ public class IotMainWorkOrderBomMaterialServiceImpl implements IotMainWorkOrderB
|
|
private DeptService deptService;
|
|
private DeptService deptService;
|
|
@Autowired
|
|
@Autowired
|
|
private IotCommonBomMaterialService iotCommonBomMaterialService;
|
|
private IotCommonBomMaterialService iotCommonBomMaterialService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IotDeviceService iotDeviceService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SapOrgApi sapOrgApi;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeptSapOrgApi deptSapOrgApi;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Long createIotMainWorkOrderBomMaterial(IotMainWorkOrderBomMaterialSaveReqVO createReqVO) {
|
|
public Long createIotMainWorkOrderBomMaterial(IotMainWorkOrderBomMaterialSaveReqVO createReqVO) {
|
|
@@ -89,8 +101,43 @@ public class IotMainWorkOrderBomMaterialServiceImpl implements IotMainWorkOrderB
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public PageResult<IotMainWorkOrderBomMaterialRespVO> selectMaterialsByDept(IotMainWorkOrderBomMaterialPageReqVO pageReqVO) {
|
|
public PageResult<IotMainWorkOrderBomMaterialRespVO> selectMaterialsByDept(IotMainWorkOrderBomMaterialPageReqVO pageReqVO) {
|
|
- DeptDO dept = deptService.getDept(pageReqVO.getDeptId());
|
|
|
|
- if (Objects.isNull(dept)) {throw new ServiceException();}
|
|
|
|
|
|
+ // 根据 设备 关联的 SAP工厂 库存地点 成本中心 查询 本地库存 SAP库存
|
|
|
|
+ // 查询设备所属的部门
|
|
|
|
+ IotDeviceDO device = iotDeviceService.getIotDevice(pageReqVO.getDeviceId());
|
|
|
|
+ if (ObjUtil.isEmpty(device)) {
|
|
|
|
+ throw exception(IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.isNull(device.getDeptId())) {
|
|
|
|
+ throw exception(IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ // 查询设备所属部门下的所有子部门列表
|
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
|
+ ids.add(device.getDeptId());
|
|
|
|
+ // 查询设备所属部门关联的SAP工厂 成本中心 库存地点
|
|
|
|
+ List<DeptSapOrgRespDTO> sapOrgS = deptSapOrgApi.getSapOrgListByDeptIds(ids);
|
|
|
|
+ Set<Long> factoryIds = new HashSet<>();
|
|
|
|
+ Set<Long> costCenterIds = new HashSet<>();
|
|
|
|
+ Set<Long> stockLocationIds = new HashSet<>();
|
|
|
|
+ if (CollUtil.isEmpty(sapOrgS)) {
|
|
|
|
+ throw exception(IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ sapOrgS.forEach(sapOrg -> {
|
|
|
|
+ if (ObjUtil.isNotEmpty(sapOrg.getFactoryId())) {
|
|
|
|
+ factoryIds.add(sapOrg.getFactoryId());
|
|
|
|
+ }
|
|
|
|
+ if (ObjUtil.isNotEmpty(sapOrg.getCostCenterId())) {
|
|
|
|
+ costCenterIds.add(sapOrg.getCostCenterId());
|
|
|
|
+ }
|
|
|
|
+ if (ObjUtil.isNotEmpty(sapOrg.getStockLocationId())) {
|
|
|
|
+ stockLocationIds.add(sapOrg.getStockLocationId());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // DeptDO dept = deptService.getDept(pageReqVO.getDeptId());
|
|
|
|
+ // if (Objects.isNull(dept)) {throw new ServiceException();}
|
|
// 查询 bom 节点已经关联的物料列表
|
|
// 查询 bom 节点已经关联的物料列表
|
|
IotCommonBomMaterialSaveReqVO reqVO = new IotCommonBomMaterialSaveReqVO();
|
|
IotCommonBomMaterialSaveReqVO reqVO = new IotCommonBomMaterialSaveReqVO();
|
|
reqVO.setBomNodeId(pageReqVO.getBomNodeId());
|
|
reqVO.setBomNodeId(pageReqVO.getBomNodeId());
|
|
@@ -105,8 +152,8 @@ public class IotMainWorkOrderBomMaterialServiceImpl implements IotMainWorkOrderB
|
|
bomNodePair = CollectionUtils.convertMap(bomMaterials, IotCommonBomMaterialDO::getCode);
|
|
bomNodePair = CollectionUtils.convertMap(bomMaterials, IotCommonBomMaterialDO::getCode);
|
|
}
|
|
}
|
|
IPage<IotMainWorkOrderBomMaterialRespVO> iotMaintainMaterialDOIPage =
|
|
IPage<IotMainWorkOrderBomMaterialRespVO> iotMaintainMaterialDOIPage =
|
|
- iotMainWorkOrderBomMaterialMapper.selectMaterialsByDept(Page.of(pageReqVO.getPageNo(), pageReqVO.getPageSize()),
|
|
|
|
- pageReqVO.getDeptId(), dept.getParentId(), materialCodes);
|
|
|
|
|
|
+ iotMainWorkOrderBomMaterialMapper.selectMaterialsBySapOrg(Page.of(pageReqVO.getPageNo(), pageReqVO.getPageSize()),
|
|
|
|
+ pageReqVO.getDeptId(), null, materialCodes, factoryIds, costCenterIds, stockLocationIds);
|
|
List<IotMainWorkOrderBomMaterialRespVO> materials = iotMaintainMaterialDOIPage.getRecords();
|
|
List<IotMainWorkOrderBomMaterialRespVO> materials = iotMaintainMaterialDOIPage.getRecords();
|
|
if (CollUtil.isNotEmpty(materials)) {
|
|
if (CollUtil.isNotEmpty(materials)) {
|
|
for (IotMainWorkOrderBomMaterialRespVO material : materials) {
|
|
for (IotMainWorkOrderBomMaterialRespVO material : materials) {
|