feat: 生成编号和删除限制等

This commit is contained in:
caiyuchao
2025-09-25 20:12:03 +08:00
parent 7faa891554
commit 7dc8906da7
6 changed files with 36 additions and 4 deletions

View File

@@ -12,10 +12,12 @@ public interface ErrorCodeConstants {
ErrorCode CUSTOMER_NAME_DUPLICATE = new ErrorCode(1_100_001_002, "客户名称`{}`已存在");
ErrorCode CUSTOMER_CODE_DUPLICATE = new ErrorCode(1_100_001_003, "客户编号`{}`已存在");
ErrorCode CUSTOMER_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_100_001_004, "导入客户数据不能为空!");
ErrorCode CUSTOMER_EXISTS_PROJECT = new ErrorCode(1_100_001_005, "已存在该客户的项目,请先删除项目");
ErrorCode PROJECT_NOT_EXISTS = new ErrorCode(1_100_002_001, "项目不存在");
ErrorCode PROJECT_NAME_DUPLICATE = new ErrorCode(1_100_002_002, "项目名称`{}`已存在");
ErrorCode PROJECT_CODE_DUPLICATE = new ErrorCode(1_100_002_003, "项目编号`{}`已存在");
ErrorCode PROJECT_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_100_002_004, "导入项目数据不能为空!");
ErrorCode PROJECT_EXISTS_LICENSE = new ErrorCode(1_100_001_005, "已存在该项目的License请先删除License");
ErrorCode LICENSE_NOT_EXISTS = new ErrorCode(1_100_003_001, "License不存在");
ErrorCode LICENSE_SN_DUPLICATE = new ErrorCode(1_100_003_002, "License SN`{}`已存在");
ErrorCode LICENSE_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_100_003_003, "导入License数据不能为空");

View File

@@ -29,4 +29,7 @@ public class DashboardRespVO {
@Schema(description = "签单率")
private Long signingRate;
@Schema(description = "完成率")
private Long completionRate;
}

View File

@@ -36,6 +36,7 @@ import java.util.stream.Collectors;
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_EXISTS_PROJECT;
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_IMPORT_LIST_IS_EMPTY;
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_NAME_DUPLICATE;
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
@@ -82,6 +83,8 @@ public class CustomerServiceImpl implements CustomerService {
dashboardRespVO.setUserCount(customerMapper.selectUserCount());
dashboardRespVO.setSigningRate(BigDecimal.valueOf(contractCount).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(projectCount), 0, RoundingMode.HALF_UP).longValue());
dashboardRespVO.setCompletionRate(BigDecimal.valueOf(contractCount).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(licenseCount), 0, RoundingMode.HALF_UP).longValue());
return dashboardRespVO;
}
@@ -144,6 +147,10 @@ public class CustomerServiceImpl implements CustomerService {
if (customerDO == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
List<ProjectDO> projects = projectMapper.selectList(Wrappers.<ProjectDO>lambdaQuery().eq(ProjectDO::getCustomerId, id));
if (CollUtil.isNotEmpty(projects)) {
throw exception(CUSTOMER_EXISTS_PROJECT);
}
return customerDO;
}
@@ -214,7 +221,7 @@ public class CustomerServiceImpl implements CustomerService {
@Override
public Integer selectMaxCode() {
Integer maxCode = customerMapper.selectMaxCode();
return maxCode == null || maxCode < 2000 ? 2000 : maxCode + 1;
return maxCode == null || maxCode < 2000 ? 2000 : maxCode;
}
@Override

View File

@@ -19,6 +19,7 @@ import org.agt.module.license.controller.admin.project.vo.ProjectPageReqVO;
import org.agt.module.license.controller.admin.project.vo.ProjectRespVO;
import org.agt.module.license.controller.admin.project.vo.ProjectSaveReqVO;
import org.agt.module.license.dal.dataobject.customer.CustomerDO;
import org.agt.module.license.dal.dataobject.license.LicenseDO;
import org.agt.module.license.dal.dataobject.project.ProjectDO;
import org.agt.module.license.dal.mysql.comment.CommentMapper;
import org.agt.module.license.dal.mysql.customer.CustomerMapper;
@@ -34,6 +35,7 @@ import java.util.List;
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_CODE_DUPLICATE;
import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_EXISTS_LICENSE;
import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_IMPORT_LIST_IS_EMPTY;
import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_NAME_DUPLICATE;
import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_NOT_EXISTS;
@@ -123,6 +125,10 @@ public class ProjectServiceImpl implements ProjectService {
if (projectDO == null) {
throw exception(PROJECT_NOT_EXISTS);
}
List<LicenseDO> licenses = licenseMapper.selectList(Wrappers.<LicenseDO>lambdaQuery().eq(LicenseDO::getProjectId, projectDO.getId()));
if (CollUtil.isNotEmpty(licenses)) {
throw exception(PROJECT_EXISTS_LICENSE);
}
return projectDO;
}
@@ -198,7 +204,7 @@ public class ProjectServiceImpl implements ProjectService {
@Override
public Integer selectMaxCode() {
Integer maxCode = projectMapper.selectMaxCode();
return maxCode == null || maxCode < 2000 ? 2000 : maxCode + 1;
return maxCode == null || maxCode < 2000 ? 2000 : maxCode;
}
@Override

View File

@@ -3,7 +3,14 @@
<mapper namespace="org.agt.module.license.dal.mysql.customer.CustomerMapper">
<select id="selectMaxCode" resultType="Integer">
SELECT max(`code` + 0) from crm_customer;
SELECT
MIN( t1.num + 1 ) AS next_num
FROM
( SELECT CAST( `code` AS UNSIGNED ) AS num FROM crm_customer ) t1
LEFT JOIN ( SELECT CAST( `code` AS UNSIGNED ) AS num FROM crm_customer ) t2 ON t2.num = t1.num + 1
WHERE
t2.num IS NULL
AND t1.num >= 2000
</select>
<select id="selectUserCount" resultType="Long">

View File

@@ -3,7 +3,14 @@
<mapper namespace="org.agt.module.license.dal.mysql.project.ProjectMapper">
<select id="selectMaxCode" resultType="Integer">
SELECT max(`code` + 0) from crm_project;
SELECT
MIN( t1.num + 1 ) AS next_num
FROM
( SELECT CAST( `code` AS UNSIGNED ) AS num FROM crm_project ) t1
LEFT JOIN ( SELECT CAST( `code` AS UNSIGNED ) AS num FROM crm_project ) t2 ON t2.num = t1.num + 1
WHERE
t2.num IS NULL
AND t1.num >= 2000
</select>
<select id="selectOldMaxCode" resultType="Integer">