异常处理改成能带参数。

This commit is contained in:
c
2026-03-13 15:34:37 +08:00
parent 112413f7d4
commit 30a6258f1e
19 changed files with 900 additions and 178 deletions

View File

@@ -1,7 +1,29 @@
package com.niuan.erp.common.exception;
import lombok.Getter;
@Getter
public class BusinessException extends RuntimeException {
private final Object[] args;
public BusinessException(String message) {
super(message);
this.args = null;
}
public BusinessException(String message, Object... args) {
super(message);
this.args = args;
}
public BusinessException(String message, Throwable cause) {
super(message, cause);
this.args = null;
}
public BusinessException(String message, Throwable cause, Object... args) {
super(message, cause);
this.args = args;
}
}

View File

@@ -1,7 +1,29 @@
package com.niuan.erp.common.exception;
import lombok.Getter;
@Getter
public class SystemException extends RuntimeException {
private final Object[] args;
public SystemException(String message) {
super(message);
this.args = null;
}
public SystemException(String message, Object... args) {
super(message);
this.args = args;
}
public SystemException(String message, Throwable cause) {
super(message, cause);
this.args = null;
}
public SystemException(String message, Throwable cause, Object... args) {
super(message, cause);
this.args = args;
}
}

View File

@@ -68,7 +68,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public ResponseEntity<?> handleBusinessException(BusinessException e, Locale locale) {
return ResponseEntity.ok().body(
BaseResult.error(3, messageSource.getMessage(e.getMessage(), null, locale)));
BaseResult.error(3, messageSource.getMessage(e.getMessage(), e.getArgs(), locale)));
}
/**
@@ -80,7 +80,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(SystemException.class)
public ResponseEntity<?> handleSystemException(SystemException e, Locale locale) {
return ResponseEntity.ok().body(
BaseResult.error(4, messageSource.getMessage(e.getMessage(), null, locale)));
BaseResult.error(4, messageSource.getMessage(e.getMessage(), e.getArgs(), locale)));
}
// /**
@@ -90,7 +90,7 @@ public class GlobalExceptionHandler {
// * @return
// */
// @ExceptionHandler(Exception.class)
// public ResponseEntity<?> handleException(Exception e, Locale locale) {
// public ExceptionHandler(Exception e, Locale locale) {
// return ResponseEntity.badRequest().body(
// BaseResult.error(-1, e.getMessage()));
// }

View File

