@@ -1,29 +1,7 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(), e.getArgs(), locale)));
|
||||
BaseResult.error(3, messageSource.getMessage(e.getMessage(), null, 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(), e.getArgs(), locale)));
|
||||
BaseResult.error(4, messageSource.getMessage(e.getMessage(), null, locale)));
|
||||
}
|
||||
|
||||
// /**
|
||||
@@ -90,7 +90,7 @@ public class GlobalExceptionHandler {
|
||||
// * @return
|
||||
// */
|
||||
// @ExceptionHandler(Exception.class)
|
||||
// public ExceptionHandler(Exception e, Locale locale) {
|
||||
// public ResponseEntity<?> handleException(Exception e, Locale locale) {
|
||||
// return ResponseEntity.badRequest().body(
|
||||
// BaseResult.error(-1, e.getMessage()));
|
||||
// }
|
||||
|
||||
@@ -72,23 +72,21 @@ 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", dto.bomName());
|
||||
throw new BusinessException("production.bom.exception.duplicate_bom_name");
|
||||
}
|
||||
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", items.size() - itemPartNumbers.size());
|
||||
throw new BusinessException("production.bom.exception.duplicate_bom_item");
|
||||
}
|
||||
items.forEach(item -> {
|
||||
if (item.itemPosition().split(",").length != item.manufactureCount()) {
|
||||
throw new BusinessException("production.bom.exception.unpair_position_count",
|
||||
item.partNumber(), item.itemPosition().split(",").length, item.manufactureCount());
|
||||
throw new BusinessException("production.bom.exception.unpair_position_count");
|
||||
}
|
||||
});
|
||||
var searchBomItemWrapper = new LambdaQueryWrapper<WarehouseItem>().in(WarehouseItem::getPartNumber, itemPartNumbers);
|
||||
long existingCount = warehouseItemMapper.selectCount(searchBomItemWrapper);
|
||||
if (existingCount != items.size()) {
|
||||
throw new BusinessException("production.bom.exception.unexists_bom_item", items.size() - existingCount);
|
||||
if (warehouseItemMapper.selectCount(searchBomItemWrapper) != items.size()) {
|
||||
throw new BusinessException("production.bom.exception.unexists_bom_item");
|
||||
}
|
||||
|
||||
// save
|
||||
|
||||
@@ -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", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.no_device_items");
|
||||
}
|
||||
|
||||
List<String> snList = deviceItems.stream()
|
||||
@@ -69,8 +69,7 @@ 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",
|
||||
snList.size() - uniqueSnSet.size());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.duplicate_sn_in_request");
|
||||
}
|
||||
|
||||
List<String> macList = deviceItems.stream()
|
||||
@@ -81,8 +80,7 @@ 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",
|
||||
macList.size() - uniqueMacSet.size());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.duplicate_mac_in_request");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,19 +92,17 @@ 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",
|
||||
serialNumList.size() - uniqueSerialNumSet.size());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.duplicate_serial_num_in_request");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> invalidStatusSn = deviceItems.stream()
|
||||
.filter(item -> !"已激活".equals(item.alTxt()))
|
||||
.map(DeviceAddDto::productSn)
|
||||
.map(item -> "SN号:" + item.productSn())
|
||||
.toList();
|
||||
|
||||
if (!invalidStatusSn.isEmpty()) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_activation_status",
|
||||
String.join(", ", invalidStatusSn));
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_activation_status");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<Device> snWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -118,11 +114,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",
|
||||
String.join(", ", duplicateSnInDb));
|
||||
throw new BusinessException("production.finished_product_receipt.exception.sn_already_exists");
|
||||
}
|
||||
|
||||
if (!macList.isEmpty()) {
|
||||
@@ -136,11 +132,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",
|
||||
String.join(", ", duplicateMacInDb));
|
||||
throw new BusinessException("production.finished_product_receipt.exception.mac_already_exists");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +151,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",
|
||||
String.join(", ", duplicateSerialNumInDb));
|
||||
throw new BusinessException("production.finished_product_receipt.exception.serial_num_already_exists");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,10 +190,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", dto.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
Document entity = finishedProductReceiptConverter.toEntity(dto);
|
||||
@@ -211,10 +207,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", id);
|
||||
throw new BusinessException("production.finished_product_receipt.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
|
||||
@@ -227,17 +223,14 @@ 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", 0);
|
||||
throw new BusinessException("production.finished_product_receipt.exception.ids_empty");
|
||||
}
|
||||
|
||||
List<Document> entities = this.baseMapper.selectBatchIds(ids);
|
||||
boolean hasApproved = entities.stream()
|
||||
.anyMatch(e -> e.getFormStatus() == FormStatus.APPROVE);
|
||||
if (hasApproved) {
|
||||
long approvedCount = entities.stream()
|
||||
.filter(e -> e.getFormStatus() == FormStatus.APPROVE)
|
||||
.count();
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved_batch", approvedCount);
|
||||
throw new BusinessException("production.finished_product_receipt.exception.cannot_delete_approved_batch");
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
@@ -273,15 +266,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", "null");
|
||||
throw new BusinessException("production.finished_product_receipt.exception.request_null");
|
||||
}
|
||||
|
||||
if (request.keyAccountId() <= 0) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_key_account", request.keyAccountId());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_key_account");
|
||||
}
|
||||
|
||||
if (request.outstockList() == null || request.outstockList().isEmpty()) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.empty_outstock_list", request.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.empty_outstock_list");
|
||||
}
|
||||
|
||||
// 提取有效SN列表
|
||||
@@ -292,18 +285,18 @@ public class FinishedProductReceiptServiceImpl extends ServiceImpl<DocumentMappe
|
||||
.toList();
|
||||
|
||||
if (validSnList.isEmpty()) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_sn_list", request.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.invalid_sn_list");
|
||||
}
|
||||
|
||||
// 检查单据是否存在
|
||||
Document document = this.baseMapper.selectById(request.id());
|
||||
if (document == null) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.document_not_found", request.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.document_not_found");
|
||||
}
|
||||
|
||||
// 检查单据状态
|
||||
if (document.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_receipt.exception.document_not_approved", request.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.document_not_approved");
|
||||
}
|
||||
|
||||
// 使用事务处理出货操作
|
||||
@@ -322,7 +315,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", request.id());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.no_device_updated");
|
||||
}
|
||||
|
||||
// 检查是否所有设备都已出货
|
||||
@@ -343,10 +336,8 @@ 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", request.id(), e.getMessage());
|
||||
throw new BusinessException("production.finished_product_receipt.exception.outstock_failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,32 +66,31 @@ 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", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.out_stock_type.not_null");
|
||||
}
|
||||
if (!StringUtils.hasText(dto.formCode())) {
|
||||
throw new BusinessException("production.finished_product_shipment.validate.form_code.not_null", dto.formName());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.form_code.not_null");
|
||||
}
|
||||
if (!StringUtils.hasText(dto.formName())) {
|
||||
throw new BusinessException("production.finished_product_shipment.validate.form_name.not_null", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.form_name.not_null");
|
||||
}
|
||||
if (dto.storeNo() == null) {
|
||||
throw new BusinessException("production.finished_product_shipment.validate.store_no.not_null", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.store_no.not_null");
|
||||
}
|
||||
|
||||
List<FinishedProductShipmentItemDto> shipmentItems = dto.shipmentItems();
|
||||
|
||||
if (shipmentItems == null || shipmentItems.isEmpty()) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
|
||||
}
|
||||
|
||||
// 校验明细项
|
||||
for (FinishedProductShipmentItemDto item : shipmentItems) {
|
||||
if (!StringUtils.hasText(item.partNumber())) {
|
||||
throw new BusinessException("production.finished_product_shipment.validate.part_number.not_blank", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.part_number.not_blank");
|
||||
}
|
||||
if (item.productCount() == null || item.productCount() <= 0) {
|
||||
throw new BusinessException("production.finished_product_shipment.validate.product_count.positive",
|
||||
item.partNumber(), item.productCount());
|
||||
throw new BusinessException("production.finished_product_shipment.validate.product_count.positive");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,13 +100,12 @@ public class FinishedProductShipmentServiceImpl extends ServiceImpl<DocumentMapp
|
||||
.toList();
|
||||
|
||||
if (partNumberList.isEmpty()) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items", dto.formCode());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
|
||||
}
|
||||
|
||||
Set<String> uniquePartNumberSet = new HashSet<>(partNumberList);
|
||||
if (uniquePartNumberSet.size() != partNumberList.size()) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.duplicate_part_number_in_request",
|
||||
partNumberList.size() - uniquePartNumberSet.size());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.duplicate_part_number_in_request");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<WarehouseItem> itemWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -119,11 +117,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",
|
||||
String.join(", ", notFoundPartNumbers));
|
||||
throw new BusinessException("production.finished_product_shipment.exception.part_number_not_found");
|
||||
}
|
||||
|
||||
Document entity = finishedProductShipmentConverter.toEntity(dto);
|
||||
@@ -162,10 +160,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", dto.id());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
Document entity = finishedProductShipmentConverter.toEntity(dto);
|
||||
@@ -179,10 +177,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", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
this.baseMapper.deleteById(id);
|
||||
@@ -196,17 +194,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", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.already_approved", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.already_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.no_shipment_items");
|
||||
}
|
||||
|
||||
Integer storeNo = entity.getStoreNo();
|
||||
@@ -225,10 +223,7 @@ 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",
|
||||
item.getPartNumber(),
|
||||
stock != null ? stock.getProductCount() : 0,
|
||||
item.getProductCount());
|
||||
throw new BusinessException("production.finished_product_shipment.exception.insufficient_stock");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,10 +247,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", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_approved", id);
|
||||
throw new BusinessException("production.finished_product_shipment.exception.not_approved");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<DocumentMaterial> itemWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
@@ -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("production.production_issue.exception.not_exists", id);
|
||||
throw new BusinessException("没有发料单");
|
||||
}
|
||||
if (!issue.getFormStatus().equals(FormStatus.NO_APPROVE)) {
|
||||
throw new BusinessException("production.production_issue.exception.already_approved", id);
|
||||
throw new BusinessException("已审核");
|
||||
}
|
||||
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("production.production_issue.exception.not_exists", id);
|
||||
throw new BusinessException("没有发料单");
|
||||
}
|
||||
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
|
||||
throw new BusinessException("production.production_issue.exception.not_approved", id);
|
||||
throw new BusinessException("已审核");
|
||||
}
|
||||
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("production.production_issue.exception.not_exists", id);
|
||||
throw new BusinessException("没有发料单");
|
||||
}
|
||||
|
||||
// 检查发料单状态,只有审核通过的才能生成退料单
|
||||
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
|
||||
throw new BusinessException("production.production_issue.exception.only_approved_can_return", id);
|
||||
throw new BusinessException("只有审核通过的发料单才能生成退料单");
|
||||
}
|
||||
|
||||
// 获取发料单明细
|
||||
List<DocumentMaterial> materials = documentMaterialMapper
|
||||
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, issue.getId()));
|
||||
if (materials == null || materials.isEmpty()) {
|
||||
throw new BusinessException("production.production_issue.exception.no_items", id);
|
||||
throw new BusinessException("发料单没有明细");
|
||||
}
|
||||
|
||||
// 创建退料单
|
||||
|
||||
@@ -231,12 +231,11 @@ 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", plan.getId());
|
||||
throw new BusinessException("production.production_plan.exception.must_no_complete");
|
||||
}
|
||||
});
|
||||
if (plans.stream().collect(Collectors.groupingBy(ProductionPlan::getStoreNo)).size() > 1) {
|
||||
throw new BusinessException("production.production_plan.exception.more_than_one_warehouse",
|
||||
plans.stream().collect(Collectors.groupingBy(ProductionPlan::getStoreNo)).size());
|
||||
throw new BusinessException("production.production_plan.exception.more_than_one_warehouse");
|
||||
}
|
||||
plans.forEach(plan -> {
|
||||
plan.setUpdateUserId(SecurityUtils.getUserId());
|
||||
|
||||
@@ -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", issueId);
|
||||
throw new BusinessException("production.production_issue.exception.issue_not_exists");
|
||||
}
|
||||
|
||||
if (!issue.getFormStatus().equals(FormStatus.APPROVE)) {
|
||||
throw new BusinessException("production.production_issue.exception.only_approved_can_return", issueId);
|
||||
throw new BusinessException("production.production_issue.exception.only_approved_can_return");
|
||||
}
|
||||
|
||||
if (dto.items() == null || dto.items().isEmpty()) {
|
||||
throw new BusinessException("production.production_issue.exception.no_return_items", issueId);
|
||||
throw new BusinessException("production.production_issue.exception.no_return_items");
|
||||
}
|
||||
|
||||
// 使用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("production.production_return.exception.not_exists", id);
|
||||
throw new BusinessException("退料单不存在");
|
||||
}
|
||||
if (!returnDoc.getFormStatus().equals(FormStatus.NO_APPROVE)) {
|
||||
throw new BusinessException("production.production_return.exception.already_approved", id);
|
||||
throw new BusinessException("退料单已经审核");
|
||||
}
|
||||
|
||||
// 获取退料单明细
|
||||
List<DocumentMaterial> materials = documentMaterialMapper
|
||||
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, returnDoc.getId()));
|
||||
if (materials == null || materials.isEmpty()) {
|
||||
throw new BusinessException("production.production_return.exception.no_items", id);
|
||||
throw new BusinessException("退料单没有明细");
|
||||
}
|
||||
|
||||
// 更新库存
|
||||
@@ -194,17 +194,17 @@ public class ProductionReturnServiceImpl extends ServiceImpl<DocumentMapper, Doc
|
||||
// 获取退料单
|
||||
Document returnDoc = this.baseMapper.selectById(id);
|
||||
if (Objects.isNull(returnDoc)) {
|
||||
throw new BusinessException("production.production_return.exception.not_exists", id);
|
||||
throw new BusinessException("退料单不存在");
|
||||
}
|
||||
if (!returnDoc.getFormStatus().equals(FormStatus.APPROVE)) {
|
||||
throw new BusinessException("production.production_return.exception.not_approved", id);
|
||||
throw new BusinessException("退料单不是已审核状态,不能反审");
|
||||
}
|
||||
|
||||
// 获取退料单明细
|
||||
List<DocumentMaterial> materials = documentMaterialMapper
|
||||
.selectList(new LambdaQueryWrapper<DocumentMaterial>().eq(DocumentMaterial::getDocumentNo, returnDoc.getId()));
|
||||
if (materials == null || materials.isEmpty()) {
|
||||
throw new BusinessException("production.production_return.exception.no_items", id);
|
||||
throw new BusinessException("退料单没有明细");
|
||||
}
|
||||
|
||||
// 更新库存
|
||||
|
||||
@@ -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", dto.vendorName());
|
||||
throw new BusinessException("purchase.purchase_order.validate.id.not_null");
|
||||
}
|
||||
|
||||
Document entity = this.baseMapper.selectById(dto.id());
|
||||
if (entity == null) {
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_not_exists", dto.id());
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_has_inbound");
|
||||
}
|
||||
|
||||
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", dto.orderId());
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_not_exists");
|
||||
}
|
||||
|
||||
if (order.getFormStatus() == FormStatus.COMPLETE) {
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_already_completed", dto.orderId());
|
||||
throw new BusinessException("purchase.purchase_order.exception.order_already_completed");
|
||||
}
|
||||
|
||||
List<PurchaseOrderItem> items = purchaseOrderItemMapper.selectList(
|
||||
@@ -279,15 +279,14 @@ 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", inboundItem.itemId());
|
||||
throw new BusinessException("purchase.purchase_order.exception.item_not_exists");
|
||||
}
|
||||
|
||||
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",
|
||||
item.getPartNumber(), remaining, inboundItem.inboundCount());
|
||||
throw new BusinessException("purchase.purchase_order.exception.inbound_count_exceed");
|
||||
}
|
||||
|
||||
item.setReceiptCount(currentReceiptCount + inboundItem.inboundCount());
|
||||
|
||||
@@ -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", dto.id());
|
||||
throw new BusinessException("sale.sale_order.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
// 计算新的订单总额
|
||||
@@ -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", id);
|
||||
throw new BusinessException("sale.sale_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
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", 0);
|
||||
throw new BusinessException("sale.sale_order.exception.ids_empty");
|
||||
}
|
||||
|
||||
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", approvedCount);
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_delete_approved_batch");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("sale.sale_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("sale.sale_order.exception.already_approved", id);
|
||||
throw new BusinessException("sale.sale_order.exception.already_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("sale.sale_order.exception.no_sale_order_items");
|
||||
}
|
||||
|
||||
// 验证并扣除库存
|
||||
@@ -252,12 +252,11 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
|
||||
}
|
||||
|
||||
if (stock == null) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found", item.getPartNumber());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
|
||||
}
|
||||
|
||||
if (stock.getProductCount() < item.getSaleCount()) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock",
|
||||
item.getPartNumber(), stock.getProductCount(), item.getSaleCount());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
|
||||
}
|
||||
|
||||
// 扣除库存 - 如果有多条记录,只更新第一条
|
||||
@@ -286,10 +285,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", id);
|
||||
throw new BusinessException("sale.sale_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("sale.sale_order.exception.not_approved", id);
|
||||
throw new BusinessException("sale.sale_order.exception.not_approved");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<SaleOrderItem> itemWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -302,7 +301,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
|
||||
.count();
|
||||
|
||||
if (shippedCount > 0) {
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_unapprove_with_shipped", id, shippedCount);
|
||||
throw new BusinessException("sale.sale_order.exception.cannot_unapprove_with_shipped");
|
||||
}
|
||||
|
||||
// 恢复库存
|
||||
@@ -330,7 +329,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
|
||||
}
|
||||
|
||||
if (stock == null) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found", item.getPartNumber());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
|
||||
}
|
||||
|
||||
// 恢复库存 - 只更新第一条记录
|
||||
@@ -399,7 +398,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", file != null ? file.getOriginalFilename() : null);
|
||||
throw new BusinessException("sale.sale_order.exception.file_empty");
|
||||
}
|
||||
|
||||
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
|
||||
@@ -430,7 +429,7 @@ public class SaleOrderServiceImpl extends ServiceImpl<DocumentMapper, Document>
|
||||
|
||||
return items;
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("sale.sale_order.exception.import_failed", file.getOriginalFilename(), e.getMessage());
|
||||
throw new BusinessException("sale.sale_order.exception.import_failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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", dto.loginName());
|
||||
throw new BusinessException("sys.sysuser.validate.password.not_null");
|
||||
}
|
||||
if (!dto.passWord().equals(dto.confirmPassword())) {
|
||||
throw new BusinessException("sys.sysuser.validate.password.not_match", dto.loginName());
|
||||
throw new BusinessException("sys.sysuser.validate.password.not_match");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("sys.sysuser.exception.not_exists");
|
||||
}
|
||||
|
||||
// 检查登录账号是否已存在
|
||||
@@ -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", dto.loginName());
|
||||
throw new BusinessException("sys.sysuser.validate.password.not_match");
|
||||
}
|
||||
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", id);
|
||||
throw new BusinessException("sys.sysuser.exception.not_exists");
|
||||
}
|
||||
|
||||
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", loginName);
|
||||
throw new BusinessException("sys.sysuser.exception.login_name_exists");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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", dto.storeNo(), existingInit.getId());
|
||||
throw new BusinessException("warehouse.inventory_count.exception.init_already_exists");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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", dto.id());
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.inventory_count.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("warehouse.inventory_count.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
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", 0);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.ids_empty");
|
||||
}
|
||||
|
||||
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", approvedCount);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.cannot_delete_approved_batch");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.inventory_count.exception.already_approved", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.already_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.no_items");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_approved", id);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.not_approved");
|
||||
}
|
||||
|
||||
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", file != null ? file.getOriginalFilename() : null);
|
||||
throw new BusinessException("warehouse.inventory_count.exception.file_empty");
|
||||
}
|
||||
|
||||
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", file.getOriginalFilename(), e.getMessage());
|
||||
throw new BusinessException("warehouse.inventory_count.exception.import_failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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", dto.formCode());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.id_required");
|
||||
}
|
||||
|
||||
Document existingEntity = this.baseMapper.selectById(dto.id());
|
||||
if (existingEntity == null) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found", dto.id());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
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", 0);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.ids_empty");
|
||||
}
|
||||
|
||||
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", approvedCount);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.cannot_delete_approved_batch");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.already_approved", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.already_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.no_materials");
|
||||
}
|
||||
|
||||
Integer outStoreNo = entity.getOutStoreNo();
|
||||
@@ -270,10 +270,7 @@ 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",
|
||||
material.getPartNumber(),
|
||||
outStock != null ? outStock.getProductCount() : 0,
|
||||
material.getProductCount());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,10 +337,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", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_approved", id);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.not_approved");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -394,11 +391,10 @@ 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", material.getPartNumber());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.stock_not_found");
|
||||
}
|
||||
if (inStock.getProductCount() < material.getProductCount()) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock_for_unapprove",
|
||||
material.getPartNumber(), inStock.getProductCount(), material.getProductCount());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock_for_unapprove");
|
||||
}
|
||||
inStock.setProductCount(inStock.getProductCount() - material.getProductCount());
|
||||
inStock.setUpdateDate(LocalDateTime.now());
|
||||
@@ -429,8 +425,7 @@ 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",
|
||||
dto.storeNo(), dto.outStoreNo());
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.same_warehouse");
|
||||
}
|
||||
|
||||
Map<String, Integer> partCountMap = new HashMap<>();
|
||||
@@ -448,13 +443,12 @@ 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", partNumber);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.part_not_found");
|
||||
}
|
||||
|
||||
Long stockCount = (Long) stockInfo.get("productCount");
|
||||
if (stockCount == null || stockCount < totalTransfer) {
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock",
|
||||
partNumber, stockCount != null ? stockCount : 0, totalTransfer);
|
||||
throw new BusinessException("warehouse.stock_transfer_order.exception.insufficient_stock");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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", warehouseItemId);
|
||||
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
|
||||
}
|
||||
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", dto.warehouseItemId());
|
||||
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
|
||||
}
|
||||
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", item.vendorId());
|
||||
throw new BusinessException("warehouse.warehouse_item.exception.vendor_duplicate");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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", warehouseItemId);
|
||||
throw new BusinessException("warehouse.warehouse_item.exception.not_found");
|
||||
}
|
||||
return warehouseItem.getPartNumber();
|
||||
}
|
||||
|
||||
@@ -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", dto.id());
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
|
||||
}
|
||||
if (existingEntity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_update_approved", dto.id());
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_update_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved");
|
||||
}
|
||||
|
||||
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", 0);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.ids_empty");
|
||||
}
|
||||
|
||||
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", approvedCount);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.cannot_delete_approved_batch");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() == FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.already_approved", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.already_approved");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.no_materials");
|
||||
}
|
||||
|
||||
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", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_found");
|
||||
}
|
||||
if (entity.getFormStatus() != FormStatus.APPROVE) {
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_approved", id);
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.not_approved");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<DocumentMaterial> materialWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -258,11 +258,10 @@ 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", material.getPartNumber());
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.stock_not_found");
|
||||
}
|
||||
if (existingStock.getProductCount() < material.getProductCount()) {
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.insufficient_stock_for_unapprove",
|
||||
material.getPartNumber(), existingStock.getProductCount(), material.getProductCount());
|
||||
throw new BusinessException("warehouse.warehouse_receipt.exception.insufficient_stock_for_unapprove");
|
||||
}
|
||||
existingStock.setProductCount(existingStock.getProductCount() - material.getProductCount());
|
||||
existingStock.setUpdateDate(LocalDateTime.now());
|
||||
|
||||
Reference in New Issue
Block a user