From 1b98a1a24f39cfacb693e7dddb1629ee323d823e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=AD=A6=E6=88=90?= <1274337408@qq.com> Date: Mon, 19 Oct 2026 16:52:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BC=9A=E7=AE=A1=E7=90=86-=E5=88=86?= =?UTF-8?q?=E5=B7=A5=E4=BC=9A=E5=B9=B2=E9=83=A8=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=B9=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E2=80=9C=E5=9F=BA=E5=B1=82?= =?UTF-8?q?=E5=B9=B2=E9=83=A8=E2=80=9D=E8=A7=92=E8=89=B2=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=BA=E5=B7=B2=E6=88=90=E5=8A=9F=E5=88=86=E9=85=8D=E5=88=86?= =?UTF-8?q?=E5=B7=A5=E4=BC=9A=E5=B9=B2=E9=83=A8=E8=A7=92=E8=89=B2=E7=9A=84?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E8=A1=A5=E9=BD=90=E8=AF=A5=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budwk/app/base/constant/RoleConstant.java | 1 + .../sys/controller/SysUnionController.java | 54 +++++++++++++------ .../SysUnionSchoolAuditInterceptor.java | 8 +++ .../db/init_branch_union_cadre_role.sql | 36 +++++++++++++ 4 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/db/init_branch_union_cadre_role.sql diff --git a/src/main/java/com/budwk/app/base/constant/RoleConstant.java b/src/main/java/com/budwk/app/base/constant/RoleConstant.java index 2f843ab..c5f8ef0 100644 --- a/src/main/java/com/budwk/app/base/constant/RoleConstant.java +++ b/src/main/java/com/budwk/app/base/constant/RoleConstant.java @@ -34,6 +34,7 @@ RoleConstant { SCHOOL_OUTLAY_ADMIN("校工会经费管理员"), BRANCH_UNION_ADMIN("分工会管理员"), + BRANCH_UNION_CADRE("基层干部"), BRANCH_UNION_CHAIRMAN("分工会主席"), BRANCH_UNION_VICE_CHAIRMAN("分工会副主席"), BRANCH_UNION_OPERATOR("分工会操作员"), diff --git a/src/main/java/com/budwk/app/sys/controller/SysUnionController.java b/src/main/java/com/budwk/app/sys/controller/SysUnionController.java index 79d6acd..ab9a1b0 100644 --- a/src/main/java/com/budwk/app/sys/controller/SysUnionController.java +++ b/src/main/java/com/budwk/app/sys/controller/SysUnionController.java @@ -357,26 +357,29 @@ public class SysUnionController { unionCadre.setIsJoin(true); dao.insert(unionCadre); - // 去走工作流 boolean isAdmin = AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name()); - Dict args = Dict.create(); - args.set("submit", isAdmin ? "admin" : "branch"); - args.set(FlowConst.SUBMIT_TYPE, ProcessSubmitTypeEnum.APPLY.getCode()); - args.set(FlowConst.FORM_DATA, unionCadre); - - ProcessInstance instance = flowEngine.startProcessInstanceByKey("JCGHWY", unionCadre.getId(), SecurityUtil.getUserId(), args); - // 自动完成第一个申请任务 - List doingTaskList = flowEngine.processTaskService().getDoingTaskList(instance.getId(), null); - for (ProcessTask task : doingTaskList) { - flowEngine.executeProcessTask(task.getId(), SecurityUtil.getUserId(), args); - } - if (isAdmin) { // 如果是管理员,直接加角色 sysRoleService.clear("sys_user_role", Cnd.where("roleId", "=", role.getId()).and("userId", "=", userId).and("unionId", "=", unionId)); sysRoleService.insert("sys_user_role", Chain.make("roleId", role.getId()).add("userId", userId).add("unionId", unionId)); + Sys_role cadreRole = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_CADRE); + sysRoleService.clear("sys_user_role", Cnd.where("roleId", "=", cadreRole.getId()).and("userId", "=", userId).and("unionId", "=", unionId)); + sysRoleService.insert("sys_user_role", Chain.make("roleId", cadreRole.getId()).add("userId", userId).add("unionId", unionId)); sysRoleService.clearCache(); sysUserService.clearCache(); + } else { + // 分工会管理员添加干部时提交校工会审核。 + Dict args = Dict.create(); + args.set("submit", "branch"); + args.set(FlowConst.SUBMIT_TYPE, ProcessSubmitTypeEnum.APPLY.getCode()); + args.set(FlowConst.FORM_DATA, unionCadre); + + ProcessInstance instance = flowEngine.startProcessInstanceByKey("JCGHWY", unionCadre.getId(), SecurityUtil.getUserId(), args); + // 自动完成第一个申请任务 + List doingTaskList = flowEngine.processTaskService().getDoingTaskList(instance.getId(), null); + for (ProcessTask task : doingTaskList) { + flowEngine.executeProcessTask(task.getId(), SecurityUtil.getUserId(), args); + } } return Result.success(); @@ -385,11 +388,19 @@ public class SysUnionController { @At @ApiOperation("删除分工会人员角色") @SaCheckPermission("sys.manager.union.branchOfficer") + @Aop(TransAop.READ_COMMITTED) public Result deleteBranchUnionUserRole(String userId, String roleCode, String unionId) { Sys_role role = sysRoleService.fetch(Cnd.where("code", "=", roleCode)); if (Lang.isEmpty(role)) { throw new BaseException("无法找到{}对应编码的角色", roleCode); } + Cnd unionCadreCnd = Cnd.where("userId", "=", userId) + .and("unionId", "=", unionId).and("roleCode", "=", roleCode); + List unionCadres = dao.query(Sys_union_cadre.class, unionCadreCnd); + // 删除干部申请时同步删除流程,避免审核列表残留空白待办。 + for (Sys_union_cadre unionCadre : unionCadres) { + flowEngine.processInstanceService().deleteProcessInstanceByBusinessKey(unionCadre.getId()); + } Cnd cnd = Cnd.NEW(); cnd.and("roleId", "=", role.getId()); if (StrUtil.isNotBlank(userId)) { @@ -401,8 +412,20 @@ public class SysUnionController { sysRoleService.clear("sys_user_role", cnd); - dao.clear(Sys_union_cadre.class, Cnd.where("userId", "=", userId) - .and("unionId", "=", unionId).and("roleCode", "=", roleCode)); + dao.clear(Sys_union_cadre.class, unionCadreCnd); + + List branchUnionRoleCodes = sysDictService.getSubListByCode("BRANCH_UNION_ROLES") + .stream().map(Sys_dict::getCode).toList(); + List branchUnionRoleIds = CollUtil.isEmpty(branchUnionRoleCodes) ? List.of() : + sysRoleService.query(Cnd.where("code", "in", branchUnionRoleCodes)) + .stream().map(Sys_role::getId).toList(); + int branchUnionRoleCount = CollUtil.isEmpty(branchUnionRoleIds) ? 0 : dao.count(Sys_user_role.class, + Cnd.where("userId", "=", userId).and("unionId", "=", unionId).and("roleId", "in", branchUnionRoleIds)); + if (branchUnionRoleCount == 0) { + Sys_role cadreRole = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_CADRE); + sysRoleService.clear("sys_user_role", Cnd.where("roleId", "=", cadreRole.getId()) + .and("userId", "=", userId).and("unionId", "=", unionId)); + } sysRoleService.clearCache(); sysUserService.clearCache(); @@ -510,6 +533,7 @@ public class SysUnionController { """); Cnd cnd = Cnd.NEW(); cnd.and("t.taskName", "=", "2978a74a-75c1-4f95-99f9-9c08c480f1b5"); + cnd.and("info.id", "is not", null); if (pageForm.getAudit()) { cnd.and("t.taskState", "in", List.of(ProcessTaskStateEnum.FINISHED.getCode(), ProcessTaskStateEnum.WITHDRAW.getCode(), ProcessTaskStateEnum.INTERRUPT.getCode())); diff --git a/src/main/java/com/budwk/app/sys/interceptor/SysUnionSchoolAuditInterceptor.java b/src/main/java/com/budwk/app/sys/interceptor/SysUnionSchoolAuditInterceptor.java index 39de1e1..f9c32f4 100644 --- a/src/main/java/com/budwk/app/sys/interceptor/SysUnionSchoolAuditInterceptor.java +++ b/src/main/java/com/budwk/app/sys/interceptor/SysUnionSchoolAuditInterceptor.java @@ -1,6 +1,7 @@ package com.budwk.app.sys.interceptor; import cn.hutool.json.JSONUtil; +import com.budwk.app.base.constant.RoleConstant; import com.budwk.app.flow.constant.FlowConst; import com.budwk.app.flow.engine.FlowInterceptor; import com.budwk.app.flow.engine.core.Execution; @@ -44,6 +45,13 @@ public class SysUnionSchoolAuditInterceptor implements FlowInterceptor { sysRoleService.insert("sys_user_role", Chain.make("roleId", role.getId()) .add("userId", unionBean.getUserId()).add("unionId", unionBean.getUnionId())); + // 分工会干部统一增加基层干部角色,便于按干部身份集中管理。 + Sys_role cadreRole = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_CADRE); + sysRoleService.clear("sys_user_role", Cnd.where("roleId", "=", cadreRole.getId()) + .and("userId", "=", unionBean.getUserId()).and("unionId", "=", unionBean.getUnionId())); + sysRoleService.insert("sys_user_role", Chain.make("roleId", cadreRole.getId()) + .add("userId", unionBean.getUserId()).add("unionId", unionBean.getUnionId())); + // 清除缓存 sysRoleService.clearCache(); sysUserService.clearCache(); diff --git a/src/main/resources/db/init_branch_union_cadre_role.sql b/src/main/resources/db/init_branch_union_cadre_role.sql new file mode 100644 index 0000000..889a8bf --- /dev/null +++ b/src/main/resources/db/init_branch_union_cadre_role.sql @@ -0,0 +1,36 @@ +-- 初始化“基层干部”角色,并为已成功分配分工会干部角色的人员补齐该角色。 +SET @now := CAST(UNIX_TIMESTAMP(NOW()) * 1000 AS UNSIGNED); + +INSERT INTO `sys_role` + (`id`, `name`, `code`, `aliasName`, `disabled`, `unitid`, `note`, `sort`, `createdBy`, `createdAt`, `updatedBy`, `updatedAt`, `delFlag`) +SELECT + 'c1d5a6e7b8f94032a1b2c3d4e5f60718', '基层干部', 'BRANCH_UNION_CADRE', 'BranchUnionCadre', + 0, NULL, '分工会干部统一身份角色', 50, '', @now, '', @now, 0 +FROM DUAL +WHERE NOT EXISTS ( + SELECT 1 FROM `sys_role` WHERE `code` = 'BRANCH_UNION_CADRE' +); + +INSERT INTO `sys_user_role` (`roleId`, `userId`, `unionId`) +SELECT DISTINCT + cadre_role.`id`, assigned_role.`userId`, assigned_role.`unionId` +FROM `sys_user_role` assigned_role +INNER JOIN `sys_role` business_role + ON business_role.`id` = assigned_role.`roleId` +INNER JOIN `sys_dict` branch_role_parent + ON branch_role_parent.`code` = 'BRANCH_UNION_ROLES' +INNER JOIN `sys_dict` branch_role_item + ON branch_role_item.`parentId` = branch_role_parent.`id` + AND branch_role_item.`code` = business_role.`code` +INNER JOIN `sys_role` cadre_role + ON cadre_role.`code` = 'BRANCH_UNION_CADRE' +WHERE assigned_role.`userId` IS NOT NULL + AND assigned_role.`unionId` IS NOT NULL + AND assigned_role.`unionId` <> '' + AND NOT EXISTS ( + SELECT 1 + FROM `sys_user_role` existing_cadre + WHERE existing_cadre.`roleId` = cadre_role.`id` + AND existing_cadre.`userId` = assigned_role.`userId` + AND existing_cadre.`unionId` = assigned_role.`unionId` + );