From 9f971c5e5878f9487079beea39c3843bc56e641c Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 15 Apr 2019 09:37:08 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E5=A2=9E=E5=8A=A0=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/FlowDesignApplication.java | 7 +- .../flowable/constant/FlowableConstant.java | 3 +- blade-service/blade-flow/pom.xml | 26 ++++- .../springblade/flowable/FlowApplication.java | 27 ++++- .../engine/config/FlowableConfiguration.java | 7 ++ .../engine/constant/FlowableConstant.java | 31 +++++ .../controller/FlowModelController.java | 2 +- .../engine/service/impl/FlowServiceImpl.java | 57 ++++++++- .../src/main/resources/application.yml | 7 +- .../processes/ExpenseProcess.bpmn20.xml | 108 ------------------ .../processes/LeaveProcess.bpmn20.xml | 101 ++++++++++++++++ .../system/controller/MenuController.java | 10 +- 12 files changed, 263 insertions(+), 123 deletions(-) create mode 100644 blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java delete mode 100644 blade-service/blade-flow/src/main/resources/processes/ExpenseProcess.bpmn20.xml create mode 100644 blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml diff --git a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/FlowDesignApplication.java b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/FlowDesignApplication.java index f92cd37a..0a2a2b51 100644 --- a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/FlowDesignApplication.java +++ b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/FlowDesignApplication.java @@ -20,6 +20,7 @@ import org.flowable.ui.common.conf.DevelopmentConfiguration; import org.flowable.ui.common.rest.idm.remote.RemoteAccountResource; import org.springblade.core.launch.BladeApplication; import org.springblade.core.launch.constant.AppConstant; +import org.springblade.flowable.constant.FlowableConstant; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; @@ -27,9 +28,6 @@ import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServic import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; -import static org.springblade.flowable.constant.FlowableConstant.BASE_PACHAGE; -import static org.springblade.flowable.constant.FlowableConstant.FLOWABLE_BASE_PACKAGE; - /** * FlowDesign启动器 * @@ -37,14 +35,13 @@ import static org.springblade.flowable.constant.FlowableConstant.FLOWABLE_BASE_P */ @SpringBootApplication( exclude = { - SecurityAutoConfiguration.class, SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class, LiquibaseAutoConfiguration.class } ) @ComponentScan( - basePackages = {BASE_PACHAGE, FLOWABLE_BASE_PACKAGE}, + basePackages = {AppConstant.BASE_PACKAGES, FlowableConstant.FLOWABLE_BASE_PACKAGES}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RemoteAccountResource.class, DevelopmentConfiguration.class}) ) public class FlowDesignApplication { diff --git a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/constant/FlowableConstant.java b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/constant/FlowableConstant.java index 0c1d5834..246774b8 100644 --- a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/constant/FlowableConstant.java +++ b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/constant/FlowableConstant.java @@ -22,8 +22,7 @@ package org.springblade.flowable.constant; * @author Chill */ public interface FlowableConstant { - String BASE_PACHAGE = "org.springblade"; - String FLOWABLE_BASE_PACKAGE = "org.flowable.ui"; + String FLOWABLE_BASE_PACKAGES = "org.flowable.ui"; String css = ".css"; String js = ".js"; diff --git a/blade-service/blade-flow/pom.xml b/blade-service/blade-flow/pom.xml index d451e71e..197bd3c3 100644 --- a/blade-service/blade-flow/pom.xml +++ b/blade-service/blade-flow/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - blade-ops + blade-service org.springblade 2.0.0.RC8 @@ -37,12 +37,36 @@ ${bladex.tool.version} provided + + org.mybatis + mybatis-spring + 2.0.0 + org.flowable flowable-spring-boot-starter ${flowable.version} + + org.flowable + flowable-ui-modeler-rest + ${flowable.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.apache.logging.log4j + log4j-core + + + org.slf4j + jul-to-slf4j + + + diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java index cbb79dd2..163509c7 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java @@ -16,10 +16,20 @@ */ package org.springblade.flowable; +import org.flowable.ui.common.conf.DevelopmentConfiguration; import org.springblade.core.cloud.feign.EnableBladeFeign; import org.springblade.core.launch.BladeApplication; import org.springblade.core.launch.constant.AppConstant; -import org.springframework.cloud.client.SpringCloudApplication; +import org.springblade.flowable.engine.constant.FlowableConstant; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; /** * Flowable启动器 @@ -27,7 +37,20 @@ import org.springframework.cloud.client.SpringCloudApplication; * @author Chill */ @EnableBladeFeign -@SpringCloudApplication +@EnableDiscoveryClient +@EnableCircuitBreaker +@SpringBootApplication( + exclude = { + SecurityAutoConfiguration.class, + UserDetailsServiceAutoConfiguration.class, + LiquibaseAutoConfiguration.class, + MultipartAutoConfiguration.class + } +) +@ComponentScan( + basePackages = {AppConstant.BASE_PACKAGES, FlowableConstant.FLOWABLE_BASE_PACKAGES}, + excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {DevelopmentConfiguration.class}) +) public class FlowApplication { public static void main(String[] args) { diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java index fa453234..4460a672 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java @@ -20,7 +20,9 @@ import lombok.AllArgsConstructor; import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.boot.EngineConfigurationConfigurer; import org.flowable.spring.boot.FlowableProperties; +import org.flowable.ui.modeler.properties.FlowableModelerAppProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -34,6 +36,11 @@ import org.springframework.context.annotation.Configuration; public class FlowableConfiguration implements EngineConfigurationConfigurer { private FlowableProperties flowableProperties; + @Bean + public FlowableModelerAppProperties flowableModelerAppProperties() { + return new FlowableModelerAppProperties(); + } + @Override public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName(flowableProperties.getActivityFontName()); diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java new file mode 100644 index 00000000..85bd6b93 --- /dev/null +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.flowable.engine.constant; + +/** + * 流程常量. + * + * @author zhuangqian + */ +public interface FlowableConstant { + + String FLOWABLE_BASE_PACKAGES = "org.flowable.ui"; + + String suffix = ".bpmn20.xml"; + + +} diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowModelController.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowModelController.java index 51bc9274..371c37c0 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowModelController.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowModelController.java @@ -74,7 +74,7 @@ public class FlowModelController { */ @PostMapping("/deploy") @ApiOperation(value = "部署", notes = "传入模型id和分类", position = 7) - public R deploy(@ApiParam(value = "模型id") @RequestParam String modelId, @ApiParam(value = "分类") @RequestParam String category) { + public R deploy(@ApiParam(value = "模型id") @RequestParam String modelId, @ApiParam(value = "工作流分类") @RequestParam String category) { boolean temp = flowService.deploy(modelId, category); return R.status(temp); } diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java index aadd168a..3ac1d901 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java @@ -18,18 +18,37 @@ package org.springblade.flowable.engine.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.flowable.engine.RepositoryService; +import org.flowable.engine.repository.Deployment; +import org.flowable.engine.repository.ProcessDefinition; +import org.flowable.ui.modeler.domain.Model; +import org.flowable.ui.modeler.serviceapi.ModelService; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.flowable.engine.constant.FlowableConstant; import org.springblade.flowable.engine.entity.FlowModel; import org.springblade.flowable.engine.mapper.FlowMapper; import org.springblade.flowable.engine.service.FlowService; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** - * FlowServiceImpl + * 工作流服务实现类 * * @author Chill */ +@Slf4j @Service +@AllArgsConstructor public class FlowServiceImpl extends ServiceImpl implements FlowService { + + private RepositoryService repositoryService; + private ModelService modelService; + @Override public IPage selectFlowPage(IPage page, FlowModel flowModel) { return page.setRecords(baseMapper.selectFlowPage(page, flowModel)); @@ -37,6 +56,40 @@ public class FlowServiceImpl extends ServiceImpl implemen @Override public boolean deploy(String modelId, String category) { - return false; + Model model = modelService.getModel(modelId); + byte[] bytes = modelService.getBpmnXML(model); + + String processName = model.getName(); + if (!StringUtil.endsWithIgnoreCase(processName, FlowableConstant.suffix)) { + processName += FlowableConstant.suffix; + } + + Deployment deployment = repositoryService.createDeployment() + .addBytes(processName, bytes) + .name(model.getName()) + .key(model.getKey()) + .deploy(); + + log.debug("流程部署--------deploy:" + deployment + " 分类---------->" + category); + + List list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); + + StringBuilder logBuilder = new StringBuilder(500); + List logArgs = new ArrayList<>(); + // 设置流程分类 + for (ProcessDefinition processDefinition : list) { + if (StringUtil.isNotBlank(category)) { + repositoryService.setProcessDefinitionCategory(processDefinition.getId(), category); + } + logBuilder.append("部署成功,流程ID={} \n"); + logArgs.add(processDefinition.getId()); + } + + if (list.size() == 0) { + throw new ServiceException("部署失败,未找到流程"); + } else { + log.info(logBuilder.toString(), logArgs.toArray()); + return true; + } } } diff --git a/blade-service/blade-flow/src/main/resources/application.yml b/blade-service/blade-flow/src/main/resources/application.yml index 5af24db9..4fb24594 100644 --- a/blade-service/blade-flow/src/main/resources/application.yml +++ b/blade-service/blade-flow/src/main/resources/application.yml @@ -1,6 +1,11 @@ flowable: - async-executor-activate: false activity-font-name: \u5B8B\u4F53 label-font-name: \u5B8B\u4F53 annotation-font-name: \u5B8B\u4F53 check-process-definitions: false + common: + app: + idm-url: http://localhost:9999 + idm-admin: + user: admin + password: test diff --git a/blade-service/blade-flow/src/main/resources/processes/ExpenseProcess.bpmn20.xml b/blade-service/blade-flow/src/main/resources/processes/ExpenseProcess.bpmn20.xml deleted file mode 100644 index a779d37b..00000000 --- a/blade-service/blade-flow/src/main/resources/processes/ExpenseProcess.bpmn20.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - 报销流程 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 500}]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml b/blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml new file mode 100644 index 00000000..f9f2444e --- /dev/null +++ b/blade-service/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml @@ -0,0 +1,101 @@ + + + + 请假流程 + + + + + + + + + + + + + + + + + + + + + + + + + 3}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java index 1f8f42bb..cadfe1b2 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java @@ -50,7 +50,6 @@ import static org.springblade.common.cache.CacheNames.AUTH_ROUTES; @AllArgsConstructor @RequestMapping("/menu") @Api(value = "菜单", tags = "菜单") -@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) public class MenuController extends BladeController { private IMenuService menuService; @@ -61,6 +60,7 @@ public class MenuController extends BladeController { * 详情 */ @GetMapping("/detail") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "详情", notes = "传入menu", position = 1) public R detail(Menu menu) { Menu detail = menuService.getOne(Condition.getQueryWrapper(menu)); @@ -76,6 +76,7 @@ public class MenuController extends BladeController { @ApiImplicitParam(name = "code", value = "菜单编号", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query", dataType = "string") }) + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "列表", notes = "传入menu", position = 2) public R> list(@ApiIgnore @RequestParam Map menu) { @SuppressWarnings("unchecked") @@ -88,6 +89,7 @@ public class MenuController extends BladeController { * 前端菜单数据 */ @GetMapping("/routes") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据", position = 3) public R> routes(BladeUser user) { List list = menuService.routes(user.getRoleId()); @@ -98,6 +100,7 @@ public class MenuController extends BladeController { * 前端按钮数据 */ @GetMapping("/buttons") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "前端按钮数据", notes = "前端按钮数据", position = 4) public R> buttons(BladeUser user) { List list = menuService.buttons(user.getRoleId()); @@ -108,6 +111,7 @@ public class MenuController extends BladeController { * 获取菜单树形结构 */ @GetMapping("/tree") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "树形结构", notes = "树形结构", position = 5) public R> tree() { List tree = menuService.tree(); @@ -118,6 +122,7 @@ public class MenuController extends BladeController { * 获取权限分配树形结构 */ @GetMapping("/grant-tree") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "权限分配树形结构", notes = "权限分配树形结构", position = 6) public R> grantTree(BladeUser user) { return R.data(menuService.grantTree(user)); @@ -127,6 +132,7 @@ public class MenuController extends BladeController { * 获取权限分配树形结构 */ @GetMapping("/role-tree-keys") + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "角色所分配的树", notes = "角色所分配的树", position = 7) public R> roleTreeKeys(String roleIds) { return R.data(menuService.roleTreeKeys(roleIds)); @@ -137,6 +143,7 @@ public class MenuController extends BladeController { */ @PostMapping("/submit") @CacheEvict(cacheNames = {AUTH_ROUTES}) + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "新增或修改", notes = "传入menu", position = 8) public R submit(@Valid @RequestBody Menu menu) { return R.status(menuService.saveOrUpdate(menu)); @@ -148,6 +155,7 @@ public class MenuController extends BladeController { */ @PostMapping("/remove") @CacheEvict(cacheNames = {AUTH_ROUTES}) + @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) @ApiOperation(value = "删除", notes = "传入ids", position = 9) public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { return R.status(menuService.removeByIds(Func.toIntList(ids)));