|
|
|
@ -1,17 +1,19 @@
|
|
|
|
|
package org.dromara.wms.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.wms.domain.*;
|
|
|
|
|
import org.dromara.wms.domain.BaseMaterialCategory;
|
|
|
|
|
import org.dromara.wms.domain.WmsInstockDetail;
|
|
|
|
|
import org.dromara.wms.domain.WmsInstockPrint;
|
|
|
|
|
import org.dromara.wms.domain.bo.BaseMaterialInfoBo;
|
|
|
|
|
import org.dromara.wms.domain.bo.WmsInstockDetailBo;
|
|
|
|
|
import org.dromara.wms.domain.vo.BaseMaterialInfoVo;
|
|
|
|
@ -26,9 +28,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 入库单-物料Service业务层处理
|
|
|
|
@ -142,6 +145,49 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
return a>0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * 修改入库单-物料
|
|
|
|
|
// *
|
|
|
|
|
// * @param bo 入库单-物料
|
|
|
|
|
// * @return 是否修改成功
|
|
|
|
|
// */
|
|
|
|
|
// @Override
|
|
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
// public Boolean updateByBo(WmsInstockDetailBo bo) {
|
|
|
|
|
// String username = LoginHelper.getUsername();
|
|
|
|
|
// if (bo.getPrintNum()==null){
|
|
|
|
|
// WmsInstockDetail update = MapstructUtils.convert(bo, WmsInstockDetail.class);
|
|
|
|
|
// update.setUpdateBy(username);
|
|
|
|
|
// // validEntityBeforeSave(update);
|
|
|
|
|
// return baseMapper.updateDetail(update)>0;
|
|
|
|
|
// }
|
|
|
|
|
// if (bo.getPrintedNum()==null){
|
|
|
|
|
// bo.setPrintedNum(new BigDecimal(0));
|
|
|
|
|
// }
|
|
|
|
|
// //分包数量不能超过入库数量
|
|
|
|
|
// if (bo.getPrintNum().add(bo.getPrintedNum()).compareTo(bo.getInstockQty())>0){
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// Integer printNum = (int)wmsInstockPrintService.queryPrintNum(bo) + 1;
|
|
|
|
|
// String order = generateOrder(printNum);
|
|
|
|
|
// WmsInstockPrint wmsInstockPrint = new WmsInstockPrint();
|
|
|
|
|
// BeanUtils.copyProperties(bo,wmsInstockPrint);
|
|
|
|
|
// String instockCode = bo.getInstockCode();
|
|
|
|
|
// String materialCode = bo.getMaterialCode();
|
|
|
|
|
// String batchCode = instockCode+materialCode+order;
|
|
|
|
|
// wmsInstockPrint.setBatchCode(batchCode);
|
|
|
|
|
// wmsInstockPrint.setApportionQty(bo.getPrintNum());
|
|
|
|
|
// wmsInstockPrint.setMaterialQty(bo.getBarcodeNum());
|
|
|
|
|
// wmsInstockPrint.setCreateBy(username);
|
|
|
|
|
// // int rows = wmsInstockPrintService.insertWmsInstockPrint(wmsInstockPrint);
|
|
|
|
|
// WmsInstockDetail wmsInstockDetail = new WmsInstockDetail();
|
|
|
|
|
// wmsInstockDetail.setPrintedNum(bo.getPrintedNum().add(bo.getPrintNum()));
|
|
|
|
|
// LambdaUpdateWrapper<WmsInstockDetail> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
// updateWrapper.eq(WmsInstockDetail::getInstockDetailId,bo.getInstockDetailId());
|
|
|
|
|
// wmsInstockDetail.setUpdateBy(username);
|
|
|
|
|
// int update = baseMapper.update(wmsInstockDetail, updateWrapper);
|
|
|
|
|
// return update>0;
|
|
|
|
|
// }
|
|
|
|
|
/**
|
|
|
|
|
* 修改入库单-物料
|
|
|
|
|
*
|
|
|
|
@ -152,38 +198,85 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean updateByBo(WmsInstockDetailBo bo) {
|
|
|
|
|
String username = LoginHelper.getUsername();
|
|
|
|
|
if (bo.getPrintNum()==null){
|
|
|
|
|
|
|
|
|
|
// 如果 splitPackageCount 为空,执行常规更新
|
|
|
|
|
if (bo.getSplitPackageCount() == null) {
|
|
|
|
|
WmsInstockDetail update = MapstructUtils.convert(bo, WmsInstockDetail.class);
|
|
|
|
|
update.setUpdateBy(username);
|
|
|
|
|
// validEntityBeforeSave(update);
|
|
|
|
|
return baseMapper.updateDetail(update)>0;
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
|
|
}
|
|
|
|
|
if (bo.getPrintedNum()==null){
|
|
|
|
|
bo.setPrintedNum(new BigDecimal(0));
|
|
|
|
|
}
|
|
|
|
|
//分包数量不能超过入库数量
|
|
|
|
|
if (bo.getPrintNum().add(bo.getPrintedNum()).compareTo(bo.getInstockQty())>0){
|
|
|
|
|
|
|
|
|
|
// 获取当前明细
|
|
|
|
|
WmsInstockDetail detail = baseMapper.selectById(bo.getInstockDetailId());
|
|
|
|
|
if (detail == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Integer printNum = (int)wmsInstockPrintService.queryPrintNum(bo) + 1;
|
|
|
|
|
String order = generateOrder(printNum);
|
|
|
|
|
WmsInstockPrint wmsInstockPrint = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo,wmsInstockPrint);
|
|
|
|
|
String instockCode = bo.getInstockCode();
|
|
|
|
|
String materialCode = bo.getMaterialCode();
|
|
|
|
|
String batchCode = instockCode+materialCode+order;
|
|
|
|
|
wmsInstockPrint.setBatchCode(batchCode);
|
|
|
|
|
wmsInstockPrint.setApportionQty(bo.getPrintNum());
|
|
|
|
|
wmsInstockPrint.setMaterialQty(bo.getBarcodeNum());
|
|
|
|
|
wmsInstockPrint.setCreateBy(username);
|
|
|
|
|
// int rows = wmsInstockPrintService.insertWmsInstockPrint(wmsInstockPrint);
|
|
|
|
|
WmsInstockDetail wmsInstockDetail = new WmsInstockDetail();
|
|
|
|
|
wmsInstockDetail.setPrintedNum(bo.getPrintedNum().add(bo.getPrintNum()));
|
|
|
|
|
LambdaUpdateWrapper<WmsInstockDetail> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq(WmsInstockDetail::getInstockDetailId,bo.getInstockDetailId());
|
|
|
|
|
wmsInstockDetail.setUpdateBy(username);
|
|
|
|
|
int update = baseMapper.update(wmsInstockDetail, updateWrapper);
|
|
|
|
|
return update>0;
|
|
|
|
|
|
|
|
|
|
BigDecimal printed = detail.getPrintedNum() != null ? detail.getPrintedNum() : BigDecimal.ZERO;
|
|
|
|
|
BigDecimal remaining = detail.getInstockQty().subtract(printed);
|
|
|
|
|
if (remaining.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
return false; // 无剩余
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int splitInt = bo.getSplitPackageCount() != null ? bo.getSplitPackageCount() : 1;
|
|
|
|
|
BigDecimal split = BigDecimal.valueOf(splitInt);
|
|
|
|
|
int copiesInt = bo.getPrintCopies() != null ? bo.getPrintCopies() : 1;
|
|
|
|
|
BigDecimal copies = BigDecimal.valueOf(copiesInt);
|
|
|
|
|
|
|
|
|
|
// 获取当前打印序列
|
|
|
|
|
Integer printSeq = (int) wmsInstockPrintService.queryPrintNum(bo) + 1;
|
|
|
|
|
String baseOrder = generateOrder(printSeq);
|
|
|
|
|
|
|
|
|
|
BigDecimal totalPackaged = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
|
if (splitInt > 1) {
|
|
|
|
|
// 分包逻辑
|
|
|
|
|
if (remaining.compareTo(split) < 0 || remaining.remainder(split).compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
return false; // 无法平均分包
|
|
|
|
|
}
|
|
|
|
|
BigDecimal per = remaining.divide(split, 0, RoundingMode.DOWN);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= splitInt; i++) {
|
|
|
|
|
String order = baseOrder + "-" + String.format("%03d", i);
|
|
|
|
|
String batchCode = bo.getInstockCode() + bo.getMaterialCode() + order;
|
|
|
|
|
|
|
|
|
|
WmsInstockPrint print = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo, print);
|
|
|
|
|
print.setBatchCode(batchCode);
|
|
|
|
|
print.setApportionQty(per);
|
|
|
|
|
print.setMaterialQty(1L); // 每个包打印1份,使用Long类型
|
|
|
|
|
print.setCreateBy(username);
|
|
|
|
|
|
|
|
|
|
wmsInstockPrintService.insertWmsInstockPrint(print);
|
|
|
|
|
|
|
|
|
|
totalPackaged = totalPackaged.add(per);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 重复打印逻辑(split == 1)
|
|
|
|
|
if (copiesInt < 1) {
|
|
|
|
|
copiesInt = 1;
|
|
|
|
|
}
|
|
|
|
|
copies = BigDecimal.valueOf(copiesInt);
|
|
|
|
|
|
|
|
|
|
String order = baseOrder;
|
|
|
|
|
String batchCode = bo.getInstockCode() + bo.getMaterialCode() + order;
|
|
|
|
|
|
|
|
|
|
WmsInstockPrint print = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo, print);
|
|
|
|
|
print.setBatchCode(batchCode);
|
|
|
|
|
print.setApportionQty(remaining);
|
|
|
|
|
print.setMaterialQty(copies.longValue()); // 转换为Long
|
|
|
|
|
print.setCreateBy(username);
|
|
|
|
|
|
|
|
|
|
wmsInstockPrintService.insertWmsInstockPrint(print);
|
|
|
|
|
|
|
|
|
|
totalPackaged = remaining;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新 printedNum
|
|
|
|
|
detail.setPrintedNum(printed.add(totalPackaged));
|
|
|
|
|
baseMapper.updateById(detail);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public String generateOrder(Integer value){
|
|
|
|
|
if (value.toString().length()<3){
|
|
|
|
|