新增 报备进展记录
This commit is contained in:
1 parent
ac74fa9204
commit
1759de5af3
13 files changed
+639
-24
No files matched your search
@@ -0,0 +1,91 @@
|
||||
package com.bycrm.controller;
|
||||
|
||||
import com.bycrm.common.Result;
|
||||
import com.bycrm.dto.ReportProgressDTO;
|
||||
import com.bycrm.entity.ReportProgress;
|
||||
import com.bycrm.service.ReportProgressService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报备进展记录控制器
|
||||
*/
|
||||
@Api(tags = "报备进展管理")
|
||||
@RestController
|
||||
@RequestMapping("/report-progress")
|
||||
public class ReportProgressController {
|
||||
|
||||
private final ReportProgressService reportProgressService;
|
||||
|
||||
public ReportProgressController(ReportProgressService reportProgressService) {
|
||||
this.reportProgressService = reportProgressService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据报备ID获取进展记录列表
|
||||
*/
|
||||
@ApiOperation("根据报备ID获取进展记录列表")
|
||||
@GetMapping("/report/{reportId}")
|
||||
public Result<List<ReportProgress>> getProgressByReportId(
|
||||
@ApiParam("报备ID") @PathVariable Long reportId) {
|
||||
List<ReportProgress> progressList = reportProgressService.getProgressByReportId(reportId);
|
||||
return Result.success(progressList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取进展记录
|
||||
*/
|
||||
@ApiOperation("根据ID获取进展记录")
|
||||
@GetMapping("/{id}")
|
||||
public Result<ReportProgress> getProgressById(
|
||||
@ApiParam("进展ID") @PathVariable Long id) {
|
||||
ReportProgress progress = reportProgressService.getProgressById(id);
|
||||
return Result.success(progress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建进展记录
|
||||
*/
|
||||
@ApiOperation("创建进展记录")
|
||||
@PostMapping
|
||||
public Result<Void> createProgress(
|
||||
@ApiParam("进展记录数据") @RequestBody @Valid ReportProgressDTO progressDTO,
|
||||
HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
reportProgressService.createProgress(progressDTO, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新进展记录
|
||||
*/
|
||||
@ApiOperation("更新进展记录")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Void> updateProgress(
|
||||
@ApiParam("进展ID") @PathVariable Long id,
|
||||
@ApiParam("进展记录数据") @RequestBody @Valid ReportProgressDTO progressDTO,
|
||||
HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
reportProgressService.updateProgress(id, progressDTO, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除进展记录(根据需求不可删除,所以不提供该接口)
|
||||
*/
|
||||
// @ApiOperation("删除进展记录")
|
||||
// @DeleteMapping("/{id}")
|
||||
// public Result<Void> deleteProgress(
|
||||
// @ApiParam("进展ID") @PathVariable Long id,
|
||||
// HttpServletRequest request) {
|
||||
// Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
// reportProgressService.deleteProgress(id, currentUserId);
|
||||
// return Result.success();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 报备进展记录 DTO
|
||||
*/
|
||||
@Data
|
||||
public class ReportProgressDTO {
|
||||
|
||||
/**
|
||||
* 关联报备ID
|
||||
*/
|
||||
@NotNull(message = "报备ID不能为空")
|
||||
private Long reportId;
|
||||
|
||||
/**
|
||||
* 进展内容
|
||||
*/
|
||||
@NotBlank(message = "进展内容不能为空")
|
||||
private String progressContent;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 报备进展记录实体
|
||||
*/
|
||||
@Data
|
||||
public class ReportProgress implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 进展ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 关联报备ID
|
||||
*/
|
||||
private Long reportId;
|
||||
|
||||
/**
|
||||
* 进展内容
|
||||
*/
|
||||
private String progressContent;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createdBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 关联查询字段 - 创建人姓名
|
||||
*/
|
||||
private String creatorName;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.bycrm.mapper;
|
||||
|
||||
import com.bycrm.entity.ReportProgress;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报备进展记录 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ReportProgressMapper {
|
||||
|
||||
/**
|
||||
* 根据ID查询进展记录
|
||||
*/
|
||||
ReportProgress selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 根据报备ID查询进展记录列表
|
||||
*/
|
||||
List<ReportProgress> selectByReportId(@Param("reportId") Long reportId);
|
||||
|
||||
/**
|
||||
* 插入进展记录
|
||||
*/
|
||||
int insert(ReportProgress reportProgress);
|
||||
|
||||
/**
|
||||
* 更新进展记录
|
||||
*/
|
||||
int update(ReportProgress reportProgress);
|
||||
|
||||
/**
|
||||
* 根据ID删除进展记录
|
||||
*/
|
||||
int deleteById(@Param("id") Long id);
|
||||
}
|
||||
@@ -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("进展记录不可删除");
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user