1.9K Star 8.3K Fork 4.2K

人人开源 / renren-fast

 / 详情

考虑过集成activity工作流吗?

Backlog
Opened this issue  
2021-03-01 16:59

现在工作流也挺常用希望作者集成进去 :laughing:

Comments (2)

Hoenwang created任务
Hoenwang set related repository to 人人开源/renren-fast
Expand operation logs

可以自己集成的,这边是我的例子,仅供参考。
pom.xml中增加:

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.activiti.dependencies</groupId>
        <artifactId>activiti-dependencies</artifactId>
        <version>7.1.113</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
....

    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring-boot-starter</artifactId>
    </dependency>

加一个xml配置activity.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
    <property name="jdbcUrl" value="jdbc:mysql://IP:Port/DbName?allowMultiQueries=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false"></property>
    <property name="jdbcUsername" value="root"></property>
    <property name="jdbcPassword" value="root"></property>
    <property name="databaseSchemaUpdate" value="true"></property>
  </bean>


</beans>

写一个SecurityUtils.java:

package io.renren.common.utils;

import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

/**
 * 这个SecurityUtil 是activiti7官方demo中的,
 * 为了不与本框架的security冲突,所有工作流的security使用这个类进行身份识别
 * @author ishing
 */
@Component
public class SecurityUtil {

    private Logger logger = LoggerFactory.getLogger(SecurityUtil.class);

    @Autowired
    private UserDetailsService userDetailsService;

    public void logInAs(String username) {

        if("admin".equals(username)){
            return;
        }
        UserDetails user = userDetailsService.loadUserByUsername(username);
        if (user == null) {
            throw new IllegalStateException("User " + username + " doesn't exist, please provide a valid user");
        }
        logger.info("> Logged in as: " + username);
        SecurityContextHolder.setContext(new SecurityContextImpl(new Authentication() {
            @Override
            public Collection<? extends GrantedAuthority> getAuthorities() {
                return user.getAuthorities();
            }

            @Override
            public Object getCredentials() {
                return user.getPassword();
            }

            @Override
            public Object getDetails() {
                return user;
            }

            @Override
            public Object getPrincipal() {
                return user;
            }

            @Override
            public boolean isAuthenticated() {
                return true;
            }

            @Override
            public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {

            }

            @Override
            public String getName() {
                return user.getUsername();
            }
        }));
        org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(username);
    }
}

写一个impl类:

package io.renren.modules.apply.service.impl;
import static io.renren.common.utils.ShiroUtils.getUserEntity;
import static io.renren.common.utils.ShiroUtils.getUserId;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.Constant.ApplyStatus;
import io.renren.common.utils.Constant.IsAgreed;
import io.renren.common.utils.FlowGen;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.SecurityUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.api.runtime.shared.query.Page;
import org.activiti.api.runtime.shared.query.Pageable;
import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.builders.TaskPayloadBuilder;
import org.activiti.api.task.model.payloads.ClaimTaskPayload;
import org.activiti.api.task.runtime.TaskRuntime;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

  @Autowired
  private RuntimeService runtimeService;
  @Autowired
  private ProcessRuntime processRuntime;
  @Autowired
  private TaskRuntime taskRuntime;


@Service("applyService")
public class ApplyServiceImpl extends ServiceImpl<CommApplyDao, CommApply> implements
    ApplyService {
  @Override
  public int unhandledTasksNum() {

    try {

      securityUtil.logInAs(getUserEntity().getUsername());

      //判断当前用户有没有任务要做。
      Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10000));

      return tasks.getContent().size();
    } catch (SecurityException e) {
      logger.info("获取待办失败:" + e.getMessage());
      return 0;
    }
  }

}

谢谢!我这边需要一些审批驳回之类的应该业务还挺复杂,有现成稳定版的最好

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
980474 yeel 1586666645
Java
1
https://git.oschina.net/renrenio/renren-fast.git
git@git.oschina.net:renrenio/renren-fast.git
renrenio
renren-fast
renren-fast

Search