springboot+flowable-ui 步骤

参考文章

黑月ゞ / springboot-flowable-modeler

1,引用jar


<dependency>
    <groupId>mysqlgroupId>
    <artifactId>mysql-connector-javaartifactId>
dependency>
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-jdbcartifactId>
dependency>
<dependency>
    <groupId>org.mybatis.spring.bootgroupId>
    <artifactId>mybatis-spring-boot-starterartifactId>
    <version>${mybatis-spring-boot}version>
dependency>

<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-spring-boot-starter-basicartifactId>
    <version>${flowable.version}version>
dependency>

<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-ui-commonartifactId>
    <version>${flowable.version}version>
dependency>
<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-ui-modeler-restartifactId>
    <version>${flowable.version}version>
dependency>
<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-idm-spring-configuratorartifactId>
    <version>${flowable.version}version>
dependency>
<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-ui-idm-restartifactId>
    <version>${flowable.version}version>
dependency>
<dependency>
    <groupId>org.flowablegroupId>
    <artifactId>flowable-ui-idm-confartifactId>
    <version>${flowable.version}version>
dependency>
<dependency>
    <groupId>org.liquibasegroupId>
    <artifactId>liquibase-coreartifactId>
    <version>3.6.2version>
dependency>

2,添加UI静态文件

从flowable官网中下载ui的war包,解压里面的 idm, modeler war包,导入两个war中的 static 包下的文件。或者直接从 黑月ゞ / springboot-flowable-modeler 获取

3,文件配置

3.1 application.yml

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/flowable?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=CTT
    username: root
    password: 111111
flowable:
  #关闭定时任务JOB
  async-executor-activate: false
  common:
    app:
      idm-url: http://localhost:9091/demo-flowable/idm/index.html
  idm:
    app:
      admin:
        user-id: admin
        password: test
        first-name: admin
        last-name: admin
  rest:
    app:
      authentication-mode: verify-privilege
  modeler:
    app:
      rest-enabled: true
  database-schema-update: true
mybatis:
  mapper-locations: classpath:/META-INF/modeler-mybatis-mappings/*.xml
  config-location: classpath:/META-INF/mybatis-config.xml
  configuration-properties:
    prefix:
    blobType: BLOB
    boolValue: TRUE

3.2 mybatis-config.xml



<configuration>
	
	<settings>
		
		<setting name="cacheEnabled" value="false" />
		
		<setting name="lazyLoadingEnabled" value="false" />
		<setting name="multipleResultSetsEnabled" value="true" />
		<setting name="useColumnLabel" value="true" />
		<setting name="defaultStatementTimeout" value="25000" />
		<setting name="useGeneratedKeys" value="true" />
		<setting name="defaultExecutorType" value="REUSE" />
		<setting name="callSettersOnNulls" value="true" />
	settings>
configuration>

3.3 stencilset 国际化文件

stencilset_bpmn.json 汉化,内容太多,请看源码
springboot+flowable-ui 步骤_第1张图片

4,Java配置


import org.flowable.ui.common.rest.idm.remote.RemoteAccountResource;
import org.flowable.ui.modeler.rest.app.EditorGroupsResource;
import org.flowable.ui.modeler.rest.app.EditorUsersResource;
import org.flowable.ui.modeler.rest.app.StencilSetResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@ComponentScan(value = {
        "org.flowable.ui.idm.rest.app",
        "org.flowable.ui.common.rest.exception",
        "org.flowable.ui.modeler.rest.app",
        "org.flowable.ui.common.rest"},
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = RemoteAccountResource.class),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = StencilSetResource.class),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorUsersResource.class),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = EditorGroupsResource.class)
        })
@EnableAsync
public class AppDispatcherServletConfiguration implements WebMvcRegistrations {

    private static final Logger LOGGER = LoggerFactory.getLogger(AppDispatcherServletConfiguration.class);

    @Bean
    public SessionLocaleResolver localeResolver() {
        return new SessionLocaleResolver();
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LOGGER.debug("Configuring localeChangeInterceptor");
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("language");
        return localeChangeInterceptor;
    }

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        LOGGER.debug("Creating requestMappingHandlerMapping");
        RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
        requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
        requestMappingHandlerMapping.setRemoveSemicolonContent(false);
        Object[] interceptors = {localeChangeInterceptor()};
        requestMappingHandlerMapping.setInterceptors(interceptors);
        return requestMappingHandlerMapping;
    }

}

import org.flowable.ui.idm.properties.FlowableIdmAppProperties;
import org.flowable.ui.idm.servlet.ApiDispatcherServletConfiguration;
import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;


@Configuration
@EnableConfigurationProperties({FlowableIdmAppProperties.class, FlowableModelerAppProperties.class})
@ComponentScan(basePackages = {
        "org.flowable.ui.idm.conf",
        "org.flowable.ui.idm.security",
        "org.flowable.ui.idm.service",
        "org.flowable.ui.modeler.repository",
        "org.flowable.ui.modeler.service",
        "org.flowable.ui.common.filter",
        "org.flowable.ui.common.service",
        "org.flowable.ui.common.repository",
        "org.flowable.ui.common.security",
        "org.flowable.ui.common.tenant"}, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = org.flowable.ui.idm.conf.ApplicationConfiguration.class)})
public class ApplicationConfiguration {


    @Bean
    public ServletRegistrationBean apiServlet(ApplicationContext applicationContext) {
        AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
        dispatcherServletConfiguration.setParent(applicationContext);
        dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
        DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");
        registrationBean.setName("Flowable IDM App API Servlet");
        registrationBean.setLoadOnStartup(1);
        registrationBean.setAsyncSupported(true);
        return registrationBean;
    }
}

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: fumin
 * @Description:
 * @Date: Create in 2019/5/20 10:26
 */
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        springProcessEngineConfiguration.setActivityFontName("宋体");
        springProcessEngineConfiguration.setLabelFontName("宋体");
        springProcessEngineConfiguration.setAnnotationFontName("宋体");
    }
}

