package com.huigou.topsun.base;

import com.huigou.topsun.base.bsnMessage.appliction.BsnMessageApplication;
import com.huigou.topsun.base.bsnMessage.domain.ActiveStatus;
import com.huigou.topsun.base.bsnMessage.domain.BsnMessageExecute;
import com.huigou.topsun.base.bsnMessage.domain.BsnMessageSponsor;
import com.huigou.uasp.bmp.common.application.BaseApplication;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 自定义主页"专项任务"板块展示数据
 */
@Aspect
@Component
public class DefinitionHomepageTaskData extends BaseApplication {
    @Autowired
    BsnMessageApplication bsnMessageApplication;

    /**
     * 替换原方法方法体
     * 主页专项任务数据替换为自定义数据
     * @return 当前用户的”专项任务“数据
     */
    @Around("execution(public java.util.Map<String, Object> com.huigou.uasp.bpm.engine.application.impl.WorkflowApplicationImpl.queryTrackingTasks())")
    public  Map<String, Object>  replaceQueryTrackingTasks(){
        // 当前登录用户是否以任务发起人的身份发起过任务流程
//        List<BsnMessageSponsor> messageSponsors = bsnMessageApplication.queryFinishBsnMessageSponsor();
//            for (BsnMessageSponsor sponsor : messageSponsors) {
//                //该流程下是否所有单位已就绪
//                BsnMessageExecute systemExecute = bsnMessageApplication.isExecutesReady(sponsor.getId());
//                //若就绪更新其中流程、流程下审批任务的状态
//                if(systemExecute!=null){
//                    systemExecute.setActive(ActiveStatus.UNFINISHED.getValue());
//                    sponsor.setStatus(1);
//                    sponsor.addExecute(systemExecute);
//                    bsnMessageApplication.saveBsnMessageSponsor(sponsor);
//                }
//        }
        //获取任务执行人为当前用户的任务
        return this.bsnMessageApplication.queryExecuteBsnMessage();
    }
}
