修试入库锁问题处理
This commit is contained in:
parent
168d772586
commit
113b6ecd9c
|
|
@ -158,6 +158,8 @@ public interface ITypeService {
|
||||||
*/
|
*/
|
||||||
int updateNumAddOrSubtract(Type type);
|
int updateNumAddOrSubtract(Type type);
|
||||||
|
|
||||||
|
int updateNumAddOrSubtractTwo(Type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据父级id查询所有子级
|
* 根据父级id查询所有子级
|
||||||
* @param parentIds
|
* @param parentIds
|
||||||
|
|
@ -175,4 +177,11 @@ public interface ITypeService {
|
||||||
List<Type> equipmentTypeLease(Long typeId, String typeName, Long deptId);
|
List<Type> equipmentTypeLease(Long typeId, String typeName, Long deptId);
|
||||||
|
|
||||||
Long getUserDeptId();
|
Long getUserDeptId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id查询用户部门id
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Long getUserDeptIdByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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查询结果
|
* 根据parent_id查询结果
|
||||||
* @param parentIds
|
* @param parentIds
|
||||||
|
|
@ -1074,4 +1156,27 @@ public class TypeServiceImpl implements ITypeService {
|
||||||
}
|
}
|
||||||
return sysUser.getDeptId();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.material.repair.service.impl;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
|
@ -70,6 +71,8 @@ public class RepairInputDetailsServiceImpl implements IRepairInputDetailsService
|
||||||
@Resource
|
@Resource
|
||||||
private BackApplyInfoMapper backApplyInfoMapper;
|
private BackApplyInfoMapper backApplyInfoMapper;
|
||||||
|
|
||||||
|
private final ReentrantLock lock = new ReentrantLock(true);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ITypeService typeService;
|
private ITypeService typeService;
|
||||||
/**
|
/**
|
||||||
|
|
@ -1053,27 +1056,27 @@ public class RepairInputDetailsServiceImpl implements IRepairInputDetailsService
|
||||||
*/
|
*/
|
||||||
private int updateStorageNum(RepairInputDetails inputApplyDetails) {
|
private int updateStorageNum(RepairInputDetails inputApplyDetails) {
|
||||||
int result = 0;
|
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 {
|
try {
|
||||||
Type type = new Type();
|
result = typeService.updateNumAddOrSubtractTwo(type);
|
||||||
type.setModelTitle("修试入库");
|
|
||||||
type.setCode(inputApplyDetails.getInputCode());
|
|
||||||
type.setTypeId(inputApplyDetails.getTypeId());
|
|
||||||
type.setStyle("2");
|
|
||||||
type.setInputNum(BigDecimal.valueOf(1));
|
|
||||||
type.setMaId(inputApplyDetails.getMaId());
|
|
||||||
result = machineMapper.updateStatus(inputApplyDetails.getMaId(), 1);
|
result = machineMapper.updateStatus(inputApplyDetails.getMaId(), 1);
|
||||||
result = typeService.updateNumAddOrSubtract(type);
|
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
} catch (DataAccessException e) {
|
} catch (DataAccessException e) {
|
||||||
// 捕获数据库异常,特别是死锁
|
// 捕获数据库异常,特别是死锁
|
||||||
|
|
||||||
throw new ServiceException("更新出入库次数失败,请重试,设备id是:"+inputApplyDetails.getMaId());
|
throw new ServiceException("更新出入库次数失败,请重试,设备id是:"+inputApplyDetails.getMaId());
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue