Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use a custom organizational structure in Activiti

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Overview

We know that activiti is a good process engine, it has its own personnel organization structure, but it is only limited to the management of users and user groups. The task generated by the process (UserTask) involves the Owner of the task, the executor of the task (assignee), as well as the candidates and candidate users of the task. In China's process business needs, only relying on this area of personnel search is not able to meet the current business needs. For an example of the leave process, the process is as follows:

[description]: the superior supervisor and the leader of the department are all related to the organizational structure of the initiator, and this search algorithm can be understood as the search processing of the reporting line. In addition, in the domestic process processing scheme, there are some personnel search algorithms such as other business. Therefore, we generally need to use the organizational structure of our business to implement the process processing.

two。 Let the Activiti engine hook up its own organizational structure

To achieve organizational architecture-related integration in the process, we need to first understand which business requirements are currently using organizational architecture requirements, on the basis of our previous massive implementation of domestic business processes, we summarize the following points:

The assignment of the executive of the task

The agent of the task

Notification of task

Permissions to start the process

In the process of the integration of process engine and organizational architecture, only the first item of Activiti is related to organizational structure, and the other aspects only need to be realized through our own extension table.

2.1 the handler of the task is assigned 2.1.1. Default handling of hooking with people's organizations in activiti

In Activiti, there are only a few tables related to the organization shelf, and we show its table structure as follows:

