feat: 增改时校验客户名称和编号唯一
This commit is contained in:
@@ -8,5 +8,7 @@ import org.agt.framework.common.exception.ErrorCode;
|
|||||||
* @since: 2025-05-22
|
* @since: 2025-05-22
|
||||||
*/
|
*/
|
||||||
public interface ErrorCodeConstants {
|
public interface ErrorCodeConstants {
|
||||||
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(2000, "客户不存在");
|
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_100_001_001, "客户不存在");
|
||||||
|
ErrorCode CUSTOMER_NAME_DUPLICATE = new ErrorCode(1_100_001_002, "客户名称`{}`已存在");
|
||||||
|
ErrorCode CUSTOMER_CODE_DUPLICATE = new ErrorCode(1_100_001_003, "客户编号`{}`已存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_CODE_DUPLICATE;
|
||||||
|
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_NAME_DUPLICATE;
|
||||||
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
|
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,6 +30,8 @@ public class CustomerServiceImpl implements CustomerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createCustomer(CustomerSaveReqVO createReqVO) {
|
public Long createCustomer(CustomerSaveReqVO createReqVO) {
|
||||||
|
// 校验客户名称和编号是否唯一
|
||||||
|
validateCustomerNameAndCodeUnique(createReqVO.getName(), createReqVO.getCode(), createReqVO.getId());
|
||||||
// 插入
|
// 插入
|
||||||
CustomerDO customer = BeanUtils.toBean(createReqVO, CustomerDO.class);
|
CustomerDO customer = BeanUtils.toBean(createReqVO, CustomerDO.class);
|
||||||
customerMapper.insert(customer);
|
customerMapper.insert(customer);
|
||||||
@@ -37,6 +41,8 @@ public class CustomerServiceImpl implements CustomerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCustomer(CustomerSaveReqVO updateReqVO) {
|
public void updateCustomer(CustomerSaveReqVO updateReqVO) {
|
||||||
|
// 校验客户名称和编号是否唯一
|
||||||
|
validateCustomerNameAndCodeUnique(updateReqVO.getName(), updateReqVO.getCode(), updateReqVO.getId());
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateCustomerExists(updateReqVO.getId());
|
validateCustomerExists(updateReqVO.getId());
|
||||||
// 更新
|
// 更新
|
||||||
@@ -58,6 +64,17 @@ public class CustomerServiceImpl implements CustomerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateCustomerNameAndCodeUnique(String name, String code, Long id) {
|
||||||
|
Boolean isNameUnique = validateCustomerNameUnique(name, id);
|
||||||
|
if (!isNameUnique) {
|
||||||
|
throw exception(CUSTOMER_NAME_DUPLICATE, name);
|
||||||
|
}
|
||||||
|
Boolean isCodeUnique = validateCustomerCodeUnique(code, id);
|
||||||
|
if (!isCodeUnique) {
|
||||||
|
throw exception(CUSTOMER_CODE_DUPLICATE, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomerDO getCustomer(Long id) {
|
public CustomerDO getCustomer(Long id) {
|
||||||
return customerMapper.selectById(id);
|
return customerMapper.selectById(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user