按需求调整

This commit is contained in:
andy committed 2026-02-03 15:37:25 +08:00
1 parent 8aa3af986f
commit daacd7d742
17 files changed
+602 -165

No files matched your search

@@ -4,6 +4,7 @@ import com.bycrm.common.PageResult;
import com.bycrm.dto.PageQuery;
import com.bycrm.dto.ReportAuditDTO;
import com.bycrm.dto.ReportDTO;
import com.bycrm.dto.ReportUpdateDTO;
import com.bycrm.vo.ReportVO;
/**
@@ -27,6 +28,11 @@ public interface ReportService {
*/
void createReport(ReportDTO reportDTO, Long currentUserId);
/**
* 更新报备
*/
void updateReport(Long id, ReportUpdateDTO updateDTO, Long currentUserId);
/**
* 审核报备
*/
@@ -5,12 +5,13 @@ import com.bycrm.common.PageResult;
import com.bycrm.dto.PageQuery;
import com.bycrm.dto.ReportAuditDTO;
import com.bycrm.dto.ReportDTO;
import com.bycrm.dto.ReportUpdateDTO;
import com.bycrm.entity.Report;
import com.bycrm.entity.Customer;
import com.bycrm.entity.School;
import com.bycrm.entity.User;
import com.bycrm.exception.BusinessException;
import com.bycrm.mapper.CustomerMapper;
import com.bycrm.mapper.ReportMapper;
import com.bycrm.mapper.SchoolMapper;
import com.bycrm.mapper.UserMapper;
import com.bycrm.service.ReportService;
import com.bycrm.service.SystemConfigService;
@@ -32,16 +33,16 @@ import java.util.stream.Collectors;
public class ReportServiceImpl implements ReportService {
private final ReportMapper reportMapper;
private final CustomerMapper customerMapper;
private final SchoolMapper schoolMapper;
private final UserMapper userMapper;
private final SystemConfigService systemConfigService;
public ReportServiceImpl(ReportMapper reportMapper,
CustomerMapper customerMapper,
SchoolMapper schoolMapper,
UserMapper userMapper,
SystemConfigService systemConfigService) {
this.reportMapper = reportMapper;
this.customerMapper = customerMapper;
this.schoolMapper = schoolMapper;
this.userMapper = userMapper;
this.systemConfigService = systemConfigService;
}
@@ -86,23 +87,47 @@ public class ReportServiceImpl implements ReportService {
throw new BusinessException("您未关联经销商,无法提交报备");
}
// 检查客户是否存在
Customer customer = customerMapper.selectById(reportDTO.getCustomerId());
if (customer == null) {
throw new BusinessException("客户不存在");
// 防撞单校验:根据是否有 schoolId 选择不同的校验方式
Report existingReport = null;
if (reportDTO.getSchoolId() != null) {
// 有学校ID,按学校ID+产品+项目类型校验
existingReport = reportMapper.selectValidBySchoolAndProduct(
reportDTO.getSchoolId(),
reportDTO.getProduct(),
reportDTO.getProjectType()
);
} else {
// 没有学校ID,按学校名称+产品+项目类型校验
existingReport = reportMapper.selectValidBySchoolNameAndProduct(
reportDTO.getSchoolName(),
reportDTO.getProduct(),
reportDTO.getProjectType()
);
}
// 防撞单校验:检查该客户是否已存在有效报备
Report existingReport = reportMapper.selectValidByCustomerId(reportDTO.getCustomerId());
Boolean allowOverlap = systemConfigService.getBooleanConfigValue("report.allow.overlap", false);
if (existingReport != null && !allowOverlap) {
throw new BusinessException("该客户已被其他经销商报备,无法重复报备");
throw new BusinessException("该项目已报备");
}
// 如果有学校ID,查询学校信息
String schoolName = reportDTO.getSchoolName();
Long schoolId = reportDTO.getSchoolId();
if (schoolId != null) {
School school = schoolMapper.selectById(schoolId);
if (school != null) {
schoolName = school.getSchoolName();
}
}
// 创建报备
Report report = new Report();
report.setDealerId(currentUser.getDealerId());
report.setCustomerId(reportDTO.getCustomerId());
report.setSchoolId(schoolId); // 可以为 NULL
report.setSchoolName(schoolName);
report.setProduct(reportDTO.getProduct());
report.setProjectType(reportDTO.getProjectType());
report.setDescription(reportDTO.getDescription());
report.setStatus(Constants.REPORT_STATUS_PENDING);
report.setCreatedAt(LocalDateTime.now());
@@ -138,11 +163,6 @@ public class ReportServiceImpl implements ReportService {
report.setProtectStartDate(today);
Integer protectDays = systemConfigService.getIntegerConfigValue("report.protect.days", Constants.DEFAULT_PROTECT_DAYS);
report.setProtectEndDate(today.plusDays(protectDays));
// 更新客户状态为保护中
Customer customer = customerMapper.selectById(report.getCustomerId());
customer.setStatus(Constants.CUSTOMER_STATUS_PROTECTED);
customerMapper.update(customer);
} else {
// 审核驳回
report.setStatus(Constants.REPORT_STATUS_REJECTED);
@@ -153,6 +173,43 @@ public class ReportServiceImpl implements ReportService {
reportMapper.update(report);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateReport(Long id, ReportUpdateDTO updateDTO, Long currentUserId) {
// 获取当前用户
User currentUser = userMapper.selectById(currentUserId);
if (currentUser.getRole() != Constants.USER_ROLE_ADMIN) {
throw new BusinessException("只有管理员才能编辑报备");
}
Report report = reportMapper.selectById(id);
if (report == null) {
throw new BusinessException("报备不存在");
}
// 只有已通过的报备才能编辑
if (report.getStatus() != Constants.REPORT_STATUS_APPROVED) {
throw new BusinessException("只能编辑已通过的报备");
}
// 如果状态改为作废,必须填写作废原因
if (updateDTO.getStatus() == Constants.REPORT_STATUS_CANCELED) {
if (updateDTO.getCancelReason() == null || updateDTO.getCancelReason().trim().isEmpty()) {
throw new BusinessException("作废时必须填写作废原因");
}
}
// 更新报备信息
report.setProduct(updateDTO.getProduct());
report.setProjectType(updateDTO.getProjectType());
report.setDescription(updateDTO.getDescription());
report.setStatus(updateDTO.getStatus());
report.setCancelReason(updateDTO.getCancelReason());
report.setUpdatedAt(LocalDateTime.now());
reportMapper.update(report);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void withdrawReport(Long id, Long currentUserId) {
@@ -189,15 +246,6 @@ public class ReportServiceImpl implements ReportService {
// 批量更新报备状态
List<Long> ids = expiringReports.stream().map(Report::getId).collect(Collectors.toList());
reportMapper.batchUpdateExpired(ids);
// 批量更新客户状态为可报备
expiringReports.forEach(report -> {
Customer customer = customerMapper.selectById(report.getCustomerId());
if (customer != null && customer.getStatus() == Constants.CUSTOMER_STATUS_PROTECTED) {
customer.setStatus(Constants.CUSTOMER_STATUS_AVAILABLE);
customerMapper.update(customer);
}
});
}
@Override
@@ -236,6 +284,9 @@ public class ReportServiceImpl implements ReportService {
case Constants.REPORT_STATUS_EXPIRED:
vo.setStatusDesc("已失效");
break;
case Constants.REPORT_STATUS_CANCELED:
vo.setStatusDesc("已作废");
break;
default:
vo.setStatusDesc("未知");
}