CREATE TABLE `act_ru_ task` (`ID_ `varchar (64) COLLATE utf8_bin NOT NULL DEFAULT'', `REV_ `int (11) DEFAULT NULL, `EXECUTION_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, `PROC_INST_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, `PROC_DEF_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, `NAME_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `PARENT_TASK_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL `OWNER_ `varchar (4000) COLLATE utf8_bin DEFAULT NULL, `ASSIGNEE_ `varchar (4000) COLLATE utf8_bin DEFAULT NULL, `DELEGATION_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, `PRIORITY_ `int (11) DEFAULT NULL, `CREATE_TIME_ `timestamp (3) NOT NULL DEFAULT CURRENT_TIMESTAMP (3) ON UPDATE CURRENT_TIMESTAMP (3), `DUE_DATE_ `datetime (3) DEFAULT NULL `CATEGORY_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `SUSPENSION_STATE_ `int (11) DEFAULT NULL, `TENANT_ID_ `varchar (255) COLLATE utf8_bin DEFAULT'', `FORM_KEY_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `CREATE_BY_ `varchar (64) COLLATE utf8_bin DEFAULT NULL COMMENT 'creator ID', `UPDATE_BY_ (64) COLLATE utf8_bin DEFAULT NULL COMMENT' Update`UPDATE_TIME_ `datetime DEFAULT NULL COMMENT' `SOL_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL COMMENT 'business solution ID', `AGENT_USER_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL COMMENT' agent ID', PRIMARY KEY (`ID_ `), KEY `ACT_IDX_TASK_ create` (`CREATE_TIME_`), KEY `ACT_FK_TASK_ EXE` (`EXECUTION_ID_ `), KEY `ACT_FK_TASK_ PROCINST` (`PROC_INST_ID_`) KEY `ACT_FK_TASK_ PROCDEF` (`PROC_DEF_ID_ `), CONSTRAINT `ACT_FK_TASK_ EXE` FOREIGN KEY (`ID_`) REFERENCES `act_ru_ execution` (`ID_ `), CONSTRAINT `ACT_FK_TASK_ PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_ procdef` (`ID_ `), CONSTRAINT `ACT_FK_TASK_ PROCINST` FOREIGN KEY (`PROC_INST_ID_`) REFERENCES `act_ru_ execution` (`ID_ `) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin) CREATE TABLE `act_ru_ identitylink` (`ID_ `varchar (64) COLLATE utf8_bin NOT NULL DEFAULT'', `REV_ `int (11) DEFAULT NULL, `GROUP_ID_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `TYPE_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `USER_ID_ `varchar (255) COLLATE utf8_bin DEFAULT NULL, `TASK_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, `PROC_INST_ID_ (64) COLLATE utf8_bin DEFAULT NULL `PROC_DEF_ID_ `varchar (64) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`ID_ `), KEY `ACT_IDX_IDENT_LNK_ USER` (`USER_ID_`), KEY `ACT_IDX_IDENT_LNK_ GROUP` (`GROUP_ID_ `), KEY `ACT_IDX_ATHRZ_ PROCEDEF` (`PROC_DEF_ID_`), KEY `ACT_FK_TSKASS_ TASK` (`TASK_ID_ `), KEY `ACT_FK_IDL_ PROCINST` (`PROC_INST_ID_`) CONSTRAINT `ACT_FK_ATHRZ_ ProceF` FOREIGN KEY (`PROC_DEF_ID_ `) REFERENCES `act_re_ procdef` (`ID_`), CONSTRAINT `ACT_FK_IDL_ PROCINST` FOREIGN KEY (`ACT_FK_TSKASS_ `) REFERENCES `act_ru_ execution` (`ID_`), CONSTRAINT `ACT_FK_TSKASS_ TASK` FOREIGN KEY (`TASK_ID_ `) REFERENCES `act_ru_ task` (`ID_`) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

[description] owner,assignee in act_ru_task is the owner and executor of the task, while act_ru_identitylink is the personnel association table of the task. In the field, groupId is the user group Id,userId, the task Id,type associated with the user Id,taskId, and the type of task that the user participates in.

In order to simplify the algorithm for people to participate in tasks, we can expand our participation table without the act_ru_ identifier table, but this table can meet our calculation needs for task personnel at present.

2.1.2. Granted by the personnel of the task

How can people be granted through activiti's native api? First of all, let's talk about the timing of the grant. When the status of the activiti task jumps to a task node, it will generate a record in the act_ru_ task table. When it is generated, we need to calculate the people and groups participating in the task through the personnel configuration attributes defined by the process, combined with our own organizational structure and business search (such as report lines), so as to assign the task to these users. In addition, the task is assigned by hand.

Let's talk about the first one, personnel authorization when the task is created.

Activiti provides the task creation event, so we can define a listener on its event. How to configure this listener, please refer to our other article.

Event Mechanism and listening processing of Activiti

With regard to the global event definition of activiti, we only need to define the following task to create a listener (TaskCreateListener), and get the entity object TaskEntity of the task, and change the executor and owner of the task through setAssignee and setOwner.

TaskEntity.setAssignee (nodePath.getAssignee ()); taskEntity.setOwner (userId); taskEntity.addCandidateUsers (Arrays.asList (uIds)); taskEntity.addCandidateGroup (identityInfo.getIdentityInfoId ())

Now let's talk about another one: manually assign tasks when they are generated.

This method needs to be implemented through the following api of taskService

2.2. Expand your own personnel lookup architecture

The personnel configuration of the node of the process is very difficult to provide a set of general configuration rules to realize the user lookup, because we only set the attribute configuration of config for the personnel lookup of the node, and the developer user implements the corresponding definition classification according to these configurations, and implements his own process lookup method.

The process is configured as follows:

We provide a total staffing classification so that we can display the following list of staffing categories in the staffing of the process node:

Package com.redxun.bpm.core.identity.service;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import org.springframework.beans.factory.InitializingBean;/** * entity type classification service class * @ author csx * * / public class IdentityTypeService implements InitializingBean {/ / process task personnel computing service class mapping private Map identityCalServicesMap=new LinkedHashMap (); / process task personnel computing service class private List identityCalServices=new ArrayList () @ Override public void afterPropertiesSet () throws Exception {for (IdentityCalService service:identityCalServices) {identityCalServicesMap.put (service.getTypeKey (), service);}} public List getIdentityCalServices () {return identityCalServices;} public void setIdentityCalServices (List identityCalServices) {this.identityCalServices = identityCalServices;} public Map getIdentityCalServicesMap () {return identityCalServicesMap }} at the same time, the user's information is calculated according to the node configuration of the process, in order to obtain the personnel configuration information, and the user realizes the personnel search according to the personnel configuration. The definition of the interface is as follows: import java.util.Collection;import com.redxun.org.api.model.IdentityInfo / * * Task personnel computing service interface class * @ author mansan * * / public interface IdentityCalService {/ / personnel computing type public String getTypeKey (); / / personnel computing name public String getTypeName (); / / personnel computing description public String getDescp () / * the human entity returned by the computing node * @ param idCalConfig * @ return * / public Collection calIdentities (IdentityCalConfig idCalConfig);} the configuration and personnel search of the user group are as follows: package com.redxun.bpm.core.identity.service;/** * Abstract entity Computing Service Class * @ author csx * / public abstract class AbstractIdentityCalService implements IdentityCalService {/ / classified Key protected String typeKey / / Classification name protected String typeName; / / Classification description protected String description; / / Class name processed by protected String handlerClass; public String getTypeKey () {return typeKey;} public void setTypeKey (String typeKey) {this.typeKey = typeKey;} public String getTypeName () {return typeName;} public void setTypeName (String typeName) {this.typeName = typeName } public String getDescription () {return description;} public void setDescription (String description) {this.description = description;} @ Override public String getDescp () {return this.description;}} package com.redxun.bpm.core.identity.service.impl;import java.util.ArrayList;import java.util.Collection;import java.util.List;import javax.annotation.Resource;import org.apache.commons.lang3.StringUtils Import com.redxun.bpm.core.identity.service.AbstractIdentityCalService;import com.redxun.bpm.core.identity.service.IdentityCalConfig;import com.redxun.core.constants.MBoolean;import com.redxun.org.api.model.IdentityInfo;import com.redxun.saweb.context.ContextUtil;import com.redxun.sys.org.entity.OsGroup;import com.redxun.sys.org.entity.OsRelType;import com.redxun.sys.org.entity.OsUser;import com.redxun.sys.org.manager.OsGroupManager;import com.redxun.sys.org.manager.OsRelTypeManager Import com.redxun.sys.org.manager.OsUserManager;/** * user group calculation * @ author mansan * * / public class GroupCalServiceImpl extends AbstractIdentityCalService {@ Resource private OsGroupManager osGroupManager; @ Resource private OsRelTypeManager osRelTypeManager; @ Resource private OsUserManager osUserManager; @ Override public Collection calIdentities (IdentityCalConfig idCalConfig) {OsRelType osRelType=osRelTypeManager.getBelongRelType (); / / whether user boolean isCalUsers=MBoolean.YES.name () .equals (idCalConfig.getIsCalUser ()) needs to be calculated. List identityList=new ArrayList (); / / get the node configuration information of the process, and get the user or group String jsonConfig=idCalConfig.getJsonConfig () based on the node; if (StringUtils.isNotEmpty (jsonConfig)) {String [] groupIds=jsonConfig.split ("[,]") For (String gId:groupIds) {if (isCalUsers) {/ / calculate user List users=osUserManager.getByGroupIdRelTypeId (gId, osRelType.getId ()); identityList.addAll (users);} else {/ / only calculate its user group OsGroup osGroup=osGroupManager.get (gId) If {identityList.add (osGroup);} return identityList;}} 2.3. Customize to find my to-do list

Although TaskService provides search tasks by person API, but from my personal point of view, those do not meet our search algorithm, so it is necessary to customize my task list. The search is nothing more than looking up according to the act_ru_ task table of Activiti. If it is combined with the corresponding user group of the user, it also needs to be looked up with act_ru_identitylink. This depends on what ORM framework is used for your underlying database access. In JSAAS, our interface is as follows. We provide the following interface to find my to-do list by time, item name, status, etc., and return it by page. The interface is as follows:

The custom Sql it looks for is as follows:

SELECT V.* FROM (SELECT T.* FROM ACT_RU_TASK T WHERE T.ASSIGNEE_=# {userId} UNION SELECT T.* FROM ACT_RU_TASK T LEFT JOIN ACT_RU_IDENTITYLINK ION T.IDC) I.taskmate ID_ WHERE I.USER_ID_=# {userId} AND I.TYPERPERATE candidate 'AND T.ASSIGNEE _ IS NULL UNION SELECT T.* FROM ACT_RU_TASK T ACT_RU_IDENTITYLINK I OS_REL_INST R WHERE T.ASSIGNEE _ IS NULL AND T.IDPs I.TASUPPRONEEID.PARTY1and R.PARTY2_=# {userId} and I.TYPENEEITY candidate 'AND R.REL_TYPE_ID_=# {relTypeId}) V WHERE 1 and NAME_ like # {name} and DESCRIPTION_ like # {description} And CREATE_TIME_ > = # {createtime1} and CREATE_TIME_

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report