banner
biuaxia

biuaxia

"万物皆有裂痕,那是光进来的地方。"
github
bilibili
tg_channel

Blue Ling Global Interception Process Node

title: Landray Global Intercept Flow Nodes
date: 2021-09-06 15:16:00
comment: false
toc: true
category:

  • Landray
    tags:
  • Landray
  • Global
  • Intercept
  • Flow
  • Nodes
  • Listener

spring.xml#

The complete content of spring.xml is as follows:

<?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-2.0.xsd">

    <bean
            id="beanName"
            class="packageName"/>

</beans>

plugin.xml#

The complete content of plugin.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<plugin
	xmlns="http://www.example.org/plugin-config"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.example.org/plugin-config ../../plugin.xsd ">

    <!--SMS approver node event-->
	<extension
			point="com.landray.kmss.lbpm.engine.event">
		<item name="listener">
			<param name="unid" value="kmImissiveSmsMainListener"/>
			<param name="messageKey" value=""/>
			<param name="eventTypes" value="manualNodeHanlderGetterEvent"/>
			<param name="listener" value="kmImissiveSmsMainListener"/>
			<param name="enforce" value="true"/>
		</item>
	</extension>

</plugin>

Reverse create the corresponding Bean.

Listener#

The complete code is as follows:

package com.landray.kmss.jtt.sms.listener;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.landray.kmss.common.model.IBaseModel;
import com.landray.kmss.km.imissive.model.KmImissiveMain;
import com.landray.kmss.sys.lbpm.engine.builder.ManualNodeDefinition;
import com.landray.kmss.sys.lbpm.engine.builder.ProcessDefinition;
import com.landray.kmss.sys.lbpm.engine.manager.event.EventExecutionContext;
import com.landray.kmss.sys.lbpm.engine.manager.event.IEventListener;
import com.landray.kmss.sys.lbpmservice.node.support.ManualNodeHanlderGetterEvent;
import com.landray.kmss.sys.organization.interfaces.ISysOrgCoreService;
import com.landray.kmss.sys.organization.model.SysOrgPerson;
import com.landray.kmss.sys.right.interfaces.ExtendAuthModel;
import com.landray.kmss.util.SpringBeanUtil;
import com.landray.kmss.util.UserUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;

public class GlobalSmsListener implements IEventListener {

    private static final Log log = LogFactory.getLog(GlobalSmsListener.class);

    @Override
    public void handleEvent(EventExecutionContext execution, String s) throws Exception {
        ManualNodeHanlderGetterEvent manualNodeHanlderGetterEvent = (ManualNodeHanlderGetterEvent) execution.getEvent();
        ManualNodeDefinition manualNodeDefinition = manualNodeHanlderGetterEvent.getManualNodeDefinition();

        log.info("HandlerIds type: " + JSONUtil.toJsonStr(manualNodeDefinition.getHandlerSelectType()));

        ProcessDefinition processDefinition = manualNodeDefinition.getProcessDefinition();

        // Model information
        IBaseModel mainModel = execution.getMainModel();
        String notifyType = processDefinition.getNotifyType();

        boolean classResult = mainModel instanceof KmImissiveMain;
        if (!classResult) {
            return;
        }

        ExtendAuthModel kmImissiveMain = Convert.convert(ExtendAuthModel.class, mainModel);

        String docSubject = kmImissiveMain.getDocSubject();
        log.info("Predefined information-docSubject: " + docSubject);

        final String mobileStr = "mobile";
        log.info("SMS matching-notification type: " + notifyType);
        log.info("SMS matching: " + StrUtil.containsAny(notifyType, mobileStr));

        if (StrUtil.containsAny(notifyType, mobileStr)) {
            String handlerIds = manualNodeDefinition.getHandlerIds();
            log.info("HandlerIds matching: " + JSONUtil.toJsonStr(handlerIds));
            List<String> userIdList = StrUtil.splitTrim(handlerIds, ';');

            ISysOrgCoreService sysOrgCoreService =
                    (ISysOrgCoreService) SpringBeanUtil.getBean("sysOrgCoreService");
            String[] userIdArray = ArrayUtil.toArray(userIdList, String.class);
            log.info("userIdArray matching: " + JSONUtil.toJsonStr(userIdArray));
            try {
                List byPrimaryKeys = sysOrgCoreService.findByPrimaryKeys(userIdArray);
                // Try to parse positions into specific personnel
                List expandToPerson = sysOrgCoreService.expandToPerson(byPrimaryKeys);
                // Try to parse common positions
                List parseSysOrgRole = sysOrgCoreService.parseSysOrgRole(byPrimaryKeys,
                        sysOrgCoreService.findByPrimaryKey(
                                UserUtil.getUser().getFdId()));

                // Add to the collection
                List result = new ArrayList(2 * (expandToPerson.size() + parseSysOrgRole.size()));
                result.addAll(expandToPerson);
                result.addAll(parseSysOrgRole);

                if (CollUtil.isNotEmpty(result)) {
                    for (Object itemObj : result) {
                        try {
                            SysOrgPerson user = Convert.convert(SysOrgPerson.class, itemObj);
                            String fdName = user.getFdName();
                            String fdMobileNo = user.getFdMobileNo();
                            if (StrUtil.isBlank(fdMobileNo)) {
                                log.error("Recipient [" + fdName + "] mobile number is empty, will not send!");
                                continue;
                            }
                        } catch (Exception e) {
                            log.error("Failed to send message, possibly due to incorrect recipient. ");
                            log.error(itemObj.toString());
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        } else {
            log.debug("The content of the to-do does not match the SMS, will not send!");
        }
    }

}

Verification#

This code will be triggered for modules related to the process. In the code, only document modules are manually processed, and the process node needs to be configured with SMS notification method to be triggered.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.