package cn.stylefeng.workflow.api.format;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.rule.format.BaseSimpleFieldFormatProcess;
import cn.stylefeng.workflow.api.NodeApi;
import cn.stylefeng.workflow.api.entity.design.Node;

public class NodeFormatProcess extends BaseSimpleFieldFormatProcess {

    @Override
    public Class<?> getItemClass() {
        return Long.class;
    }

    @Override
    public Object simpleItemFormat(Object businessId) {
        if (ObjectUtil.isEmpty(businessId)) {
            return null;
        }

        NodeApi nodeApi = SpringUtil.getBean(NodeApi.class);

        try {
            Node nodeInfo = nodeApi.getNodeInfo(Convert.toLong(businessId));
            return nodeInfo.getNodeName();
        } catch (Exception e) {

            return null;
        }
    }

}
