Selaa lähdekoodia

添加申请人自选任务分配脚本实现

dongpo 7 kuukautta sitten
vanhempi
commit
f24873cd7b

+ 1 - 0
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTaskRuleScriptEnum.java

@@ -14,6 +14,7 @@ import lombok.Getter;
 public enum BpmTaskRuleScriptEnum {
 
     START_USER(10L, "流程发起人"),
+    APPLY_SELECT(22L, "申请人自选"),
 
     LEADER_X1(20L, "流程发起人的一级领导"),
     LEADER_X2(21L, "流程发起人的二级领导");

+ 8 - 8
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/oa/entry/vo/OaEntrySaveReqVO.java

@@ -36,20 +36,20 @@ public class OaEntrySaveReqVO {
     @Schema(description = "电子邮箱")
     private String email;
 
-    @Schema(description = "教育背景")
+    @Schema(description = "教育背景", example = "本科")
     private String education;
 
-    @Schema(description = "工作经验")
+    @Schema(description = "工作经验", example = "5年Java开发经验")
     private String workExperience;
 
     @Schema(description = "备注")
     private String remarks;
 
     @Schema(description = "最后审核时间", requiredMode = Schema.RequiredMode.REQUIRED)
-    @NotEmpty(message = "最后审核时间不能为空")
+    // @NotEmpty(message = "最后审核时间不能为空")
     private String finalAuditDate;
 
-    @Schema(description = "入职表单主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "27428")
+    @Schema(description = "入职表单主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
     private Integer id;
 
     @Schema(description = "入职日期")
@@ -62,17 +62,17 @@ public class OaEntrySaveReqVO {
     private String auditStatus;
 
     @Schema(description = "当前审核人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29870")
-    @NotEmpty(message = "当前审核人编号不能为空")
+    // @NotEmpty(message = "当前审核人编号不能为空")
     private String currentAuditEmployeeId;
 
-    @Schema(description = "数据来源,0流程添加、1手动添加", requiredMode = Schema.RequiredMode.REQUIRED)
-    @NotEmpty(message = "数据来源,0流程添加、1手动添加不能为空")
+    @Schema(description = "数据来源,0流程添加、1手动添加", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
+    // @NotEmpty(message = "数据来源,0流程添加、1手动添加不能为空")
     private String infoSource;
 
     @Schema(description = "审批,true 通过,false 驳回", example = "true")
     private Boolean auditPass;
 
-    @Schema(description = "发起人自选审批人 Map", example = " [1, 2]")
+    @Schema(description = "发起人自选审批人 Map", example = " [1, 1]")
     private List<Long> startUserSelectAssignees;
 
     @Schema(description = "附件主键id", example = "[1, 2]")

+ 48 - 0
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskAssignApplySelectScript.java

@@ -0,0 +1,48 @@
+package cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.impl;
+
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.module.bpm.enums.definition.BpmTaskRuleScriptEnum;
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.BpmTaskAssignScript;
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
+import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.flowable.engine.runtime.ProcessInstance;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * 分配给 申请人自选 审批的 Script 实现类
+ *
+ * @author dp
+ */
+@Component
+public class BpmTaskAssignApplySelectScript implements BpmTaskAssignScript {
+
+    @Resource
+    @Lazy // 解决循环依赖
+    private BpmProcessInstanceService bpmProcessInstanceService;
+
+    @Override
+    public Set<Long> calculateTaskCandidateUsers(DelegateExecution execution) {
+        ProcessInstance processInstance = bpmProcessInstanceService.getProcessInstance(execution.getProcessInstanceId());
+        Assert.notNull(processInstance, "流程实例({})不能为空", execution.getProcessInstanceId());
+        Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance);
+        Assert.notNull(startUserSelectAssignees, "流程实例({}) 的申请人自选审批人不能为空",
+                execution.getProcessInstanceId());
+        // 获得审批人
+        List<Long> assignees = startUserSelectAssignees.get(execution.getCurrentActivityId());
+        return new LinkedHashSet<>(assignees);
+    }
+
+    @Override
+    public BpmTaskRuleScriptEnum getEnum() {
+        return BpmTaskRuleScriptEnum.APPLY_SELECT;
+    }
+
+}

+ 2 - 1
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/entry/OaEntryService.java

@@ -7,13 +7,14 @@ import cn.iocoder.yudao.module.bpm.controller.admin.oa.entry.vo.OaEntryPageReqVO
 import cn.iocoder.yudao.module.bpm.controller.admin.oa.entry.vo.OaEntrySaveReqVO;
 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskApproveReqVO;
 import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.entry.OaEntryDO;
+import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
  * 入职流程信息 Service 接口
  *
  * @author 芋道源码
  */
-public interface OaEntryService {
+public interface OaEntryService extends IService<OaEntryDO> {
 
     /**
      * 创建入职流程信息

+ 16 - 14
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/entry/OaEntryServiceImpl.java

@@ -2,36 +2,36 @@ package cn.iocoder.yudao.module.bpm.service.oa.entry;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.IdUtil;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
 import cn.iocoder.yudao.module.bpm.controller.admin.oa.entry.vo.OaEntryPageReqVO;
 import cn.iocoder.yudao.module.bpm.controller.admin.oa.entry.vo.OaEntrySaveReqVO;
 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskApproveReqVO;
-import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskReturnReqVO;
 import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.entry.OaEntryDO;
 import cn.iocoder.yudao.module.bpm.dal.mysql.oa.entry.OaEntryMapper;
 import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
 import cn.iocoder.yudao.module.infra.api.file.dto.FileDTO;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
 import org.flowable.engine.runtime.ProcessInstance;
 import org.flowable.task.api.Task;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import javax.annotation.Resource;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
-import java.util.*;
-
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_ENTRY_NOT_EXISTS;
 
 /**
  * 入职流程信息 Service 实现类
@@ -40,7 +40,7 @@ import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
  */
 @Service
 @Validated
-public class OaEntryServiceImpl implements OaEntryService {
+public class OaEntryServiceImpl extends ServiceImpl<OaEntryMapper, OaEntryDO> implements OaEntryService {
 
     /**
      * OA 入职对应的流程定义 KEY
@@ -63,6 +63,7 @@ public class OaEntryServiceImpl implements OaEntryService {
     private RuntimeService runtimeService;
 
     @Override
+    @Transactional
     public Integer startOaEntry(Long userId, OaEntrySaveReqVO createReqVO) {
         //判断是否已经发起流程
         Boolean auditPass = createReqVO.getAuditPass();
@@ -70,7 +71,8 @@ public class OaEntryServiceImpl implements OaEntryService {
         String uuid = IdUtil.fastSimpleUUID();
         // 插入
         OaEntryDO oaEntry = BeanUtils.toBean(createReqVO, OaEntryDO.class);
-        oaEntryMapper.insert(oaEntry);
+        oaEntry.setEntryId(uuid);
+        this.saveOrUpdate(oaEntry);
         //如果提交
         if (auditPass){
             // 发起 BPM 流程
@@ -97,8 +99,8 @@ public class OaEntryServiceImpl implements OaEntryService {
 
         //保存附件uuid
         if (CollectionUtil.isNotEmpty(createReqVO.getFileIdList())) {
-            LambdaUpdateWrapper<FileDTO> wrapper = new LambdaUpdateWrapper<>();
-            wrapper.in(FileDTO::getId, createReqVO.getFileIdList()).set(FileDTO::getServiceId, uuid);
+            // LambdaUpdateWrapper<FileDTO> wrapper = new LambdaUpdateWrapper<>();
+            // wrapper.in(FileDTO::getId, createReqVO.getFileIdList()).set(FileDTO::getServiceId, uuid);
         }
         // todo 站内信发送
         // loanInfoService.sendMassage(actBaseInfo);