package com.ruoyi.flowable.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.FileType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sms.SmsSenderUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.flowable.common.constant.ProcessConstants;
import com.ruoyi.flowable.common.constant.UUIDGenerator;
import com.ruoyi.flowable.common.enums.FlowStatusEnum;
import com.ruoyi.flowable.factory.FlowServiceFactory;
import com.ruoyi.flowable.service.*;
import com.ruoyi.invest.domain.*;
import com.ruoyi.invest.mapper.InvestmentOpportunityMapper;
import com.ruoyi.invest.service.*;
import com.ruoyi.invest.domain.vo.TProjectPoolVo;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.tool.service.ITUnifyFileService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;

/**
 * 项目池Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-21
 */
@Service
public class InvestmentOpportunityServiceImpl extends FlowServiceFactory implements IInvestmentOpportunityService
{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Value("${spring.profiles.active}")
    private String active;
    @Autowired
    private InvestmentOpportunityMapper investmentOpportunityMapper;

    @Autowired
    private ITProjectPoolService tProjectPoolService;

    @Autowired
    private ITProjectCompanyService tProjectCompanyService;

    @Autowired
    private ITProjectContactsService tProjectContactsService;

    @Autowired
    private ITProjectCirculationService tProjectCirculationService;

    @Autowired
    private ITUnifyFileService tUnifyFileService;

    @Autowired
    private IFlowBaseInfoService activitiBaseInfoService;
    @Autowired
    private IFlowInstanceService flowInstanceService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private SysDeptMapper sysDeptMapper;
    @Autowired
    private ITProjectReviewService tProjectReviewService;
    @Autowired
    private ISysFormService sysFormService;

    @Autowired
    private IFlowService flowService;

    /**
     * 查询项目阶段为投资机会、项目立项、尽职背调、项目投决、并不是关闭的流程、并没有终止的项目列表（总）
     *
     * @param tProjectPool 项目池
     * @return 项目池
     */
    @Override
    public List<TProjectPool> selectProjectList(TProjectPool tProjectPool)
    {
        return investmentOpportunityMapper.selectProjectList(tProjectPool);
    }
    /**
     * 查询可申请项目列表（总）
     *
     * @param tProjectPool 项目池
     * @return 项目池集合
     */
    public List<TProjectPool> selectApplicableProjectList(TProjectPool tProjectPool){
        return investmentOpportunityMapper.selectApplicableProjectList(tProjectPool);
    }
    @Override
    public List<TProjectPoolVo> selectAllInvestmentOpportunityList(TProjectPool tProjectPool){
        return investmentOpportunityMapper.selectAllInvestmentOpportunityList(tProjectPool);
    }
    @Override
    public List<TProjectPoolVo> getMyTaskList(String userId, TProjectPool tProjectPool){
        return investmentOpportunityMapper.getMyTaskList(userId, tProjectPool);
    }
    @Override
    public List<TProjectPoolVo> getMyDoneTaskList(String userId, TProjectPool tProjectPool){
        return investmentOpportunityMapper.getMyDoneTaskList(userId, tProjectPool);
    }
    @Override
    public List<TProjectPoolVo> getMyList(String userId, TProjectPool tProjectPool){
        return investmentOpportunityMapper.getMyList(userId, tProjectPool);
    }
    /**
     * 查询项目池
     * 
     * @param pInstId 流程实例Id
     * @return 项目池
     */
    @Override
    public TProjectPool selectTProjectPoolByProcInstId(String pInstId)
    {
        return investmentOpportunityMapper.selectTProjectPoolByProcInstId(pInstId);
    }

