/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.act.service;

import java.io.InputStream;
import java.util.*;

import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.modules.oa.entity.OaNotify;
import com.jeeplus.modules.oa.entity.OaNotifyRecord;
import com.jeeplus.modules.oa.service.OaNotifyService;
import com.jeeplus.modules.sg.advence.activiti.entity.Advance;
import com.jeeplus.modules.sg.advence.activiti.service.AdvanceService;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.Construction;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.Disclose;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.ReturnTodo;
import com.jeeplus.modules.sg.managementcenter.activiti.service.ConstructionService;
import com.jeeplus.modules.sg.managementcenter.activiti.utils.MyActiviUtils;
import com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo;
import com.jeeplus.modules.sg.managementcenter.materialinfo.mapper.MaterialInfoMapper;
import com.jeeplus.modules.sg.managementcenter.materialproject.entity.MaterialProject;
import com.jeeplus.modules.sg.managementcenter.materialproject.mapper.MaterialProjectMapper;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project1;
import com.jeeplus.modules.sg.materialmodule.activiti.entity.MaterialModule;
import com.jeeplus.modules.sg.materialmodule.activiti.service.MaterialModuleService;
import com.jeeplus.modules.sg.materialmodule.activiti.service.NonPowerService;
import com.jeeplus.modules.sg.picking.activiti.entity.MaterialReport;
import com.jeeplus.modules.sg.picking.activiti.entity.PickApplication;
import com.jeeplus.modules.sg.picking.activiti.entity.ShowList;
import com.jeeplus.modules.sg.picking.activiti.service.PickIngService;
import com.jeeplus.modules.sg.picking.activiti.service.ShowListService;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricProcessInstanceQuery;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.javax.el.ExpressionFactory;
import org.activiti.engine.impl.javax.el.ValueExpression;
import org.activiti.engine.impl.juel.ExpressionFactoryImpl;
import org.activiti.engine.impl.juel.SimpleContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.delegate.ActivityBehavior;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.activiti.engine.task.Comment;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.BaseService;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.mapper.ActMapper;
import com.jeeplus.modules.act.utils.ActUtils;
import com.jeeplus.modules.act.utils.ProcessDefCache;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;

import javax.servlet.ServletContext;

/**
 * 流程定义相关Service
 *
 * @author jeeplus
 * @version 2016-11-03
 */
@Service
@Transactional(readOnly = true)
public class ActTaskService extends BaseService {

    @Autowired
    private ActMapper actMapper;

    @Autowired
    private ProcessEngineFactoryBean processEngine;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private FormService formService;
    @Autowired
    private HistoryService historyService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private IdentityService identityService;
    @Autowired
    private ConstructionService constructionService;
    @Autowired
    private ShowListService showListService;
    @Autowired
    private MaterialModuleService materialModuleService;
    @Autowired
    private AdvanceService advanceService;
    @Autowired
    private OaNotifyService oaNotifyService;
    @Autowired
    private PickIngService pickIngService;
    @Autowired
    private ActProcessService actProcessService;
    @Autowired
    private ActTaskService actTaskService;

    @Autowired
    private MaterialProjectMapper materialProjectMapper;
    @Autowired
    private MaterialInfoMapper materialInfoMapper;

    /**
     * 获取待办任务列表
     *
     * @return
     */
    public Page<HashMap<String, String>> newTodoList(Page<HashMap<String, String>> page, Act act, String reserveProjectName,String projectId,String projectName) {
        List<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
        Project project = new Project();
        String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId());

        // =============== 已经签收的任务  ===============
        TaskQuery todoTaskQuery = taskService.createTaskQuery().taskAssignee(userId).active()
                .includeProcessVariables().orderByTaskCreateTime().desc();

        // 设置查询条件
        if (StringUtils.isNotBlank(act.getProcDefKey())) {
            todoTaskQuery.processDefinitionKey(act.getProcDefKey());
        }
        //开始时间
        if (act.getBeginDate() != null) {
            todoTaskQuery.taskCreatedAfter(act.getBeginDate());
        }
        //结束时间
        if (act.getEndDate() != null) {
            todoTaskQuery.taskCreatedBefore(act.getEndDate());
        }
        if ((null!=reserveProjectName &&!"".equals(reserveProjectName)) || (null!=projectId && !"".equals(projectId)) || (null!=projectName && !"".equals(projectName))) {
            if (null!= reserveProjectName && !"".equals(reserveProjectName)) {
                project.setReserveProjectName(reserveProjectName);
            }
            if (null!= projectId && !"".equals(projectId)) {
                project.setProjectId(projectId);
            }
            if (null!= projectName && !"".equals(projectName)) {
                project.setProjectName(projectName);
            }
            ReturnTodo procInsIDAll = constructionService.findProcInsIDAll(project);
            //通过输入的查询结果获取所有的项目信息
            if (procInsIDAll!=null) {
                List<String> strings = new ArrayList<>();
                String xcProcInsId = procInsIDAll.getXcProcInsId();
                String scProcInsId = procInsIDAll.getScProcInsId();
                String xnProcInsId = procInsIDAll.getXnProcInsId();
                String maProcInsId = procInsIDAll.getMaProcInsId();
                String xfProcInsId = procInsIDAll.getXfProcInsId();
                String mmProcInsId = procInsIDAll.getMmProcInsId();
                String xsProcInsId = procInsIDAll.getXsProcInsId();
                String mpProcInsId = procInsIDAll.getMpProcInsId();
                if (null!=xcProcInsId && !"".equals(xcProcInsId)) {
                    strings.add(xcProcInsId);
                }
                if (null!=scProcInsId && !"".equals(scProcInsId)) {
                    strings.add(scProcInsId);
                }
                if (null!=xnProcInsId && !"".equals(xnProcInsId)) {
                    strings.add(xnProcInsId);
                }
                if (null!=maProcInsId && !"".equals(maProcInsId)) {
                    strings.add(maProcInsId);
                }
                if (null!=xfProcInsId && !"".equals(xfProcInsId)) {
                    strings.add(xfProcInsId);
                }
                if (null!=mmProcInsId && !"".equals(mmProcInsId)) {
                    strings.add(mmProcInsId);
                }
                if (null!=xsProcInsId && !"".equals(xsProcInsId)) {
                    strings.add(xsProcInsId);
                }
                if (null!=mpProcInsId && !"".equals(mpProcInsId)) {
                    strings.add(mpProcInsId);
                }

                if (null != strings && strings.size() > 0) {
                    todoTaskQuery.processInstanceIdIn(strings);
                }
            }
        }
/*        if (!"".equals(xmName) && xmName != null) {
            List<String> strings = constructionService.insIdByName(xmName);
            if (strings != null && strings.size() > 0) {
                todoTaskQuery.processInstanceIdIn(strings);
            } else {
                strings.add("");
                todoTaskQuery.processInstanceIdIn(strings);
            }
        }*/


        // =============== 等待签收的任务  ===============
        TaskQuery toClaimQuery = taskService.createTaskQuery().taskCandidateUser(userId)
                .includeProcessVariables().active().orderByTaskCreateTime().desc();

        // 设置查询条件
        if (StringUtils.isNotBlank(act.getProcDefKey())) {
            toClaimQuery.processDefinitionKey(act.getProcDefKey());
        }
        if (act.getBeginDate() != null) {
            toClaimQuery.taskCreatedAfter(act.getBeginDate());
        }
        if (act.getEndDate() != null) {
            toClaimQuery.taskCreatedBefore(act.getEndDate());
        }

        long taskCount = todoTaskQuery.count();
        long claimCount = toClaimQuery.count();
        long total = taskCount + claimCount;
        page.setCount(total);


        int start = page.getFirstResult();
        int end = page.getFirstResult() + page.getMaxResults();
        // 查询列表
        List<Task> todoList = Lists.newArrayList();
        // 查询列表
        List<Task> toClaimList = Lists.newArrayList();
        if (end == -1) {//不分页
            todoList = todoTaskQuery.list();
            toClaimList = toClaimQuery.list();
        } else {

            if (end <= taskCount) {
                todoList = todoTaskQuery.listPage(start, page.getMaxResults());
            } else if (start < taskCount) {
                todoList = todoTaskQuery.listPage(start, (int) taskCount - start);
                toClaimList = toClaimQuery.listPage(0, end - (int) taskCount);
            } else {
                toClaimList = toClaimQuery.listPage(start - (int) taskCount, page.getMaxResults());
            }
        }


        for (Task task : todoList) {
            HashMap map = new HashMap();
            map.put("task.assignee", task.getAssignee());
            map.put("task.id", task.getId());
            map.put("task.createTime", task.getCreateTime());
            map.put("task.name", task.getName());
            map.put("task.executionId", task.getExecutionId());
            map.put("task.processDefinitionId", task.getProcessDefinitionId());
            map.put("task.processInstanceId", task.getProcessInstanceId());
            project.setProcInsId(task.getProcessInstanceId());
            Project s = constructionService.procInsIdAllName(project);
            if (null!=s && !"".equals(s)) {
                map.put("task.projectId", s.getProjectId());
                map.put("task.projectName", s.getProjectName());
                map.put("task.reserveProjectName", s.getReserveProjectName());
            }
            /*if ("".equalsIgnoreCase(s) || null == s) {
                String s2 = constructionService.idProjectName3(task.getProcessInstanceId());
                if ("".equalsIgnoreCase(s2) || null == s2) {
                    String s1 = constructionService.idProjectName2(task.getProcessInstanceId());
                    if ("".equalsIgnoreCase(s1) || null == s1) {
                        String s4 = constructionService.idProjectName4(task.getProcessInstanceId());
                        if ("".equalsIgnoreCase(s4) || null == s4) {
                        } else {
                            map.put("task.projectName", s4);
                        }
                    } else {
                        map.put("task.projectName", s1);
                    }
                } else {
                    map.put("task.projectName", s2);
                }
            }else {
                map.put("task.projectName", s);
            }*/
            map.put("task.taskDefinitionKey", task.getTaskDefinitionKey());
            map.put("vars", task.getProcessVariables());
            map.put("procDef.name", ProcessDefCache.get(task.getProcessDefinitionId()).getName());
            map.put("procDef.version", ProcessDefCache.get(task.getProcessDefinitionId()).getVersion());
            map.put("status", "todo");
            map.put("title", task.getProcessVariables().get("title"));
            page.getList().add(map);
        }


        for (Task task : toClaimList) {
            HashMap map = new HashMap();
            map.put("task.assignee", task.getAssignee());
            map.put("task.id", task.getId());
            map.put("task.name", task.getName());
            map.put("task.createTime", task.getCreateTime());
            map.put("task.executionId", task.getExecutionId());
            map.put("task.processInstanceId", task.getProcessInstanceId());
            map.put("task.processDefinitionId", task.getProcessDefinitionId());
            map.put("task.taskDefinitionKey", task.getTaskDefinitionKey());
            map.put("vars", task.getProcessVariables());
            map.put("procDef.name", ProcessDefCache.get(task.getProcessDefinitionId()).getName());
            map.put("procDef.version", ProcessDefCache.get(task.getProcessDefinitionId()).getVersion());
            map.put("status", "claim");
            map.put("title", task.getProcessVariables().get("title"));
            page.getList().add(map);
        }

