Browse Source

维修出库

lipenghui 4 tháng trước cách đây
mục cha
commit
442ae06392

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -30,4 +30,5 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_SAP_STOCK_NOT_EXISTS = new ErrorCode(131, "PMS SAP 库存(通用库存/项目部库存)不存在");
     ErrorCode IOT_MAINTAIN_MATERIAL_NOT_EXISTS = new ErrorCode(129, "工单物料不存在");
     ErrorCode IOT_INFORMATION_DB_NOT_EXISTS = new ErrorCode(130, "知识库不存在");
+    ErrorCode IOT_LOCK_STOCK_FUSHU = new ErrorCode(131, "超过本地库存");
 }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/IotMaintainController.java

@@ -56,7 +56,7 @@ public class IotMaintainController {
     @PutMapping("/update")
     @Operation(summary = "更新维修工单")
     @PreAuthorize("@ss.hasPermission('rq:iot-maintain:update')")
-    public CommonResult<Boolean> updateIotMaintain(@Valid @RequestBody IotMaintainSaveReqVO updateReqVO) {
+    public CommonResult<Boolean> updateIotMaintain(@Valid @RequestBody IotMaintainSaveVO updateReqVO) {
         iotMaintainService.updateIotMaintain(updateReqVO);
         return success(true);
     }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainService.java

@@ -30,7 +30,7 @@ public interface IotMaintainService {
      *
      * @param updateReqVO 更新信息
      */
-    void updateIotMaintain(@Valid IotMaintainSaveReqVO updateReqVO);
+    void updateIotMaintain(@Valid IotMaintainSaveVO updateReqVO);
 
     /**
      * 删除维修工单

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

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.maintain;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -9,22 +10,28 @@ import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageR
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainSaveVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotlockstock.IotLockStockDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.IotMaintainDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.material.IotMaintainMaterialDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotlockstock.IotLockStockMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotoutbound.IotOutboundMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.maintain.IotMaintainMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.maintain.material.IotMaintainMaterialMapper;
+import com.google.common.collect.ImmutableMap;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_LOCK_STOCK_FUSHU;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAINTAIN_NOT_EXISTS;
 
 /**
@@ -40,6 +47,10 @@ public class IotMaintainServiceImpl implements IotMaintainService {
     private IotMaintainMapper iotMaintainMapper;
     @Resource
     private IotMaintainMaterialMapper iotMaintainMaterialMapper;
+    @Resource
+    private IotLockStockMapper iotLockStockMapper;
+    @Resource
+    private IotOutboundMapper iotOutboundMapper;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -59,19 +70,62 @@ public class IotMaintainServiceImpl implements IotMaintainService {
             return bean;
         }).collect(Collectors.toList());
         iotMaintainMaterialMapper.insertBatch(collect);
-        // 返回
+
         return iotMaintain.getId();
     }
 
     @Override
-    public void updateIotMaintain(IotMaintainSaveReqVO updateReqVO) {
+    public void updateIotMaintain(IotMaintainSaveVO updateReqVO) {
         // 校验存在
-        validateIotMaintainExists(updateReqVO.getId());
+        validateIotMaintainExists(updateReqVO.getMaintain().getId());
         // 更新
-        IotMaintainDO updateObj = BeanUtils.toBean(updateReqVO, IotMaintainDO.class);
+        IotMaintainDO updateObj = BeanUtils.toBean(updateReqVO.getMaintain(), IotMaintainDO.class);
         iotMaintainMapper.updateById(updateObj);
+
+        List<IotMaintainMaterialSaveReqVO> maintainMaterials = updateReqVO.getMaintainMaterials();
+        //删除工单物料
+        iotMaintainMaterialMapper.deleteByMap(ImmutableMap.of("maintainId", updateObj.getId()));
+        //插入工单物料
+        List<IotMaintainMaterialDO> collect = maintainMaterials.stream().map(e -> {
+            IotMaintainMaterialDO bean = BeanUtils.toBean(e, IotMaintainMaterialDO.class);
+            bean.setMaintainId(updateObj.getId());
+            bean.setDeleted(false);
+            return bean;
+        }).collect(Collectors.toList());
+        iotMaintainMaterialMapper.insertBatch(collect);
     }
 
+    /**
+     * 减少本地库存并记录出库
+     * @param maintainSaveVO 维修工单信息
+     */
+    private void localStockAndOut(IotMaintainSaveVO maintainSaveVO) {
+        List<IotMaintainMaterialSaveReqVO> maintainMaterials = maintainSaveVO.getMaintainMaterials();
+        //判断物料不为空
+        if (CollUtil.isNotEmpty(maintainMaterials)) {
+            maintainMaterials.forEach(e ->{
+                String code = e.getCode();
+                //减去本地库存
+                if ("本地库存".equals(e.getSourceType())){
+                    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(BigDecimal.valueOf(e.getDepleteCount()));
+                        if (subtract.compareTo(BigDecimal.ZERO) < 0){
+                            throw new ServiceException(IOT_LOCK_STOCK_FUSHU);
+                        }
+                        iotLockStockDO.setQuantity(subtract);
+                        iotLockStockMapper.updateById(iotLockStockDO);
+                        //todo 安全库存提醒?
+                    }
+                }
+                //记录出库
+            });
+        }
+    }
+
+
     @Override
     public void deleteIotMaintain(Long id) {
         // 校验存在