diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantBaseDO.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantBaseDO.java index f4f0ea50..cb9951ad 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantBaseDO.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantBaseDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.framework.tenant.core.db; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import lombok.Data; import lombok.EqualsAndHashCode; @@ -17,5 +18,9 @@ public abstract class TenantBaseDO extends BaseDO { * 多租户编号 */ private Long tenantId; - + /** + * 工作流使用,用于判断是否有审核权限 + */ + @TableField(exist = false) + private Boolean isAuthorised = false; } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/expenseapply/ExpenseApplyController.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/expenseapply/ExpenseApplyController.java index 4f063ec6..13c37fea 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/expenseapply/ExpenseApplyController.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/expenseapply/ExpenseApplyController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.bpm.service.expenseapplytrip.ExpenseApplyTripService; +import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.*; import cn.iocoder.yudao.module.bs.convert.expenseapply.ExpenseApplyConvert; import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO; @@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.bs.enums.BillTypeEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.context.annotation.Lazy; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -43,6 +45,9 @@ public class ExpenseApplyController { private ExpenseApplyService expenseApplyService; @Resource private ExpenseApplyTripService expenseApplyTripService; + @Resource + @Lazy // 解决循环依赖 + private BpmTaskService taskService; @PostMapping("/create") @Operation(summary = "创建申请单") @PreAuthorize("@ss.hasPermission('bs:expense-apply:create')") @@ -74,6 +79,7 @@ public class ExpenseApplyController { expenseApplyService.setNickNameField(CollUtil.toList(expenseApply)); expenseApplyService.setDeptNameField(CollUtil.toList(expenseApply)); } + taskService.handleApprovalAuthority(CollUtil.toList(expenseApply)); return success(expenseApply); } @@ -93,7 +99,6 @@ public class ExpenseApplyController { PageResult pageResult = expenseApplyService.getExpenseApplyPage(pageVO); List list = pageResult.getList(); if (CollUtil.isNotEmpty(list)) { - //cqptodo 待设置用户名称 expenseApplyService.setNickNameField(list); List applids = list.stream().map(ExpenseApplyDO::getId).collect(Collectors.toList()); LambdaQueryWrapperX queryWrapper = new LambdaQueryWrapperX<>(); @@ -107,6 +112,8 @@ public class ExpenseApplyController { } apply.getExpenseApplyTrips().add(tripDO); } + taskService.handleApprovalAuthority(list); + } return success(pageResult); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java index fc45887b..f9047554 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bpm.service.task; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*; import org.flowable.task.api.Task; @@ -128,4 +129,5 @@ public interface BpmTaskService { */ void updateTaskExtAssign(Task task); + List handleApprovalAuthority(List list); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 8f470ebc..44c91ebe 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -1,14 +1,18 @@ package cn.iocoder.yudao.module.bpm.service.task; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*; import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert; import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; @@ -38,6 +42,7 @@ import javax.annotation.Resource; import javax.validation.Valid; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; @@ -316,5 +321,34 @@ public class BpmTaskServiceImpl implements BpmTaskService { private HistoricTaskInstance getHistoricTask(String id) { return historyService.createHistoricTaskInstanceQuery().taskId(id).taskTenantId(TenantContextHolder.getTenantId().toString()).singleResult(); } - + @Override + public List handleApprovalAuthority(List list) { + if (CollUtil.isNotEmpty(list)) { + for (T t : list) { + Object processInstanceId = ReflectUtil.getFieldValue(t, "processInstanceId"); + if (processInstanceId != null) { + List taskList = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(Convert.toStr(processInstanceId)) + .taskTenantId(TenantContextHolder.getTenantId().toString()) + .list(); + if (CollUtil.isNotEmpty(taskList)) { + //endtime为null表示未结束的task + List taskIdS = taskList.stream().filter(tk -> tk.getEndTime() == null).map(HistoricTaskInstance::getId).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(taskIdS)) { + LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); + wrapperX.in(BpmTaskExtDO::getTaskId, taskIdS); + wrapperX.in(BpmTaskExtDO::getAssigneeUserId, SecurityFrameworkUtils.getLoginUserId()); + boolean exists = taskExtMapper.exists(wrapperX); + if (exists) { + t.setIsAuthorised(true); + } else { + t.setIsAuthorised(false); + } + } + } + } + } + } + return list; + } }