From 91ad9cb3a6429dc3f527c4ef1b5c723ccdf0895a Mon Sep 17 00:00:00 2001 From: JiaoTianBo Date: Tue, 31 Mar 2026 18:07:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(project):=20=E5=AE=9E=E7=8E=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增项目修改接口,支持更新除敏感字段之外的信息 - 新增项目删除接口,支持根据ID删除项目 - 实现项目状态更新,支持更新状态及相关日期和进度 - 实现项目进度更新,验证进度范围并自动标记完成状态 - 新增项目经理更新接口,通过经理真实姓名查询用户并更新项目经理ID - 添加权限校验注解,保证接口安全性 - 增加日志记录,便于操作追踪与问题排查 --- .../project/ProjectManagementController.java | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/main/java/cn/yinlihupo/controller/project/ProjectManagementController.java diff --git a/src/main/java/cn/yinlihupo/controller/project/ProjectManagementController.java b/src/main/java/cn/yinlihupo/controller/project/ProjectManagementController.java new file mode 100644 index 0000000..4a9f385 --- /dev/null +++ b/src/main/java/cn/yinlihupo/controller/project/ProjectManagementController.java @@ -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 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 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 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 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 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); + } + +}