@@ -72,21 +72,23 @@ public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomSe
// 检验数据
var searchBomNameWrapper = new LambdaQueryWrapper<Bom>().eq(Bom::getBomName, dto.bomName());
if (this.baseMapper.selectCount(searchBomNameWrapper) > 0) {
throw new BusinessException("production.bom.exception.duplicate_bom_name");
throw new BusinessException("production.bom.exception.duplicate_bom_name", dto.bomName());
}
List<BomItemAddDto> items = dto.bomItems();
List<String> itemPartNumbers = items.stream().map(BomItemAddDto::partNumber).distinct().toList();
if (items.size() != itemPartNumbers.size()) {
throw new BusinessException("production.bom.exception.duplicate_bom_item");
throw new BusinessException("production.bom.exception.duplicate_bom_item", items.size() - itemPartNumbers.size());
}
items.forEach(item -> {
if (item.itemPosition().split(",").length != item.manufactureCount()) {
throw new BusinessException("production.bom.exception.unpair_position_count");
throw new BusinessException("production.bom.exception.unpair_position_count",
item.partNumber(), item.itemPosition().split(",").length, item.manufactureCount());
}
});
var searchBomItemWrapper = new LambdaQueryWrapper<WarehouseItem>().in(WarehouseItem::getPartNumber, itemPartNumbers);
if (warehouseItemMapper.selectCount(searchBomItemWrapper) != items.size()) {
throw new BusinessException("production.bom.exception.unexists_bom_item");
long existingCount = warehouseItemMapper.selectCount(searchBomItemWrapper);
if (existingCount != items.size()) {
throw new BusinessException("production.bom.exception.unexists_bom_item", items.size() - existingCount);
}
// save

View File

@@ -60,7 +60,7 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
List<DeviceAddDto> deviceItems = dto.deviceItems();
if (deviceItems == null || deviceItems.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.no_device_items");
throw new BusinessException("production.finished_product_receipt.exception.no_device_items", dto.formCode());
}
List<String> snList = deviceItems.stream()
@@ -69,7 +69,8 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
Set<String> uniqueSnSet = new HashSet<>(snList);
if (uniqueSnSet.size() != snList.size()) {
throw new BusinessException("production.finished_product_receipt.exception.duplicate_sn_in_request");
throw new BusinessException("production.finished_product_receipt.exception.duplicate_sn_in_request",
snList.size() - uniqueSnSet.size());
}
List<String> macList = deviceItems.stream()
@@ -80,7 +81,8 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
if (!macList.isEmpty()) {
Set<String> uniqueMacSet = new HashSet<>(macList);
if (uniqueMacSet.size() != macList.size()) {
throw new BusinessException("production.finished_product_receipt.exception.duplicate_mac_in_request");
throw new BusinessException("production.finished_product_receipt.exception.duplicate_mac_in_request",
macList.size() - uniqueMacSet.size());
}
}
@@ -92,17 +94,19 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
if (!serialNumList.isEmpty()) {
Set<String> uniqueSerialNumSet = new HashSet<>(serialNumList);
if (uniqueSerialNumSet.size() != serialNumList.size()) {
throw new BusinessException("production.finished_product_receipt.exception.duplicate_serial_num_in_request");
throw new BusinessException("production.finished_product_receipt.exception.duplicate_serial_num_in_request",
serialNumList.size() - uniqueSerialNumSet.size());
}
}
List<String> invalidStatusSn = deviceItems.stream()
.filter(item -> !"已激活".equals(item.alTxt()))
.map(item -> "SN号" + item.productSn())
.map(DeviceAddDto::productSn)
.toList();
if (!invalidStatusSn.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.invalid_activation_status");
throw new BusinessException("production.finished_product_receipt.exception.invalid_activation_status",
String.join(", ", invalidStatusSn));
}
LambdaQueryWrapper<Device> snWrapper = new LambdaQueryWrapper<>();
@@ -114,11 +118,11 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
List<String> duplicateSnInDb = snList.stream()
.filter(existingSnSet::contains)
.map(sn -> "SN号" + sn)
.toList();
if (!duplicateSnInDb.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.sn_already_exists");
throw new BusinessException("production.finished_product_receipt.exception.sn_already_exists",
String.join(", ", duplicateSnInDb));
}
if (!macList.isEmpty()) {
@@ -132,11 +136,11 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
List<String> duplicateMacInDb = macList.stream()
.filter(existingMacSet::contains)
.map(mac -> "MAC地址" + mac)
.toList();
if (!duplicateMacInDb.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.mac_already_exists");
throw new BusinessException("production.finished_product_receipt.exception.mac_already_exists",
String.join(", ", duplicateMacInDb));
}
}
@@ -151,11 +155,11 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
List<String> duplicateSerialNumInDb = serialNumList.stream()
.filter(existingSerialNumSet::contains)
.map(serialNum -> "序列号:" + serialNum)
.toList();
if (!duplicateSerialNumInDb.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.serial_num_already_exists");
throw new BusinessException("production.finished_product_receipt.exception.serial_num_already_exists",
String.join(", ", duplicateSerialNumInDb));
}
}
@@ -190,10 +194,10 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
public void updateFinishedProductReceipt(FinishedProductReceiptDto dto) {
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("production.finished_product_receipt.exception.not_found");
throw new BusinessException("production.finished_product_receipt.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_receipt.exception.cannot_update_approved");
throw new BusinessException("production.finished_product_receipt.exception.cannot_update_approved", dto.id());
}
Document entity = finishedProductReceiptConverter.toEntity(dto);
@@ -207,10 +211,10 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
public void deleteFinishedProductReceipt(long id) {
Document existingEntity = this.baseMapper.selectById(id);
if (existingEntity == null) {
throw new BusinessException("production.finished_product_receipt.exception.not_found");
throw new BusinessException("production.finished_product_receipt.exception.not_found", id);
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved");
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved", id);
}
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
@@ -223,14 +227,17 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
@Override
public void deleteBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.ids_empty");
throw new BusinessException("production.finished_product_receipt.exception.ids_empty", 0);
}
List<Document> entities = this.baseMapper.selectBatchIds(ids);
boolean hasApproved = entities.stream()
.anyMatch(e -> e.getFormStatus() == FormStatus.APPROVE);
if (hasApproved) {
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved_batch");
long approvedCount = entities.stream()
.filter(e -> e.getFormStatus() == FormStatus.APPROVE)
.count();
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved_batch", approvedCount);
}
for (Long id : ids) {
@@ -266,15 +273,15 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
@Override
public void saveOutstock(DeviceOutstockRequest request) {
if (request == null) {
throw new BusinessException("production.finished_product_receipt.exception.request_null");
throw new BusinessException("production.finished_product_receipt.exception.request_null", "null");
}
if (request.keyAccountId() <= 0) {
throw new BusinessException("production.finished_product_receipt.exception.invalid_key_account");
throw new BusinessException("production.finished_product_receipt.exception.invalid_key_account", request.keyAccountId());
}
if (request.outstockList() == null || request.outstockList().isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.empty_outstock_list");
throw new BusinessException("production.finished_product_receipt.exception.empty_outstock_list", request.id());
}
// 提取有效SN列表
@@ -285,18 +292,18 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
.toList();
if (validSnList.isEmpty()) {
throw new BusinessException("production.finished_product_receipt.exception.invalid_sn_list");
throw new BusinessException("production.finished_product_receipt.exception.invalid_sn_list", request.id());
}
// 检查单据是否存在
Document document = this.baseMapper.selectById(request.id());
if (document == null) {
throw new BusinessException("production.finished_product_receipt.exception.document_not_found");
throw new BusinessException("production.finished_product_receipt.exception.document_not_found", request.id());
}
// 检查单据状态
if (document.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_receipt.exception.document_not_approved");
throw new BusinessException("production.finished_product_receipt.exception.document_not_approved", request.id());
}
// 使用事务处理出货操作
@@ -315,7 +322,7 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
int updatedCount = deviceMapper.update(null, updateWrapper);
if (updatedCount == 0) {
throw new BusinessException("production.finished_product_receipt.exception.no_device_updated");
throw new BusinessException("production.finished_product_receipt.exception.no_device_updated", request.id());
}
// 检查是否所有设备都已出货
@@ -336,8 +343,10 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
document.setUpdateUserId(SecurityUtils.getUserId());
document.setUpdateUserName(SecurityUtils.getUserName());
this.baseMapper.updateById(document);
} catch (BusinessException e) {
throw e;
} catch (Exception e) {
throw new BusinessException("production.finished_product_receipt.exception.outstock_failed");
throw new BusinessException("production.finished_product_receipt.exception.outstock_failed", request.id(), e.getMessage());
}
}
}

