From 19dbe921d83392f1943c63c5fbeb319077b1a641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B5=E6=9F=B3=E5=8D=8E?= <290631660@qq.com> Date: Thu, 13 Apr 2023 01:14:18 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[add]=20=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=EF=BC=9A=E6=B5=81=E7=A8=8B=E8=AE=BE=E8=AE=A1=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/i18n/messages.properties | 1 + hh-modules/hh-flow/pom.xml | 4 + .../controller/FlowDefinitionController.java | 50 +++++- .../com/hh/flow/mapper/FlowNodeMapper.java | 10 ++ .../flow/service/IFlowDefinitionService.java | 9 + .../com/hh/flow/service/IFlowNodeService.java | 10 ++ .../impl/FlowDefinitionServiceImpl.java | 28 ++++ .../service/impl/FlowNodeServiceImpl.java | 7 + .../com/hh/flow/utils/FlowConfigUtil.java | 1 - .../mapper/flow/FlowDefinitionMapper.xml | 45 ++++- .../resources/mapper/flow/FlowNodeMapper.xml | 4 + .../resources/templates/vue/index.vue.ftlh | 2 + .../resources/templates/xml/mapper.xml.ftlh | 1 - hh-ui/src/api/flow/definition.js | 17 ++ hh-ui/src/router/index.js | 14 ++ hh-ui/src/views/flow/definition/design.vue | 156 ++++++++++++++++++ hh-ui/src/views/flow/definition/dialog.vue | 2 +- hh-ui/src/views/flow/definition/index.vue | 24 +-- 18 files changed, 355 insertions(+), 30 deletions(-) create mode 100644 hh-ui/src/views/flow/definition/design.vue diff --git a/hh-admin/src/main/resources/i18n/messages.properties b/hh-admin/src/main/resources/i18n/messages.properties index f561d733..d75fbe3d 100644 --- a/hh-admin/src/main/resources/i18n/messages.properties +++ b/hh-admin/src/main/resources/i18n/messages.properties @@ -42,6 +42,7 @@ no.view.permission=\u60A8\u6CA1\u6709\u67E5\u770B\u6570\u636E\u7684\u6743\u9650\ controller.page=\u5206\u9875\u67E5\u8BE2\u5931\u8D25 controller.list=\u67E5\u8BE2\u5217\u8868\u5931\u8D25 controller.add=\u65B0\u589E\u5931\u8D25 +controller.save=\u4FDD\u5B58\u5931\u8D25 controller.update=\u66F4\u65B0\u5931\u8D25 controller.delete=\u5220\u9664\u5931\u8D25 controller.export=\u5BFC\u51FA\u5931\u8D25 diff --git a/hh-modules/hh-flow/pom.xml b/hh-modules/hh-flow/pom.xml index 32efdd81..6dd5e86e 100644 --- a/hh-modules/hh-flow/pom.xml +++ b/hh-modules/hh-flow/pom.xml @@ -25,5 +25,9 @@ com.hh hh-operatelog + + com.hh + hh-swagger + diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/controller/FlowDefinitionController.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/controller/FlowDefinitionController.java index 99fcacdd..b28096ec 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/controller/FlowDefinitionController.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/controller/FlowDefinitionController.java @@ -3,16 +3,16 @@ package com.hh.flow.controller; import java.util.List; import javax.annotation.Resource; +import com.hh.common.utils.ExceptionUtil; +import com.hh.common.utils.MessageUtils; +import com.hh.flow.domain.FlowNode; +import com.hh.flow.service.IFlowNodeService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.hh.log.annotaion.Log; import com.hh.mybatis.controller.BaseController; import com.hh.mybatis.domain.R; @@ -28,6 +28,7 @@ import com.hh.mybatis.domain.TableDataInfo; * @date 2023-04-11 */ @Validated +@Api(value = "流程定义控制器", tags = {"流程定义管理"}) @RestController @RequestMapping("/flow/definition") public class FlowDefinitionController extends BaseController @@ -35,6 +36,9 @@ public class FlowDefinitionController extends BaseController @Resource private IFlowDefinitionService flowDefinitionService; + @Resource + private IFlowNodeService nodeService; + @Override public IFlowDefinitionService getBaseService() { @@ -62,6 +66,18 @@ public class FlowDefinitionController extends BaseController return getBaseInfo(id); } + /** + * 获取流程定义详细信息 + */ + @PreAuthorize("@ss.hasPermi('flow:definition:query')") + @GetMapping(value = "/getNodeList/{definitionId}") + public R> getNodeList(@PathVariable("definitionId") Long definitionId) + { + FlowNode flowNode = new FlowNode(); + flowNode.setDefinitionId(definitionId); + return R.ok(nodeService.selectList(flowNode)); + } + /** * 新增流程定义 */ @@ -73,6 +89,24 @@ public class FlowDefinitionController extends BaseController return baseAdd(flowDefinition); } + /** + * 保存流程结点 + */ + @PreAuthorize("@ss.hasPermi('flow:definition:saveNode')") + @Log(title = "流程定义", businessType = BusinessType.INSERT) + @PostMapping("/saveNode") + public R saveNode(@RequestBody List nodeList, Long definitionId) + { + try { + flowDefinitionService.saveNode(nodeList, definitionId); + return R.ok(); + } catch (Exception e) { + String msg = MessageUtils.message("controller.save"); + logger.error(msg, e); + return R.fail(ExceptionUtil.handleMsg(msg, e)); + } + } + /** * 修改流程定义 */ diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/mapper/FlowNodeMapper.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/mapper/FlowNodeMapper.java index dc25730a..94085ed5 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/mapper/FlowNodeMapper.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/mapper/FlowNodeMapper.java @@ -4,6 +4,8 @@ import com.hh.flow.domain.FlowNode; import com.hh.mybatis.mapper.BaseMapper; import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.Collection; import java.util.List; /** @@ -16,4 +18,12 @@ public interface FlowNodeMapper extends BaseMapper { List queryNewVersionFlowNodeByFlowCode(String flowCode); List queryFlowNodeByFlowCodeAndVersion(@NotBlank String flowCode, @NotBlank String version); + + /** + * 根据ids批量删除 + * + * @param definitionId 需要删除的数据主键集合 + * @return 结果 + */ + int deleteByDefinitionId(Long definitionId); } diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowDefinitionService.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowDefinitionService.java index 49dacb79..dd9c1701 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowDefinitionService.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowDefinitionService.java @@ -1,7 +1,9 @@ package com.hh.flow.service; import com.hh.flow.domain.FlowDefinition; +import com.hh.flow.domain.FlowNode; import com.hh.mybatis.service.IBaseService; +import org.springframework.web.bind.annotation.RequestBody; import java.util.List; @@ -15,4 +17,11 @@ public interface IFlowDefinitionService extends IBaseService { List queryByCodeList(List flowCodeList); void closeFlowByCodeList(List flowCodeList); + + /** + * 保存流程结点 + * @param flowNodeList + * @param definitionId + */ + void saveNode(@RequestBody List flowNodeList, Long definitionId); } diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowNodeService.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowNodeService.java index ccdd64c2..b81ad5a7 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowNodeService.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/IFlowNodeService.java @@ -4,6 +4,8 @@ import com.hh.flow.domain.FlowNode; import com.hh.mybatis.service.IBaseService; import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.Collection; import java.util.List; /** @@ -29,4 +31,12 @@ public interface IFlowNodeService extends IBaseService { * @return */ List queryFlowNodeByFlowCodeAndVersion(@NotBlank String flowCode, @NotBlank String version); + + /** + * 根据definitionId批量删除 + * + * @param definitionId 需要删除的数据集合 + * @return 结果 + */ + int deleteByDefinitionId(Long definitionId); } diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowDefinitionServiceImpl.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowDefinitionServiceImpl.java index 8b5964d2..15f35d8a 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowDefinitionServiceImpl.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowDefinitionServiceImpl.java @@ -1,13 +1,21 @@ package com.hh.flow.service.impl; +import com.hh.common.utils.AssertUtil; import com.hh.flow.domain.FlowDefinition; +import com.hh.flow.domain.FlowNode; +import com.hh.flow.enums.NodeTypeEnum; import com.hh.flow.mapper.FlowDefinitionMapper; import com.hh.flow.service.IFlowDefinitionService; +import com.hh.flow.service.IFlowNodeService; +import com.hh.mybatis.domain.R; import com.hh.mybatis.service.impl.BaseServiceImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestBody; import javax.annotation.Resource; import java.util.List; +import java.util.stream.Collectors; /** * 流程定义Service业务层处理 @@ -20,6 +28,9 @@ public class FlowDefinitionServiceImpl extends BaseServiceImpl i @Resource private FlowDefinitionMapper definitionMapper; + @Resource + private IFlowNodeService nodeService; + @Override public FlowDefinitionMapper getBaseMapper() { return definitionMapper; @@ -34,4 +45,21 @@ public class FlowDefinitionServiceImpl extends BaseServiceImpl i public void closeFlowByCodeList(List flowCodeList) { definitionMapper.closeFlowByCodeList(flowCodeList); } + + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveNode(@RequestBody List flowNodeList, Long definitionId) + { + List nodeTypes = flowNodeList.stream().map(FlowNode::getNodeType).collect(Collectors.toList()); + AssertUtil.isTrue(nodeTypes.contains(NodeTypeEnum.start.getKey()) + && nodeTypes.contains(NodeTypeEnum.end.getKey()), "必须有开始结点和结束结点"); + FlowDefinition flowDefinition = selectById(definitionId); + nodeService.deleteByDefinitionId(definitionId); + for (FlowNode flowNode : flowNodeList) { + flowNode.setDefinitionId(definitionId); + flowNode.setVersion(flowDefinition.getVersion()); + } + nodeService.batchInsert(flowNodeList); + } } diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowNodeServiceImpl.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowNodeServiceImpl.java index 523eeaa9..290d9b40 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowNodeServiceImpl.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/service/impl/FlowNodeServiceImpl.java @@ -8,6 +8,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.Collection; import java.util.List; /** @@ -35,4 +37,9 @@ public class FlowNodeServiceImpl extends BaseServiceImpl implements IF public List queryFlowNodeByFlowCodeAndVersion(@NotBlank String flowCode, @NotBlank String version) { return nodeMapper.queryFlowNodeByFlowCodeAndVersion(flowCode, version); } + + @Override + public int deleteByDefinitionId(Long definitionId){ + return nodeMapper.deleteByDefinitionId(definitionId); + } } diff --git a/hh-modules/hh-flow/src/main/java/com/hh/flow/utils/FlowConfigUtil.java b/hh-modules/hh-flow/src/main/java/com/hh/flow/utils/FlowConfigUtil.java index 540dc07a..68a61ae5 100644 --- a/hh-modules/hh-flow/src/main/java/com/hh/flow/utils/FlowConfigUtil.java +++ b/hh-modules/hh-flow/src/main/java/com/hh/flow/utils/FlowConfigUtil.java @@ -224,7 +224,6 @@ public class FlowConfigUtil { AssertUtil.notBlank(target, "【" + nodeName + "】" + FlowConstant.LOST_DEST_NODE); AssertUtil.isFalse(targetSet.contains(target), "[" + nodeName + "]" + FlowConstant.SAME_DEST_NODE); targetSet.add(target); - String roleCode = skip.getRoleCode(); String value = skip.getConditionValue(); AssertUtil.isFalse(conditionSet.contains(value), "[" + nodeName + "]" + FlowConstant.SAME_CONDITION_VALUE); conditionSet.add(value); diff --git a/hh-modules/hh-flow/src/main/resources/mapper/flow/FlowDefinitionMapper.xml b/hh-modules/hh-flow/src/main/resources/mapper/flow/FlowDefinitionMapper.xml index 69b6b9dc..51093d12 100644 --- a/hh-modules/hh-flow/src/main/resources/mapper/flow/FlowDefinitionMapper.xml +++ b/hh-modules/hh-flow/src/main/resources/mapper/flow/FlowDefinitionMapper.xml @@ -17,6 +17,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + + select t.id, t.flow_code, t.flow_name, t.version, t.is_publish, t.create_by, t.create_time, t.update_by, t.update_time, t.del_flag from flow_definition t @@ -32,9 +50,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select a.id, a.flow_code, a.flow_name, a.version, a.is_publish, a.create_by, a.create_time, a.update_by, a.update_time, a.del_flag, + b.id as sub_id, b.node_type as sub_node_type, b.definition_id as sub_definition_id, b.node_name as sub_node_name, b.node_code as sub_node_code, b.version as sub_version, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.del_flag as sub_del_flag + from flow_definition a + left join flow_node b on b.definition_id = a.id + where a.id = #{id}