新增-erp库位重复编码优化异常抛出
This commit is contained in:
@@ -10,16 +10,17 @@ import com.zt.plat.framework.common.exception.ErrorCode;
|
|||||||
public interface ErrorCodeConstants {
|
public interface ErrorCodeConstants {
|
||||||
|
|
||||||
// ========== 示例模块 1-001-000-000 ==========
|
// ========== 示例模块 1-001-000-000 ==========
|
||||||
ErrorCode MATERIAL_OTHER_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode MATERIAL_OTHER_NOT_EXISTS = new ErrorCode(1_001_000_001, "物料不存在");
|
||||||
ErrorCode ELEMENT_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode ELEMENT_NOT_EXISTS = new ErrorCode(1_001_000_001, "金属元素不存在");
|
||||||
ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_001_000_001, "联系人不存在");
|
||||||
ErrorCode ACCOUNT_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode ACCOUNT_NOT_EXISTS = new ErrorCode(1_001_000_001, "账户条款不存在");
|
||||||
ErrorCode MATERIAL_DESTROY_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode MATERIAL_DESTROY_NOT_EXISTS = new ErrorCode(1_001_000_001, "物料回收率不存在");
|
||||||
ErrorCode MATERIAL_INFOMATION_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode MATERIAL_INFOMATION_NOT_EXISTS = new ErrorCode(1_001_000_001, "物料信息不存在");
|
||||||
ErrorCode COMPANY_RELATIVITY_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode COMPANY_RELATIVITY_NOT_EXISTS = new ErrorCode(1_001_000_001, "公司关系不存在");
|
||||||
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_001_000_001, "库位不存在");
|
||||||
ErrorCode FACTORY_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode WAREHOUSE_CODE_EXISTS = new ErrorCode(1_001_000_002, "库位编码已存在");
|
||||||
ErrorCode TAX_NOT_EXISTS = new ErrorCode(1_001_000_001, "示例不存在");
|
ErrorCode FACTORY_NOT_EXISTS = new ErrorCode(1_001_000_001, "工厂不存在");
|
||||||
|
ErrorCode TAX_NOT_EXISTS = new ErrorCode(1_001_000_001, "公司关系不存在");
|
||||||
|
|
||||||
|
|
||||||
ErrorCode BUSINESS_RULE_NOT_EXISTS = new ErrorCode(1_027_100_001, "规则模型不存在");
|
ErrorCode BUSINESS_RULE_NOT_EXISTS = new ErrorCode(1_027_100_001, "规则模型不存在");
|
||||||
|
|||||||
@@ -33,4 +33,10 @@ public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String selectMaxCode();
|
String selectMaxCode();
|
||||||
|
|
||||||
|
default WarehouseDO selectByCode(String code){
|
||||||
|
return selectOne(new LambdaQueryWrapperX<WarehouseDO>()
|
||||||
|
.eq(WarehouseDO::getCoding, code)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.zt.plat.module.base.enums.ErrorCodeConstants.WAREHOUSE_CODE_EXISTS;
|
||||||
import static com.zt.plat.module.base.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
|
import static com.zt.plat.module.base.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,16 +36,17 @@ public class WarehouseServiceImpl implements WarehouseService {
|
|||||||
// 插入
|
// 插入
|
||||||
WarehouseDO warehouse = BeanUtils.toBean(createReqVO, WarehouseDO.class);
|
WarehouseDO warehouse = BeanUtils.toBean(createReqVO, WarehouseDO.class);
|
||||||
// 库位编码自动生成,格式 KW-0001,依次新增
|
// 库位编码自动生成,格式 KW-0001,依次新增
|
||||||
String maxCode = warehouseMapper.selectMaxCode();
|
// String maxCode = warehouseMapper.selectMaxCode();
|
||||||
if (maxCode == null) {
|
// if (maxCode == null) {
|
||||||
warehouse.setCoding("KW-0001");
|
// warehouse.setCoding("KW-0001");
|
||||||
} else {
|
// } else {
|
||||||
String prefix = "KW-";
|
// String prefix = "KW-";
|
||||||
String numberPart = maxCode.substring(prefix.length());
|
// String numberPart = maxCode.substring(prefix.length());
|
||||||
int nextNumber = Integer.parseInt(numberPart) + 1;
|
// int nextNumber = Integer.parseInt(numberPart) + 1;
|
||||||
String nextCode = prefix + String.format("%04d", nextNumber);
|
// String nextCode = prefix + String.format("%04d", nextNumber);
|
||||||
warehouse.setCoding(nextCode);
|
// warehouse.setCoding(nextCode);
|
||||||
}
|
// }
|
||||||
|
validateWarehouseCodeExists(warehouse.getCoding());
|
||||||
warehouseMapper.insert(warehouse);
|
warehouseMapper.insert(warehouse);
|
||||||
// 返回
|
// 返回
|
||||||
return BeanUtils.toBean(warehouse, WarehouseRespVO.class);
|
return BeanUtils.toBean(warehouse, WarehouseRespVO.class);
|
||||||
@@ -68,12 +70,12 @@ public class WarehouseServiceImpl implements WarehouseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteWarehouseListByIds(List<Long> ids) {
|
public void deleteWarehouseListByIds(List<Long> ids) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateWarehouseExists(ids);
|
validateWarehouseExists(ids);
|
||||||
// 删除
|
// 删除
|
||||||
warehouseMapper.deleteByIds(ids);
|
warehouseMapper.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateWarehouseExists(List<Long> ids) {
|
private void validateWarehouseExists(List<Long> ids) {
|
||||||
List<WarehouseDO> list = warehouseMapper.selectByIds(ids);
|
List<WarehouseDO> list = warehouseMapper.selectByIds(ids);
|
||||||
@@ -88,6 +90,13 @@ public class WarehouseServiceImpl implements WarehouseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateWarehouseCodeExists(String code) {
|
||||||
|
WarehouseDO warehouse = warehouseMapper.selectByCode(code);
|
||||||
|
if (warehouse != null) {
|
||||||
|
throw exception(WAREHOUSE_CODE_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WarehouseDO getWarehouse(Long id) {
|
public WarehouseDO getWarehouse(Long id) {
|
||||||
return warehouseMapper.selectById(id);
|
return warehouseMapper.selectById(id);
|
||||||
@@ -101,7 +110,7 @@ public class WarehouseServiceImpl implements WarehouseService {
|
|||||||
@Override
|
@Override
|
||||||
public void enableWarehouseList(List<WarehouseRespVO> saveReqVOS) {
|
public void enableWarehouseList(List<WarehouseRespVO> saveReqVOS) {
|
||||||
List<WarehouseDO> updateObj = BeanUtils.toBean(saveReqVOS, WarehouseDO.class);
|
List<WarehouseDO> updateObj = BeanUtils.toBean(saveReqVOS, WarehouseDO.class);
|
||||||
List<BatchResult> count = warehouseMapper.updateById(updateObj);
|
List<BatchResult> count = warehouseMapper.updateById(updateObj);
|
||||||
if (CollUtil.isEmpty(count)) {
|
if (CollUtil.isEmpty(count)) {
|
||||||
throw exception(WAREHOUSE_NOT_EXISTS);
|
throw exception(WAREHOUSE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user