feat: 校验客户编号是否唯一
This commit is contained in:
@@ -87,6 +87,13 @@ public class CustomerController {
|
|||||||
return success(isExists);
|
return success(isExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/code-unique")
|
||||||
|
@Operation(summary = "校验客户编号是否唯一")
|
||||||
|
public CommonResult<Boolean> validateCustomerCodeUnique(@RequestParam(value = "code", required = false) String code, @RequestParam(value = "id", required = false) Long id) {
|
||||||
|
Boolean isExists = customerService.validateCustomerCodeUnique(code, id);
|
||||||
|
return success(isExists);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/max-sn")
|
@GetMapping("/max-sn")
|
||||||
@Operation(summary = "返回当前最大客户sn")
|
@Operation(summary = "返回当前最大客户sn")
|
||||||
public CommonResult<Integer> selectMaxCode() {
|
public CommonResult<Integer> selectMaxCode() {
|
||||||
|
|||||||
@@ -30,5 +30,9 @@ public interface CustomerMapper extends BaseMapperX<CustomerDO> {
|
|||||||
return selectOne(CustomerDO::getName, name);
|
return selectOne(CustomerDO::getName, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default CustomerDO selectByCode(String code) {
|
||||||
|
return selectOne(CustomerDO::getCode, code);
|
||||||
|
}
|
||||||
|
|
||||||
Integer selectMaxCode();
|
Integer selectMaxCode();
|
||||||
}
|
}
|
||||||
@@ -60,6 +60,15 @@ public interface CustomerService {
|
|||||||
*/
|
*/
|
||||||
Boolean validateCustomerNameExists(String name, Long id);
|
Boolean validateCustomerNameExists(String name, Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验客户编号是否唯一
|
||||||
|
*
|
||||||
|
* @param code 客户编号
|
||||||
|
* @param id 客户id
|
||||||
|
* @return 是否存在
|
||||||
|
*/
|
||||||
|
Boolean validateCustomerCodeUnique(String code, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前最大的sn号
|
* 查询当前最大的sn号
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -87,6 +87,25 @@ public class CustomerServiceImpl implements CustomerService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean validateCustomerCodeUnique(String code, Long id) {
|
||||||
|
if (StrUtil.isBlank(code)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CustomerDO customer = customerMapper.selectByCode(code);
|
||||||
|
if (customer == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 如果 id 为空,说明不用比较是否为相同 id 的客户
|
||||||
|
if (id == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!customer.getId().equals(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer selectMaxCode() {
|
public Integer selectMaxCode() {
|
||||||
Integer maxCode = customerMapper.selectMaxCode();
|
Integer maxCode = customerMapper.selectMaxCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user