diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java index 31fd88c9..1e1b33c6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java @@ -158,6 +158,8 @@ public interface ITypeService { */ int updateNumAddOrSubtract(Type type); + int updateNumAddOrSubtractTwo(Type type); + /** * 根据父级id查询所有子级 * @param parentIds @@ -175,4 +177,11 @@ public interface ITypeService { List equipmentTypeLease(Long typeId, String typeName, Long deptId); Long getUserDeptId(); + + /** + * 根据用户id查询用户部门id + * @param userId + * @return + */ + Long getUserDeptIdByUserId(Long userId); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index c5e5246f..444014b6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -338,6 +338,88 @@ public class TypeServiceImpl implements ITypeService { } } + + @Override + public int updateNumAddOrSubtractTwo(Type type) { + try { + Long deptId = getUserDeptId(); + int result = 0; + // 根据typeId查询物资名称和规格型号 + Type info = typeMapper.selectTypeByTypeId(type.getTypeId()); + BigDecimal storageNum = BigDecimal.ZERO;; + // 查询库存 + if (info != null) { + if ("3".equals(type.getStyle()) && type.getPreStoreNum() != null){ + storageNum= type.getPreStoreNum(); + } else { + if ("1".equals(info.getManageType())) { + storageNum = typeMapper.getStorageNumByTypeId(type); + } else { + storageNum = typeMapper.getMaCodeNum(type); + } + } + } + + type.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + type.setPreStoreNum(storageNum); + type.setMaterialName(info.getMaterialName()); + type.setTypeName(info.getTypeName()); + type.setMethod("/warehousing/addList"); + type.setResultMsg("操作成功"); + type.setStatus(0); + // 插入修改记录 + if ("1".equals(type.getStyle())) { + result = typeMapper.updateMaTypeStockNum(type); + if (result > 0) { + type.setStorageNum(type.getPreStoreNum().subtract(type.getOutNum())); + type.setCompanyId(deptId); + typeMapper.insertStorageNumLog(type); + } else { + throw new RuntimeException("更新库存失败"); + } + } else if (type.getStyle() == null) { + result = typeMapper.updateStorageNum(type); + if (result > 0) { + type.setModelTitle("直接修改库存"); + type.setCompanyId(deptId); + typeMapper.insertStorageNumLog(type); + } else { + throw new RuntimeException("更新库存失败"); + } + } else { + result = typeMapper.addStockNum(type); + if (result > 0) { + type.setStorageNum(type.getPreStoreNum().add(type.getInputNum())); + type.setCompanyId(deptId); + typeMapper.insertStorageNumLog(type); + } else { + throw new RuntimeException("更新库存失败"); + } + try { + //盘点往bm_storage_log表 + if ("3".equals(type.getStyle())) { + if(type.getMaId()!=null){ + type.setInputType(0); + }else{ + type.setInputType(1); + } + type.setCompanyId(deptId); + typeMapper.insertBmStorageNumLog(type); + } + } catch (Exception e) { + type.setResultMsg("操作失败"); + type.setStatus(1); + type.setCompanyId(deptId); + typeMapper.insertBmStorageNumLog(type); + throw new RuntimeException("更新库存失败"); + } + } + return result; + } catch (Exception e) { + throw new RuntimeException("更新库存失败"); + } + } + /** * 根据parent_id查询结果 * @param parentIds @@ -1074,4 +1156,27 @@ public class TypeServiceImpl implements ITypeService { } return sysUser.getDeptId(); } + + @Override + public Long getUserDeptIdByUserId(Long userId) { + SysUser sysUser = typeMapper.getUserDeptId(userId); + if (sysUser != null) { + //获取祖籍部门id + SysDept sysDept = typeMapper.getDeptIdByUserId(sysUser.getDeptId()); + if (sysDept != null && sysDept.getAncestors() != null) { + String ancestors = sysDept.getAncestors(); + String[] ancestorArray = ancestors.split(","); + + // 计算逗号数量(数组长度-1) + int commaCount = ancestorArray.length - 1; + + // 根据逗号数量决定取哪个值 + if (commaCount == 2) { // 两个逗号,如 "0,100,101" + // 取最后一个数据 + sysUser.setDeptId(Long.valueOf(ancestorArray[ancestorArray.length - 1])); + } + } + } + return sysUser.getDeptId(); + } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/SysUserBean.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/SysUserBean.java new file mode 100644 index 00000000..e54ab497 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/SysUserBean.java @@ -0,0 +1,26 @@ +package com.bonus.material.push.domain; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @Author:liang.chao + * @Date:2025/8/23 - 14:35 + */ +@Data +public class SysUserBean { + + private Long userId; + + private String nickName; + + private String phoneNumber; + + private int purchaseNum; + + private int repairExamineNum; + + private Long companyId; + +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairInputDetailsServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairInputDetailsServiceImpl.java index 7fc6b9c4..3bd8987a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairInputDetailsServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairInputDetailsServiceImpl.java @@ -3,6 +3,7 @@ package com.bonus.material.repair.service.impl; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import cn.hutool.core.collection.CollectionUtil; @@ -70,6 +71,8 @@ public class RepairInputDetailsServiceImpl implements IRepairInputDetailsService @Resource private BackApplyInfoMapper backApplyInfoMapper; + private final ReentrantLock lock = new ReentrantLock(true); + @Resource private ITypeService typeService; /** @@ -1053,27 +1056,27 @@ public class RepairInputDetailsServiceImpl implements IRepairInputDetailsService */ private int updateStorageNum(RepairInputDetails inputApplyDetails) { int result = 0; - - + Type type = new Type(); + type.setModelTitle("修试入库"); + type.setCode(inputApplyDetails.getInputCode()); + type.setTypeId(inputApplyDetails.getTypeId()); + type.setStyle("2"); + type.setInputNum(BigDecimal.valueOf(1)); + type.setMaId(inputApplyDetails.getMaId()); + lock.lock(); try { - Type type = new Type(); - type.setModelTitle("修试入库"); - type.setCode(inputApplyDetails.getInputCode()); - type.setTypeId(inputApplyDetails.getTypeId()); - type.setStyle("2"); - type.setInputNum(BigDecimal.valueOf(1)); - type.setMaId(inputApplyDetails.getMaId()); + result = typeService.updateNumAddOrSubtractTwo(type); result = machineMapper.updateStatus(inputApplyDetails.getMaId(), 1); - result = typeService.updateNumAddOrSubtract(type); - + return result; } catch (DataAccessException e) { // 捕获数据库异常,特别是死锁 throw new ServiceException("更新出入库次数失败,请重试,设备id是:"+inputApplyDetails.getMaId()); + } finally { + lock.unlock(); } - return result;