View File

@@ -66,31 +66,32 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
throw new BusinessException("production.finished_product_shipment.validate.dto.not_null");
}
if (dto.outStockType() == null) {
throw new BusinessException("production.finished_product_shipment.validate.out_stock_type.not_null");
throw new BusinessException("production.finished_product_shipment.validate.out_stock_type.not_null", dto.formCode());
}
if (!StringUtils.hasText(dto.formCode())) {
throw new BusinessException("production.finished_product_shipment.validate.form_code.not_null");
throw new BusinessException("production.finished_product_shipment.validate.form_code.not_null", dto.formName());
}
if (!StringUtils.hasText(dto.formName())) {
throw new BusinessException("production.finished_product_shipment.validate.form_name.not_null");
throw new BusinessException("production.finished_product_shipment.validate.form_name.not_null", dto.formCode());
}
if (dto.storeNo() == null) {
throw new BusinessException("production.finished_product_shipment.validate.store_no.not_null");
throw new BusinessException("production.finished_product_shipment.validate.store_no.not_null", dto.formCode());
}
List<FinishedProductShipmentItemDto> shipmentItems = dto.shipmentItems();
if (shipmentItems == null || shipmentItems.isEmpty()) {
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items", dto.formCode());
}
// 校验明细项
for (FinishedProductShipmentItemDto item : shipmentItems) {
if (!StringUtils.hasText(item.partNumber())) {
throw new BusinessException("production.finished_product_shipment.validate.part_number.not_blank");
throw new BusinessException("production.finished_product_shipment.validate.part_number.not_blank", dto.formCode());
}
if (item.productCount() == null || item.productCount() <= 0) {
throw new BusinessException("production.finished_product_shipment.validate.product_count.positive");
throw new BusinessException("production.finished_product_shipment.validate.product_count.positive",
item.partNumber(), item.productCount());
}
}
@@ -100,12 +101,13 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
.toList();
if (partNumberList.isEmpty()) {
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items", dto.formCode());
}
Set<String> uniquePartNumberSet = new HashSet<>(partNumberList);
if (uniquePartNumberSet.size() != partNumberList.size()) {
throw new BusinessException("production.finished_product_shipment.exception.duplicate_part_number_in_request");
throw new BusinessException("production.finished_product_shipment.exception.duplicate_part_number_in_request",
partNumberList.size() - uniquePartNumberSet.size());
}
LambdaQueryWrapper<WarehouseItem> itemWrapper = new LambdaQueryWrapper<>();
@@ -117,11 +119,11 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
List<String> notFoundPartNumbers = partNumberList.stream()
.filter(pn -> !existingPartNumberSet.contains(pn))
.map(pn -> "物料编号:" + pn)
.toList();
if (!notFoundPartNumbers.isEmpty()) {
throw new BusinessException("production.finished_product_shipment.exception.part_number_not_found");
throw new BusinessException("production.finished_product_shipment.exception.part_number_not_found",
String.join(", ", notFoundPartNumbers));
}
Document entity = finishedProductShipmentConverter.toEntity(dto);
@@ -160,10 +162,10 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
public void updateFinishedProductShipment(FinishedProductShipmentDto dto) {
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("production.finished_product_shipment.exception.not_found");
throw new BusinessException("production.finished_product_shipment.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_shipment.exception.cannot_update_approved");
throw new BusinessException("production.finished_product_shipment.exception.cannot_update_approved", dto.id());
}
Document entity = finishedProductShipmentConverter.toEntity(dto);
@@ -177,10 +179,10 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
public void deleteFinishedProductShipment(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("production.finished_product_shipment.exception.not_found");
throw new BusinessException("production.finished_product_shipment.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_shipment.exception.cannot_delete_approved");
throw new BusinessException("production.finished_product_shipment.exception.cannot_delete_approved", id);
}
this.baseMapper.deleteById(id);
@@ -194,17 +196,17 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
public void approve(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("production.finished_product_shipment.exception.not_found");
throw new BusinessException("production.finished_product_shipment.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_shipment.exception.already_approved");
throw new BusinessException("production.finished_product_shipment.exception.already_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> itemWrapper = new LambdaQueryWrapper<>();
itemWrapper.eq(DocumentMaterial::getDocumentNo, id);
List<DocumentMaterial> items = documentMaterialMapper.selectList(itemWrapper);
if (items == null || items.isEmpty()) {
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items", id);
}
Integer storeNo = entity.getStoreNo();
@@ -223,7 +225,10 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
for (DocumentMaterial item : items) {
Stock stock = stockMap.get(item.getPartNumber());
if (stock == null || stock.getProductCount() < item.getProductCount()) {
throw new BusinessException("production.finished_product_shipment.exception.insufficient_stock");
throw new BusinessException("production.finished_product_shipment.exception.insufficient_stock",
item.getPartNumber(),
stock != null ? stock.getProductCount() : 0,
item.getProductCount());
}
}
@@ -247,10 +252,10 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
public void unapprove(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("production.finished_product_shipment.exception.not_found");
throw new BusinessException("production.finished_product_shipment.exception.not_found", id);
}
if (entity.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("production.finished_product_shipment.exception.not_approved");
throw new BusinessException("production.finished_product_shipment.exception.not_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> itemWrapper = new LambdaQueryWrapper<>();

View File

@@ -127,10 +127,10 @@ public class ProductionIssueServiceImpl extends ServiceImpl<DocumentMapper, Docu
public void approvingProductionIssue(long id) {
Document issue = this.baseMapper.selectById(id);
if (Objects.isNull(issue)) {
throw new BusinessException("没有发料单");
throw new BusinessException("production.production_issue.exception.not_exists", id);
}
if (!issue.getFormStatus().equals(FormStatus.NO_APPROVE)) {
throw new BusinessException("已审核");
throw new BusinessException("production.production_issue.exception.already_approved", id);
}
List<DocumentMaterial> materials = documentMaterialMapper
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, issue.getId()));
@@ -160,10 +160,10 @@ public class ProductionIssueServiceImpl extends ServiceImpl<DocumentMapper, Docu
public void rejectProductionIssue(long id) {
Document issue = this.baseMapper.selectById(id);
if (Objects.isNull(issue)) {
throw new BusinessException("没有发料单");
throw new BusinessException("production.production_issue.exception.not_exists", id);
}
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
throw new BusinessException("已审核");
throw new BusinessException("production.production_issue.exception.not_approved", id);
}
List<DocumentMaterial> materials = documentMaterialMapper
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, issue.getId()));
@@ -194,19 +194,19 @@ public class ProductionIssueServiceImpl extends ServiceImpl<DocumentMapper, Docu
// 获取发料单
Document issue = this.baseMapper.selectById(id);
if (Objects.isNull(issue)) {
throw new BusinessException("没有发料单");
throw new BusinessException("production.production_issue.exception.not_exists", id);
}
// 检查发料单状态,只有审核通过的才能生成退料单
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
throw new BusinessException("只有审核通过的发料单才能生成退料单");
throw new BusinessException("production.production_issue.exception.only_approved_can_return", id);
}
// 获取发料单明细
List<DocumentMaterial> materials = documentMaterialMapper
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, issue.getId()));
if (materials == null || materials.isEmpty()) {
throw new BusinessException("发料单没有明细");
throw new BusinessException("production.production_issue.exception.no_items", id);
}
// 创建退料单

