工具类输出当前ApplicationContext所有被装配的类

package org.springblade.desk.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringUtil implements ApplicationContextAware {

    /**
     * 当前IOC
     *
     */
    private static ApplicationContext applicationContext;
    /**
     * 设置applicationContext
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    /**
     * 从当前IOC获取bean
     */
    public static <T> T getObject(Class<T> clazz){
        return applicationContext.getBean(clazz);
    }

    public static void showClass(){
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for(String beanDefinitionName : beanDefinitionNames){
            System.out.println(beanDefinitionName);
        }
    }
}

//业务类
package org.springblade.desk.listener.task;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springblade.core.mp.support.Condition;
import org.springblade.desk.entity.ProcessPurchaseOrder;
import org.springblade.desk.entity.ProcessPurchaseOrderDetail;
import org.springblade.desk.service.impl.PurchaseOrderDetailServiceImpl;
import org.springblade.desk.service.impl.PurchaseOrderServiceImpl;
import org.springblade.desk.utils.SpringUtil;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * create by Dell on 2020/6/23
 */
@Component
public class PurchaseOrderTaskListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        PurchaseOrderServiceImpl purchaseOrderServiceImpl= SpringUtil.getObject(PurchaseOrderServiceImpl.class);
        PurchaseOrderDetailServiceImpl purchaseOrderDetailServiceImpl= SpringUtil.getObject(PurchaseOrderDetailServiceImpl.class);
        System.out.println("采购订单进入监听事件delegateTask=========================="+delegateTask);
        String processInstanceId = delegateTask.getProcessInstanceId() ;
        ProcessPurchaseOrder entity = new ProcessPurchaseOrder();
        entity.setProcessInstanceId(processInstanceId);
        List<ProcessPurchaseOrder> list = purchaseOrderServiceImpl.list(Condition.getQueryWrapper(entity));
        if(list!=null&&!list.isEmpty()){
            for(ProcessPurchaseOrder bean : list){
                ProcessPurchaseOrderDetail line = new ProcessPurchaseOrderDetail();
                line.setOrderNumber(bean.getOrderNumber());
                List<ProcessPurchaseOrderDetail> lineList = purchaseOrderDetailServiceImpl.list(Condition.getQueryWrapper(line));
            }
        }
        System.out.println("taskListener"+ list.size()+"--------");
    }
}

//借鉴=============== https://www.jianshu.com/p/56d5be0dab91

 

posted @ 2020-07-09 17:15  红尘沙漏  阅读(235)  评论(0编辑  收藏  举报