Browse Source

维修消息发送

lipenghui 3 months ago
parent
commit
b353be5bf8

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/materials/vo/IotMaintainMaterialsSaveReqVO.java

@@ -62,4 +62,8 @@ public class IotMaintainMaterialsSaveReqVO {
 
     @Schema(description = "单位")
     private String unit;
+
+    private Long factoryId;
+
+    private Long costCenterId;
 }

+ 7 - 8
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/maintain/IotMaintainMaterialsDO.java

@@ -1,15 +1,12 @@
 package cn.iocoder.yudao.module.pms.dal.dataobject.maintain;
 
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
-import java.util.*;
-import java.math.BigDecimal;
-import java.math.BigDecimal;
-import java.math.BigDecimal;
+
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.time.LocalDateTime;
-import com.baomidou.mybatisplus.annotation.*;
-import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
 
 /**
  * 维修工单对应物料 DO
@@ -93,4 +90,6 @@ public class IotMaintainMaterialsDO extends BaseDO {
      */
     private String remark;
 
+    private Long factoryId;
+    private Long costCenterId;
 }

+ 31 - 33
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainServiceImpl.java

@@ -151,7 +151,7 @@ public class IotMaintainServiceImpl implements IotMaintainService {
         if ("out".equals(createReqVO.getMaintain().getType())){
             String processInstanceId = processInstanceApi.createProcessInstance(SecurityFrameworkUtils.getLoginUserId(),
                     new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY).setBusinessKey(String.valueOf(iotMaintain.getId())));
-            // 将流程实例id 更新到 供应商主数据表
+            // 将流程实例id 更新到维修工单主数据表
             iotMaintainMapper.updateById(new IotMaintainDO().setId(iotMaintain.getId()).setProcessInstanceId(processInstanceId).setAuditStatus(FailureAuditStatusEnum.PROCESS.getStatus()));
         }
         //异步写入故障知识库
@@ -214,7 +214,7 @@ public class IotMaintainServiceImpl implements IotMaintainService {
         //本地库存减少且记录出库
         localStockAndOut(updateReqVO);
         if ("in".equals(updateReqVO.getMaintain().getType())) {
-            sendMessage(BeanUtils.toBean(updateReqVO, IotMaintainDO.class));
+            sendMessage(BeanUtils.toBean(updateReqVO.getMaintain(), IotMaintainDO.class));
         }
         //委外发起流程
         if ("out".equals(updateReqVO.getMaintain().getType())){
@@ -230,38 +230,36 @@ public class IotMaintainServiceImpl implements IotMaintainService {
         List<IotMaintainBomSaveReqVO> maintainMaterials = maintainSaveVO.getMaintainMaterials();
         //判断物料不为空
         if (CollUtil.isNotEmpty(maintainMaterials)) {
-            maintainMaterials.forEach(f ->{
-                f.getMaterials().forEach(e ->{
-                    String code = e.getMaterialCode();
-                    //减去本地库存
-                    if ("本地库存".equals(e.getMaterialSource())){
-                        List<IotLockStockDO> stockDOS = iotLockStockMapper.selectByMap(ImmutableMap.of("material_code", code, "dept_id", maintainSaveVO.getMaintain().getDeptId()));
-                        if (CollUtil.isNotEmpty(stockDOS)) {
-                            IotLockStockDO iotLockStockDO = stockDOS.get(0);
-                            BigDecimal quantity = iotLockStockDO.getQuantity();
-                            BigDecimal subtract = quantity.subtract(e.getQuantity());
-                            if (subtract.compareTo(BigDecimal.ZERO) < 0){
-                                throw new ServiceException(IOT_LOCK_STOCK_FUSHU);
-                            }
-                            iotLockStockDO.setQuantity(subtract);
-                            iotLockStockMapper.updateById(iotLockStockDO);
-                        }
+            maintainMaterials.forEach(f -> f.getMaterials().forEach(e ->{
+                String code = e.getMaterialCode();
+                //减去本地库存
+                if ("本地库存".equals(e.getMaterialSource())){
+                    List<IotLockStockDO> stockDOS = iotLockStockMapper.selectByMap(ImmutableMap.of("material_code", code, "factory_id", e.getFactoryId(),"cost_center_id", e.getCostCenterId()));
+                    if (CollUtil.isNotEmpty(stockDOS)) {
+                        IotLockStockDO iotLockStockDO = stockDOS.get(0);
+                        BigDecimal quantity = iotLockStockDO.getQuantity();
+                        BigDecimal subtract = quantity.subtract(e.getQuantity());
+//                            if (subtract.compareTo(BigDecimal.ZERO) < 0){
+//                                throw new ServiceException(IOT_LOCK_STOCK_FUSHU);
+//                            }
+                        iotLockStockDO.setQuantity(subtract);
+                        iotLockStockMapper.updateById(iotLockStockDO);
                     }
-                    //记录出库
-                    IotOutboundDO outboundDO = new IotOutboundDO();
-                    outboundDO.setDeptId(maintainSaveVO.getMaintain().getDeptId());
-                    outboundDO.setMaterialCode(code);
-                    outboundDO.setMaterialName(e.getMaterialName());
-                    outboundDO.setDeliveryTime(LocalDateTimeUtil.now());
-                    outboundDO.setReason("故障维修");
-                    outboundDO.setStatus(0);
-                    outboundDO.setType(1);
-                    outboundDO.setDeleted(false);
-                    outboundDO.setUnit(e.getUnit());
-                    outboundDO.setUnitPrice(e.getUnitPrice());
-                    iotOutboundMapper.insert(outboundDO);
-                });
-            });
+                }
+                //记录出库
+                IotOutboundDO outboundDO = new IotOutboundDO();
+                outboundDO.setDeptId(maintainSaveVO.getMaintain().getDeptId());
+                outboundDO.setMaterialCode(code);
+                outboundDO.setMaterialName(e.getMaterialName());
+                outboundDO.setDeliveryTime(LocalDateTimeUtil.now());
+                outboundDO.setReason("故障维修");
+                outboundDO.setStatus(0);
+                outboundDO.setType(1);
+                outboundDO.setDeleted(false);
+                outboundDO.setUnit(e.getUnit());
+                outboundDO.setUnitPrice(e.getUnitPrice());
+                iotOutboundMapper.insert(outboundDO);
+            }));
         }
         //更新故障上报的状态为工单处理完成
         IotMaintainSaveReqVO iotMaintain = maintainSaveVO.getMaintain();