feat(project): 实现项目管理相关接口
- 新增项目修改接口,支持更新除敏感字段之外的信息 - 新增项目删除接口,支持根据ID删除项目 - 实现项目状态更新,支持更新状态及相关日期和进度 - 实现项目进度更新,验证进度范围并自动标记完成状态 - 新增项目经理更新接口,通过经理真实姓名查询用户并更新项目经理ID - 添加权限校验注解,保证接口安全性 - 增加日志记录,便于操作追踪与问题排查
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
package cn.yinlihupo.controller.project;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.yinlihupo.common.core.BaseResponse;
|
||||
import cn.yinlihupo.common.util.ResultUtils;
|
||||
import cn.yinlihupo.domain.entity.Project;
|
||||
import cn.yinlihupo.domain.entity.SysUser;
|
||||
import cn.yinlihupo.mapper.ProjectMapper;
|
||||
import cn.yinlihupo.mapper.SysUserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 项目管理控制器
|
||||
* 提供项目的增删改查功能
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/project")
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectManagementController {
|
||||
|
||||
private final ProjectMapper projectMapper;
|
||||
private final SysUserMapper sysUserMapper;
|
||||
|
||||
/**
|
||||
* 修改项目
|
||||
*/
|
||||
@SaCheckPermission("project:center:update")
|
||||
@PutMapping
|
||||
public BaseResponse<Void> update(@RequestBody Project project) {
|
||||
if (project.getId() == null) {
|
||||
return ResultUtils.error("项目ID不能为空");
|
||||
}
|
||||
|
||||
Project exist = projectMapper.selectById(project.getId());
|
||||
if (exist == null || exist.getDeleted() == 1) {
|
||||
return ResultUtils.error("项目不存在");
|
||||
}
|
||||
|
||||
// 不更新敏感字段
|
||||
project.setCreateTime(null);
|
||||
project.setDeleted(null);
|
||||
project.setProjectCode(null);
|
||||
|
||||
projectMapper.updateById(project);
|
||||
log.info("修改项目成功, id: {}", project.getId());
|
||||
return ResultUtils.success("修改成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
*/
|
||||
@SaCheckPermission("project:center:delete")
|
||||
@DeleteMapping("/{id}")
|
||||
public BaseResponse<Void> delete(@PathVariable Long id) {
|
||||
Project project = projectMapper.selectById(id);
|
||||
if (project == null || project.getDeleted() == 1) {
|
||||
return ResultUtils.error("项目不存在");
|
||||
}
|
||||
|
||||
projectMapper.deleteById(id);
|
||||
log.info("删除项目成功, id: {}", id);
|
||||
return ResultUtils.success("删除成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新项目状态
|
||||
*/
|
||||
@SaCheckPermission("project:center:update")
|
||||
@PutMapping("/{id}/status")
|
||||
public BaseResponse<Void> updateStatus(@PathVariable Long id, @RequestParam String status) {
|
||||
Project project = projectMapper.selectById(id);
|
||||
if (project == null || project.getDeleted() == 1) {
|
||||
return ResultUtils.error("项目不存在");
|
||||
}
|
||||
|
||||
project.setStatus(status);
|
||||
|
||||
// 如果项目开始,设置实际开始日期
|
||||
if ("ongoing".equals(status) && project.getActualStartDate() == null) {
|
||||
project.setActualStartDate(LocalDate.now());
|
||||
}
|
||||
|
||||
// 如果项目完成,设置实际结束日期
|
||||
if ("completed".equals(status)) {
|
||||
project.setActualEndDate(LocalDate.now());
|
||||
project.setProgress(100);
|
||||
}
|
||||
|
||||
projectMapper.updateById(project);
|
||||
log.info("更新项目状态成功, id: {}, status: {}", id, status);
|
||||
return ResultUtils.success("更新成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新项目进度
|
||||
*/
|
||||
@SaCheckPermission("project:center:update")
|
||||
@PutMapping("/{id}/progress")
|
||||
public BaseResponse<Void> updateProgress(@PathVariable Long id, @RequestParam Integer progress) {
|
||||
if (progress < 0 || progress > 100) {
|
||||
return ResultUtils.error("进度值必须在0-100之间");
|
||||
}
|
||||
|
||||
Project project = projectMapper.selectById(id);
|
||||
if (project == null || project.getDeleted() == 1) {
|
||||
return ResultUtils.error("项目不存在");
|
||||
}
|
||||
|
||||
project.setProgress(progress);
|
||||
|
||||
// 如果进度达到100%,自动标记为已完成
|
||||
if (progress == 100) {
|
||||
project.setStatus("completed");
|
||||
project.setActualEndDate(LocalDate.now());
|
||||
}
|
||||
|
||||
projectMapper.updateById(project);
|
||||
log.info("更新项目进度成功, id: {}, progress: {}", id, progress);
|
||||
return ResultUtils.success("更新成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新项目经理
|
||||
* 根据真实姓名查询用户ID
|
||||
*/
|
||||
@SaCheckPermission("project:center:update")
|
||||
@PutMapping("/{id}/manager")
|
||||
public BaseResponse<Void> updateManager(@PathVariable Long id, @RequestParam String managerName) {
|
||||
Project project = projectMapper.selectById(id);
|
||||
if (project == null || project.getDeleted() == 1) {
|
||||
return ResultUtils.error("项目不存在");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(managerName)) {
|
||||
return ResultUtils.error("项目经理姓名不能为空");
|
||||
}
|
||||
|
||||
// 根据真实姓名查询用户
|
||||
SysUser user = sysUserMapper.selectByRealName(managerName);
|
||||
if (user == null) {
|
||||
log.warn("项目经理 '{}' 未在系统中找到匹配的用户", managerName);
|
||||
return ResultUtils.error("指定的项目经理不存在: " + managerName);
|
||||
}
|
||||
|
||||
project.setManagerId(user.getId());
|
||||
projectMapper.updateById(project);
|
||||
log.info("更新项目经理成功, id: {}, managerName: {}, managerId: {}", id, managerName, user.getId());
|
||||
return ResultUtils.success("更新成功", null);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user