View File

@@ -231,11 +231,12 @@ public class ProductionPlanServiceImpl extends ServiceImpl<ProductionPlanMapper,
.selectList(new LambdaQueryWrapper<ProductionPlan>().in(ProductionPlan::getId, dto.ids()));
plans.forEach(plan -> {
if (!plan.getProductionStatus().equals(ProductionPlanStatus.NoComplete)) {
throw new BusinessException("production.production_plan.exception.must_no_complete");
throw new BusinessException("production.production_plan.exception.must_no_complete", plan.getId());
}
});
if (plans.stream().collect(Collectors.groupingBy(ProductionPlan::getStoreNo)).size() > 1) {
throw new BusinessException("production.production_plan.exception.more_than_one_warehouse");
throw new BusinessException("production.production_plan.exception.more_than_one_warehouse",
plans.stream().collect(Collectors.groupingBy(ProductionPlan::getStoreNo)).size());
}
plans.forEach(plan -> {
plan.setUpdateUserId(SecurityUtils.getUserId());

View File

@@ -90,15 +90,15 @@ public class ProductionReturnServiceImpl extends ServiceImpl<DocumentMapper, Doc
public void createProductionReturn(Long issueId, ProductionIssueAddDto dto) {
Document issue = this.baseMapper.selectById(issueId);
if (Objects.isNull(issue)) {
throw new BusinessException("production.production_issue.exception.issue_not_exists");
throw new BusinessException("production.production_issue.exception.issue_not_exists", issueId);
}
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
throw new BusinessException("production.production_issue.exception.only_approved_can_return");
throw new BusinessException("production.production_issue.exception.only_approved_can_return", issueId);
}
if (dto.items() == null || dto.items().isEmpty()) {
throw new BusinessException("production.production_issue.exception.no_return_items");
throw new BusinessException("production.production_issue.exception.no_return_items", issueId);
}
// 使用Converter转换主表信息
@@ -148,17 +148,17 @@ public class ProductionReturnServiceImpl extends ServiceImpl<DocumentMapper, Doc
// 获取退料单
Document returnDoc = this.baseMapper.selectById(id);
if (Objects.isNull(returnDoc)) {
throw new BusinessException("退料单不存在");
throw new BusinessException("production.production_return.exception.not_exists", id);
}
if (!returnDoc.getFormStatus().equals(FormStatus.NO_APPROVE)) {
throw new BusinessException("退料单已经审核");
throw new BusinessException("production.production_return.exception.already_approved", id);
}
// 获取退料单明细
List<DocumentMaterial> materials = documentMaterialMapper
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, returnDoc.getId()));
if (materials == null || materials.isEmpty()) {
throw new BusinessException("退料单没有明细");
throw new BusinessException("production.production_return.exception.no_items", id);
}
// 更新库存
@@ -194,17 +194,17 @@ public class ProductionReturnServiceImpl extends ServiceImpl<DocumentMapper, Doc
// 获取退料单
Document returnDoc = this.baseMapper.selectById(id);
if (Objects.isNull(returnDoc)) {
throw new BusinessException("退料单不存在");
throw new BusinessException("production.production_return.exception.not_exists", id);
}
if (!returnDoc.getFormStatus().equals(FormStatus.APPROVE)) {
throw new BusinessException("退料单不是已审核状态,不能反审");
throw new BusinessException("production.production_return.exception.not_approved", id);
}
// 获取退料单明细
List<DocumentMaterial> materials = documentMaterialMapper
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, returnDoc.getId()));
if (materials == null || materials.isEmpty()) {
throw new BusinessException("退料单没有明细");
throw new BusinessException("production.production_return.exception.no_items", id);
}
// 更新库存

