|
@@ -1,5 +1,6 @@
|
|
package cn.iocoder.yudao.module.pms.service.maintain;
|
|
package cn.iocoder.yudao.module.pms.service.maintain;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
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;
|
|
@@ -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.IotMaintainSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainSaveVO;
|
|
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.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.IotMaintainDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.material.IotMaintainMaterialDO;
|
|
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.IotMaintainMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintain.material.IotMaintainMaterialMapper;
|
|
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.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
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;
|
|
|
|
+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;
|
|
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;
|
|
private IotMaintainMapper iotMaintainMapper;
|
|
@Resource
|
|
@Resource
|
|
private IotMaintainMaterialMapper iotMaintainMaterialMapper;
|
|
private IotMaintainMaterialMapper iotMaintainMaterialMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotLockStockMapper iotLockStockMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotOutboundMapper iotOutboundMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -59,19 +70,62 @@ public class IotMaintainServiceImpl implements IotMaintainService {
|
|
return bean;
|
|
return bean;
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
iotMaintainMaterialMapper.insertBatch(collect);
|
|
iotMaintainMaterialMapper.insertBatch(collect);
|
|
- // 返回
|
|
|
|
|
|
+
|
|
return iotMaintain.getId();
|
|
return iotMaintain.getId();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@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);
|
|
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
|
|
@Override
|
|
public void deleteIotMaintain(Long id) {
|
|
public void deleteIotMaintain(Long id) {
|
|
// 校验存在
|
|
// 校验存在
|