        return page;

    }

    /**
     * 获取待办任务列表（旧）
     *
     * @return
     */
    public Page<HashMap<String, String>> todoList(Page<HashMap<String, String>> page, Act act) {
        List<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
        String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId());


        // =============== 已经签收的任务  ===============
        TaskQuery todoTaskQuery = taskService.createTaskQuery().taskAssignee(userId).active()
                .includeProcessVariables().orderByTaskCreateTime().desc();

        // 设置查询条件
        if (StringUtils.isNotBlank(act.getProcDefKey())) {
            todoTaskQuery.processDefinitionKey(act.getProcDefKey());
        }
        if (act.getBeginDate() != null) {
            todoTaskQuery.taskCreatedAfter(act.getBeginDate());
        }
        if (act.getEndDate() != null) {
            todoTaskQuery.taskCreatedBefore(act.getEndDate());
        }


        // =============== 等待签收的任务  ===============
        TaskQuery toClaimQuery = taskService.createTaskQuery().taskCandidateUser(userId)
                .includeProcessVariables().active().orderByTaskCreateTime().desc();

        // 设置查询条件
        if (StringUtils.isNotBlank(act.getProcDefKey())) {
            toClaimQuery.processDefinitionKey(act.getProcDefKey());
        }
        if (act.getBeginDate() != null) {
            toClaimQuery.taskCreatedAfter(act.getBeginDate());
        }
        if (act.getEndDate() != null) {
            toClaimQuery.taskCreatedBefore(act.getEndDate());
        }

        long taskCount = todoTaskQuery.count();
        long claimCount = toClaimQuery.count();
        long total = taskCount + claimCount;
        page.setCount(total);


        int start = page.getFirstResult();
        int end = page.getFirstResult() + page.getMaxResults();
        // 查询列表
        List<Task> todoList = Lists.newArrayList();
        // 查询列表
        List<Task> toClaimList = Lists.newArrayList();
        if (end == -1) {//不分页
            todoList = todoTaskQuery.list();
            toClaimList = toClaimQuery.list();
        } else {

            if (end <= taskCount) {
                todoList = todoTaskQuery.listPage(start, page.getMaxResults());
            } else if (start < taskCount) {
                todoList = todoTaskQuery.listPage(start, (int) taskCount - start);
                toClaimList = toClaimQuery.listPage(0, end - (int) taskCount);
            } else {
                toClaimList = toClaimQuery.listPage(start - (int) taskCount, page.getMaxResults());
            }
        }


        for (Task task : todoList) {
            HashMap map = new HashMap();
            map.put("task.assignee", task.getAssignee());
            map.put("task.id", task.getId());
            map.put("task.createTime", task.getCreateTime());
            map.put("task.name", task.getName());
            map.put("task.executionId", task.getExecutionId());
            map.put("task.processDefinitionId", task.getProcessDefinitionId());
            map.put("task.processInstanceId", task.getProcessInstanceId());
            map.put("task.taskDefinitionKey", task.getTaskDefinitionKey());
            map.put("vars", task.getProcessVariables());
            map.put("procDef.name", ProcessDefCache.get(task.getProcessDefinitionId()).getName());
            map.put("procDef.version", ProcessDefCache.get(task.getProcessDefinitionId()).getVersion());
            map.put("status", "todo");
            map.put("title", task.getProcessVariables().get("title"));
            page.getList().add(map);
        }


        for (Task task : toClaimList) {
            HashMap map = new HashMap();
            map.put("task.assignee", task.getAssignee());
            map.put("task.id", task.getId());
            map.put("task.name", task.getName());
            map.put("task.createTime", task.getCreateTime());
            map.put("task.executionId", task.getExecutionId());
            map.put("task.processInstanceId", task.getProcessInstanceId());
            map.put("task.processDefinitionId", task.getProcessDefinitionId());
            map.put("task.taskDefinitionKey", task.getTaskDefinitionKey());
            map.put("vars", task.getProcessVariables());
            map.put("procDef.name", ProcessDefCache.get(task.getProcessDefinitionId()).getName());
            map.put("procDef.version", ProcessDefCache.get(task.getProcessDefinitionId()).getVersion());
            map.put("status", "claim");
            map.put("title", task.getProcessVariables().get("title"));
            page.getList().add(map);
        }

        return page;

    }

    /**
     * 获取已办任务列表
     *
     * @param page
     * @return
     */
    public Page<HashMap<String, String>> historicList(Page<HashMap<String, String>> page, Act act) {
        String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId());

        HistoricTaskInstanceQuery histTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished()
                .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();

        // 设置查询条件
        if (StringUtils.isNotBlank(act.getProcDefKey())) {
            histTaskQuery.processDefinitionKey(act.getProcDefKey());
        }
        if (act.getBeginDate() != null) {
            histTaskQuery.taskCompletedAfter(act.getBeginDate());
        }
        if (act.getEndDate() != null) {
            histTaskQuery.taskCompletedBefore(act.getEndDate());
        }

        // 查询总数
        page.setCount(histTaskQuery.count());
        page.initialize();

        // 查询列表
        List<HistoricTaskInstance> histList = Lists.newArrayList();
        if (page.getMaxResults() == -1) {
            histList = histTaskQuery.list();
        } else {
            histList = histTaskQuery.listPage(page.getFirstResult(), page.getMaxResults());
        }
        for (HistoricTaskInstance histTask : histList) {
            Act e = new Act();
            e.setHistTask(histTask);
            e.setVars(histTask.getProcessVariables());
//			e.setTaskVars(histTask.getTaskLocalVariables());
//			System.out.println(histTask.getId()+"  =  "+histTask.getProcessVariables() + "  ========== " + histTask.getTaskLocalVariables());
            e.setProcDef(ProcessDefCache.get(histTask.getProcessDefinitionId()));
//			e.setProcIns(runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult());
//			e.setProcExecUrl(ActUtils.getProcExeUrl(task.getProcessDefinitionId()));
            e.setStatus("finish");
            HashMap map = new HashMap();
            map.put("task.assignee", histTask.getAssignee());
            map.put("task.id", histTask.getId());
            map.put("task.name", histTask.getName());
            map.put("task.endTime", histTask.getEndTime());
            map.put("task.executionId", histTask.getExecutionId());
            map.put("task.processInstanceId", histTask.getProcessInstanceId());
            map.put("task.processDefinitionId", histTask.getProcessDefinitionId());
            map.put("task.taskDefinitionKey", histTask.getTaskDefinitionKey());
            map.put("vars", histTask.getProcessVariables());
            map.put("procDef.name", ProcessDefCache.get(histTask.getProcessDefinitionId()).getName());
            map.put("procDef.version", ProcessDefCache.get(histTask.getProcessDefinitionId()).getVersion());
            try {
                map.put("status", queryProcessState(histTask.getProcessInstanceId()));
            } catch (Exception e1) {
                e1.printStackTrace();
            }

            page.getList().add(map);
        }
        return page;
    }

    /**
     * 获取流转历史任务列表
     *
     * @param procInsId 流程实例
     * @param startAct  开始活动节点名称
     * @param endAct    结束活动节点名称
     */
    public List<Act> histoicFlowList(String procInsId, String startAct, String endAct) {
        List<Act> actList = Lists.newArrayList();
        List<HistoricActivityInstance> list = Lists.newArrayList();
        List<HistoricActivityInstance> historicActivityInstances2 = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId)
                .orderByHistoricActivityInstanceStartTime().asc().orderByHistoricActivityInstanceEndTime().asc().list();
        ;
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
            if (historicActivityInstance.getEndTime() != null) {
                list.add(historicActivityInstance);
            }
        }

        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
            if (historicActivityInstance.getEndTime() == null) {
                list.add(historicActivityInstance);
            }
        }
        boolean start = false;
        Map<String, Integer> actMap = Maps.newHashMap();

        for (int i = 0; i < list.size(); i++) {

            HistoricActivityInstance histIns = list.get(i);

            // 过滤开始节点前的节点
            if (StringUtils.isNotBlank(startAct) && startAct.equals(histIns.getActivityId())) {
                start = true;
            }
            if (StringUtils.isNotBlank(startAct) && !start) {
                continue;
            }

            // 只显示开始节点和结束节点，并且执行人不为空的任务
            if (StringUtils.isNotBlank(histIns.getAssignee())
                    || "startEvent".equals(histIns.getActivityType())
                    || "endEvent".equals(histIns.getActivityType())) {

                // 给节点增加一个序号
                Integer actNum = actMap.get(histIns.getActivityId());
                if (actNum == null) {
                    actMap.put(histIns.getActivityId(), actMap.size());
                }

                Act e = new Act();
                e.setHistIns(histIns);
                // 获取流程发起人名称
                if ("startEvent".equals(histIns.getActivityType())) {
                    List<HistoricProcessInstance> il = historyService.createHistoricProcessInstanceQuery().processInstanceId(procInsId).orderByProcessInstanceStartTime().asc().list();
//					List<HistoricIdentityLink> il = historyService.getHistoricIdentityLinksForProcessInstance(procInsId);
                    if (il.size() > 0) {
                        if (StringUtils.isNotBlank(il.get(0).getStartUserId())) {
                            User user = UserUtils.getByLoginName(il.get(0).getStartUserId());
                            if (user != null) {
                                e.setAssignee(histIns.getAssignee());
                                e.setAssigneeName(user.getName());
                            }
                        }
                    }
                }
                // 获取任务执行人名称
                if (StringUtils.isNotEmpty(histIns.getAssignee())) {
                    User user = UserUtils.getByLoginName(histIns.getAssignee());
                    if (user != null) {
                        e.setAssignee(histIns.getAssignee());
                        e.setAssigneeName(user.getName());
                    }
                }
                // 获取意见评论内容
                if (StringUtils.isNotBlank(histIns.getTaskId())) {
                    List<Comment> commentList = taskService.getTaskComments(histIns.getTaskId());
                    if (commentList.size() > 0) {
                        e.setComment(commentList.get(0).getFullMessage());
                    }
                }
                actList.add(e);
            }

            // 过滤结束节点后的节点
            if (StringUtils.isNotBlank(endAct) && endAct.equals(histIns.getActivityId())) {
                boolean bl = false;
                Integer actNum = actMap.get(histIns.getActivityId());
                // 该活动节点，后续节点是否在结束节点之前，在后续节点中是否存在
                for (int j = i + 1; j < list.size(); j++) {
                    HistoricActivityInstance hi = list.get(j);
                    Integer actNumA = actMap.get(hi.getActivityId());
                    if ((actNumA != null && actNumA < actNum) || StringUtils.equals(hi.getActivityId(), histIns.getActivityId())) {
                        bl = true;
                    }
                }
                if (!bl) {
                    break;
                }
            }
        }
        return actList;
    }

    /**
     * 获取流程定义列表
     *
     * @param category 流程分类
     */
    public Page<Object[]> processList(Page<Object[]> page, String category) {
        /*
         * 保存两个对象，一个是ProcessDefinition（流程定义），一个是Deployment（流程部署）
         */
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery()
                .latestVersion().active().orderByProcessDefinitionKey().asc();

        if (StringUtils.isNotEmpty(category)) {
            processDefinitionQuery.processDefinitionCategory(category);
        }

        page.setCount(processDefinitionQuery.count());
        List<ProcessDefinition> processDefinitionList = Lists.newArrayList();
        if (page.getMaxResults() == -1) {//不分页
            processDefinitionList = processDefinitionQuery.list();
        } else {
            processDefinitionList = processDefinitionQuery.listPage(page.getFirstResult(), page.getMaxResults());
        }
        for (ProcessDefinition processDefinition : processDefinitionList) {
            String deploymentId = processDefinition.getDeploymentId();
            Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
            page.getList().add(new Object[]{processDefinition, deployment});
        }
        return page;
    }

    /**
     * 获取流程表单（首先获取任务节点表单KEY，如果没有则取流程开始节点表单KEY）
     *
     * @return
     */
    public String getFormKey(String procDefId, String taskDefKey) {
        String formKey = "";
        if (StringUtils.isNotBlank(procDefId)) {
            if (StringUtils.isNotBlank(taskDefKey)) {
                try {
                    formKey = formService.getTaskFormKey(procDefId, taskDefKey);
                } catch (Exception e) {
                    formKey = "";
                }
            }
            if (StringUtils.isBlank(formKey)) {
                formKey = formService.getStartFormKey(procDefId);
            }
            if (StringUtils.isBlank(formKey)) {
                formKey = "/404";
            }
        }
        logger.debug("getFormKey: {}", formKey);
        return formKey;
    }

    /**
     * 获取正在运行的流程实例对象
     *
     * @param procInsId
     * @return
     */
    @Transactional(readOnly = false)
    public ProcessInstance getProcIns(String procInsId) {
        return runtimeService.createProcessInstanceQuery().processInstanceId(procInsId).singleResult();
    }

    /**
     * 获取已经结束流程实例对象
     *
     * @param procInsId
     * @return
     */
    @Transactional(readOnly = false)
    public HistoricProcessInstance getFinishedProcIns(String procInsId) {
        return historyService.createHistoricProcessInstanceQuery().processInstanceId(procInsId).singleResult();
    }


    /**
     * 获取正在运行的流程实例对象列表
     *
     * @param procDefKey
     * @return
     */
    @Transactional(readOnly = false)
    public List<ProcessInstance> getRunngingProcIns(String procDefKey, User user, int[] pageParams) {
        ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(procDefKey).active().orderByProcessInstanceId().desc();
        List<ProcessInstance> list = new ArrayList<ProcessInstance>();
        if (User.isAdmin(user.getId())) {
            list = query.listPage(pageParams[0], pageParams[1]);
        } else {
            list = query.involvedUser(user.getLoginName()).listPage(pageParams[0], pageParams[1]);
        }
        return list;
    }


    /**
     * 获取已经结束的流程实例对象列表
     *
     * @param procDefKey
     * @return
     */
    @Transactional(readOnly = false)
    public List<HistoricProcessInstance> getFinishedProcIns(String procDefKey, User user, int[] pageParams) {
        HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionKey(procDefKey).finished().orderByProcessInstanceEndTime().desc();
        List<HistoricProcessInstance> list = new ArrayList<HistoricProcessInstance>();
        if (User.isAdmin(user.getId())) {
            list = query.listPage(pageParams[0], pageParams[1]);
        } else {
            list = query.involvedUser(user.getLoginName()).listPage(pageParams[0], pageParams[1]);
        }
        return list;
    }

    /**
     * 获取我发起的流程申请列表
     *
     * @param user
     * @return
     */
    @Transactional(readOnly = false)
    public Page<HashMap> getMyStartedProcIns(User user, Page<HashMap> page) throws Exception {
        HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().startedBy(user.getLoginName()).includeProcessVariables().orderByProcessInstanceStartTime().desc();
        page.setCount(query.count());
        List<HistoricProcessInstance> histList = Lists.newArrayList();
        if (page.getMaxResults() == -1) {//不分页
            histList = query.list();
        } else {
            histList = query.involvedUser(user.getLoginName()).listPage(page.getFirstResult(), page.getMaxResults());
        }
        for (HistoricProcessInstance historicProcessInstance : histList) {

            HashMap map = new HashMap();
//			p.getActivityId());
//			map.put("suspended", String.valueOf(p.isSuspended()));
//			historicProcessInstance.
            String state = queryProcessState(historicProcessInstance.getId());
            map.put("procIns.endTime", historicProcessInstance.getEndTime());
            map.put("procIns.startTime", historicProcessInstance.getStartTime());
            map.put("procIns.processInstanceId", historicProcessInstance.getId());
            map.put("procDef.processDefinitionId", historicProcessInstance.getProcessDefinitionId());
            map.put("vars", historicProcessInstance.getProcessVariables());
            map.put("procDef.name", historicProcessInstance.getProcessDefinitionName());
            map.put("procDef.version", historicProcessInstance.getProcessDefinitionVersion());
            map.put("procIns.status", state);
            page.getList().add(map);
        }

        return page;
    }

    /**
     * 启动流程
     *
     * @param procDefKey    流程定义KEY
     * @param businessTable 业务表表名
     * @param businessId    业务表编号
     * @return 流程实例ID
     */
    @Transactional(readOnly = false)
    public String startProcess(String procDefKey, String businessTable, String businessId) {
        return startProcess(procDefKey, businessTable, businessId, "");
    }

    /**
     * 启动流程
     *
     * @param procDefKey    流程定义KEY
     * @param businessTable 业务表表名
     * @param businessId    业务表编号
     * @param title         流程标题，显示在待办任务标题
     * @return 流程实例ID
     */
    @Transactional(readOnly = false)
    public String startProcess(String procDefKey, String businessTable, String businessId, String title) {
        Map<String, Object> vars = Maps.newHashMap();
        return startProcess(procDefKey, businessTable, businessId, title, vars);
    }

    /**
     * 启动流程
     *
     * @param procDefKey    流程定义KEY
     * @param businessTable 业务表表名
     * @param businessId    业务表编号
     * @param title         流程标题，显示在待办任务标题
     * @param vars          流程变量
     * @return 流程实例ID
     */
    @SuppressWarnings("unused")
    @Transactional(readOnly = false)
    public String startProcess(String procDefKey, String businessTable, String businessId, String title, Map<String, Object> vars) {
        //String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId())
        // 设置流程变量
        if (vars == null) {
            vars = Maps.newHashMap();
        }

        String userId = (String) vars.get("applyUserId");
        if (userId == null) {
            userId = UserUtils.getUser().getLoginName();
        }
        String userName = UserUtils.getByLoginName(userId).getName();
        vars.put("userName", userName);

        // 用来设置启动流程的人员ID，引擎会自动把用户ID保存到activiti:initiator中
        identityService.setAuthenticatedUserId(userId);

        // 设置流程标题
        if (StringUtils.isNotBlank(title)) {
            vars.put("title", title);
        }

        // 启动流程
        ProcessInstance procIns = runtimeService.startProcessInstanceByKey(procDefKey, businessTable + ":" + businessId, vars);

        // 更新业务表流程实例ID
        Act act = new Act();
        act.setBusinessTable(businessTable);// 业务表名
        act.setBusinessId(businessId);    // 业务表ID
        act.setProcInsId(procIns.getId());
        act.setVars(vars);
        actMapper.updateProcInsIdByBusinessId(act);
        return act.getProcInsId();
    }


    /**
     * 新启动流程
     *
     * @param procDefKey    流程定义KEY
     * @param businessTable 业务表表名
     * @param businessId    业务表编号
     * @param title         流程标题，显示在待办任务标题
     * @param vars          流程变量
     * @return 流程实例ID
     */
    @SuppressWarnings("unused")
    @Transactional(readOnly = false)
    public String startProcessNew(String procDefKey, String businessTable, String businessId, String title, Map<String, Object> vars) {
        //String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId())
        // 设置流程变量
        if (vars == null) {
            vars = Maps.newHashMap();
        }

        String userId = (String) vars.get("applyUserId");
        if (userId == null) {
            userId = UserUtils.getUser().getLoginName();
        }
        String userName = UserUtils.getByLoginName(userId).getName();
        vars.put("userName", userName);

        String processer = (String) vars.get("processer");
        if (processer != null) {
            vars.put("processer", processer);
        }

        // 用来设置启动流程的人员ID，引擎会自动把用户ID保存到activiti:initiator中
        identityService.setAuthenticatedUserId(userId);

        // 设置流程标题
        if (StringUtils.isNotBlank(title)) {
            vars.put("title", title);
        }

        // 启动流程
        ProcessInstance procIns = runtimeService.startProcessInstanceByKey(procDefKey, businessTable + ":" + businessId, vars);

        // 更新业务表流程实例ID
        Act act = new Act();
        act.setBusinessTable(businessTable);// 业务表名
        act.setBusinessId(businessId);    // 业务表ID
        act.setProcInsId(procIns.getId());
        act.setVars(vars);
        actMapper.updateProcInsIdByBusinessId(act);
        return act.getProcInsId();
    }

    /**
     * 获取任务
     *
     * @param taskId 任务ID
     */
    public Task getTask(String taskId) {
        return taskService.createTaskQuery().taskId(taskId).singleResult();
    }

    /**
     * 删除任务
     *
     * @param taskId       任务ID
     * @param deleteReason 删除原因
     */
    public void deleteTask(String taskId, String deleteReason) {
        taskService.deleteTask(taskId, deleteReason);
    }

    /**
     * 签收任务
     *
     * @param taskId 任务ID
     * @param userId 签收用户ID（用户登录名）
     */
    @Transactional(readOnly = false)
    public void claim(String taskId, String userId) {
        taskService.claim(taskId, userId);
    }

    /**
     * 提交任务, 并保存意见
     *
     * @param taskId    任务ID
     * @param procInsId 流程实例ID，如果为空，则不保存任务提交意见
     * @param comment   任务提交意见的内容
     * @param vars      任务变量
     */
    @Transactional(readOnly = false)
    public void complete(String taskId, String procInsId, String comment, Map<String, Object> vars) {
        complete(taskId, procInsId, comment, "", vars);
    }

    /**
     * 提交任务, 并保存意见
     *
     * @param taskId    任务ID
     * @param procInsId 流程实例ID，如果为空，则不保存任务提交意见
     * @param comment   任务提交意见的内容
     * @param title     流程标题，显示在待办任务标题
     * @param vars      任务变量
     */
    @Transactional(readOnly = false)
    public void complete(String taskId, String procInsId, String comment, String title, Map<String, Object> vars) {
        // 添加意见
        if (StringUtils.isNotBlank(procInsId) && StringUtils.isNotBlank(comment)) {
            taskService.addComment(taskId, procInsId, comment);
        }

        // 设置流程变量
        if (vars == null) {
            vars = Maps.newHashMap();
        }

        // 设置流程标题
        if (StringUtils.isNotBlank(title)) {
            vars.put("title", title);
        }

        // 提交任务
        taskService.complete(taskId, vars);
    }

    /**
     * 完成第一个任务
     *
     * @param procInsId
     */
    public void completeFirstTask(String procInsId) {
        completeFirstTask(procInsId, null, null, null);
    }

    /**
     * 完成第一个任务
     *
     * @param procInsId
     * @param comment
     * @param title
     * @param vars
     */
    public void completeFirstTask(String procInsId, String comment, String title, Map<String, Object> vars) {
        String userId = UserUtils.getUser().getLoginName();
        Task task = taskService.createTaskQuery().taskAssignee(userId).processInstanceId(procInsId).active().singleResult();
        if (task != null) {
            complete(task.getId(), procInsId, comment, title, vars);
        }
    }

    /**
     * 查询流程实例状态
     *
     * @param processInstanceId
     * @return
     * @throws Exception
     */
    public String queryProcessState(String processInstanceId) throws Exception {
        // 通过流程实例ID查询流程实例
        ProcessInstance pi = runtimeService.createProcessInstanceQuery()
                .processInstanceId(processInstanceId).singleResult();
        if (pi != null) {
            if (pi.isSuspended()) {
                //执行实例
                return "[已挂起]";
            } else {
                //执行实例
                List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).active().orderByTaskCreateTime().desc().listPage(0, 1);
                return "[进行中] :" + tasks.get(0).getName();
            }

        } else {
            HistoricProcessInstance pi2 = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
            if (pi2 != null) {
                if (pi2.getDeleteReason() == null) {
                    return "[正常结束]";
                } else if (pi2.getDeleteReason().equals("用户撤销")) {
                    return "[用户撤销]";
                } else {
                    return "[流程作废] :" + pi2.getDeleteReason();
                }

            } else {
                return "[已删除]";
            }

        }
    }

    /**
     * 终止流程实例
     *
     * @param processInstanceId
     */
    public void endProcessInstance(String processInstanceId, String deleteReason) throws Exception {
        runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
    }


