新增 报备进展记录

This commit is contained in:
andy committed 2026-01-28 16:04:49 +08:00
1 parent ac74fa9204
commit 1759de5af3
13 files changed
+639 -24

No files matched your search

@@ -0,0 +1,37 @@
package com.bycrm.service;
import com.bycrm.entity.ReportProgress;
import com.bycrm.dto.ReportProgressDTO;
import java.util.List;
/**
* 报备进展记录服务接口
*/
public interface ReportProgressService {
/**
* 根据报备ID获取进展记录列表
*/
List<ReportProgress> getProgressByReportId(Long reportId);
/**
* 根据ID获取进展记录
*/
ReportProgress getProgressById(Long id);
/**
* 创建进展记录
*/
void createProgress(ReportProgressDTO progressDTO, Long currentUserId);
/**
* 更新进展记录
*/
void updateProgress(Long id, ReportProgressDTO progressDTO, Long currentUserId);
/**
* 删除进展记录(不提供删除功能,根据需求不可删除)
*/
// void deleteProgress(Long id, Long currentUserId);
}
@@ -0,0 +1,119 @@
package com.bycrm.service.impl;
import com.bycrm.common.Constants;
import com.bycrm.dto.ReportProgressDTO;
import com.bycrm.entity.Report;
import com.bycrm.entity.ReportProgress;
import com.bycrm.entity.User;
import com.bycrm.exception.BusinessException;
import com.bycrm.mapper.ReportMapper;
import com.bycrm.mapper.ReportProgressMapper;
import com.bycrm.mapper.UserMapper;
import com.bycrm.service.ReportProgressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
/**
* 报备进展记录服务实现
*/
@Service
public class ReportProgressServiceImpl implements ReportProgressService {
private final ReportProgressMapper reportProgressMapper;
private final ReportMapper reportMapper;
private final UserMapper userMapper;
public ReportProgressServiceImpl(ReportProgressMapper reportProgressMapper,
ReportMapper reportMapper,
UserMapper userMapper) {
this.reportProgressMapper = reportProgressMapper;
this.reportMapper = reportMapper;
this.userMapper = userMapper;
}
@Override
public List<ReportProgress> getProgressByReportId(Long reportId) {
return reportProgressMapper.selectByReportId(reportId);
}
@Override
public ReportProgress getProgressById(Long id) {
return reportProgressMapper.selectById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void createProgress(ReportProgressDTO progressDTO, Long currentUserId) {
// 获取当前用户
User currentUser = userMapper.selectById(currentUserId);
// 检查报备是否存在
Report report = reportMapper.selectById(progressDTO.getReportId());
if (report == null) {
throw new BusinessException("报备不存在");
}
// 检查权限:经销商只能操作自己的报备
if (currentUser.getRole() == Constants.USER_ROLE_DEALER) {
if (!report.getDealerId().equals(currentUser.getDealerId())) {
throw new BusinessException("您只能操作自己报备的进展记录");
}
}
// 检查报备状态是否为已通过
if (report.getStatus() != Constants.REPORT_STATUS_APPROVED) {
throw new BusinessException("只有审核通过的报备才能添加进展记录");
}
// 创建进展记录
ReportProgress progress = new ReportProgress();
progress.setReportId(progressDTO.getReportId());
progress.setProgressContent(progressDTO.getProgressContent());
progress.setCreatedBy(currentUserId);
progress.setCreatedAt(LocalDateTime.now());
progress.setUpdatedAt(LocalDateTime.now());
reportProgressMapper.insert(progress);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProgress(Long id, ReportProgressDTO progressDTO, Long currentUserId) {
// 获取当前用户
User currentUser = userMapper.selectById(currentUserId);
// 检查进展记录是否存在
ReportProgress existingProgress = reportProgressMapper.selectById(id);
if (existingProgress == null) {
throw new BusinessException("进展记录不存在");
}
// 检查报备是否存在
Report report = reportMapper.selectById(existingProgress.getReportId());
if (report == null) {
throw new BusinessException("关联的报备不存在");
}
// 检查权限:经销商只能操作自己的报备
if (currentUser.getRole() == Constants.USER_ROLE_DEALER) {
if (!report.getDealerId().equals(currentUser.getDealerId())) {
throw new BusinessException("您只能操作自己报备的进展记录");
}
}
// 更新进展记录
existingProgress.setProgressContent(progressDTO.getProgressContent());
existingProgress.setUpdatedAt(LocalDateTime.now());
reportProgressMapper.update(existingProgress);
}
// 根据需求,不提供删除功能
// @Override
// public void deleteProgress(Long id, Long currentUserId) {
// throw new BusinessException("进展记录不可删除");
// }
}