fixed bug

This commit is contained in:
2025-09-09 10:24:33 +08:00
parent 363f7d1a2f
commit 35ebacc326
6 changed files with 158 additions and 39 deletions

View File

@@ -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=软删除 */

View File

@@ -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后续需要优化
// 设置接取人为用户名非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);
}

View File

@@ -20,10 +20,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectBizModuleVo">
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
</sql>
<select id="selectBizModuleList" parameterType="BizModule" resultMap="BizModuleResult">
@@ -129,11 +141,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<select id="selectAssignedModules" parameterType="Long" resultMap="BizModuleResult">
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
</select>

View File

@@ -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;
},
/** 下载按钮操作 */

View File

@@ -43,7 +43,7 @@
</div>
</el-form>
<el-table v-loading="loading" :data="moduleList" @selection-change="handleSelectionChange" @row-click="handleRowClick" @cell-click="handleCellClick">
<el-table v-loading="loading" :data="moduleList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="模块ID" align="center" prop="moduleId" />
<el-table-column label="模块名称" align="center" prop="moduleName">

View File

@@ -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;
})
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("添加完成");
location.reload();
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,14 +616,12 @@ 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.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 = '修改模块'
},