//	/**
//	 * 委派任务
//	 * @param taskId 任务ID
//	 * @param userId 被委派人
//	 */
//	public void delegateTask(String taskId, String userId){
//		taskService.delegateTask(taskId, userId);
//	}
//
//	/**
//	 * 被委派人完成任务
//	 * @param taskId 任务ID
//	 */
//	public void resolveTask(String taskId){
//		taskService.resolveTask(taskId);
//	}
//
//	/**
//	 * 回退任务
//	 * @param taskId
//	 */
//	public void backTask(String taskId){
//		taskService.
//	}

    ////////////////////////////////////////////////////////////////////

    /**
     * 读取带跟踪的图片
     *
     * @param executionId 环节ID
     * @return 封装了各种节点信息
     */
    public InputStream tracePhoto(String processDefinitionId, String executionId) {
        // ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);

        List<String> activeActivityIds = Lists.newArrayList();
        if (runtimeService.createExecutionQuery().executionId(executionId).count() > 0) {
            activeActivityIds = runtimeService.getActiveActivityIds(executionId);
        }

        List<String> highLightedFlows = Lists.newArrayList();
        // 获得历史活动记录实体（通过启动时间正序排序，不然有的线可以绘制不出来）
        List<HistoricActivityInstance> historicActivityInstances = Lists.newArrayList();
        List<HistoricActivityInstance> historicActivityInstances2 = historyService
                .createHistoricActivityInstanceQuery().executionId(executionId).orderByHistoricActivityInstanceStartTime().asc().orderByHistoricActivityInstanceEndTime().asc().list();
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
            if (historicActivityInstance.getEndTime() != null) {
                historicActivityInstances.add(historicActivityInstance);
            }
        }

        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
            if (historicActivityInstance.getEndTime() == null) {
                historicActivityInstances.add(historicActivityInstance);
            }
        }

        List<String> highLightedActivities = Lists.newArrayList();
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
            highLightedActivities.add(historicActivityInstance.getActivityId());
        }
        // 计算活动线
        highLightedFlows = this.getHighLightedFlows((ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processDefinitionId), historicActivityInstances);

        // 不使用spring请使用下面的两行代码
        //	 ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl)ProcessEngines.getDefaultProcessEngine();
        //	 Context.setProcessEngineConfiguration(defaultProcessEngine.getProcessEngineConfiguration());

        // 使用spring注入引擎请使用下面的这行代码
        Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration());

        DefaultProcessDiagramGenerator processDiagramGeneratornew = new DefaultProcessDiagramGenerator();
        //return processDiagramGeneratornew.generateDiagram(bpmnModel, "png", activeActivityIds);
        return processDiagramGeneratornew.generateDiagram(bpmnModel, "png",
                highLightedActivities, highLightedFlows,
                processEngine.getProcessEngineConfiguration().getActivityFontName(),
                processEngine.getProcessEngineConfiguration().getLabelFontName(),
                executionId, processEngine.getProcessEngineConfiguration().getClassLoader(), 1.0);
    }

    /**
     * 获得高亮线
     *
     * @param processDefinitionEntity   流程定义实体
     * @param historicActivityInstances 历史活动实体
     * @return 线ID集合
     */
    public List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) {
        List<String> highFlows = new ArrayList<String>();// 用以保存高亮的线flowId
        for (int i = 0; i < historicActivityInstances.size(); i++) {// 对历史流程节点进行遍历
            ActivityImpl activityImpl1 = processDefinitionEntity
                    .findActivity(historicActivityInstances.get(i)
                            .getActivityId());// 得到节点定义的详细信息
            List<ActivityImpl> sameStartTimeNodes = new ArrayList<ActivityImpl>();// 用以保存后需开始时间相同的节点
            HistoricActivityInstance historicActivityInstance1 = historicActivityInstances
                    .get(i);// 后续第一个节点
            for (int j = 0; j < historicActivityInstances.size(); j++) {
                if (i == j) {
                    continue;
                }
                HistoricActivityInstance historicActivityInstance2 = historicActivityInstances
                        .get(j);// 后续第一个节点
                if (historicActivityInstance1.getEndTime() != null && historicActivityInstance1.getEndTime().equals(
                        historicActivityInstance2.getStartTime())) {
                    // 如果第一个节点的结束时间和第二个节点开始时间相同保存
                    ActivityImpl sameActivityImpl2 = processDefinitionEntity
                            .findActivity(historicActivityInstance2.getActivityId());
                    sameStartTimeNodes.add(sameActivityImpl2);
                }
            }
            List<PvmTransition> pvmTransitions = activityImpl1
                    .getOutgoingTransitions();// 取出节点的所有出去的线
            for (PvmTransition pvmTransition : pvmTransitions) {
                // 对所有的线进行遍历
                ActivityImpl pvmActivityImpl = (ActivityImpl) pvmTransition
                        .getDestination();
                // 如果取出的线的目标节点存在时间相同的节点里，保存该线的id，进行高亮显示
                if (sameStartTimeNodes.contains(pvmActivityImpl)) {
                    highFlows.add(pvmTransition.getId());
                }
            }

        }
        return highFlows;
    }

    /**
     * 流程跟踪图信息
     *
     * @param processInstanceId 流程实例ID
     * @return 封装了各种节点信息
     */
    public List<Map<String, Object>> traceProcess(String processInstanceId) throws Exception {
        Execution execution = runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();//执行实例
        Object property = PropertyUtils.getProperty(execution, "activityId");
        String activityId = "";
        if (property != null) {
            activityId = property.toString();
        }
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId)
                .singleResult();
        ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
        List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

        List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
        for (ActivityImpl activity : activitiList) {

            boolean currentActiviti = false;
            String id = activity.getId();

            // 当前节点
            if (id.equals(activityId)) {
                currentActiviti = true;
            }

            Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, processInstance, currentActiviti);

            activityInfos.add(activityImageInfo);
        }

        return activityInfos;
    }

    /**
     * 封装输出信息，包括：当前节点的X、Y坐标、变量信息、任务类型、任务描述
     *
     * @param activity
     * @param processInstance
     * @param currentActiviti
     * @return
     */
    private Map<String, Object> packageSingleActivitiInfo(ActivityImpl activity, ProcessInstance processInstance,
                                                          boolean currentActiviti) throws Exception {
        Map<String, Object> vars = new HashMap<String, Object>();
        Map<String, Object> activityInfo = new HashMap<String, Object>();
        activityInfo.put("currentActiviti", currentActiviti);
        setPosition(activity, activityInfo);
        setWidthAndHeight(activity, activityInfo);

        Map<String, Object> properties = activity.getProperties();
        vars.put("节点名称", properties.get("name"));
        vars.put("任务类型", ActUtils.parseToZhType(properties.get("type").toString()));

        ActivityBehavior activityBehavior = activity.getActivityBehavior();
        logger.debug("activityBehavior={}", activityBehavior);
        if (activityBehavior instanceof UserTaskActivityBehavior) {

            Task currentTask = null;

            // 当前节点的task
            if (currentActiviti) {
                currentTask = getCurrentTaskInfo(processInstance);
            }

            // 当前任务的分配角色
            UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activityBehavior;
            TaskDefinition taskDefinition = userTaskActivityBehavior.getTaskDefinition();
            Set<Expression> candidateGroupIdExpressions = taskDefinition.getCandidateGroupIdExpressions();
            if (!candidateGroupIdExpressions.isEmpty()) {

                // 任务的处理角色
                setTaskGroup(vars, candidateGroupIdExpressions);

                // 当前处理人
                if (currentTask != null) {
                    setCurrentTaskAssignee(vars, currentTask);
                }
            }
        }

        vars.put("节点说明", properties.get("documentation"));

        String description = activity.getProcessDefinition().getDescription();
        vars.put("描述", description);

        logger.debug("trace variables: {}", vars);
        activityInfo.put("vars", vars);
        return activityInfo;
    }

    /**
     * 设置任务组
     *
     * @param vars
     * @param candidateGroupIdExpressions
     */
    private void setTaskGroup(Map<String, Object> vars, Set<Expression> candidateGroupIdExpressions) {
        String roles = "";
        for (Expression expression : candidateGroupIdExpressions) {
            String expressionText = expression.getExpressionText();
            String roleName = identityService.createGroupQuery().groupId(expressionText).singleResult().getName();
            roles += roleName;
        }
        vars.put("任务所属角色", roles);
    }

    /**
     * 设置当前处理人信息
     *
     * @param vars
     * @param currentTask
     */
    private void setCurrentTaskAssignee(Map<String, Object> vars, Task currentTask) {
        String assignee = currentTask.getAssignee();
        if (assignee != null) {
            org.activiti.engine.identity.User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
            String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName();
            vars.put("当前处理人", userInfo);
        }
    }

    /**
     * 获取当前节点信息
     *
     * @param processInstance
     * @return
     */
    private Task getCurrentTaskInfo(ProcessInstance processInstance) {
        Task currentTask = null;
        try {
            String activitiId = (String) PropertyUtils.getProperty(processInstance, "activityId");
            logger.debug("current activity id: {}", activitiId);

            currentTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey(activitiId)
                    .singleResult();
            logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

        } catch (Exception e) {
            logger.error("can not get property activityId from processInstance: {}", processInstance);
        }
        return currentTask;
    }

    /**
     * 设置宽度、高度属性
     *
     * @param activity
     * @param activityInfo
     */
    private void setWidthAndHeight(ActivityImpl activity, Map<String, Object> activityInfo) {
        activityInfo.put("width", activity.getWidth());
        activityInfo.put("height", activity.getHeight());
    }

    /**
     * 设置坐标位置
     *
     * @param activity
     * @param activityInfo
     */
    private void setPosition(ActivityImpl activity, Map<String, Object> activityInfo) {
        activityInfo.put("x", activity.getX());
        activityInfo.put("y", activity.getY());
    }


    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void auditSave(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 经研所保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void economics(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            act.setComment("[同意] " + act.getComment());
//            vars.put("design", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
        } else {
            act.setComment("[驳回] " + act.getComment());
//            vars.put("design", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 施工保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void auditSave2(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[存在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
//        vars.put("processer", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 人工选择问题类型审批
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void artificialTask(Act act) {
        /*
         * pass1 = 设计变更
         * pass2 = 项目关闭
         * pass3 = 政策处理（城区道路）
         * pass4 = 驳回施工单位
         * pass5 = 政策处理（农场/民事）
         * */
        boolean pass1 = false;
        boolean pass2 = false;
        boolean pass3 = false;
        boolean pass4 = false;
        boolean pass5 = false;
        boolean pass6 = false;
        Map<String, Object> vars = Maps.newHashMap();
        //pass对应进入问题模块，pass4对应没有问题完成施工交底
        vars.put("pass", false);
        vars.put("pass1", false);
        vars.put("pass2", false);
        vars.put("pass4", false);
        vars.put("pass3", false);
        vars.put("pass5", false);
        vars.put("pass6", false);
        vars.put("countryside", false);
        String flag = act.getFlag();
        String[] split = flag.split(";");
        for (String a : split) {
            if ("pass1".equals(a)) {
                pass1 = true;
            } else if ("pass2".equals(a)) {
                pass2 = true;
            } else if ("pass3".equals(a)) {
                pass3 = true;
            } else if ("pass4".equals(a)) {
                pass4 = true;
            } else if ("pass5".equals(a)) {
                pass5 = true;
            } else if ("pass6".equals(a)) {
                pass6 = true;
            }
        }
        if (pass4 == true) {
            act.setComment("[完成施工交底]" + act.getComment());
            act.preUpdate();
            // 对不同环节的业务逻辑进行操作
            String taskDefKey = act.getTaskDefKey();
            // 提交流程任务
//            Project user = MyActiviUtils.findUser(act.getProcInsId());
//            vars.put("processer", UserUtils.getByUserName(user.getConstructionUnitRole()).getLoginName());
            vars.put("pass4", true);
        } else {
//            Project user = MyActiviUtils.findUser(act.getProcInsId());
            if (pass1 == true) {
                vars.put("pass1", true);
//                vars.put("design", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
            }
            if (pass2 == true) {
                vars.put("pass2", true);
//                vars.put("itemClose", UserUtils.getByUserName(user.getDistributionEngineering()).getLoginName());
            }
            if (pass3 == true) {
                vars.put("pass3", true);
//                vars.put("coveredPerson", UserUtils.getByUserName(user.getConstructionUnitRole()).getLoginName());
            }
            if (pass5 == true) {
                vars.put("pass5", true);
//                vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            }
            if (pass6 == true) {
                vars.put("countryside", true);
//                vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            }
            vars.put("problem", true);
            act.setComment("[存在问题]" + act.getComment());
            act.preUpdate();
            // 对不同环节的业务逻辑进行操作
            String taskDefKey = act.getTaskDefKey();
            // 提交流程任务
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);

    }

    /**
     * 交底:运行人员审核
     */
    @Transactional(readOnly = false)
    public void humanReview(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        act.preUpdate();
        String flag = act.getFlag();
        if ("design".equals(flag)) {
            vars.put("conditions", true);
            vars.put("close", false);
            vars.put("noProblem", false);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        } else if ("closed".equals(flag)) {
            vars.put("conditions", false);
            vars.put("close", true);
            vars.put("noProblem", false);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
        } else {
            vars.put("conditions", false);
            vars.put("close", false);
            vars.put("noProblem", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }



    /**
     * 交底:项目经理交底内容自动分发
     */
    @Transactional(readOnly = false)
    public void divideForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        act.preUpdate();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        if ("design".equals(flag)) {
            vars.put("conditions", true);
            vars.put("close", false);
            vars.put("noProblem", false);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        } else if ("closed".equals(flag)) {
            vars.put("conditions", false);
            vars.put("close", true);
            vars.put("noProblem", false);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
        } else {
            vars.put("conditions", false);
            vars.put("close", false);
            vars.put("noProblem", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 运行单位经理判定设计变更
     */
    @Transactional(readOnly = false)
    public void operator(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        vars.put("jys", false);
        vars.put("conditions", false);
        vars.put("return", false);
        //获取流程id
        String procInsId = act.getProcInsId();
        Project user = MyActiviUtils.findUser(procInsId);
        if ("yes".equals(flag)) {
            String demand = MyActiviUtils.demandByProcInsId(procInsId);
            if ("经研所".equals(demand)) {
                vars.put("jys", true);
                vars.put("design", UserUtils.getByUserName(user.getAssignment().getInstituteRole()).getLoginName());
            } else {
                vars.put("conditions", true);
                vars.put("design", UserUtils.getByUserName(user.getAssignment().getDesigner()).getLoginName());
            }
        } else {
            vars.put("importTable", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 项目经理判定是否需要设计变更
     */
    @Transactional(readOnly = false)
    public void managerDesign(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        if ("yes".equals(flag)) {
//            vars.put("design", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
        } else {

        }
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 设计单位人员提交文件
     */
    @Transactional(readOnly = false)
    public void designUpload(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        //根据登陆查询所属的角色
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDesigner()).getLoginName());
        } else {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网运行人员判断变更后材料
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void operatorUpload(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        //根据登陆查询所属的角色
        vars.put("pass", "yes".equals(flag) ? true : false);
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 设计单位人员调整文件
     */
    @Transactional(readOnly = false)
    public void operatorAfter(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 运行经理审核设计变更后
     */
    @Transactional(readOnly = false)
    public void managerUpload(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        //发给施工单位人员审核
        if ("yes".equals(flag)) {
/*            String s = constructionService.idProjectName(act.getProcInsId());
            OaNotify oaNotify = new OaNotify();
            oaNotify.setType("8");
            oaNotify.setTitle(s + "设计变更完成");
            oaNotify.setStatus("1");
            oaNotify.setFiles(act.getProcInsId());*/
//            oaNotify.setOaNotifyRecordIds(byUserName.getId());
            //根据流程实例id查询对应的项目信息（如果没有，发送通知，没有该项目计划信息）
//            oaNotify.setContent(s + "：设计变更完成");
//            oaNotifyService.save(oaNotify);
//            List<OaNotifyRecord> list = oaNotify.getOaNotifyRecordList();
//            for (OaNotifyRecord o : list) {
//                发送通知到客户端
//                ServletContext context = SpringContextHolder.getBean(ServletContext.class);
//                new SystemInfoSocketHandler().sendMessageToUser(byUserName.getLoginName(), "收到一条新通知，请到我的通知查看！");
//            }
            //发送通知
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else {
            //驳回
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDesigner()).getLoginName());
        }
        //根据登陆查询所属的角色
        vars.put("pass", "yes".equals(flag) ? true : false);
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 配网经理审核设计变更后
     * */
    @Transactional(readOnly = false)
    public void afterDistribution(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        //发给施工单位人员审核
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());

        } else {
            //驳回
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDesigner()).getLoginName());
        }
        //根据登陆查询所属的角色
        vars.put("pass", "yes".equals(flag) ? true : false);
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位判断变更后材料
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void conAfterChange(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        //完成施工交底
        if ("yes".equals(flag)) {
        } else {
            //驳回
//            vars.put("design", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
        }
        //根据登陆查询所属的角色
        vars.put("pass", "yes".equals(flag) ? true : false);
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 经理保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void auditSave3(Act act, Disclose disclose, Boolean flagDesign, Boolean flagItemCLose, String flagDeal) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[存在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        /**
         * problem pass pass4 是互斥网关，同时只能执行一条线路
         * */
        //代表进入问题模块
        vars.put("problem", false);
        //没有问题
        vars.put("pass", false);
        //项目经理人工判断问题
        vars.put("pass4", false);

        /**
         * pass1 pass2 pass3 pass5 分别对应了问题模块不同的问题类型
         * pass2不可以与其它三个同时发起
         * pass3 pass5 只可同时发起一种
         * */
        //设计变更
        vars.put("pass1", false);
        //项目关闭
        vars.put("pass2", false);
        //行政政处（城区道路）
        vars.put("pass3", false);
        //1·农村政处2·民事政处/行政政处（公路/水利）
        vars.put("pass5", false);
        //获取前置条件不为空就进入项目经理人工判断问题类型
        /*if (null != disclose.getPrecondition() && !"".equals(disclose.getPrecondition())) {
            vars.put("pass4", true);
        } else {
            //如果符合项目关闭，步入项目关闭，其它问题类型不触发
            if (flagItemCLose) {
                vars.put("itemClose", "专职");
                vars.put("pass2", true);
                vars.put("problem", true);
            } else {
                //当不符合设计变更，项目关闭，政处处理时，判定项目没有问题，完成施工交底
                if (!flagDesign && "init".equals(flagDeal)) {
                    vars.put("pass", true);
                } else {
                    //判断是否符合设计变更条件，符合
                    if (flagDesign) {
                        vars.put("design", "运行人员");
                        vars.put("pass1", true);
                    }
                    //查看政处类型步入不同的问题模块
                    if ("民事农村".equals(flagDeal)) {
                        vars.put("policy", "政策处理");
                        vars.put("pass5", true);
                    } else if ("行政".equals(flagDeal)) {
                        vars.put("coveredPerson", "施工单位");
                        vars.put("pass3", true);
                    }
                }
            }
        }*/
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 交底:判断项目是否需要关闭
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void specially(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        if ("yes".equals(flag)) {
//            Project user = MyActiviUtils.findUser(act.getProcInsId());
//            vars.put("operators", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());

        } else {
            //驳回到项目经理人工判断问题
//            Project user = MyActiviUtils.findUser(act.getProcInsId());
//            vars.put("processer", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
        }
//		vars.put("yes".equals(act.getFlag())?"operators":"processer",fullName);
        vars.put("flagNo", "yes".equals(act.getFlag()) ? false : true);
        vars.put("flagYes", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 保存项目关闭 项目经理选择
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void managerFormTask(Act act, String fullName) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[存在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        if ("yes".equals(act.getFlag())) {
            vars.put("itemClose", fullName);
            vars.put("managerYes", true);
            vars.put("managerNo", false);
        } else {
            vars.put("managerYes", false);
            vars.put("managerNo", true);
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 项目关闭 配网运行人员
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void addMember(Act act, String fullTime) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        String flag = act.getFlag();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
//            vars.put("systemfulltime", UserUtils.getByUserName(user.getDistributionSystem()).getLoginName());
        } else {
//            vars.put("itemClose", UserUtils.getByUserName(user.getDistributionEngineering()).getLoginName());
        }
//		vars.put("yes".equals(act.getFlag())?"systemfulltime":"itemClose","yes".equals(act.getFlag())?fullTime:fullTime);
        vars.put("systemNo", "yes".equals(act.getFlag()) ? false : true);
        vars.put("systemYes", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 是否可以政策处理（农场/民事）
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void policiesChange(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass1", false);
        vars.put("pass2", false);
        vars.put("pass3", false);
        vars.put("reject", false);
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("pass3".equals(flag)) {
            vars.put("pass3", true);
            vars.put("policy", UserUtils.getUser().getLoginName());
            act.setComment("[通过]" + act.getComment());
        } else if ("pass1".equals(flag)) {
            vars.put("pass1", true);
//            vars.put("design", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
            act.setComment("[设计变更]" + act.getComment());
        } else if ("pass2".equals(flag)) {
            vars.put("pass2", true);
//            vars.put("itemClose", UserUtils.getByUserName(user.getDistributionEngineering()).getLoginName());
            act.setComment("[项目关闭]" + act.getComment());
        } else if ("reject".equals(flag)) {
            vars.put("reject", true);
//            vars.put("policy", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
            act.setComment("[驳回]" + act.getComment());
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 项目经理重新审核是否可以政策处理
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void managerPolicesChange(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【需要政策处理】" + act.getComment());
        } else {
            act.setComment("【无需政策处理】" + act.getComment());
        }
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 上传未签字版政策处理清单
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void notSignUpload(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【未签字版清单】" + act.getComment());
        } else {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【驳回】" + act.getComment());
        }
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 上传签字版政策处理清单
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void signUploadList(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【签字版清单】" + act.getComment());
        } else {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【驳回】" + act.getComment());
        }
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 上传签字版合同
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void contractUploadList(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【签字版合同】" + act.getComment());
        } else {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【驳回】" + act.getComment());
        }
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 上传签字版合同
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void loanUploadList(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
//        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            act.setComment("【完成政策处理】" + act.getComment());
        } else {
//            vars.put("policy", UserUtils.getByUserName(user.getDistributionPolicy()).getLoginName());
            act.setComment("【驳回】" + act.getComment());
        }
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 保存项目关闭 运行人员审批意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void addDepartment(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[存在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 政策处理
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void policiesDeal(Act act, String fullName) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[没有问题] " : "[存在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("yes".equals(act.getFlag()) ? "coveredPerson" : "coveredPerson", "yes".equals(act.getFlag()) ? fullName : fullName);
        vars.put("coveredNo", "yes".equals(act.getFlag()) ? false : true);
        vars.put("coveredYes", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 项目经理判定是否关闭
     */
    @Transactional(readOnly = false)
    public void coveredForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
        } else {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getInspectionUnit()).getLoginName());
        }
        vars.put("pass", "yes".equals(flag) ? true : false);
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网工程专职判定是否关闭
     */
    @Transactional(readOnly = false)
    public void sealForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        if ("yes".equals(flag)) {
            vars.put("receiptPerson", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
        } else {
            vars.put("receiptPerson", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        vars.put("pass", "yes".equals(flag) ? true : false);
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 政策处理：项目经理
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void phaseManager(Act act, String fullName) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        vars.put("phaseYes", false);
        vars.put("phaseNo", false);
        if ("yes".equals(flag)) {
            String manager2 = MyActiviUtils.findHistoryActivity(act.getProcInsId(), "交底:上传未盖章施工方案(行政政处(城区道路))");
            vars.put("coveredPerson", manager2);
            act.setComment("[重新发起]" + act.getComment());
            vars.put("phaseYes", true);
        } else {
            act.setComment("[无需发起，结束流程]" + act.getComment());
            vars.put("phaseNo", true);
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 政策处理：配网政策处理专职 : 收据
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void receiptForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        vars.put("determine", false);
        vars.put("pass", false);
        vars.put("return", false);
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("determine".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistributionSystem()).getLoginName());
            act.setComment("[确认关闭]" + act.getComment());
            vars.put("determine", true);
        } else if ("pass".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
            act.setComment("[判定变更或关闭]" + act.getComment());
            vars.put("pass", true);
        } else {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistribution()).getLoginName());
            act.setComment("[驳回]" + act.getComment());
            vars.put("return", true);
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网工程专职判定变更或关闭
     */
    @Transactional(readOnly = false)
    public void singleForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDesigner()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网项目经理判定变更或关闭
     */
    @Transactional(readOnly = false)
    public void documentsForm(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("close", false);
        vars.put("conditions", false);
        vars.put("return", false);
        if ("close".equals(flag)) {
            vars.put("close", true);
        } else if ("design".equals(flag)) {
            vars.put("conditions", true);
            //配网运行人员
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else if ("no".equals(flag)) {
            vars.put("return", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        //变更项目状态

        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网系统专职确认系统关闭
     */
    @Transactional(readOnly = false)
    public void confirmClose(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        constructionService.updateCloseStatus(act.getProcInsId());
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void newAuditSave(Act act, String tuser, Construction construction) {

//		String comment = act.getComment();
        // 设置意见
//		constructionService.save(construction);
        if ("manager".equals(act.getFlag())) {
            act.setComment(act.getComment());
        } else if ("company".equals(act.getFlag())) {
            act.setComment(act.getComment());
        } else {
            act.setComment(act.getComment());
        }
//		act.setComment(("yes".equals(act.getFlag())?"[同意] ":"[驳回] ")+act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
//		Map<String, Object> vars = Maps.newHashMap();
        Map<String, Object> vars = new HashMap<>();
        String flag = act.getFlag();
        if ("manager".equals(flag)) {
            vars.put("manager", true);
            vars.put("company", false);
            vars.put("reject", false);
            if (tuser != null || tuser != "") {
                String loginName = UserUtils.getByLoginName(tuser).getLoginName();
                vars.put("processer", loginName);
            }
        } else if ("company".equals(flag)) {
            vars.put("manager", false);
            vars.put("company", true);
            vars.put("reject", false);
            String loginName = UserUtils.getUser().getLoginName();
            vars.put("processer", loginName);
        } else {
            vars.put("manager", false);
            vars.put("company", false);
            vars.put("reject", true);
        }
        constructionService.newUpdate(construction);
//		vars.put("processer", UserUtils.get(construction.getTuser().getId()).getLoginName());
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 判断下一个节点是互斥网关还是用户任务节点
     *
     * @param processInstanceId 任务Id信息
     * @return 下一个用户任务用户组信息
     * @throws Exception
     */
    public boolean isNextGatewaty(String processInstanceId) {

        ProcessDefinitionEntity processDefinitionEntity = null;

        String id = null;

        ActivityImpl nextActivityImpl = null;

        //获取流程实例Id信息
        //String processInstanceId = taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId();


        //获取流程发布Id信息
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if (processInstance == null) {
            return false;
        }
        String definitionId = processInstance.getProcessDefinitionId();

        processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(definitionId);

        ExecutionEntity execution = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

        //当前流程节点Id信息
        String activitiId = execution.getActivityId();

        //获取流程所有节点信息
        List<ActivityImpl> activitiList = processDefinitionEntity.getActivities();

        //遍历所有节点信息
        for (ActivityImpl activityImpl : activitiList) {
            id = activityImpl.getId();
            if (activitiId.equals(id)) {
                //获取下一个节点信息
                {

                    PvmActivity ac = null;

                    Object s = null;

                    // 如果遍历节点为用户任务并且节点不是当前节点信息
                    if ("userTask".equals(activityImpl.getProperty("type")) && !activitiId.equals(activityImpl.getId())) {
                        // 获取该节点下一个节点信息
                        TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activityImpl.getActivityBehavior())
                                .getTaskDefinition();
                        return false;
                    } else if ("exclusiveGateway".equals(activityImpl.getProperty("type"))) {// 当前节点为exclusiveGateway
                        List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions();
                        //outTransitionsTemp = ac.getOutgoingTransitions();

                        // 如果网关路线判断条件为空信息
//          if (StringUtils.isEmpty(elString)) {
                        // 获取流程启动时设置的网关判断条件信息
                        String elString = getGatewayCondition(activityImpl.getId(), processInstanceId);
//          }
                        // 如果排他网关只有一条线路信息
                        if (outTransitions.size() == 1) {
                            return false;
                        } else if (outTransitions.size() > 1) { // 如果排他网关有多条线路信息
                            return true;
                        }
                    } else {
                        // 获取节点所有流向线路信息
                        List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions();
                        List<PvmTransition> outTransitionsTemp = null;
                        for (PvmTransition tr : outTransitions) {
                            ac = tr.getDestination(); // 获取线路的终点节点
                            // 如果流向线路为排他网关
                            if ("exclusiveGateway".equals(ac.getProperty("type"))) {
                                return true;
                            } else if ("userTask".equals(ac.getProperty("type"))) {
                                return false;
                            } else {
                                return false;
                            }
                        }
                        return false;
                    }
                    return false;
                }
            }
        }

        return false;
    }


    /**
     * 下一个任务节点信息,
     * <p>
     * 如果下一个节点为用户任务则直接返回,
     * <p>
     * 如果下一个节点为排他网关, 获取排他网关Id信息, 根据排他网关Id信息和execution获取流程实例排他网关Id为key的变量值,
     * 根据变量值分别执行排他网关后线路中的el表达式, 并找到el表达式通过的线路后的用户任务
     *
     * @param activityImpl      流程节点信息
     * @param activityId        当前流程节点Id信息
     * @param elString          排他网关顺序流线段判断条件
     * @param processInstanceId 流程实例Id信息
     * @return
     */
    private TaskDefinition nextTaskDefinition(ActivityImpl activityImpl, String activityId, String elString, String processInstanceId) {

        PvmActivity ac = null;

        Object s = null;

        // 如果遍历节点为用户任务并且节点不是当前节点信息
        if ("userTask".equals(activityImpl.getProperty("type")) && !activityId.equals(activityImpl.getId())) {
            // 获取该节点下一个节点信息
            TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activityImpl.getActivityBehavior())
                    .getTaskDefinition();
            return taskDefinition;
        } else if ("exclusiveGateway".equals(activityImpl.getProperty("type"))) {// 当前节点为exclusiveGateway
            List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions();
            //outTransitionsTemp = ac.getOutgoingTransitions();

            // 如果网关路线判断条件为空信息
//          if (StringUtils.isEmpty(elString)) {
            // 获取流程启动时设置的网关判断条件信息
            elString = getGatewayCondition(activityImpl.getId(), processInstanceId);
//          }
            // 如果排他网关只有一条线路信息
            if (outTransitions.size() == 1) {
                return nextTaskDefinition((ActivityImpl) outTransitions.get(0).getDestination(), activityId,
                        elString, processInstanceId);
            } else if (outTransitions.size() > 1) { // 如果排他网关有多条线路信息
                for (PvmTransition tr1 : outTransitions) {
                    s = tr1.getProperty("conditionText"); // 获取排他网关线路判断条件信息
                    // 判断el表达式是否成立
                    if (isCondition(activityImpl.getId(), StringUtils.trim(s.toString()), elString)) {
                        return nextTaskDefinition((ActivityImpl) tr1.getDestination(), activityId, elString,
                                processInstanceId);
                    }

                }
            }
        } else {
            // 获取节点所有流向线路信息
            List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions();
            List<PvmTransition> outTransitionsTemp = null;
            for (PvmTransition tr : outTransitions) {
                ac = tr.getDestination(); // 获取线路的终点节点
                // 如果流向线路为排他网关
                if ("exclusiveGateway".equals(ac.getProperty("type"))) {
                    outTransitionsTemp = ac.getOutgoingTransitions();

                    // 如果网关路线判断条件为空信息
                    if (StringUtils.isEmpty(elString)) {
                        // 获取流程启动时设置的网关判断条件信息
                        elString = getGatewayCondition(ac.getId(), processInstanceId);
                    }

                    // 如果排他网关只有一条线路信息
                    if (outTransitionsTemp.size() == 1) {
                        return nextTaskDefinition((ActivityImpl) outTransitionsTemp.get(0).getDestination(), activityId,
                                elString, processInstanceId);
                    } else if (outTransitionsTemp.size() > 1) { // 如果排他网关有多条线路信息
                        for (PvmTransition tr1 : outTransitionsTemp) {
                            s = tr1.getProperty("conditionText"); // 获取排他网关线路判断条件信息
                            // 判断el表达式是否成立
                            if (isCondition(ac.getId(), StringUtils.trim(s.toString()), elString)) {
                                return nextTaskDefinition((ActivityImpl) tr1.getDestination(), activityId, elString,
                                        processInstanceId);
                            }
                        }
                    }
                } else if ("userTask".equals(ac.getProperty("type"))) {
                    return ((UserTaskActivityBehavior) ((ActivityImpl) ac).getActivityBehavior()).getTaskDefinition();
                } else {
                }
            }
            return null;
        }
        return null;
    }

    /**
     * 查询流程启动时设置排他网关判断条件信息
     *
     * @param gatewayId         排他网关Id信息, 流程启动时设置网关路线判断条件key为网关Id信息
     * @param processInstanceId 流程实例Id信息
     * @return
     */
    public String getGatewayCondition(String gatewayId, String processInstanceId) {
        Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult();
        Object object = runtimeService.getVariable(execution.getId(), gatewayId);
        return object == null ? "" : object.toString();
    }

    /**
     * 根据key和value判断el表达式是否通过信息
     *
     * @param key   el表达式key信息
     * @param el    el表达式信息
     * @param value el表达式传入值信息
     * @return
     */
    public boolean isCondition(String key, String el, String value) {
        ExpressionFactory factory = new ExpressionFactoryImpl();
        SimpleContext context = new SimpleContext();
        context.setVariable(key, factory.createValueExpression(value, String.class));
        ValueExpression e = factory.createValueExpression(context, el, boolean.class);
        return (Boolean) e.getValue(context);
    }

    //项目关闭
    public Boolean isJudgeItemClose(Disclose disclose) {
        Boolean flag = false;
        /*if (null != disclose.getChannel() && disclose.getChannel().equals("无")) {//施工通道
            flag = true;
        }
        if (null != disclose.getHiddenDanger() && disclose.getHiddenDanger().equals("有")) {
            flag = true;
        }
        if (null != disclose.getInfluenceConstruction() && disclose.getInfluenceConstruction().equals("有")) {
            flag = true;
        }
        if (null != disclose.getProjectRepetition() && disclose.getProjectRepetition().equals("是")) {
            flag = true;
        }
        if (null != disclose.getImplemented() && disclose.getImplemented().equals("是")) {
            flag = true;
        }
        if (null != disclose.getTransformer() && disclose.getTransformer().equals("有")) {
            flag = true;
        }*/
        //必要性说明
//		if (null!=disclose.getTransformer()&&disclose.getTransformer().equals("有")){
//			flag =true;
//		}
        return flag;
    }

    //设计变更
    public Boolean isJudgeDesign(Disclose disclose) {
        Boolean flag = false;
        /*if (null != disclose.getLineName() && disclose.getLineName().equals("否")) {
            flag = true;
        }
        if (null != disclose.getQuantities() && disclose.getQuantities().equals("否")) {
            flag = true;
        }
        if (null != disclose.getRodNumber() && disclose.getRodNumber().equals("否")) {
            flag = true;
        }*/
        return flag;
    }

    public Boolean isJudgeDeal(Disclose disclose) {
        Boolean flag = false;
/*        if (null != disclose.getAdministrationType()) {
            if (disclose.getAdministrationType().contains("民事证处") ||
                    disclose.getAdministrationType().contains("行政证处") ||
                    disclose.getAdministrationType().contains("农村证处")) {
                flag = true;
            }
        }*/
//		if (null!)
        return flag;
    }

    public String newJudgeDeal(Disclose disclose) {
        String flag = "init";
        String a = "";
        /*if (null != disclose.getAdministrationType()) {
            if (disclose.getAdministrationType().contains("民事政处") || disclose.getAdministrationType().contains("农村政处")) {
                flag = "民事农村";
            } else if (disclose.getAdministrationType().indexOf("城区道路") >= 0) {
                flag = "行政";
            }
        }*/
//		if (null!)
        return flag;
    }

    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void pickIng(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
//        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
//        vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitLeader()).getLoginName());
//		complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void materialReport(Act act,String selectNumber,String reserveName) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        String loginName = UserUtils.getByUserName("沈忱").getLoginName();
        vars.put("person", loginName);
        //保存物料上报流程信息
        MaterialReport materialReport = new MaterialReport();
        materialReport.setProjectName(reserveName);
        //保存流程定义
        showListService.materialReportSave(materialReport);
        ProcessDefinition p = actProcessService.getProcessDefinition(act.getProcDefId());
        String title = UserUtils.getUser().getName() + "在" + DateUtils.getDateTime() + "发起" + p.getName();
        String procInsId = actTaskService.startProcessNew(p.getKey(), "md_material_report_application", materialReport.getId(), title, vars);
        List<ShowList> showLists = MyActiviUtils.finaList(selectNumber);
        for (ShowList a : showLists) {
            a.preInsert();
            a.setProcInsId(procInsId);
            a.setReserveName(reserveName);
        }
        pickIngService.processTemReportList(showLists);
        //complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public Boolean materialReportBillOff(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);

        //获取当前流程的材料数据
        List<ShowList> procInsIdMaterialReport = pickIngService.findProcInsIdMaterialReport(act.getProcInsId());
        //赋值
        List<MaterialProject> materialProjects = new ArrayList<MaterialProject>();
        List<MaterialInfo> materialInfos = new ArrayList<MaterialInfo>();
        MaterialProject materialProject = null;
        MaterialInfo materialInfo = null;
        String reserveProjectName = "";
        for (ShowList showList:procInsIdMaterialReport){
            //获取储备名称名字
            reserveProjectName = showList.getReserveName();
            //获取明细数据（此处可优化为反射）
            materialInfo = new MaterialInfo();
            materialInfo.setProjectName(showList.getReserveName());//项目名称
            materialInfo.setMaterialCode(showList.getMaterialCode());//物料编码
            materialInfo.setMaterialName(showList.getMaterialDescription());//物料描述
            materialInfo.setExtendDescription(showList.getExtensionDescription());//扩展描述
            materialInfo.setUnit(showList.getMdUnits());//单位
            materialInfo.setTotalCount(showList.getMdTotalAmount());//总量
            materialInfo.setWeightTon(showList.getMdSingleWeight());//单重kg
            materialInfo.setSupplyType(showList.getMdTheParty());//甲乙供
            materialInfo.setNote(showList.getMdText());//备注
            materialInfo.preInsert();
            materialInfos.add(materialInfo);
        }

        materialProject = new MaterialProject();
        materialProject.setReserveProjectName(reserveProjectName);
        if (reserveProjectName!=""){
            List<MaterialProject> list = materialProjectMapper.findJugdeReserve(materialProject);
            if (list.size() > 0){
                return true;
            }
        }
        materialProject.preInsert();
        materialProjects.add(materialProject);
        ////添加年度物料上报统计
        materialProjectMapper.insertList(materialProjects);
        //添加月度物资上报明细
        materialInfoMapper.insertList(materialInfos);
        //原始数据
        materialInfoMapper.insertOldList(materialInfos);
        //根据流程删除临时表
        pickIngService.deleteProcInsIdMaterialReport(act.getProcInsId());

        return false;
    }

    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void managerExam(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        ShowList showList = new ShowList();
        showList.setAct(act);
        List<ShowList> newTemList = showListService.findNewTemList(showList);
        pickIngService.processList(newTemList);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionLeader()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 施工单位领导审核-物资领料
     */
    @Transactional(readOnly = false)
    public void constructionLeader(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        String loginName = UserUtils.getByUserName(user.getAssignment().getConstructionFullTime()).getLoginName();
        String loginName1 = UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName();
        vars.put("manager", "yes".equals(flag) ? loginName : loginName1);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位物资专职审核
     */
    @Transactional(readOnly = false)
    public void fullExamine(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        String loginName = UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName();
        String loginName1 = UserUtils.getByUserName(user.getAssignment().getConstructionLeader()).getLoginName();
        vars.put("manager", "yes".equals(flag) ? loginName : loginName1);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 项目中心领导审核领料单
     */
    @Transactional(readOnly = false)
    public void leaderExamine(Act act) {
        String flag = act.getFlag();

        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        if ("yes".equals(flag)) {
            showListService.updateManagerTime(act.getProcInsId());
        }
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        String loginName = UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName();
        vars.put("manager", "yes".equals(flag) ? "" : loginName);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
        //自动发起验收流程
    }

    /**managerAudit
     * 配网项目经理审核领料单
     */
    @Transactional(readOnly = false)
    public void managerAudit(Act act) {
        String flag = act.getFlag();

        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        String loginName = UserUtils.getByUserName(user.getAssignment().getDistributionFullTime()).getLoginName();
        String loginName1 = UserUtils.getByUserName(user.getAssignment().getConstructionFullTime()).getLoginName();
        vars.put("manager", "yes".equals(flag) ? loginName : loginName1);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网物资专职审核领料单
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void netExamine(Act act) {
        String flag = act.getFlag();

        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findWZUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            showListService.updateManagerTime(act.getProcInsId());
        }
        String loginName1 = UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName();
        vars.put("manager", "yes".equals(flag) ? "" : loginName1);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 结算填写现场使用量
     */
    @Transactional(readOnly = false)
    public void useQuantity(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
//        Project user = MyActiviUtils.findJSUser(act.getProcInsId());
//        String loginName = UserUtils.getByUserName(user.getProjectManageRole()).getLoginName();
//        vars.put("manager", loginName);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 复合数量修改
     */
    @Transactional(readOnly = false)
    public void reviewQuantity(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
//        Project user = MyActiviUtils.findJSUser(act.getProcInsId());
//        String loginName = UserUtils.getByUserName(user.getProjectManageRole()).getLoginName();
//        vars.put("manager", loginName);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 结算填写现场使用量
     */
    @Transactional(readOnly = false)
    public void returnDoc(Act act) {
        String flag = act.getFlag();
        //设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        //对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        //提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 保存审核意见
     * @param act
     */
    @Transactional(readOnly = false)
    public void auditDrawings(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        String flag = act.getFlag();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("design", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 保存审核意见
     */
    @Transactional(readOnly = false)
    public void applicationAudit(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        String info = "";
        //选择项目发起请求
        String flag = act.getFlag();
        String procInsId = act.getProcInsId();
        Project1 nameByInsID = constructionService.findNameByInsID(procInsId);
        if ("yes".equals(flag)) {
            PickApplication pickApplication = new PickApplication();
            pickApplication.setProjectId(nameByInsID.getId());
            info = nameByInsID.getRequireName() + "项目通过审核";
            showListService.projectUpdate(pickApplication);
        } else {
            info = nameByInsID.getRequireName() + "项目没有通过审核";
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 保存审核意见
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void contructionManager(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        String status = "";
        //选择项目发起请求
        String flag = act.getFlag();
        String procInsId = act.getProcInsId();
        Project1 project = constructionService.findNameByInsID(procInsId);
        Advance advance = new Advance();
        advance.setId(project.getId());
        if ("yes".equals(flag)) {
            status = project.getRequireName() + "提前施工通过";
            advance.setPreConstruction(1);
        } else {
            status = project.getRequireName() + "提前施工未通过";
            advance.setPreConstruction(0);
        }
        advanceService.updatePreConstruction(advance);
//		act.setComment(("yes".equals(act.getFlag())?"[同意] ":"[驳回] ")+act.getComment());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位项目经理土建开工流程-填写土建开工报告
     */
    @Transactional(readOnly = false)
    public void nonPowerStartTask(Act act) {
        // 设置意见
        act.setComment(act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息-土建流程
        Project user = MyActiviUtils.findTJUser(act.getProcInsId());
//        根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 电气开工流程提交文件
     */
    @Transactional(readOnly = false)
    public void electricalStartTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        vars.put("pass", true);
        //根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位项目经理土建施工中流程提交文件
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void nonPowerMiddleTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
//        vars.put("manager", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位项目经理电气施工中流程提交文件
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void electricalMiddleTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
//        vars.put("manager", UserUtils.getByUserName(user.getRunUnitRole()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 电气竣工流程
     */
    @Transactional(readOnly = false)
    public void electricalEndTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 上传涉电开工资料
     * */
    @Transactional(readOnly = false)
    public void powerFileTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 审核土建施工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void nonRePowerMiddleTask(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[没有问题] " : "[纯在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        } else {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 审核土建竣工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void nonRePowerEndTask(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[没有问题] " : "[纯在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findTJUser(act.getProcInsId());
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
        } else {
            //根据项目设置的流转人员，流转对应人员
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 审核涉电施工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void rePowerEnd(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[没有问题] " : "[纯在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else {
            //根据项目设置的流转人员，流转对应人员
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 审核电气竣工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void reElectricalEndTask(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[没有问题] " : "[纯在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        vars.put("noContain", false);
        vars.put("contain", false);
        vars.put("pass", false);
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
            vars.put("contain", true);
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        } else if ("noContain".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
            vars.put("noContain", true);
        } else {
            vars.put("pass", true);
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 审核土建施工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void reElectricalMiddleTask(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[没有问题] " : "[纯在问题] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        } else {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 土建竣工流程
     */
    @Transactional(readOnly = false)
    public void nonPowerEndTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("return",false);
        vars.put("re",false);
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findTJUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
        if ("yes".equals(act.getFlag())) {
                vars.put("re", true);
                vars.put("manager", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else {
            vars.put("return",true);
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 土建在线审核流程
     * */
    @Transactional(readOnly = false)
    public void acceptanceTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findTJUser(act.getProcInsId());
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        if ("yes".equals(act.getFlag())) {
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        } else {
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        //根据项目设置的流转人员，流转对应人员
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }


    /**
     * 配网项目经理判断是否完成土建工作
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void reviewNonPower(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
//        MaterialModule byProcInsId = materialModuleService.findByProcInsId(act.getProcInsId());
        Map<String, Object> vars = Maps.newHashMap();

/*        Integer nonPower = byProcInsId.getNonPower();
        Integer electrical = byProcInsId.getElectrical();
        Integer power = byProcInsId.getPower();
        // 提交流程任务
        if (nonPower == 0 && electrical == 0 && power == 1) {
            vars.put("contain", true);
        } else if (nonPower == 0 && electrical == 0 && power == 0) {
            vars.put("contain", false);
        }
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        } else {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
        }*/
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网项目经理判断是否完成电气工作
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void reviewElectrical(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
//        MaterialModule byProcInsId = materialModuleService.findByProcInsId(act.getProcInsId());
        Map<String, Object> vars = Maps.newHashMap();

/*        Integer nonPower = byProcInsId.getNonPower();
        Integer electrical = byProcInsId.getElectrical();
        Integer power = byProcInsId.getPower();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        if (nonPower == 0 && electrical == 0 && power == 1) {
            vars.put("contain", true);
        } else if (nonPower == 0 && electrical == 0 && power == 0) {
            vars.put("contain", false);
        }
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getConstructionUnitManage()).getLoginName());
        } else {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", UserUtils.getByUserName(user.getProjectManageRole()).getLoginName());
        }*/
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位项目经理判断是否包含涉电工作
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void managerWhetherTask(Act act) {
        String flag = act.getFlag();
        // 设置意见
        act.setComment(("yes".equals(flag) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
//        Project user = MyActiviUtils.sgFindUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            //根据项目设置的流转人员，流转对应人员
//            vars.put("manager", user.getConstructionUnitManage());
            vars.put("yes", true);
            vars.put("no", false);
        } else {
            //根据项目设置的流转人员，流转对应人员
            vars.put("yes", false);
            vars.put("no", true);
        }
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 施工单位项目经理 涉电开工流程提交文件
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void PowerStartTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        vars.put("pass", true);
        //根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 涉电竣工流程
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void PowerEndTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        //根据项目设置的流转人员，流转对应人员
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getRepUnit()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 配网项目经理判断涉电工作
     *
     * @param act
     */
    @Transactional(readOnly = false)
    public void PowerWhetherTask(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        //根据流程实例id查询项目的相关信息
        Project user = MyActiviUtils.findSGUser(act.getProcInsId());
        String flag = act.getFlag();
        if ("finish".equals(flag)) {
            act.setComment("[完成]" + act.getComment());
            vars.put("finish", true);
            vars.put("second", false);
            vars.put("no", false);
        } else if ("second".equals(flag)) {
            act.setComment("[纯在二次涉电]" + act.getComment());
            vars.put("finish", false);
            vars.put("second", true);
            vars.put("no", false);
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        } else {
            act.setComment("[审核不通过]" + act.getComment());
            vars.put("finish", false);
            vars.put("second", false);
            vars.put("no", true);
            vars.put("manager", UserUtils.getByUserName(user.getAssignment().getConstructionManage()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 对不同环节的业务逻辑进行操作
        String taskDefKey = act.getTaskDefKey();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 导入材料表和拆旧物资表
     */
    @Transactional(readOnly = false)
    public void importTable(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 导入工程量
     */
    @Transactional(readOnly = false)
    public void engineering(Act act, Construction construction) {
        Map<String, Object> vars = Maps.newHashMap();
        vars.put("no", false);
        vars.put("pass", false);
        vars.put("rural", false);
        vars.put("administrative", false);
        vars.put("civil", false);
        String flag = act.getFlag();
        if ("yes".equals(flag)) {
            String processingType = construction.getQuantity().getProcessingType();
            if ("".equals(processingType)) {
                vars.put("pass", true);
            } else {
                String[] split = processingType.split(",");
                for (String a : split) {
                    if ("农村政处".equals(a)) {
                        vars.put("rural", true);
                    }
                    if ("行政政处".equals(a)) {
                        vars.put("administrative", true);
                    }
                    if ("民事政处".equals(a)) {
                        vars.put("civil", true);
                    }
                }
            }
        } else {
            vars.put("no", true);
        }
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 政处是否自己进行
     */
    @Transactional(readOnly = false)
    public void ruralOffice(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        String flag = act.getFlag();
        vars.put("pass", "yes".equals(flag) ? true : false);
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistributionPolicy()).getLoginName());
        } else {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 农村专职判断
     */
    @Transactional(readOnly = false)
    public void ruralJudge(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        vars.put("conditions",false);
        vars.put("close",false);
        vars.put("pass",false);
        vars.put("return", false);
        if ("conditions".equals(flag)) {
            vars.put("conditions", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("close".equals(flag)) {
            vars.put("close", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("pass".equals(flag)) {
            vars.put("pass", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getDistributionPolicy()).getLoginName());
        }
        if ("no".equals(flag)) {
            vars.put("return", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 是否需要行政政处
     */
    @Transactional(readOnly = false)
    public void needAdministrativeOffice(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        vars.put("pass", "pass".equals(flag) ? true : false);
        if ("pass".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("no".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 是否需要继续民事政策处理
     * */
    @Transactional(readOnly = false)
    public void needCivilOffice(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("no".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 是否需要继续农村政处
     * */
    @Transactional(readOnly = false)
    public void needRuralOffice(Act act) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String flag = act.getFlag();
        vars.put("pass", "yes".equals(flag) ? true : false);
        if ("yes".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("no".equals(flag)) {
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    @Transactional(readOnly = false)
    public void ruralFiles(Act act, Construction construction) {
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findUser(act.getProcInsId());
        String ifBorrow = construction.getIfBorrow();
        vars.put("pay", false);
        vars.put("loan", false);
        if ("否".equals(ifBorrow)) {
            vars.put("pay", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        if ("是".equals(ifBorrow)) {
            vars.put("loan", true);
            vars.put("design", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        }
        // 设置意见
        act.preUpdate();
        // 提交流程任务
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 交底:是否借款
     */
    @Transactional(readOnly = false)
    public void ruralLoan(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 交底:是否支付
     */
    @Transactional(readOnly = false)
    public void ruralPays(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 填写wbs编码
     */
    @Transactional(readOnly = false)
    public void wbsTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findFundUser(act.getProcInsId());
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getInspectionUnit()).getLoginName());
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }

    /**
     * 填写资产卡片号
     */
    @Transactional(readOnly = false)
    public void assetTask(Act act) {
        // 设置意见
        act.setComment(("yes".equals(act.getFlag()) ? "[同意] " : "[驳回] ") + act.getComment());
        act.preUpdate();
        // 提交流程任务
        Map<String, Object> vars = Maps.newHashMap();
        Project user = MyActiviUtils.findFundUser(act.getProcInsId());
        vars.put("manager", UserUtils.getByUserName(user.getAssignment().getOwnerManager()).getLoginName());
        vars.put("pass", "yes".equals(act.getFlag()) ? true : false);
        complete(act.getTaskId(), act.getProcInsId(), act.getComment(), vars);
    }
}
