How Activiti's process interacts with external business data

How to connect with external forms through process approval

 

In the approval process of the process, we have many businesses that need to be approved for the process, but in fact, most of these businesses are not related to the process. They only have some business data that needs to be involved in the approval action. Such as:

For the sales and purchase contracts, the formulation of the purchase contract needs to go through the approval process. Once the approval is completed, the subsequent execution of the purchase contract is completed by the processing of the purchase contract module itself, and the follow-up has nothing to do with the approval operation. In the system design, we need to develop a separate module to process the purchase contract, but we also hope that some of their information needs to be involved in the approval, and after the approval is completed, the purchase contract can be modified.

In order to illustrate the principle of integrated development more vividly, let's take a simple example: if a supplier is put into storage, we need to approve the supplier's information in the early stage. Once the approval is passed, our subsequent business modules can use the supplier's information. information. For this reason, we have carried out flexible processing based on activiti. This article first introduces one of the convenient and quick methods. The premise of this article is that the supplier management module already exists. We need to add a field act_inst_id_ to the supplier table to store the process instance ID of Activiti for subsequent tracking of the supplier's approval process.

 

step one

Create online forms based on supplier information such as:
1.png

Step 2

Write the supplier's data processing interface

1. Create a supplier by approving the data of the form

When the implementation process is created at startup, the supplier's creation interface is called, and the interface ProcessStartAfterHandler can be implemented.

2. Update supplier data via approval form

Implement the TaskAfterHandler interface

3. Trigger the approval status of supplier data through the approval of the approval form

Just implement ProcessEndHandler.

code description

The following is our implementation of the above three implementations in CrmProviderManager, the code is as follows:

@Service
public class CrmProviderManager extends BaseManager<CrmProvider> implements
ProcessStartAfterHandler,TaskAfterHandler,ProcessEndHandler{


    /**
  * Create supplier from Json data
  * @param json
  * @param bpmInstId
  * @return
  */
public CrmProvider createFromJson(String json,String actInstId){
  CrmProvider crmProvider=JSON.parseObject(json, CrmProvider.class);
 //Associate process instance ID
 crmProvider.setActInstId(actInstId);
  crmProviderDao.create(crmProvider);
 return crmProvider;
}
/**
  * Update the value of the supplier via Json
  * @param json
  * @param busKey
  */
public void updateFromJson(String json,String busKey){
  CrmProvider orgProvider=get(busKey);
 if(orgProvider==null) return;
  CrmProvider newProvider=JSON.parseObject(json,CrmProvider.class);
 try {
   BeanUtil.copyNotNullProperties(orgProvider, newProvider);
 } catch (Exception e) {
   e.printStackTrace ();
 }
  crmProviderDao.update(orgProvider);
}

/**
  * 1. After the process instance is created, the supplier information is created through the data of the form
  */
@Override
public String processStartAfterHandle(String json, String actInstId) {
  CrmProvider crmProvider=createFromJson(json,actInstId);
  crmProvider.setStatus(MStatus.INIT.name());
//Return the business primary key to the process instance
 return crmProvider.getProId();
}


/**
  * 2. Called when the task approval is completed to update the supplier's data
  */
@Override
public void taskAfterHandle(IExecutionCmd cmd, String nodeId, String busKey) {
  updateFromJson(cmd.getJsonData(),busKey);
}
/**
  * 3. When the process is successfully approved, update the supplier's approval status
  */
@Override
public void endHandle(BpmInst bpmInst) {
  String busKey=bpmInst.getBusKey();
  CrmProvider crmProvider=crmProviderDao.get(busKey);
 if(crmProvider!=null){
   crmProvider.setStatus(MStatus.ENABLED.name());
   crmProviderDao.update(crmProvider);
 }
}

}

 

Step 3

Configure process definitions and process solutions to achieve the following points, especially data configuration processing on nodes

Associate Approval Form

Associate approvers

Configure the data processing interface that calls the provider on the node

 

 

 

3-1.png

4.png

After the configuration is complete, the process starts in the approval process, and the corresponding supplier interface will be called to synchronize the data.

Step 4

If we need to click Add in the supplier management module, we can start the supplier approval process. At this time, we need to do a little configuration. In the global module process binding module, configure the process in the supplier module, and at the same time in the supplier add management module, call this configuration process. as follows:

5.png

Add the following calls to the supplier management module to replace the original add processing, and add a call to view the information of the process instance:

 

   //Processing add
       function _add (){
        //Check if there is a process configuration, if not, enable the local default configuration
        _ModuleFlowWin ({
          title : ' Supplier Inventory Application ' ,
          moduleKey : ' CRM_PROVIDER ' ,
         //failCall:add ,
         success : function (){
           grid . load ();
         }
        });
       }
//View process approval instance information
function checkDetail ( actInstId ){
         _OpenWindow ({
          title : 'Approval Details ' ,
          width : 800 ,
          height : 480 ,
          url : __rootPath + ' / bpm / core / bpmInst / get .do ? actInstId = ' + actInstId }) ; }
        
       

 

 

At this time, when we add a supplier in this module, the supplier's filling process application entry can be displayed. As follows:

6.png

At the same time, you can see the relevant information of the process approval in the supplier management.

7.png

The final use effect is as follows:

http://www.redxun.cn:8020/saweb/login.jsp

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326967038&siteId=291194637