解决中文乱码


import org.flowable.idm.engine.IdmEngineConfiguration;
import org.flowable.idm.spring.SpringIdmEngineConfiguration;
import org.flowable.idm.spring.authentication.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;


/**
 * flowable-ui-idm 密码登录配置
 *
 * @author zenan.qi
 * @date 2021/06/30
 */
@Configuration
public class IdmProcessEngineConfiguration extends SpringIdmEngineConfiguration {

    @Bean
    public PasswordEncoder bCryptEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public SpringEncoder passwordEncoder() {
        return new SpringEncoder(bCryptEncoder());
    }

    @Override
    public IdmEngineConfiguration setPasswordEncoder(org.flowable.idm.api.PasswordEncoder passwordEncoder) {
        return super.setPasswordEncoder(passwordEncoder());
    }
}

配置静态文件,跨域


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfigurerAdapter implements WebMvcConfigurer {

    //静态资源配置
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/p/**")
                .addResourceLocations("classpath:/templates/page/");
        registry.addResourceHandler("/a/**")
                .addResourceLocations("classpath:/templates/assets/");
        registry.addResourceHandler("/module/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/idm/**")
                .addResourceLocations("classpath:/idm/");
    }

    //跨域配置
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("*")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowCredentials(true);
    }

    private CorsConfiguration buildConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");

        return corsConfiguration;
    }


    /**
     * 跨域过滤器
     *
     * @return
     */
    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", buildConfig()); // 4
        return new CorsFilter(source);
    }
}

5,启动

访问登录界面: http://127.0.0.1:8080/idm/index.html
登录账号和密码是 admin / test
springboot+flowable-ui 步骤_第2张图片
springboot+flowable-ui 步骤_第3张图片

访问流程设计器: http://127.0.0.1:8080

springboot+flowable-ui 步骤_第4张图片

6,修改流程设计中的 候选组,候选人的查询接口

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.ManagementService;
import org.flowable.idm.api.IdmIdentityService;
import org.flowable.idm.api.User;
import org.flowable.ui.common.model.ResultListDataRepresentation;
import org.flowable.ui.common.model.UserRepresentation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/app")
public class EditorUsersResource {
    /**
     * 获得用户-自定义
     *
     * @param filter 过滤器
     * @return {@link ResultListDataRepresentation}
     */
    @RequestMapping(value = "/rest/editor-users", method = RequestMethod.GET)
    public ResultListDataRepresentation getUsers(@RequestParam(value = "filter", required = false) String filter) {
        List<UserRepresentation> userRepresentations = new ArrayList<>();
        UserRepresentation representation1 = new UserRepresentation();
        representation1.setId("001");
        representation1.setFirstName("王");
        representation1.setLastName("明");
        representation1.setEmail("[email protected]");
        representation1.setFullName("王明");
        representation1.setGroups(Lists.newArrayList());
        representation1.setPrivileges(Lists.newArrayList());
        userRepresentations.add(representation1);
        UserRepresentation representation2 = new UserRepresentation();
        representation2.setId("002");
        representation2.setFirstName("张");
        representation2.setLastName("大伟");
        representation2.setEmail("[email protected]");
        representation2.setFullName("张大伟");
        representation2.setGroups(Lists.newArrayList());
        representation2.setPrivileges(Lists.newArrayList());
        userRepresentations.add(representation2);
        if (StringUtils.isNotBlank(filter)) {
            userRepresentations = userRepresentations.stream().filter(item -> item.getFullName().contains(filter)).collect(Collectors.toList());
        }
        return new ResultListDataRepresentation(userRepresentations);
    }

}

import org.apache.commons.lang3.StringUtils;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.IdmIdentityService;
import org.flowable.ui.common.model.GroupRepresentation;
import org.flowable.ui.common.model.ResultListDataRepresentation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Rest resource for managing groups, used in the editor app.
 */
@RestController
@RequestMapping("/app")
public class EditorGroupsResource {
    /**
     * 获得团体-自定义
     *
     * @param filter 过滤器
     * @return {@link ResultListDataRepresentation}
     */
    @RequestMapping(value = "/rest/editor-groups", method = RequestMethod.GET)
    public ResultListDataRepresentation getGroups(@RequestParam(required = false, value = "filter") String filter) {
        List<GroupRepresentation> result = new ArrayList<>();
        GroupRepresentation presentation1 = new GroupRepresentation();
        presentation1.setId("001");
        presentation1.setName("经理");
        presentation1.setType("1");
        result.add(presentation1);
        GroupRepresentation presentation2 = new GroupRepresentation();
        presentation2.setId("002");
        presentation2.setName("销售");
        presentation2.setType("1");
        result.add(presentation2);
        if (StringUtils.isNotBlank(filter)) {
            result = result.stream().filter(item -> item.getName().contains(filter)).collect(Collectors.toList());
        }
        return new ResultListDataRepresentation(result);
    }
}

效果:
springboot+flowable-ui 步骤_第5张图片

你可能感兴趣的:(java,spring,boot)