    @Override
    public AjaxResult start(TProjectPool tProjectPool) {

        // 根据key值获取最新的流程部署id
        String pDefId = null;
        ProcessInstance pInst = null;
        try {
            List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
                    .processDefinitionKey("dgt-invest-workflow")
                    .orderByProcessDefinitionVersion().desc().list();
            if(list.size()==0){
                return AjaxResult.error("未找到该流程，无法开启流程！");
            }
            pDefId = list.get(0).getId();
            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(pDefId)
                    .latestVersion().singleResult();
            if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) {
                return AjaxResult.error("流程已被挂起,请先激活流程");
            }
            if(StringUtils.isNotBlank(pDefId)){

                //设置参数
                Map<String, Object> formProperties = new HashMap<String, Object>();
                // 设置流程发起人Id到流程中
                SysUser sysUser = SecurityUtils.getLoginUser().getUser();
                identityService.setAuthenticatedUserId(sysUser.getUserId().toString());
                formProperties.put("auditPass",tProjectPool.isFlag()?true:false);
                formProperties.put(ProcessConstants.PROCESS_INITIATOR, sysUser.getUserId());
                String leader=sysDeptMapper.selectDeptLeader("投资部");
                formProperties.put("MANAGER",sysUserService.selectUserByUserName(leader).getUserId());
                pInst = runtimeService.startProcessInstanceById(pDefId, formProperties);
               // ProcessInstance p = runtimeService.startProcessInstanceById(procDefId, variables);
                if(pInst!=null){
                    String nickName= SecurityUtils.getLoginUser().getUser().getNickName();
                    String userId=SecurityUtils.getLoginUser().getUserId().toString();
                    //保存信息
                    // todo 设置主键及创建人
                    tProjectPool.setCreateBy(userId);
                    tProjectPool.setId(IdUtils.fastSimpleUUID());
                    tProjectPool.setProcInstId(pInst.getProcessInstanceId());
                    if(tProjectPool.isFlag()){
                        tProjectPool.setStatus(1);//提交
                    }else{
                        tProjectPool.setStatus(0);//暂存
                    }
                    int number = tProjectPoolService.selectTProjectPoolCode(DateUtils.lastTwoDigits()+"-");
                    tProjectPool.setProjectCode(tProjectPool.getProjectGroup() + "-" + DateUtils.lastTwoDigits() + "-" + String.format("%03d",number+1));
                    TProjectCompany tProjectCompany = tProjectPool.gettProjectCompany();
                    tProjectCompany.setCreateBy(userId);
                    tProjectCompany.setId(IdUtils.fastSimpleUUID());
                    TProjectContacts tProjectContacts = tProjectPool.gettProjectContacts();
                    tProjectContacts.setCreateBy(userId);
                    tProjectContacts.setId(IdUtils.fastSimpleUUID());
                    // todo 设置项目联系人
                    tProjectPool.setProjectContacts(tProjectContacts.getId());
                    // todo 设置公司信息关联关系
                    tProjectCompany.setProjectPoolId(tProjectPool.getId());
                    // todo 保存公司附件信息
                    tUnifyFileService.insertTUnifyFileList(tProjectPool.getListFile(),
                            tProjectPool.getId(),
                            tProjectCompany.getId(),
                            String.valueOf(FileType.COMPANY.ordinal()),
                            nickName);

                    // todo 保存BP附件信息
                    tUnifyFileService.insertTUnifyFileLists(tProjectPool.getBpFile(),
                            tProjectPool.getId(),
                            tProjectPool.getId(),
                            String.valueOf(FileType.BP.ordinal()),
                            nickName,"a","1");

                    // todo 保存其他附件信息
                    tUnifyFileService.insertTUnifyFileLists(tProjectPool.getOtherFile(),
                            tProjectPool.getId(),
                            tProjectPool.getId(),
                            String.valueOf(FileType.OTHER.ordinal()),
                            nickName,"k","1");

                    tProjectCompanyService.insertTProjectCompany(tProjectCompany);
                    tProjectContactsService.insertTProjectContacts(tProjectContacts);
                    // todo 增加项目创建记录
                    tProjectCirculationService.insertTProjectCirculation(tProjectPool.getId(),"项目报备",nickName);
                    tProjectPoolService.insertTProjectPool(tProjectPool);
                    FlowBaseInfo flowBaseInfo = new FlowBaseInfo();
                    flowBaseInfo.setCreateBy(userId);
                    flowBaseInfo.setId(UUIDGenerator.uuid());
                    flowBaseInfo.setFormProperties(flowInstanceService.getFormProperties(pInst));
                    flowBaseInfo.setProcDefId(pDefId);
                    flowBaseInfo.setProcInsId(pInst.getId());
                    flowBaseInfo.setTaskName("申请人");
                    flowBaseInfo.setFlag(true);
                    flowBaseInfo.setComment(tProjectPool.isFlag() ? "[提交]" : "[暂存]");
                    flowBaseInfo.setStatus(FlowStatusEnum.STARTED.getName());
                    flowBaseInfo.setFlag(tProjectPool.isFlag());
                    activitiBaseInfoService.addActivitiBaseInfo(flowBaseInfo);
                    if (flowBaseInfo.isFlag()) {
                        getAssignee(tProjectPool, flowBaseInfo);
                    }
                    if (Objects.equals(active, "druid")) {
                        //todo 短信
                        sendMessage(flowBaseInfo,"");
                    }
                    //更新代办任务数量
                    sysFormService.updateToDoNumber();
                    return AjaxResult.success();
                }
                return AjaxResult.error();
            }
            return AjaxResult.error();
        } catch (Exception e) {
            /*res.put("status",false);
            res.put("msg", "流程定义id为空, 无法开启流程！");*/
            e.printStackTrace();
            return AjaxResult.error("msg", "流程定义id为空, 无法开启流程！");

        }


    }
    @Override
    public AjaxResult complete(TProjectPool tProjectPool, TProjectReview tProjectReview, FlowBaseInfo flow,HttpServletRequest request) throws Exception {
        Task task=taskService.createTaskQuery().processInstanceId(tProjectPool.getProcInstId()).singleResult();
        //Task task = taskService.createTaskQuery().taskId(taskVo.getId()).singleResult();
        if (Objects.isNull(task)) {
            return AjaxResult.error("任务不存在");
        }
        //当前你登录人
        SysUser userInfo=SecurityUtils.getLoginUser().getUser();
        Map<String, Object> rs = new HashMap<String, Object>();
        rs.put("status",true);
        Map<String, Object> formProperties = new HashMap<>();
        formProperties.put("auditPass", tProjectPool.isFlag());
        //部门负责人
        String leader=sysDeptMapper.selectDeptLeader("投资部");
        SysUser sysUser=sysUserService.selectUserByUserName(leader);
        formProperties.put("MANAGER",sysUser.getUserId());
        if(StringUtils.isNotBlank(tProjectPool.getIsTerminate())) {//不为空代表结束流程
            formProperties.put("whetherToEnd", true);
        }else{
            formProperties.put("whetherToEnd", false);
        }
        Map<String, Object> fpMap = flowService.getFormProperties(task.getProcessDefinitionId(), task.getId());
        try {
            rs = flowService.taskComplete( task.getId(), tProjectPool.isFlag(), formProperties, userInfo.getUserId().toString());
        } catch (Exception e) {
            e.printStackTrace();
            rs.put("status", false);
            rs.put("msg", "流程审批失败");
        }
        boolean status = (boolean) rs.get("status");
        // 审核成功, 则记录审核信息
        if (status) {
            //软件工程院审批
            if ("softwareDept".equals(task.getTaskDefinitionKey())) {
                tProjectReview.setProjectPoolId(tProjectPool.getId());
                tProjectReview.setCreateBy(userInfo.getNickName());
                tProjectReview.setReviewPerson(userInfo.getNickName());
                tProjectReview.setReviewPersonId(userInfo.getUserId().toString());
                // todo 增加上传评审意见记录
                tProjectCirculationService.insertTProjectCirculation(tProjectReview.getProjectPoolId(), "上传评估考察意见", userInfo.getNickName());
                if(StringUtils.isNotBlank(tProjectReview.getReviewId())){
                    tProjectReview.setId(tProjectReview.getReviewId());
                    tProjectReviewService.updateTProjectReview(tProjectReview);
                }else {
                    tProjectReviewService.insertTProjectReview(tProjectReview);
                }
                tProjectPool.setProjectStage("2");//项目阶段-评估考察
                tProjectPool.setProjectState("b");//项目状态-评估考察中
            }

            if ("modifyApply".equals(task.getTaskDefinitionKey())) {
                String nickName= SecurityUtils.getLoginUser().getUser().getNickName();
                String userId=SecurityUtils.getLoginUser().getUserId().toString();
                TProjectCompany tProjectCompany = tProjectPool.gettProjectCompany();
                tProjectCompany.setCreateBy(userId);
                tProjectCompany.setId(IdUtils.fastSimpleUUID());
                TProjectContacts tProjectContacts = tProjectPool.gettProjectContacts();
                tProjectContacts.setCreateBy(userId);
                tProjectContacts.setId(IdUtils.fastSimpleUUID());
                // todo 设置项目联系人
                tProjectPool.setProjectContacts(tProjectContacts.getId());
                // todo 设置公司信息关联关系
                tProjectCompany.setProjectPoolId(tProjectPool.getId());

                // todo 保存公司附件信息
                tUnifyFileService.insertTUnifyFileList(tProjectPool.getListFile(),
                        tProjectPool.getId(),
                        tProjectCompany.getId(),
                        String.valueOf(FileType.COMPANY.ordinal()),
                        nickName);

                // todo 保存BP附件信息
                tUnifyFileService.insertTUnifyFileLists(tProjectPool.getBpFile(),
                        tProjectPool.getId(),
                        tProjectPool.getId(),
                        String.valueOf(FileType.BP.ordinal()),
                        nickName,"a","1");

                // todo 保存其他附件信息
                tUnifyFileService.insertTUnifyFileLists(tProjectPool.getOtherFile(),
                        tProjectPool.getId(),
                        tProjectPool.getId(),
                        String.valueOf(FileType.OTHER.ordinal()),
                        nickName,"k","1");

                tProjectCompanyService.insertTProjectCompany(tProjectCompany);
                tProjectContactsService.insertTProjectContacts(tProjectContacts);

            }

            //FlowBaseInfo flow = new FlowBaseInfo();
            if(flow==null){
                flow = new FlowBaseInfo();
            }
            flow.setId(UUIDGenerator.uuid());
            flow.setFormProperties(flowService.getFormProperties(fpMap, request.getParameterMap()));
            flow.setStatus(FlowStatusEnum.RUNNING.getName());
            flow.setProcDefId(task.getProcessDefinitionId());
            flow.setProcInsId(task.getProcessInstanceId());
            flow.setTaskDefKey(task.getTaskDefinitionKey());
            String isOk = tProjectPool.isFlag() ? "[同意]" : "[驳回]";
            if ("modifyApply".equals(task.getTaskDefinitionKey())) {
                tProjectPool.setStatus(tProjectPool.isFlag() ? 1 : 4);
                isOk = tProjectPool.isFlag() ? "[提交]" : "[关闭]";
            } else {
                tProjectPool.setStatus(tProjectPool.isFlag() ? 2 : 0);
                if("presidents".equals(task.getTaskDefinitionKey())){//总裁室
                    if(!tProjectPool.isFlag()&&StringUtils.isNotBlank(tProjectPool.getIsTerminate())){//如果不为空代表可能是驳回（终止）或者观望
                        isOk= "[关闭]";
                    }
                }
            }
            if (null != flow.getComment()) {
                flow.setComment(isOk + flow.getComment());
            } else {
                flow.setComment(isOk);
            }
            flow.setTaskName(task.getName());
            flow.setCreateBy(SecurityUtils.getLoginUser().getUserId().toString());
            flow.setFlag(tProjectPool.isFlag());
            ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).active().singleResult();
            String result="";
            // 表示流程已经审批结束了
            if (processInstance == null) {
                flow.setStatus(FlowStatusEnum.ENDED.getName());
                if (!"modifyApply".equals(task.getTaskDefinitionKey())) {//
                    if(tProjectPool.isFlag()) {//审批通过
                        tProjectPool.setStatus(3);
                        tProjectPool.setProjectStage("3");//项目阶段-项目立项
                        tProjectPool.setProjectState("c");//项目状态-准备立项材料
                        // todo 增加项目创建记录
                        tProjectCirculationService.insertTProjectCirculation(tProjectPool.getId(), "项目报备完成", userInfo.getNickName());
                    }else{//总裁室的驳回
                        if(StringUtils.isNotBlank(tProjectPool.getIsTerminate())) {
                            tProjectPool.setStatus(4);//流程状态为关闭
                            if ("1".equals(tProjectPool.getIsTerminate())) {
                                result="【终止】";
                                tProjectPool.setProjectStatus("1");//终止
                            } else {
                                result="【观望】";
                                tProjectPool.setProjectStatus("2");//观望
                            }
                        }
                    }
                }
            }
            tProjectPool.setUpdateBy(userInfo.getNickName());

            tProjectPoolService.updateTProjectPool(tProjectPool);
            activitiBaseInfoService.addActivitiBaseInfo(flow);
            if(flow.isFlag()){
                getAssignee(tProjectPool,flow);
            }
            if (Objects.equals(active, "druid")) {
                //todo 短信
                sendMessage(flow,result);
            }
        }
        return AjaxResult.success();
    }
    // todo 短信
    public void sendMessage(FlowBaseInfo flowBaseInfo,String result) {
        boolean flag = flowBaseInfo.isFlag();
        String procInsId = flowBaseInfo.getProcInsId();
        // 待办任务
        List<Task> tasks = taskService.createTaskQuery().processInstanceId(procInsId).list();
        // 对应业务单据
        TProjectPool projectPool = investmentOpportunityMapper.selectTProjectPoolByProcInstId(procInsId);
        if (projectPool == null) {
            return;
        }
        // 申请人
        SysUser applyUserInfo = sysUserService.selectUserById(Long.valueOf(projectPool.getCreateBy()));
        // 当前登录人
        SysUser loginUser = SecurityUtils.getLoginUser().getUser();

        if(tasks.size()>0) {
            for (int i = 0; i < tasks.size(); i++) {
                Task task = tasks.get(i);
                if (task != null) {
                    if (Objects.equals(applyUserInfo.getUserId(), loginUser.getUserId()) && !flag) {
                        // 如果是申请人暂存或者关闭或者自己驳回，不用给自己发审批短信
                        continue;
                    } else {
                        // 申请人提交，给下一个审批人发短信
                        // 审批人同意，给下一个审批人发短信
                        if (flag) { //给审批人发送短信
                            String assignee = task.getAssignee();
                            if (org.apache.commons.lang3.StringUtils.isNotBlank(assignee)) { // 给审批人发送短信
                                SysUser auditUser = sysUserService.selectUserById(Long.valueOf(assignee));
                                String auditContents = auditUser.getNickName() + ",您好。投资系统中" + projectPool.getProjectName() + "的项目机会流程待处理，请查看！";
                                if (auditUser != null && StringUtils.isNotBlank(auditUser.getPhonenumber())) {
                                    try{
                                        SmsSenderUtils.sendSms(auditUser.getPhonenumber(), auditContents);
                                    } catch (IOException e) {
                                        logger.error("短信发送失败"+e.getMessage());
                                    }
                                }
                            }
                        } else { // 审批人驳回，给申请人发短信
                            String rejectContents = applyUserInfo.getNickName()+"，您好。你在投资系统中提交" + projectPool.getProjectName() + "的项目机会申请已审核，结果为【驳回】，请查看！";
                            if (applyUserInfo != null && StringUtils.isNotBlank(applyUserInfo.getPhonenumber())) {
                                try{
                                    SmsSenderUtils.sendSms(applyUserInfo.getPhonenumber(), rejectContents);
                                } catch (IOException e) {
                                    logger.error("短信发送失败"+e.getMessage());
                                }
                            }
                        }
                    }
                }
            }
        }else{
            String completeContents ="";
            if(flag) {
                // 审批完成，给申请人发短信
                //XXX，您好。你在投资系统中提交“XXX”的项目立项申请已审核，结果为【通过】/【驳回】/【观望】！
                completeContents = applyUserInfo.getNickName()+"，您好。你在投资系统中提交" +projectPool.getProjectName() + "的项目机会申请已审核，结果为【同意】，请查看！";
                if (applyUserInfo != null && StringUtils.isNotBlank(applyUserInfo.getPhonenumber())) {
                    try{
                        SmsSenderUtils.sendSms(applyUserInfo.getPhonenumber(), completeContents);
                    } catch (IOException e) {
                        logger.error("短信发送失败"+e.getMessage());
                    }
                }

            }else{
                if(StringUtils.isNotEmpty(result)){//代表是终止或者观望
                    completeContents = applyUserInfo.getNickName()+"，您好。你在投资系统中提交" +projectPool.getProjectName() + "的项目机会申请已审核，结果为"+result+"，请查看！";
                    if (applyUserInfo != null && StringUtils.isNotBlank(applyUserInfo.getPhonenumber())) {
                        try{
                            SmsSenderUtils.sendSms(applyUserInfo.getPhonenumber(), completeContents);
                        } catch (IOException e) {
                            logger.error("短信发送失败"+e.getMessage());
                        }
                    }
                }
            }

        }
    }
    /**
     * 跳节点
     * @param projectPool
     * @param flow
     * @throws Exception
     */
    public void getAssignee(TProjectPool projectPool, FlowBaseInfo flow) throws Exception {
        SysUser sysUser=SecurityUtils.getLoginUser().getUser();//当前登陆人
        if (sysUser == null) {
            sysUser=sysUserService.selectUserById(Long.parseLong(projectPool.getCreateBy()));
        }
        List<Task> tasks = taskService.createTaskQuery().processInstanceId(flow.getProcInsId()).list();
        Long userId=sysUser.getUserId();
        for(int i = 0; i < tasks.size(); i++) {
            Task task = tasks.get(i);
            if (task == null || StringUtils.isBlank(task.getAssignee())) {
                return;
            }
            Long assignee = Long.parseLong(task.getAssignee());
            if ("deptLeader".equals(task.getTaskDefinitionKey()) && (userId.equals(assignee) || projectPool.getCreateBy().equals(assignee))) {
                JumpNode(projectPool, flow);
            }
        }
    }
    public Map<String, Object> JumpNode(TProjectPool projectPool, FlowBaseInfo flow) throws Exception{
        List<Task> list = taskService.createTaskQuery().processInstanceId(flow.getProcInsId()).list();
        String taskId=null;
        Map<String, Object> rs = new HashMap<String, Object>();
        rs.put("status",true);
        if (list.size()>0) {
            taskId = list.get(0).getId();
            flow.setTaskId(taskId);
            boolean flag = flow.isFlag();
            //当前流程节点Id信息
//            ExecutionEntity execution = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(flow.getProcInsId()).singleResult();
//            String activitiId = execution.getActivityId();
            Map<String, Object> formProperties = new HashMap<>();
            formProperties.put("auditPass", flow.isFlag());
            //部门负责人
            String leader=sysDeptMapper.selectDeptLeader("投资部");
            SysUser sysUser=sysUserService.selectUserByUserName(leader);
            formProperties.put("MANAGER",sysUser.getUserId());
            if(StringUtils.isNotBlank(projectPool.getIsTerminate())) {//不为空代表结束流程
                formProperties.put("whetherToEnd", true);
            }else{
                formProperties.put("whetherToEnd", false);
            }
            //当前登陆人
            Long userId=SecurityUtils.getUserId();
            try {
                //表单审核
                rs = flowService.taskComplete(taskId, flag, formProperties, userId.toString());
            } catch (Exception e) {
                e.printStackTrace();
                rs.put("status", false);
                rs.put("msg", "流程审批失败");
            }
            if (flow.isFlag()){
                getAssignee(projectPool,flow);
            }

        }
        return rs;
    }

}
