fix: 修复删除问题

This commit is contained in:
caiyuchao
2025-10-09 18:33:15 +08:00
parent 992583038b
commit be83d79e30
2 changed files with 13 additions and 8 deletions

View File

@@ -141,6 +141,12 @@ public class CustomerServiceImpl implements CustomerService {
public void deleteCustomer(Long id) { public void deleteCustomer(Long id) {
// 校验存在 // 校验存在
CustomerDO customerDO = validateCustomerExists(id); CustomerDO customerDO = validateCustomerExists(id);
List<ProjectDO> projects = projectMapper.selectList(Wrappers.<ProjectDO>lambdaQuery().eq(ProjectDO::getCustomerId, id));
if (CollUtil.isNotEmpty(projects)) {
throw exception(CUSTOMER_EXISTS_PROJECT);
}
// 删除 // 删除
customerMapper.deleteById(id); customerMapper.deleteById(id);
@@ -152,10 +158,7 @@ public class CustomerServiceImpl implements CustomerService {
if (customerDO == null) { if (customerDO == null) {
throw exception(CUSTOMER_NOT_EXISTS); 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; return customerDO;
} }

View File

@@ -115,6 +115,11 @@ public class ProjectServiceImpl implements ProjectService {
public void deleteProject(Long id) { public void deleteProject(Long id) {
// 校验存在 // 校验存在
ProjectDO project = validateProjectExists(id); ProjectDO project = validateProjectExists(id);
List<LicenseDO> licenses = licenseMapper.selectList(Wrappers.<LicenseDO>lambdaQuery().eq(LicenseDO::getProjectId, project.getId()));
if (CollUtil.isNotEmpty(licenses)) {
throw exception(PROJECT_EXISTS_LICENSE);
}
// 删除 // 删除
projectMapper.deleteById(id); projectMapper.deleteById(id);
LogRecordContext.putVariable("project", project); LogRecordContext.putVariable("project", project);
@@ -125,10 +130,7 @@ public class ProjectServiceImpl implements ProjectService {
if (projectDO == null) { if (projectDO == null) {
throw exception(PROJECT_NOT_EXISTS); 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; return projectDO;
} }