feat(wms): 完善钢卷打包功能的事务处理和数据一致性
- 添加事务注解确保新增、修改、删除操作的数据一致性 - 新增对打包主表ID和钢卷ID的空值校验 - 实现打包记录重量自动更新功能,包括总毛重、总净重和钢卷数量 - 在删除打包记录时自动还原钢卷到原库区状态 - 添加对钢卷销售名称的同步更新处理 - 完善删除操作中的关联明细记录清理逻辑 - 新增钢卷存在性验证确保数据完整性
This commit is contained in:
@@ -14,10 +14,16 @@ import com.klp.domain.bo.WmsMaterialCoilBo;
|
||||
import com.klp.domain.vo.WmsCoilPackingDetailVo;
|
||||
import com.klp.domain.vo.WmsMaterialCoilVo;
|
||||
import com.klp.domain.WmsCoilPackingDetail;
|
||||
import com.klp.domain.WmsCoilPackingRecord;
|
||||
import com.klp.domain.WmsMaterialCoil;
|
||||
import com.klp.mapper.WmsCoilPackingDetailMapper;
|
||||
import com.klp.mapper.WmsCoilPackingRecordMapper;
|
||||
import com.klp.mapper.WmsMaterialCoilMapper;
|
||||
import com.klp.service.IWmsCoilPackingDetailService;
|
||||
import com.klp.service.IWmsMaterialCoilService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -33,6 +39,8 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
|
||||
private final WmsCoilPackingDetailMapper baseMapper;
|
||||
private final IWmsMaterialCoilService iWmsMaterialCoilService;
|
||||
private final WmsCoilPackingRecordMapper recordMapper;
|
||||
private final WmsMaterialCoilMapper coilMapper;
|
||||
|
||||
/**
|
||||
* 查询钢卷打包明细(存储每个钢卷的库区/重量信息)
|
||||
@@ -49,11 +57,11 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
public TableDataInfo<WmsCoilPackingDetailVo> queryPageList(WmsCoilPackingDetailBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<WmsCoilPackingDetail> lqw = buildQueryWrapper(bo);
|
||||
Page<WmsCoilPackingDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
|
||||
|
||||
if (result.getRecords() != null && !result.getRecords().isEmpty()) {
|
||||
enrichCoilInfo(result.getRecords());
|
||||
}
|
||||
|
||||
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -64,11 +72,11 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
public List<WmsCoilPackingDetailVo> queryList(WmsCoilPackingDetailBo bo) {
|
||||
LambdaQueryWrapper<WmsCoilPackingDetail> lqw = buildQueryWrapper(bo);
|
||||
List<WmsCoilPackingDetailVo> list = baseMapper.selectVoList(lqw);
|
||||
|
||||
|
||||
if (list != null && !list.isEmpty()) {
|
||||
enrichCoilInfo(list);
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -78,18 +86,18 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
if (coilIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WmsMaterialCoilBo coilBo = new WmsMaterialCoilBo();
|
||||
coilBo.setCoilIds(StringUtils.join(coilIds, ","));
|
||||
List<WmsMaterialCoilVo> coilVoList = iWmsMaterialCoilService.queryList(coilBo);
|
||||
|
||||
|
||||
Map<Long, WmsMaterialCoilVo> coilMap = coilVoList.stream()
|
||||
.collect(Collectors.toMap(WmsMaterialCoilVo::getCoilId, v -> v, (a, b) -> a));
|
||||
|
||||
|
||||
for (WmsCoilPackingDetailVo detailVo : detailVos) {
|
||||
detailVo.setCoil(coilMap.get(detailVo.getCoilId()));
|
||||
}
|
||||
@@ -111,13 +119,40 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
* 新增钢卷打包明细(存储每个钢卷的库区/重量信息)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(WmsCoilPackingDetailBo bo) {
|
||||
Long packingId = bo.getPackingId();
|
||||
if (packingId == null) {
|
||||
throw new RuntimeException("打包主表ID不能为空");
|
||||
}
|
||||
|
||||
Long coilId = bo.getCoilId();
|
||||
WmsMaterialCoil coil = coilMapper.selectById(coilId);
|
||||
if (coil == null) {
|
||||
throw new RuntimeException("钢卷不存在,coilId: " + coilId);
|
||||
}
|
||||
|
||||
bo.setFromWarehouseId(coil.getWarehouseId());
|
||||
bo.setCoilGrossWeight(coil.getGrossWeight());
|
||||
bo.setCoilNetWeight(coil.getNetWeight());
|
||||
|
||||
WmsCoilPackingDetail add = BeanUtil.toBean(bo, WmsCoilPackingDetail.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
|
||||
if (flag) {
|
||||
bo.setDetailId(add.getDetailId());
|
||||
updateRecordWeight(packingId);
|
||||
|
||||
WmsMaterialCoil updateCoil = new WmsMaterialCoil();
|
||||
updateCoil.setCoilId(coilId);
|
||||
updateCoil.setWarehouseId(bo.getToWarehouseId());
|
||||
if (StringUtils.isNotBlank(bo.getSaleName())) {
|
||||
updateCoil.setSaleName(bo.getSaleName());
|
||||
}
|
||||
coilMapper.updateById(updateCoil);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
@@ -125,27 +160,91 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
|
||||
* 修改钢卷打包明细(存储每个钢卷的库区/重量信息)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateByBo(WmsCoilPackingDetailBo bo) {
|
||||
Long packingId = bo.getPackingId();
|
||||
if (packingId == null) {
|
||||
throw new RuntimeException("打包主表ID不能为空");
|
||||
}
|
||||
// coilId不能为null
|
||||
if (bo.getCoilId() == null){
|
||||
throw new RuntimeException("钢卷ID不能为空");
|
||||
}
|
||||
|
||||
WmsCoilPackingDetail update = BeanUtil.toBean(bo, WmsCoilPackingDetail.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
boolean flag = baseMapper.updateById(update) > 0;
|
||||
|
||||
if (flag) {
|
||||
updateRecordWeight(packingId);
|
||||
|
||||
WmsMaterialCoil updateCoil = new WmsMaterialCoil();
|
||||
updateCoil.setCoilId(bo.getCoilId());
|
||||
updateCoil.setWarehouseId(bo.getToWarehouseId());
|
||||
if (StringUtils.isNotBlank(bo.getSaleName())) {
|
||||
updateCoil.setSaleName(bo.getSaleName());
|
||||
}
|
||||
coilMapper.updateById(updateCoil);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(WmsCoilPackingDetail entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除钢卷打包明细(存储每个钢卷的库区/重量信息)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
if (isValid) {
|
||||
}
|
||||
|
||||
List<WmsCoilPackingDetail> details = baseMapper.selectBatchIds(ids);
|
||||
if (details.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Long> packingIds = new HashSet<>();
|
||||
for (WmsCoilPackingDetail detail : details) {
|
||||
packingIds.add(detail.getPackingId());
|
||||
}
|
||||
|
||||
boolean flag = baseMapper.deleteBatchIds(ids) > 0;
|
||||
|
||||
if (flag) {
|
||||
for (Long packingId : packingIds) {
|
||||
updateRecordWeight(packingId);
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void updateRecordWeight(Long packingId) {
|
||||
LambdaQueryWrapper<WmsCoilPackingDetail> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(WmsCoilPackingDetail::getPackingId, packingId);
|
||||
List<WmsCoilPackingDetail> details = baseMapper.selectList(lqw);
|
||||
|
||||
BigDecimal totalGrossWeight = BigDecimal.ZERO;
|
||||
BigDecimal totalNetWeight = BigDecimal.ZERO;
|
||||
|
||||
for (WmsCoilPackingDetail detail : details) {
|
||||
totalGrossWeight = totalGrossWeight.add(detail.getCoilGrossWeight() != null ? detail.getCoilGrossWeight() : BigDecimal.ZERO);
|
||||
totalNetWeight = totalNetWeight.add(detail.getCoilNetWeight() != null ? detail.getCoilNetWeight() : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
WmsCoilPackingRecord record = recordMapper.selectById(packingId);
|
||||
if (record != null) {
|
||||
record.setCoilCount((long) details.size());
|
||||
record.setTotalGrossWeight(totalGrossWeight);
|
||||
record.setTotalNetWeight(totalNetWeight);
|
||||
recordMapper.updateById(record);
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,10 +166,43 @@ public class WmsCoilPackingRecordServiceImpl implements IWmsCoilPackingRecordSer
|
||||
* 批量删除钢卷打包记录主(打包待发区专用)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
|
||||
// 先查询所有要删除的主表记录的明细记录
|
||||
LambdaQueryWrapper<WmsCoilPackingDetail> detailLqw = Wrappers.lambdaQuery();
|
||||
detailLqw.in(WmsCoilPackingDetail::getPackingId, ids);
|
||||
List<WmsCoilPackingDetail> details = detailMapper.selectList(detailLqw);
|
||||
|
||||
if (details != null && !details.isEmpty()) {
|
||||
// 将钢卷还原到打包前的状态
|
||||
for (WmsCoilPackingDetail detail : details) {
|
||||
Long coilId = detail.getCoilId();
|
||||
Long fromWarehouseId = detail.getFromWarehouseId();
|
||||
|
||||
if (coilId != null && fromWarehouseId != null) {
|
||||
WmsMaterialCoil updateCoil = new WmsMaterialCoil();
|
||||
updateCoil.setCoilId(coilId);
|
||||
updateCoil.setWarehouseId(fromWarehouseId);
|
||||
updateCoil.setSaleName(null);
|
||||
wmsMaterialCoilMapper.updateById(updateCoil);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除明细记录
|
||||
List<Long> detailIds = new ArrayList<>();
|
||||
for (WmsCoilPackingDetail detail : details) {
|
||||
detailIds.add(detail.getDetailId());
|
||||
}
|
||||
if (!detailIds.isEmpty()) {
|
||||
detailMapper.deleteBatchIds(detailIds);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除主表记录
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user