From 35ebacc326afc8346cd1c138ea801ece2c6ae09c Mon Sep 17 00:00:00 2001 From: Quella <2892744389@qq.com> Date: Tue, 9 Sep 2025 10:24:33 +0800 Subject: [PATCH] fixed bug --- .../com/ruoyi/models/domain/BizModule.java | 8 +- .../service/impl/BizModuleServiceImpl.java | 19 ++++- .../mapper/models/BizModuleMapper.xml | 33 +++++++- ruoyi-ui/src/views/project/doc/index.vue | 56 ++++++++++++- .../src/views/project/module/myModules.vue | 2 +- ruoyi-ui/src/views/project/project/index.vue | 79 +++++++++++++------ 6 files changed, 158 insertions(+), 39 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/models/domain/BizModule.java b/ruoyi-admin/src/main/java/com/ruoyi/models/domain/BizModule.java index 2237c00..b7ad69d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/models/domain/BizModule.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/models/domain/BizModule.java @@ -37,13 +37,13 @@ public class BizModule extends BaseEntity private String assignee; /** 接取时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "接取时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "接取时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date assignTime; /** 完成时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "完成时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "完成时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date finishTime; /** 删除标志0=正常,2=软删除 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/models/service/impl/BizModuleServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/models/service/impl/BizModuleServiceImpl.java index c678d2c..9c95a62 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/models/service/impl/BizModuleServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/models/service/impl/BizModuleServiceImpl.java @@ -11,6 +11,8 @@ import com.ruoyi.models.domain.BizModule; import com.ruoyi.models.service.IBizModuleService; import com.ruoyi.project.domain.BizProject; import com.ruoyi.project.service.IBizProjectService; +import com.ruoyi.system.service.ISysUserService; +import com.ruoyi.common.core.domain.entity.SysUser; /** * 模块Service业务层处理 @@ -26,6 +28,9 @@ public class BizModuleServiceImpl implements IBizModuleService { @Autowired private IBizProjectService projectService; + @Autowired + private ISysUserService sysUserService; + /** * 查询模块 * @@ -140,9 +145,17 @@ public class BizModuleServiceImpl implements IBizModuleService { } module.setStatus("1"); // 进行中 - // 这里需要设置用户名而不是用户ID,但我们需要查询用户名 - // 暂时设置为用户ID,后续需要优化 - module.setAssignee(String.valueOf(userId)); + // 设置接取人为用户名(非ID) + try { + SysUser u = sysUserService.selectUserById(userId); + if (u != null && u.getUserName() != null) { + module.setAssignee(u.getUserName()); + } else { + module.setAssignee(String.valueOf(userId)); + } + } catch (Exception ex) { + module.setAssignee(String.valueOf(userId)); + } module.setAssignTime(DateUtils.getNowDate()); return updateBizModule(module); } diff --git a/ruoyi-admin/src/main/resources/mapper/models/BizModuleMapper.xml b/ruoyi-admin/src/main/resources/mapper/models/BizModuleMapper.xml index 07c53e7..ec114b5 100644 --- a/ruoyi-admin/src/main/resources/mapper/models/BizModuleMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/models/BizModuleMapper.xml @@ -20,10 +20,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select m.module_id, m.project_id, m.module_name, m.status, m.assignee, m.assign_time, m.finish_time, - m.del_flag, m.create_by, m.create_time, m.designated_user, p.project_name + select m.module_id, + m.project_id, + m.module_name, + m.status, + COALESCE(u1.nick_name, u1.user_name, u2.nick_name, u2.user_name, m.assignee) as assignee, + m.assign_time, + m.finish_time, + m.del_flag, + m.create_by, + m.create_time, + m.designated_user, + p.project_name from biz_module m left join biz_project p on m.project_id = p.project_id + left join sys_user u1 on u1.user_id = CAST(m.assignee AS UNSIGNED) + left join sys_user u2 on u2.user_name = m.assignee - select m.module_id, m.project_id, m.module_name, m.status, m.assignee, m.assign_time, m.finish_time, - m.del_flag, m.create_by, m.create_time, m.designated_user, m.update_by, m.update_time, + select m.module_id, + m.project_id, + m.module_name, + m.status, + COALESCE(u1.nick_name, u1.user_name, u2.nick_name, u2.user_name, m.assignee) as assignee, + m.assign_time, + m.finish_time, + m.del_flag, + m.create_by, + m.create_time, + m.designated_user, + m.update_by, + m.update_time, p.project_name from biz_module m left join biz_project p on m.project_id = p.project_id + left join sys_user u1 on u1.user_id = CAST(m.assignee AS UNSIGNED) + left join sys_user u2 on u2.user_name = m.assignee where m.designated_user = #{userId} and m.del_flag = '0' order by m.create_time desc diff --git a/ruoyi-ui/src/views/project/doc/index.vue b/ruoyi-ui/src/views/project/doc/index.vue index 35754a4..a6d2e27 100644 --- a/ruoyi-ui/src/views/project/doc/index.vue +++ b/ruoyi-ui/src/views/project/doc/index.vue @@ -248,10 +248,11 @@ export default { methods: { async initProjects() { try { + let options = [] if (this.isProjectAdmin) { // 管理员/项目管理员:读取全部可管理项目 const { rows } = await listProject({ pageNum: 1, pageSize: 9999 }) - this.projectOptions = rows || [] + options = rows || [] } else if (this.isNormalUser) { // 普通用户:从“我的模块”汇总所属项目 const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 }) @@ -261,7 +262,35 @@ export default { map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName }) } }) - this.projectOptions = Array.from(map.values()) + options = Array.from(map.values()) + } + // 兼容:若管理员接口无数据,则回退到“我的模块”聚合 + if ((!options || options.length === 0)) { + const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 }) + const map = new Map() + ;(rows || []).forEach(m => { + if (m.projectId && m.projectName && !map.has(m.projectId)) { + map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName }) + } + }) + options = Array.from(map.values()) + } + // 如果路由带有项目上下文,但下拉没有,补入一项,避免空列表 + if ((this.currentContext.projectId && this.currentContext.projectName) && !options.some(p => String(p.projectId) === String(this.currentContext.projectId))) { + options.unshift({ projectId: this.currentContext.projectId, projectName: this.currentContext.projectName }) + } + this.projectOptions = options + + // 预选项目(优先使用路由上下文),并联动加载模块下拉 + if (!this.upload.meta.projectId) { + if (this.currentContext.projectId) { + this.upload.meta.projectId = this.currentContext.projectId + } else if (this.projectOptions && this.projectOptions.length > 0) { + this.upload.meta.projectId = this.projectOptions[0].projectId + } + } + if (this.upload.meta.projectId) { + await this.handleProjectChange(this.upload.meta.projectId) } } catch (e) { this.projectOptions = [] @@ -287,7 +316,8 @@ export default { this.currentContext.moduleName = query.moduleName; } if (query.projectId) { - this.currentContext.projectId = query.projectId; + // 统一为数字,避免 el-select 由于类型不一致显示原始ID + this.currentContext.projectId = parseInt(query.projectId); } if (query.projectName) { this.currentContext.projectName = query.projectName; @@ -364,12 +394,30 @@ export default { this.multiple = !selection.length; }, /** 上传按钮操作 */ - handleUpload() { + async handleUpload() { if (this.currentContext.moduleName) { this.uploadTitle = `上传文档 - ${this.currentContext.moduleName}`; } else { this.uploadTitle = "上传文档"; } + // 确保项目选项已加载,再设置默认值,避免首次显示为纯ID + if (!this.projectOptions || this.projectOptions.length === 0) { + await this.initProjects() + } + // 预选:优先使用路由上下文;否则选第一项 + if (this.currentContext.projectId) { + this.upload.meta.projectId = this.currentContext.projectId + } else { + // 默认不选任何项目,避免显示成固定ID + this.upload.meta.projectId = null + } + if (this.upload.meta.projectId) { + await this.handleProjectChange(this.upload.meta.projectId) + } else { + // 无默认项目时清空模块下拉 + this.moduleOptions = [] + this.upload.meta.moduleId = null + } this.uploadOpen = true; }, /** 下载按钮操作 */ diff --git a/ruoyi-ui/src/views/project/module/myModules.vue b/ruoyi-ui/src/views/project/module/myModules.vue index 9a224ca..55e4191 100644 --- a/ruoyi-ui/src/views/project/module/myModules.vue +++ b/ruoyi-ui/src/views/project/module/myModules.vue @@ -43,7 +43,7 @@ - + diff --git a/ruoyi-ui/src/views/project/project/index.vue b/ruoyi-ui/src/views/project/project/index.vue index 46f105d..9a2ada7 100644 --- a/ruoyi-ui/src/views/project/project/index.vue +++ b/ruoyi-ui/src/views/project/project/index.vue @@ -322,7 +322,6 @@ import { assignModule } from "@/api/project/module"; import { listUser } from "@/api/system/user"; import Cookies from "js-cookie"; import {getUserRole} from "@/api/system/role"; -import {getSysUser} from "@/api/system/user"; import moment from "moment"; import { downloadDoc } from "@/api/doc/doc"; import { getToken } from "@/utils/auth"; @@ -401,7 +400,11 @@ export default { {required: true, message: "模块名称不能为空", trigger: "blur"} ], deadline: [ - {required: true, message: "截止日期不能为空", trigger: "blur"} + {required: true, message: "截止日期不能为空", trigger: "blur"}, + { validator: (rule, value, callback) => { try { const st = this.form.startTime ? moment(this.form.startTime, 'YYYY-MM-DD') : null; const dl = value ? moment(value, 'YYYY-MM-DD') : null; if (st && dl && st.isAfter(dl)) { callback(new Error('截止日期不能早于起始日期')); } else { callback(); } } catch(e){ callback(); } }, trigger: 'change' } + ], + startTime: [ + { validator: (rule, value, callback) => { try { const st = value ? moment(value, 'YYYY-MM-DD') : null; const dl = this.form.deadline ? moment(this.form.deadline, 'YYYY-MM-DD') : null; if (st && dl && st.isAfter(dl)) { callback(new Error('起始日期不能晚于截止日期')); } else { callback(); } } catch(e){ callback(); } }, trigger: 'change' } ] }, @@ -576,21 +579,36 @@ export default { }) }, - //添加模块 + // 添加/修改模块(根据是否存在 moduleId 判断) subMitModel() { this.modelsForm.projectId = this.projectId; - this.modelsForm.status = 0;//待接取 - getSysUser(Cookies.get("username")).then(res => { - this.modelsForm.create_by = res.sysUser.nickName; - }) - addModels(this.modelsForm).then(res => { - if (res.code === 200) { - this.$message.success("添加完成"); - location.reload(); - } else { - this.$message.error("添加失败,请重试") - } - }) + const isEdit = !!this.modelsForm.moduleId; + if (!isEdit) { + // 新增:默认待接取 + this.modelsForm.status = 0; + // 使用当前登录用户名作为创建人 + this.modelsForm.create_by = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.name) || undefined; + addModels(this.modelsForm).then(res => { + if (res.code === 200) { + this.$message.success("添加完成"); + this.Models = false; + this.getModuleList(); + } else { + this.$message.error("添加失败,请重试") + } + }) + } else { + // 修改:保留原状态/接取信息,仅更新可编辑字段 + updateModels(this.modelsForm).then(res => { + if (res.code === 200) { + this.$message.success("修改完成"); + this.Models = false; + this.getModuleList(); + } else { + this.$message.error("修改失败,请重试") + } + }) + } }, //接取模块 @@ -598,13 +616,11 @@ export default { this.modelsForm.moduleId = row.moduleId //修改状态 this.modelsForm.status = 1; //已接取 - getSysUser(Cookies.get("username")).then(res => { - this.modelsForm.assignee = res.sysUser.nickName; - this.modelsForm.assignTime = moment().format('YYYY-MM-DD HH:mm:ss'); - updateModels(this.modelsForm).then(ress => { - this.$message.success("已接取") - location.reload(); - }) + this.modelsForm.assignee = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.name) || undefined; + this.modelsForm.assignTime = moment().format('YYYY-MM-DD HH:mm:ss'); + updateModels(this.modelsForm).then(ress => { + this.$message.success("已接取") + location.reload(); }) }, @@ -725,6 +741,13 @@ export default { this.$refs["form"].validate(valid => { this.finishDialog = false; if (valid) { + // 运行时校验:起始日期不得晚于截止日期 + const st = this.form.startTime ? moment(this.form.startTime, 'YYYY-MM-DD') : null + const dl = this.form.deadline ? moment(this.form.deadline, 'YYYY-MM-DD') : null + if (st && dl && st.isAfter(dl)) { + this.$modal.msgError('起始日期不能晚于截止日期') + return + } if (this.form.projectId != null) { console.log(this.form) // this.form.status = (this.form.status === '已完成' ? '1' : '0'); @@ -824,7 +847,17 @@ export default { }, // 编辑模块 editModule(row) { - this.modelsForm = { ...this.modelsForm, ...row } + // 只拷贝前端可编辑字段,避免误传无关数据导致新增 + this.modelsForm = { + moduleId: row.moduleId, + projectId: this.projectId, + moduleName: row.moduleName, + deadline: row.deadline, + status: row.status, + assignee: row.assignee, + assignTime: row.assignTime, + finishTime: row.finishTime + } this.Models = true this.title = '修改模块' },