|
|
|
|
@ -13,6 +13,7 @@ import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.wms.domain.BaseMaterialCategory;
|
|
|
|
|
import org.dromara.wms.domain.BaseMaterialInfo;
|
|
|
|
|
import org.dromara.wms.domain.WmsInstockDetail;
|
|
|
|
|
import org.dromara.wms.domain.WmsInstockPrint;
|
|
|
|
|
import org.dromara.wms.domain.bo.BaseMaterialInfoBo;
|
|
|
|
|
@ -100,6 +101,9 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
.select(BaseMaterialCategory::getMaterialCategoryName)
|
|
|
|
|
.leftJoin(BaseMaterialCategory.class, BaseMaterialCategory::getMaterialCategoryId, WmsInstockDetail::getMaterialCategoryId)
|
|
|
|
|
|
|
|
|
|
.select(BaseMaterialInfo::getInspectionRequest)//质检要求(0必检,1免检)
|
|
|
|
|
.leftJoin(BaseMaterialInfo.class, BaseMaterialInfo::getMaterialId, WmsInstockDetail::getMaterialId)
|
|
|
|
|
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getIsInspection()), WmsInstockDetail::getIsInspection, bo.getIsInspection())
|
|
|
|
|
.eq(bo.getInstockQty() != null, WmsInstockDetail::getInstockQty, bo.getInstockQty())
|
|
|
|
|
|
|
|
|
|
@ -213,10 +217,9 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
|
|
|
|
|
BigDecimal printed = detail.getPrintedNum() != null ? detail.getPrintedNum() : BigDecimal.ZERO;
|
|
|
|
|
BigDecimal remaining = detail.getInstockQty().subtract(printed);
|
|
|
|
|
if (remaining.compareTo(BigDecimal.ZERO) <= 0) {// 无剩余
|
|
|
|
|
if (remaining.compareTo(BigDecimal.ONE) < 0) {// 剩余数量小于1时无法打印
|
|
|
|
|
throw new ServiceException("无剩余数量可打印");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int splitInt = bo.getSplitPackageCount() != null ? bo.getSplitPackageCount() : 1;
|
|
|
|
|
BigDecimal split = BigDecimal.valueOf(splitInt);
|
|
|
|
|
int copiesInt = bo.getPrintCopies() != null ? bo.getPrintCopies() : 1;
|
|
|
|
|
@ -225,30 +228,72 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
// 获取当前打印序列
|
|
|
|
|
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) {// 无法平均分包
|
|
|
|
|
throw new ServiceException("无法平均分包");
|
|
|
|
|
// 分包逻辑 - 支持平均分包和自定义分包两种模式
|
|
|
|
|
List<Integer> packageQtyList = bo.getPackageQtyList();
|
|
|
|
|
String packageMode = bo.getPackageMode();
|
|
|
|
|
|
|
|
|
|
// 默认为平均分包模式
|
|
|
|
|
if (packageMode == null) {
|
|
|
|
|
packageMode = "average";
|
|
|
|
|
}
|
|
|
|
|
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.setInboundStatus("0");//入库状态(0-待入库,1-已入库,2-入库中)
|
|
|
|
|
|
|
|
|
|
wmsInstockPrintService.insertWmsInstockPrint(print);
|
|
|
|
|
|
|
|
|
|
totalPackaged = totalPackaged.add(per);
|
|
|
|
|
|
|
|
|
|
if ("custom".equals(packageMode) && packageQtyList != null && packageQtyList.size() == splitInt) {
|
|
|
|
|
// 自定义模式:使用用户指定的每包数量
|
|
|
|
|
BigDecimal totalCustomQty = packageQtyList.stream()
|
|
|
|
|
.map(BigDecimal::valueOf)
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
|
|
|
if (totalCustomQty.compareTo(remaining) > 0) {
|
|
|
|
|
throw new ServiceException("每包数量总计不能超过剩余数量");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= splitInt; i++) {
|
|
|
|
|
String order = baseOrder + String.format("%03d", i);
|
|
|
|
|
String batchCode = generateBatchCode(bo, bo.getBatchCode(), order);
|
|
|
|
|
|
|
|
|
|
BigDecimal currentPackageQty = BigDecimal.valueOf(packageQtyList.get(i - 1));
|
|
|
|
|
|
|
|
|
|
WmsInstockPrint print = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo, print);
|
|
|
|
|
print.setBatchCode(batchCode);
|
|
|
|
|
print.setApportionQty(currentPackageQty);
|
|
|
|
|
print.setMaterialQty(1L); // 每个包打印1份
|
|
|
|
|
print.setInboundStatus("0"); // 入库状态(0-待入库,1-已入库,2-入库中)
|
|
|
|
|
|
|
|
|
|
wmsInstockPrintService.insertWmsInstockPrint(print);
|
|
|
|
|
|
|
|
|
|
totalPackaged = totalPackaged.add(currentPackageQty);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 平均分包模式(默认模式)或自定义模式但数据不完整
|
|
|
|
|
if ("average".equals(packageMode) || packageQtyList == null || packageQtyList.size() != splitInt) {
|
|
|
|
|
// 使用平均分包逻辑
|
|
|
|
|
if (remaining.compareTo(split) < 0 || remaining.remainder(split).compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
throw new ServiceException("无法平均分包,剩余数量不能被平均分配");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal per = remaining.divide(split, 0, RoundingMode.DOWN);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= splitInt; i++) {
|
|
|
|
|
String order = baseOrder + String.format("%03d", i);
|
|
|
|
|
String batchCode = generateBatchCode(bo, bo.getBatchCode(), order);
|
|
|
|
|
|
|
|
|
|
WmsInstockPrint print = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo, print);
|
|
|
|
|
print.setBatchCode(batchCode);
|
|
|
|
|
print.setApportionQty(per);
|
|
|
|
|
print.setMaterialQty(1L); // 每个包打印1份
|
|
|
|
|
print.setInboundStatus("0"); // 入库状态(0-待入库,1-已入库,2-入库中)
|
|
|
|
|
|
|
|
|
|
wmsInstockPrintService.insertWmsInstockPrint(print);
|
|
|
|
|
|
|
|
|
|
totalPackaged = totalPackaged.add(per);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 使用自定义数量但数据验证失败
|
|
|
|
|
throw new ServiceException("自定义分包数量数据验证失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 重复打印逻辑(split == 1)
|
|
|
|
|
@ -257,7 +302,7 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
}
|
|
|
|
|
copies = BigDecimal.valueOf(copiesInt);
|
|
|
|
|
|
|
|
|
|
String batchCode = bo.getInstockCode() + bo.getMaterialCode() + baseOrder;
|
|
|
|
|
String batchCode = generateBatchCode(bo, bo.getBatchCode(), baseOrder);
|
|
|
|
|
|
|
|
|
|
WmsInstockPrint print = new WmsInstockPrint();
|
|
|
|
|
BeanUtils.copyProperties(bo, print);
|
|
|
|
|
@ -286,6 +331,15 @@ public class WmsInstockDetailServiceImpl implements IWmsInstockDetailService {
|
|
|
|
|
return value.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String generateBatchCode(WmsInstockDetailBo bo, String batchCode, String baseOrder){
|
|
|
|
|
if(StringUtils.isBlank(batchCode)){
|
|
|
|
|
return bo.getInstockCode() + bo.getMaterialCode() + baseOrder;
|
|
|
|
|
}else{
|
|
|
|
|
return batchCode + baseOrder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存前的数据校验
|
|
|
|
|
*/
|
|
|
|
|
|