Java接口说明

package fx.custom.apl.example.event_listener;

import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.FunctionMqMessage;
import com.fxiaoke.functions.template.EventListenerAction;
import com.fxiaoke.functions.utils.Lists;
import com.fxiaoke.functions.utils.Maps;
import fx.custom.apl.utils.QxMsgSend;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 * 借助消息函数,监听函数报错,并且给指定的同学发送企信消息
 */
public class FuncFailedEventExample implements EventListenerAction {

    @Override
    public void execute(FunctionContext context, FunctionMqMessage mq, Map<String, Object> body) {
        String apiName = String.valueOf(body.get("apiName"));
        String resMsg = String.valueOf(body.get("resMsg"));
        String msg = MessageFormat.format("APL函数{0}执行失败,报错信息【{1}】", apiName, resMsg);
        List<String> userIds = Lists.newArrayList("7964","8439");
        boolean sendRes = QxMsgSend.send2User("DSTX", userIds, msg);
        Fx.log.info("send msg " + sendRes + " msg:  " + msg);
        if (!sendRes) {
            Fx.message.throwErrorMessage("发送企信服务消息异常");
        }
    }

    public static void main(String[] args) {
        //调试器
        DebugHelper helper = new DebugHelper();
        helper.init();
        //监听事件不依赖context传递数据,主要通过arg业务参数
        FunctionContext context = FunctionContext.builder().build();
        Map<String, Object> body = Maps.of("apiName", "xxx__c", "resMsg", "nullpoint");
        new FuncFailedEventExample().execute(context, new FunctionMqMessage(), body);
    }
}


2024-10-22
0 0