View File

@@ -117,12 +117,12 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<DocumentMapper, Docume
@Override
public void updatePurchaseOrder(PurchaseOrderAddDto dto) {
if (dto.id() == null) {
throw new BusinessException("purchase.purchase_order.validate.id.not_null");
throw new BusinessException("purchase.purchase_order.validate.id.not_null", dto.vendorName());
}
Document entity = this.baseMapper.selectById(dto.id());
if (entity == null) {
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
throw new BusinessException("purchase.purchase_order.exception.order_not_exists", dto.id());
}
entity.setVendorName(dto.vendorName());
@@ -174,7 +174,7 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<DocumentMapper, Docume
public void deletePurchaseOrder(long id) {
Document order = this.baseMapper.selectById(id);
if (order == null) {
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
throw new BusinessException("purchase.purchase_order.exception.order_not_exists", id);
}
List<PurchaseOrderItem> items = purchaseOrderItemMapper.selectList(
@@ -185,7 +185,7 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<DocumentMapper, Docume
boolean hasInbound = items.stream()
.anyMatch(item -> item.getReceiptCount() != null && item.getReceiptCount() > 0);
if (hasInbound) {
throw new BusinessException("purchase.purchase_order.exception.order_has_inbound");
throw new BusinessException("purchase.purchase_order.exception.order_has_inbound", id);
}
purchaseOrderItemMapper.delete(
@@ -259,11 +259,11 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<DocumentMapper, Docume
public void inbound(PurchaseOrderInboundDto dto) {
Document order = this.baseMapper.selectById(dto.orderId());
if (order == null) {
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
throw new BusinessException("purchase.purchase_order.exception.order_not_exists", dto.orderId());
}
if (order.getFormStatus() == FormStatus.COMPLETE) {
throw new BusinessException("purchase.purchase_order.exception.order_already_completed");
throw new BusinessException("purchase.purchase_order.exception.order_already_completed", dto.orderId());
}
List<PurchaseOrderItem> items = purchaseOrderItemMapper.selectList(
@@ -279,14 +279,15 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<DocumentMapper, Docume
for (PurchaseOrderInboundItemDto inboundItem : dto.items()) {
PurchaseOrderItem item = itemMap.get(inboundItem.itemId());
if (item == null) {
throw new BusinessException("purchase.purchase_order.exception.item_not_exists");
throw new BusinessException("purchase.purchase_order.exception.item_not_exists", inboundItem.itemId());
}
int currentReceiptCount = item.getReceiptCount() != null ? item.getReceiptCount() : 0;
int remaining = item.getPurchaseCount() - currentReceiptCount;
if (inboundItem.inboundCount() > remaining) {
throw new BusinessException("purchase.purchase_order.exception.inbound_count_exceed");
throw new BusinessException("purchase.purchase_order.exception.inbound_count_exceed",
item.getPartNumber(), remaining, inboundItem.inboundCount());
}
item.setReceiptCount(currentReceiptCount + inboundItem.inboundCount());

View File

@@ -118,10 +118,10 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
public void updateSaleOrder(SaleOrderUpdateDto dto) {
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("sale.sale_order.exception.not_found");
throw new BusinessException("sale.sale_order.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("sale.sale_order.exception.cannot_update_approved");
throw new BusinessException("sale.sale_order.exception.cannot_update_approved", dto.id());
}
// 计算新的订单总额
@@ -172,10 +172,10 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
public void deleteSaleOrder(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("sale.sale_order.exception.not_found");
throw new BusinessException("sale.sale_order.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved");
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved", id);
}
this.baseMapper.deleteById(id);
@@ -188,7 +188,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
@Override
public void deleteBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
throw new BusinessException("sale.sale_order.exception.ids_empty");
throw new BusinessException("sale.sale_order.exception.ids_empty", 0);
}
LambdaQueryWrapper<Document> wrapper = new LambdaQueryWrapper<>();
@@ -196,7 +196,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
wrapper.eq(Document::getFormStatus, FormStatus.APPROVE);
Long approvedCount = this.baseMapper.selectCount(wrapper);
if (approvedCount > 0) {
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved_batch");
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved_batch", approvedCount);
}
this.baseMapper.deleteByIds(ids);
@@ -210,17 +210,17 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
public void approve(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("sale.sale_order.exception.not_found");
throw new BusinessException("sale.sale_order.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("sale.sale_order.exception.already_approved");
throw new BusinessException("sale.sale_order.exception.already_approved", id);
}
LambdaQueryWrapper<SaleOrderItem> itemWrapper = new LambdaQueryWrapper<>();
itemWrapper.eq(SaleOrderItem::getDocumentNo, id);
List<SaleOrderItem> items = saleOrderItemMapper.selectList(itemWrapper);
if (items == null || items.isEmpty()) {
throw new BusinessException("sale.sale_order.exception.no_sale_order_items");
throw new BusinessException("sale.sale_order.exception.no_sale_order_items", id);
}
// 验证并扣除库存
@@ -252,11 +252,12 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
}
if (stock == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found", item.getPartNumber());
}
if (stock.getProductCount() < item.getSaleCount()) {
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock",
item.getPartNumber(), stock.getProductCount(), item.getSaleCount());
}
// 扣除库存 - 如果有多条记录,只更新第一条
@@ -285,10 +286,10 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
public void unapprove(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("sale.sale_order.exception.not_found");
throw new BusinessException("sale.sale_order.exception.not_found", id);
}
if (entity.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("sale.sale_order.exception.not_approved");
throw new BusinessException("sale.sale_order.exception.not_approved", id);
}
LambdaQueryWrapper<SaleOrderItem> itemWrapper = new LambdaQueryWrapper<>();
@@ -301,7 +302,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
.count();
if (shippedCount > 0) {
throw new BusinessException("sale.sale_order.exception.cannot_unapprove_with_shipped");
throw new BusinessException("sale.sale_order.exception.cannot_unapprove_with_shipped", id, shippedCount);
}
// 恢复库存
@@ -329,7 +330,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
}
if (stock == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found", item.getPartNumber());
}
// 恢复库存 - 只更新第一条记录
@@ -398,7 +399,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
@Override
public List<SaleOrderItemDto> importItems(MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new BusinessException("sale.sale_order.exception.file_empty");
throw new BusinessException("sale.sale_order.exception.file_empty", file != null ? file.getOriginalFilename() : null);
}
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
@@ -429,7 +430,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
return items;
} catch (IOException e) {
throw new BusinessException("sale.sale_order.exception.import_failed");
throw new BusinessException("sale.sale_order.exception.import_failed", file.getOriginalFilename(), e.getMessage());
}
}

View File

@@ -123,10 +123,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 密码校验
if (!StringUtils.hasText(dto.passWord())) {
throw new BusinessException("sys.sysuser.validate.password.not_null");
throw new BusinessException("sys.sysuser.validate.password.not_null", dto.loginName());
}
if (!dto.passWord().equals(dto.confirmPassword())) {
throw new BusinessException("sys.sysuser.validate.password.not_match");
throw new BusinessException("sys.sysuser.validate.password.not_match", dto.loginName());
}
SysUser entity = sysUserConverter.toEntity(dto);
@@ -148,7 +148,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public void updateUser(Long id, SysUserDto dto) {
SysUser existUser = this.baseMapper.selectById(id);
if (existUser == null) {
throw new BusinessException("sys.sysuser.exception.not_exists");
throw new BusinessException("sys.sysuser.exception.not_exists", id);
}
// 检查登录账号是否已存在
@@ -163,7 +163,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 如果传了密码,则更新密码
if (StringUtils.hasText(dto.passWord())) {
if (!dto.passWord().equals(dto.confirmPassword())) {
throw new BusinessException("sys.sysuser.validate.password.not_match");
throw new BusinessException("sys.sysuser.validate.password.not_match", dto.loginName());
}
entity.setPassWord(passwordEncoder.encode(dto.passWord()));
} else {
@@ -207,7 +207,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public void setStatus(Long id, Integer status) {
SysUser user = this.baseMapper.selectById(id);
if (user == null) {
throw new BusinessException("sys.sysuser.exception.not_exists");
throw new BusinessException("sys.sysuser.exception.not_exists", id);
}
SysUser updateUser = new SysUser();
@@ -228,7 +228,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
Long count = this.baseMapper.selectCount(wrapper);
if (count > 0) {
throw new BusinessException("sys.sysuser.exception.login_name_exists");
throw new BusinessException("sys.sysuser.exception.login_name_exists", loginName);
}
}

View File

@@ -65,7 +65,7 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
.eq(Document::getReserve1, 1);
Document existingInit = this.baseMapper.selectOne(initWrapper);
if (existingInit != null) {
throw new BusinessException("warehouse.inventory_count.exception.init_already_exists");
throw new BusinessException("warehouse.inventory_count.exception.init_already_exists", dto.storeNo(), existingInit.getId());
}
}
@@ -123,10 +123,10 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
public void updateInventoryCount(InventoryCountDto dto) {
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("warehouse.inventory_count.exception.not_found");
throw new BusinessException("warehouse.inventory_count.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.inventory_count.exception.cannot_update_approved");
throw new BusinessException("warehouse.inventory_count.exception.cannot_update_approved", dto.id());
}
Document entity = inventoryCountConverter.toEntity(dto);
@@ -140,10 +140,10 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
public void deleteInventoryCount(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.inventory_count.exception.not_found");
throw new BusinessException("warehouse.inventory_count.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved");
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved", id);
}
this.baseMapper.deleteById(id);
@@ -156,7 +156,7 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
@Override
public void deleteBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
throw new BusinessException("warehouse.inventory_count.exception.ids_empty");
throw new BusinessException("warehouse.inventory_count.exception.ids_empty", 0);
}
LambdaQueryWrapper<Document> wrapper = new LambdaQueryWrapper<>();
@@ -164,7 +164,7 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
wrapper.eq(Document::getFormStatus, FormStatus.APPROVE);
Long approvedCount = this.baseMapper.selectCount(wrapper);
if (approvedCount > 0) {
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved_batch");
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved_batch", approvedCount);
}
this.baseMapper.deleteByIds(ids);
@@ -178,17 +178,17 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
public void approve(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.inventory_count.exception.not_found");
throw new BusinessException("warehouse.inventory_count.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.inventory_count.exception.already_approved");
throw new BusinessException("warehouse.inventory_count.exception.already_approved", id);
}
LambdaQueryWrapper<InventoryCountItem> itemWrapper = new LambdaQueryWrapper<>();
itemWrapper.eq(InventoryCountItem::getDocumentNo, id);
List<InventoryCountItem> items = inventoryCountItemMapper.selectList(itemWrapper);
if (items == null || items.isEmpty()) {
throw new BusinessException("warehouse.inventory_count.exception.no_items");
throw new BusinessException("warehouse.inventory_count.exception.no_items", id);
}
entity.setFormStatus(FormStatus.APPROVE);
@@ -209,10 +209,10 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
public void unapprove(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.inventory_count.exception.not_found");
throw new BusinessException("warehouse.inventory_count.exception.not_found", id);
}
if (entity.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("warehouse.inventory_count.exception.not_approved");
throw new BusinessException("warehouse.inventory_count.exception.not_approved", id);
}
LambdaQueryWrapper<InventoryCountItem> itemWrapper = new LambdaQueryWrapper<>();
@@ -284,7 +284,7 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
@Override
public List<InventoryCountItemDto> importItems(MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new BusinessException("warehouse.inventory_count.exception.file_empty");
throw new BusinessException("warehouse.inventory_count.exception.file_empty", file != null ? file.getOriginalFilename() : null);
}
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
@@ -319,7 +319,7 @@ public class InventoryCountServiceImpl extends ServiceImpl<DocumentMapper, Docum
return items;
} catch (IOException e) {
throw new BusinessException("warehouse.inventory_count.exception.import_failed");
throw new BusinessException("warehouse.inventory_count.exception.import_failed", file.getOriginalFilename(), e.getMessage());
}
}

View File

@@ -142,15 +142,15 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
@Override
public void updateStockTransferOrder(StockTransferOrderAddDto dto) {
if (dto.id() == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.id_required");
throw new BusinessException("warehouse.stock_transfer_order.exception.id_required", dto.formCode());
}
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_update_approved");
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_update_approved", dto.id());
}
Document entity = stockTransferOrderConverter.toEntity(dto);
@@ -203,10 +203,10 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
public void deleteStockTransferOrder(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved");
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved", id);
}
this.baseMapper.deleteById(id);
@@ -219,7 +219,7 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
@Override
public void deleteBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
throw new BusinessException("warehouse.stock_transfer_order.exception.ids_empty");
throw new BusinessException("warehouse.stock_transfer_order.exception.ids_empty", 0);
}
LambdaQueryWrapper<Document> wrapper = new LambdaQueryWrapper<>();
@@ -227,7 +227,7 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
wrapper.eq(Document::getFormStatus, FormStatus.APPROVE);
Long approvedCount = this.baseMapper.selectCount(wrapper);
if (approvedCount > 0) {
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved_batch");
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved_batch", approvedCount);
}
this.baseMapper.deleteByIds(ids);
@@ -241,17 +241,17 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
public void approve(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.stock_transfer_order.exception.already_approved");
throw new BusinessException("warehouse.stock_transfer_order.exception.already_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
materialWrapper.eq(DocumentMaterial::getDocumentNo, id);
List<DocumentMaterial> materialList = documentMaterialMapper.selectList(materialWrapper);
if (materialList == null || materialList.isEmpty()) {
throw new BusinessException("warehouse.stock_transfer_order.exception.no_materials");
throw new BusinessException("warehouse.stock_transfer_order.exception.no_materials", id);
}
Integer outStoreNo = entity.getOutStoreNo();
@@ -270,7 +270,10 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
for (DocumentMaterial material : materialList) {
Stock outStock = outStockMap.get(material.getPartNumber());
if (outStock == null || outStock.getProductCount() < material.getProductCount()) {
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock",
material.getPartNumber(),
outStock != null ? outStock.getProductCount() : 0,
material.getProductCount());
}
}
@@ -337,10 +340,10 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
public void reject(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found", id);
}
if (entity.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("warehouse.stock_transfer_order.exception.not_approved");
throw new BusinessException("warehouse.stock_transfer_order.exception.not_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
@@ -391,10 +394,11 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
for (DocumentMaterial material : materialList) {
Stock inStock = inStockMap.get(material.getPartNumber());
if (inStock == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found", material.getPartNumber());
}
if (inStock.getProductCount() < material.getProductCount()) {
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock_for_unapprove");
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock_for_unapprove",
material.getPartNumber(), inStock.getProductCount(), material.getProductCount());
}
inStock.setProductCount(inStock.getProductCount() - material.getProductCount());
inStock.setUpdateDate(LocalDateTime.now());
@@ -425,7 +429,8 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
private void validateTransferOrder(StockTransferOrderAddDto dto) {
if (dto.storeNo().equals(dto.outStoreNo())) {
throw new BusinessException("warehouse.stock_transfer_order.exception.same_warehouse");
throw new BusinessException("warehouse.stock_transfer_order.exception.same_warehouse",
dto.storeNo(), dto.outStoreNo());
}
Map<String, Integer> partCountMap = new HashMap<>();
@@ -443,12 +448,13 @@ public class StockTransferOrderServiceImpl extends ServiceImpl<DocumentMapper, D
Map<String, Object> stockInfo = warehouseItems.get(partNumber);
if (stockInfo == null) {
throw new BusinessException("warehouse.stock_transfer_order.exception.part_not_found");
throw new BusinessException("warehouse.stock_transfer_order.exception.part_not_found", partNumber);
}
Long stockCount = (Long) stockInfo.get("productCount");
if (stockCount == null || stockCount < totalTransfer) {
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock",
partNumber, stockCount != null ? stockCount : 0, totalTransfer);
}
}
}

View File

@@ -103,7 +103,7 @@ public class WarehouseItemServiceImpl extends ServiceImpl<WarehouseItemMapper, W
public List<ProductVendorMapDto> getVendorListByWarehouseItemId(Long warehouseItemId) {
WarehouseItem warehouseItem = this.baseMapper.selectById(warehouseItemId);
if (warehouseItem == null) {
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
throw new BusinessException("warehouse.warehouse_item.exception.not_found", warehouseItemId);
}
String partNumber = warehouseItem.getPartNumber();
@@ -148,7 +148,7 @@ public class WarehouseItemServiceImpl extends ServiceImpl<WarehouseItemMapper, W
public void saveVendorList(ProductVendorMapAddDto dto) {
WarehouseItem warehouseItem = this.baseMapper.selectById(dto.warehouseItemId());
if (warehouseItem == null) {
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
throw new BusinessException("warehouse.warehouse_item.exception.not_found", dto.warehouseItemId());
}
String partNumber = warehouseItem.getPartNumber();
@@ -156,7 +156,7 @@ public class WarehouseItemServiceImpl extends ServiceImpl<WarehouseItemMapper, W
Set<Long> vendorIds = new HashSet<>();
for (ProductVendorMapAddDto.ProductVendorMapItemDto item : dto.vendorList()) {
if (!vendorIds.add(item.vendorId())) {
throw new BusinessException("warehouse.warehouse_item.exception.vendor_duplicate");
throw new BusinessException("warehouse.warehouse_item.exception.vendor_duplicate", item.vendorId());
}
}
}
@@ -194,7 +194,7 @@ public class WarehouseItemServiceImpl extends ServiceImpl<WarehouseItemMapper, W
public String getPartNumberById(Long warehouseItemId) {
WarehouseItem warehouseItem = this.baseMapper.selectById(warehouseItemId);
if (warehouseItem == null) {
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
throw new BusinessException("warehouse.warehouse_item.exception.not_found", warehouseItemId);
}
return warehouseItem.getPartNumber();
}

View File

@@ -87,10 +87,10 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
public void updateWarehouseReceipt(WarehouseReceiptDto dto) {
Document existingEntity = this.baseMapper.selectById(dto.id());
if (existingEntity == null) {
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found", dto.id());
}
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_update_approved");
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_update_approved", dto.id());
}
Document entity = warehouseReceiptConverter.toEntity(dto);
@@ -122,10 +122,10 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
public void deleteWarehouseReceipt(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved");
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved", id);
}
this.baseMapper.deleteById(id);
@@ -138,7 +138,7 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
@Override
public void deleteBatch(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
throw new BusinessException("warehouse.warehouse_receipt.exception.ids_empty");
throw new BusinessException("warehouse.warehouse_receipt.exception.ids_empty", 0);
}
LambdaQueryWrapper<Document> wrapper = new LambdaQueryWrapper<>();
@@ -146,7 +146,7 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
wrapper.eq(Document::getFormStatus, FormStatus.APPROVE);
Long approvedCount = this.baseMapper.selectCount(wrapper);
if (approvedCount > 0) {
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved_batch");
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved_batch", approvedCount);
}
this.baseMapper.deleteByIds(ids);
@@ -160,17 +160,17 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
public void approve(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found", id);
}
if (entity.getFormStatus() == FormStatus.APPROVE) {
throw new BusinessException("warehouse.warehouse_receipt.exception.already_approved");
throw new BusinessException("warehouse.warehouse_receipt.exception.already_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
materialWrapper.eq(DocumentMaterial::getDocumentNo, id);
List<DocumentMaterial> materialList = documentMaterialMapper.selectList(materialWrapper);
if (materialList == null || materialList.isEmpty()) {
throw new BusinessException("warehouse.warehouse_receipt.exception.no_materials");
throw new BusinessException("warehouse.warehouse_receipt.exception.no_materials", id);
}
Integer storeNo = entity.getStoreNo();
@@ -233,10 +233,10 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
public void reject(long id) {
Document entity = this.baseMapper.selectById(id);
if (entity == null) {
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found", id);
}
if (entity.getFormStatus() != FormStatus.APPROVE) {
throw new BusinessException("warehouse.warehouse_receipt.exception.not_approved");
throw new BusinessException("warehouse.warehouse_receipt.exception.not_approved", id);
}
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
@@ -258,10 +258,11 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl<DocumentMapper, Doc
for (DocumentMaterial material : materialList) {
Stock existingStock = existingStockMap.get(material.getPartNumber());
if (existingStock == null) {
throw new BusinessException("warehouse.warehouse_receipt.exception.stock_not_found");
throw new BusinessException("warehouse.warehouse_receipt.exception.stock_not_found", material.getPartNumber());
}
if (existingStock.getProductCount() < material.getProductCount()) {
throw new BusinessException("warehouse.warehouse_receipt.exception.insufficient_stock_for_unapprove");
throw new BusinessException("warehouse.warehouse_receipt.exception.insufficient_stock_for_unapprove",
material.getPartNumber(), existingStock.getProductCount(), material.getProductCount());
}
existingStock.setProductCount(existingStock.getProductCount() - material.getProductCount());
existingStock.setUpdateDate(LocalDateTime.now());