Bladeren bron

流程配置

24282 2 jaren geleden
bovenliggende
commit
09ca1b5736

+ 5 - 2
hx-flow/src/main/java/com/fjhx/flow/controller/flow/FlowDefinitionController.java

@@ -4,8 +4,10 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.fjhx.flow.entity.flow.dto.FlowDefinitionDto;
 import com.fjhx.flow.entity.flow.po.FlowDefinition;
 import com.fjhx.flow.service.flow.FlowDefinitionService;
+import com.ruoyi.common.annotation.TenantIgnore;
 import com.ruoyi.common.constant.BaseSourceConstant;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author
  * @since 2023-03-15
  */
+@TenantIgnore
 @DS(BaseSourceConstant.BASE)
 @RestController
 @RequestMapping("/flowDefinition")
@@ -32,7 +35,7 @@ public class FlowDefinitionController {
      * 添加租户流程
      */
     @PostMapping("/add")
-    public void add(@RequestBody FlowDefinition flowDefinition) {
+    public void add(@Validated @RequestBody FlowDefinition flowDefinition) {
         flowDefinitionService.add(flowDefinition);
     }
 
@@ -40,7 +43,7 @@ public class FlowDefinitionController {
      * 添加租户流程版本
      */
     @PostMapping("/addVersion")
-    public void addVersion(@RequestBody FlowDefinitionDto dto) {
+    public void addVersion(@Validated @RequestBody FlowDefinitionDto dto) {
         flowDefinitionService.addVersion(dto);
     }
 

+ 0 - 22
hx-flow/src/main/java/com/fjhx/flow/controller/flow/FlowDefinitionNodeController.java

@@ -1,22 +0,0 @@
-package com.fjhx.flow.controller.flow;
-
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.ruoyi.common.constant.BaseSourceConstant;
-import org.springframework.web.bind.annotation.*;
-
-
-/**
- * <p>
- * 流程节点定义 前端控制器
- * </p>
- *
- * @author 
- * @since 2023-03-15
- */
-@DS(BaseSourceConstant.BASE)
-@RestController
-@RequestMapping("/flowDefinitionNode")
-public class FlowDefinitionNodeController {
-
-
-}

+ 0 - 19
hx-flow/src/main/java/com/fjhx/flow/controller/flow/FlowExampleDetailController.java

@@ -1,19 +0,0 @@
-package com.fjhx.flow.controller.flow;
-
-import org.springframework.web.bind.annotation.*;
-
-
-/**
- * <p>
- * 流程实例明细 前端控制器
- * </p>
- *
- * @author 
- * @since 2023-03-16
- */
-@RestController
-@RequestMapping("/flowExampleDetail")
-public class FlowExampleDetailController {
-
-
-}

+ 4 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/FlowDefinitionDto.java

@@ -5,6 +5,8 @@ import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.Valid;
+import javax.validation.constraints.NotEmpty;
 import java.util.List;
 
 @Getter
@@ -14,6 +16,8 @@ public class FlowDefinitionDto extends FlowDefinition {
     /**
      * 流程节点列表
      */
+    @Valid
+    @NotEmpty(message = "流程节点列表不能为空")
     private List<FlowDefinitionNode> flowDefinitionNodeList;
 
 }

+ 11 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/po/FlowDefinition.java

@@ -5,6 +5,9 @@ import com.ruoyi.common.core.domain.BaseIdPo;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 /**
  * <p>
  * 流程定义
@@ -21,6 +24,7 @@ public class FlowDefinition extends BaseIdPo {
     /**
      * 流程id
      */
+    @NotNull(message = "流程id不能为空")
     private Long flowInfoId;
 
     /**
@@ -31,6 +35,7 @@ public class FlowDefinition extends BaseIdPo {
     /**
      * 标题模板
      */
+    @NotBlank(message = "流程标题模板不能为空")
     private String titleTemplate;
 
     /**
@@ -43,6 +48,12 @@ public class FlowDefinition extends BaseIdPo {
      */
     private Integer currentVersion;
 
+    /**
+     * 租户id
+     */
+    @NotBlank(message = "租户id不能为空")
+    private String tenantId;
+
     private String nodeObject;
 
     private String lineObject;

+ 12 - 2
hx-flow/src/main/java/com/fjhx/flow/entity/flow/po/FlowDefinitionNode.java

@@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.BaseIdPo;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.constraints.NotNull;
+
 /**
  * <p>
  * 流程节点定义
@@ -26,11 +28,13 @@ public class FlowDefinitionNode extends BaseIdPo {
     /**
      * 节点名称
      */
+    @NotNull(message = "流程节点名称不能为空")
     private String nodeName;
 
     /**
      * 节点类型 1开始 2审核 3审批 4办理 5分支 99结束
      */
+    @NotNull(message = "流程节点类型不能为空")
     private Integer nodeType;
 
     /**
@@ -41,6 +45,7 @@ public class FlowDefinitionNode extends BaseIdPo {
     /**
      * 父节点id
      */
+    @NotNull(message = "流程父级节点不能为空")
     private Long parentId;
 
     /**
@@ -49,13 +54,18 @@ public class FlowDefinitionNode extends BaseIdPo {
     private String handlingMethod;
 
     /**
-     * 发起 / 处理对象类型(1用户 2角色 3部门
+     * 发起 / 处理对象类型(1用户 2部门负责人 3部门总监 4岗位
      */
     private Integer handleObjectType;
 
     /**
-     * 指定对象id集合
+     * 指定对象id
      */
     private Long handleObjectId;
 
+    @NotNull(message = "流程节点id不能为空")
+    public Long getId() {
+        return super.getId();
+    }
+
 }

+ 71 - 2
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowDefinitionServiceImpl.java

@@ -5,10 +5,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.flow.entity.flow.dto.FlowDefinitionDto;
 import com.fjhx.flow.entity.flow.po.FlowDefinition;
 import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
+import com.fjhx.flow.entity.flow.po.FlowInfo;
+import com.fjhx.flow.enums.NodeTypeEnum;
 import com.fjhx.flow.mapper.flow.FlowDefinitionMapper;
+import com.fjhx.flow.service.flow.FlowDefinitionNodeService;
 import com.fjhx.flow.service.flow.FlowDefinitionService;
+import com.fjhx.flow.service.flow.FlowInfoService;
+import com.ruoyi.common.constant.StatusConstant;
+import com.ruoyi.common.exception.ServiceException;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
 import java.util.List;
 
 
@@ -23,20 +32,79 @@ import java.util.List;
 @Service
 public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper, FlowDefinition> implements FlowDefinitionService {
 
+    @Autowired
+    private FlowInfoService flowInfoService;
+
+    @Autowired
+    private FlowDefinitionNodeService flowDefinitionNodeService;
+
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void add(FlowDefinition flowDefinition) {
-        // todo 判断是否已添加
+        Long flowInfoId = flowDefinition.getFlowInfoId();
+        String tenantId = flowDefinition.getTenantId();
+
+        long count = count(q -> q.eq(FlowDefinition::getFlowInfoId, flowInfoId).eq(FlowDefinition::getTenantId, tenantId));
+
+        if (count > 0) {
+            throw new ServiceException("流程已添加");
+        }
+
+        FlowInfo flowInfo = flowInfoService.getById(flowInfoId);
+        if (flowInfo == null) {
+            throw new ServiceException("没有找到流程定义");
+        }
+
+        flowDefinition.setId(IdWorker.getId());
+        flowDefinition.setFlowKey(flowInfo.getFlowKey());
+        flowDefinition.setVersionNumber(1);
+        flowDefinition.setCurrentVersion(StatusConstant.YES);
         this.save(flowDefinition);
+
+        // 添加默认流程节点
+        FlowDefinitionNode startNode = new FlowDefinitionNode();
+        startNode.setId(IdWorker.getId());
+        startNode.setFlowDefinitionId(flowDefinition.getId());
+        startNode.setNodeName("发起申请");
+        startNode.setNodeType(NodeTypeEnum.START.getKey());
+        startNode.setParentId(0L);
+
+        FlowDefinitionNode endNode = new FlowDefinitionNode();
+        endNode.setId(IdWorker.getId());
+        endNode.setFlowDefinitionId(flowDefinition.getId());
+        endNode.setNodeName("结束");
+        endNode.setNodeType(NodeTypeEnum.END.getKey());
+        endNode.setParentId(startNode.getId());
+
+        flowDefinitionNodeService.saveBatch(Arrays.asList(startNode, endNode));
     }
 
     @Override
     public void addVersion(FlowDefinitionDto dto) {
-        // todo 判断是否已添加
+        Long flowInfoId = dto.getFlowInfoId();
+        String tenantId = dto.getTenantId();
+
+        FlowDefinition flowDefinition = getOne(q -> q
+                .eq(FlowDefinition::getFlowInfoId, flowInfoId)
+                .eq(FlowDefinition::getTenantId, tenantId)
+                .orderByDesc(FlowDefinition::getVersionNumber));
+
+        if (flowDefinition == null) {
+            throw new ServiceException("未添加流程,无法新增流程版本");
+        }
+
+        dto.setId(IdWorker.getId());
+        dto.setFlowKey(flowDefinition.getFlowKey());
+        dto.setVersionNumber(flowDefinition.getVersionNumber() + 1);
+        dto.setCurrentVersion(StatusConstant.NO);
         this.save(dto);
 
+        // 添加流程节点
         List<FlowDefinitionNode> flowDefinitionNodeList = dto.getFlowDefinitionNodeList();
 
         for (FlowDefinitionNode flowDefinitionNode : flowDefinitionNodeList) {
+            flowDefinitionNode.setFlowDefinitionId(flowDefinition.getId());
+
             Long oldId = flowDefinitionNode.getId();
             long newId = IdWorker.getId();
             flowDefinitionNode.setId(newId);
@@ -48,6 +116,7 @@ public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper,
             }
         }
 
+        flowDefinitionNodeService.saveBatch(flowDefinitionNodeList);
     }
 
 }