using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Application.Web.Hubs;
using Learun.Application.WorkFlow;
using Learun.Util;
using Learun.Workflow.Engine;
using System.Collections.Generic;
using System.Web.Mvc;
using Learun.Application.Organization;

namespace Learun.Application.Web.Areas.LR_NewWorkFlow.Controllers
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创建人：研发部
    /// 日 期：2018.12.09
    /// 描 述：流程进程
    /// </summary>
    public class NWFProcessController : MvcControllerBase
    {
        private ChatHub chatHub = new ChatHub();
        private NWFProcessIBLL nWFProcessIBLL = new NWFProcessBLL();

        private NWFSchemeIBLL nWFSchemeIBLL = new NWFSchemeBLL();
        private NWFTaskIBLL nWFTaskIBLL = new NWFTaskBLL();
        private UserIBLL userIBLL = new UserBLL();


        #region 视图功能
        /// <summary>
        /// 视图功能
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Index()
        {
            ViewBag.schemeCode = Request.Params["schemeCode"];
            if (!string.IsNullOrWhiteSpace(ViewBag.schemeCode))
            {
                NWFSchemeInfoEntity schemeInfo = nWFSchemeIBLL.GetInfoEntityByCode(ViewBag.schemeCode);
                if (schemeInfo != null)
                {
                    ViewBag.schemeId = schemeInfo.F_Id;
                    ViewBag.schemeName = schemeInfo.F_Name;
                }
            }
            return View();
        }
        /// <summary>
        /// 发起流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult ReleaseForm()
        {
            return View();
        }
        /// <summary>
        /// 流程容器
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult NWFContainerForm()
        {
            return View();
        }
        /// <summary>
        /// 查看节点审核信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult LookNodeForm()
        {
            return View();
        }

        /// <summary>
        /// 创建流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult CreateForm()
        {
            return View();
        }
        /// <summary>
        /// 审核流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult AuditFlowForm()
        {
            return View();
        }
        /// <summary>
        /// 加签审核流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult SignAuditFlowForm()
        {
            return View();
        }
        /// <summary>
        /// 加签审核
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult SignFlowForm()
        {
            return View();
        }


        /// <summary>
        /// 加签审核
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult SignFlowFormNew()
        {
            return View();
        }


        /// <summary>
        /// 流程进度查看（父子流程）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult LookFlowForm()
        {
            return View();
        }

        /// <summary>
        /// 监控页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult MonitorIndex()
        {
            return View();
        }
        /// <summary>
        /// 监控详情页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult MonitorDetailsIndex()
        {
            return View();
        }
        /// <summary>
        /// 查看各个节点表单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult MonitorForm()
        {
            return View();
        }
        /// <summary>
        /// 指定审核人
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult AppointForm()
        {
            return View();
        }
        /// <summary>
        /// 批量审核页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult BatchAuditIndex()
        {
            return View();
        }

        /// <summary>
        /// 选择下一节点审核人员
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult SelectUserForm()
        {
            return View();
        }
        /// <summary>
        /// 签名弹层
        /// </summary>
        /// <returns></returns>
        public ActionResult SignForm()
        {
            return View();
        }

        #endregion

        #region 获取数据
        /// <summary>
        /// 获取我的流程信息列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetProcessList(string pagination, string queryJson)
        {
            Pagination paginationobj = pagination.ToObject<Pagination>();
            var list = nWFProcessIBLL.GetPageList(paginationobj, queryJson);
            var jsonData = new
            {
                rows = list,
                total = paginationobj.total,
                page = paginationobj.page,
                records = paginationobj.records,
            };
            return Success(jsonData);
        }
        /// <summary>
        /// 获取我的流程信息列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetTaskPageList(string pagination, string queryJson, string categoryId, string schemeCode, string ProjectId)
        {
            Pagination paginationobj = pagination.ToObject<Pagination>();
            paginationobj.sidx = "F_CreateDate DESC";
            IEnumerable<NWFProcessEntity> list = new List<NWFProcessEntity>();
            UserInfo userInfo = LoginUserInfo.Get();
            switch (categoryId)
            {
                case "1":
                    list = nWFProcessIBLL.GetMyPageList(userInfo.userId, paginationobj, queryJson, schemeCode, ProjectId);
                    break;
                case "2":
                    list = nWFProcessIBLL.GetMyTaskPageList(userInfo, paginationobj, queryJson, schemeCode, ProjectId);
                    break;
                case "3":
                    list = nWFProcessIBLL.GetMyFinishTaskPageList(userInfo, paginationobj, queryJson, schemeCode, ProjectId);
                    break;
            }      
            var jsonData = new
            {
                rows = list,
                total = paginationobj.total,
                page = paginationobj.page,
                records = paginationobj.records,
            };
            return Success(jsonData);
        }

        /// <summary>
        /// 获取批量审核任务清单
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetBatchTaskPageList(string pagination, string queryJson)
        {
            Pagination paginationobj = pagination.ToObject<Pagination>();
            UserInfo userInfo = LoginUserInfo.Get();
            var data = nWFProcessIBLL.GetMyTaskPageList(userInfo, paginationobj, queryJson, true);
            var jsonData = new
            {
                rows = data,
                total = paginationobj.total,
                page = paginationobj.page,
                records = paginationobj.records,
            };
            return Success(jsonData);
        }

        /// <summary>
        /// 获取我的流程信息列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetTask(string taskId)
        {
            var data = nWFTaskIBLL.GetEntity(taskId);
            return Success(data);
        }
        /// <summary>
        /// 点击之后就更新IsLook状态
        /// </summary>
        /// <param name="taskId">任务ID</param>
        /// <param name="isLook">是否查看</param>
        /// <param name="UserId">用户ID</param>
        /// <returns></returns>
        public ActionResult UpdateLook(string taskId, int isLook, string UserId)
        {
            nWFTaskIBLL.UpdateLook(taskId, isLook, UserId);
            return Success("状态更新成功");
        }

        [HttpGet]
        [AjaxOnly]
        public ActionResult GetProcessInfo(string processId)
        {
            var data= nWFProcessIBLL.GetEntity(processId);
            return Success(data);
        }
        #endregion

        #region 保存更新删除
        /// <summary>
        /// 删除流程进程实体
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        [HttpPost]
        [AjaxOnly]
        public ActionResult DeleteEntity(string processId)
        {
            nWFProcessIBLL.DeleteEntity(processId);
            return Success("删除成功");
        }
        #endregion

        #region 流程API
        /// <summary>
        /// 获取流程模板
        /// </summary>
        /// <param name="code">流程编码</param>
        /// <param name="ProjectId">项目ID</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetSchemeByCode(string code,string ProjectId)
        {
            var schemeInfo = nWFSchemeIBLL.GetInfoEntityByCodeAndProjectId(code, ProjectId);
            if (schemeInfo != null)
            {
                var data = nWFSchemeIBLL.GetSchemeEntity(schemeInfo.F_SchemeId);
                return Success(data);
            }
            return Fail("找不到该流程模板");
        }
        /// <summary>
        /// 根据流程进程主键获取流程模板
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetSchemeByProcessId(string processId)
        {
            var processEntity = nWFProcessIBLL.GetEntity(processId);
            if (processEntity != null)
            {
                if (string.IsNullOrEmpty(processEntity.F_SchemeId))
                {
                    var schemeInfo = nWFSchemeIBLL.GetInfoEntityByCode(processEntity.F_SchemeCode);
                    if (schemeInfo != null)
                    {
                        var data = nWFSchemeIBLL.GetSchemeEntity(schemeInfo.F_SchemeId);
                        return Success(data);
                    }
                }
                else
                {
                    var data = nWFSchemeIBLL.GetSchemeEntity(processEntity.F_SchemeId);
                    data.F_SchemeCode = processEntity.F_SchemeCode;
                    return Success(data);
                }
            }
            return Fail("找不到该流程模板");
        }

        /// <summary>
        /// 获取流程下一节点审核
        /// </summary>
        /// <param name="code">流程编码</param>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">任务主键</param>
        /// <param name="nodeId">节点ID</param>
        /// <param name="operationCode">操作编码</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetNextAuditors(string code, string processId, string taskId, string nodeId, string operationCode,string ProjectId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            var data = nWFProcessIBLL.GetNextAuditors(code, processId, taskId, nodeId, operationCode, userInfo, ProjectId);
            return Success(data);
        }

        /// <summary>
        /// 获取流程进程信息
        /// </summary>
        /// <param name="processId">进程主键</param>
        /// <param name="taskId">任务主键</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetProcessDetails(string processId, string taskId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            var data = nWFProcessIBLL.GetProcessDetails(processId, taskId, userInfo);
            if (!string.IsNullOrEmpty(data.childProcessId))
            {
                processId = data.childProcessId;
            }

            var taskNode = nWFProcessIBLL.GetTaskUserList(processId);

            string loginUserId = userInfo.userId;
            bool isLoginUserTask = false;
            string loginUserTaskType = "";
            string loginUserTaskId = "";
            foreach(var task in taskNode)
            {
                isLoginUserTask = task.nWFUserInfoList.Exists(u => u.Id.ToUpper() == loginUserId.ToUpper());
                if (isLoginUserTask)
                {
                    loginUserTaskType = task.F_Type.ToString();
                    loginUserTaskId = task.F_Id.ToString();
                    break;
                }
            }

            var jsonData = new
            {
                info = data,
                task = taskNode,
                isLoginUserProcess = loginUserId.ToUpper() == data.CreateUserId.ToUpper(),
                isLoginUserTask = isLoginUserTask,
                loginUserTaskType= loginUserTaskType,
                loginUserTaskId= loginUserTaskId
            };

            return Success(jsonData);
        }

        /// <summary>
        /// 获取子流程详细信息
        /// </summary>
        /// <param name="processId">父流程进程主键</param>
        /// <param name="taskId">父流程子流程发起主键</param>
        /// <param name="schemeCode">子流程流程模板编码</param>
        /// <param name="nodeId">父流程发起子流程节点Id</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetChildProcessDetails(string processId, string taskId, string schemeCode, string nodeId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            var data = nWFProcessIBLL.GetChildProcessDetails(processId, taskId, schemeCode, nodeId, userInfo);
            var taskNode = nWFProcessIBLL.GetTaskUserList(data.childProcessId);
            var jsonData = new
            {
                info = data,
                task = taskNode
            };

            return Success(jsonData);
        }
        /// <summary>
        /// 保存草稿
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="schemeCode">流程模板编码</param>
        /// <param name="title">标题</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult SaveDraft(string processId, string schemeCode, string title, string ObjectId, string ProjectId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.SaveDraft(processId, schemeCode, title, userInfo, ObjectId, ProjectId);
            return Success("流程草稿保存成功");
        }
        /// <summary>
        /// 删除草稿
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult DeleteDraft(string processId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.DeleteDraft(processId, userInfo);
            return Success("流程草稿删除成功");
        }


        /// <summary>
        /// 创建流程
        /// </summary>
        /// <param name="schemeCode">流程模板编码</param>
        /// <param name="processId">流程进程主键</param>
        /// <param name="title">流程进程自定义标题</param>
        /// <param name="level">流程进程等级</param>
        /// <param name="auditors">下一节点审核人</param>
        /// <param name="ObjectId">关联流程表的ID</param>
        /// <param name="ProjectId">项目ID</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult CreateFlow(string schemeCode, string processId, string title, int level, string auditors, string ObjectId, string ProjectId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            if (string.IsNullOrEmpty(ObjectId))
            {
                if (nWFProcessIBLL.GetEntity(processId) != null)
                {
                    ObjectId = nWFProcessIBLL.GetEntity(processId).F_ObjectId;
                }               
            }
            nWFProcessIBLL.CreateFlow(schemeCode, processId, title, level, auditors, userInfo, ObjectId, ProjectId); 
            //根据流程进程主键获取当前审批人员集合
            var list = (List<NWFTaskEntity>)nWFTaskIBLL.GetUnFinishTaskList(processId);
            var taskRelationList = (List<NWFTaskRelationEntity>)nWFTaskIBLL.GetTaskUserList(list[0].F_Id);
            if (taskRelationList != null && taskRelationList.Count > 0)
            {
                //支持多个审批人时的通知
                foreach (NWFTaskRelationEntity taskRelation in taskRelationList)
                {
                    chatHub.Send(taskRelation.F_UserId, ProjectId);
                }
            }
            return Success("流程创建成功");
        }

        /// <summary>
        /// 创建流程(子流程)
        /// </summary>
        /// <param name="schemeCode">流程模板编码</param>
        /// <param name="processId">流程进程主键</param>
        /// <param name="parentProcessId">父流程进程主键</param>
        /// <param name="parentTaskId">父流程任务主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult CreateChildFlow(string schemeCode, string processId, string parentProcessId, string parentTaskId, string ProjectId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.CreateChildFlow(schemeCode, processId, parentProcessId, parentTaskId, userInfo, ProjectId);
            return Success("流程创建成功");
        }

        /// <summary>
        /// 重新创建流程
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult AgainCreateFlow(string processId, string title)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.AgainCreateFlow(processId, userInfo,title);

            //根据流程进程主键获取当前审批人员集合
            var list = (List<NWFTaskEntity>)nWFTaskIBLL.GetUnFinishTaskList(processId);
            var taskRelationList = (List<NWFTaskRelationEntity>)nWFTaskIBLL.GetTaskUserList(list[0].F_Id);
            if (taskRelationList != null && taskRelationList.Count > 0)
            {
                //支持多个审批人时的通知
                foreach (NWFTaskRelationEntity taskRelation in taskRelationList)
                {
                    chatHub.Send(taskRelation.F_UserId, "");
                }
            }
            return Success("流程重新创建成功");
        }
        /// <summary>
        /// 审批流程
        /// </summary>
        /// <param name="operationCode">流程审批操作码agree 同意 disagree 不同意 lrtimeout 超时</param>
        /// <param name="operationName">流程审批操名称</param>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">流程任务主键</param>
        /// <param name="des">审批意见</param>
        /// <param name="auditors">下一节点指定审核人</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult AuditFlow(string operationCode, string operationName, string processId, string taskId, string des, string auditors, string stamp, string signUrl)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.AuditFlow(operationCode, operationName, processId, taskId, des, auditors, stamp, signUrl, userInfo);
            //根据流程进程主键获取当前审批人员集合
            var list = (List<NWFTaskEntity>)nWFTaskIBLL.GetUnFinishTaskList(processId);
            foreach (var item in list)
            {
                var taskRelationList = (List<NWFTaskRelationEntity>)nWFTaskIBLL.GetTaskUserList(list[0].F_Id);
                if (taskRelationList != null && taskRelationList.Count > 0)
                {
                    //支持多个审批人时的通知
                    foreach (NWFTaskRelationEntity taskRelation in taskRelationList)
                    {
                        if (taskRelation.F_Result == 0)
                        {
                            chatHub.Send(taskRelation.F_UserId, null);
                        }
                    }
                }
            }
            chatHub.Send(userInfo.userId, null);
            return Success("流程审批成功");
        }
        /// <summary>
        /// 审批流程
        /// </summary>
        /// <param name="operationCode">流程审批操作码agree 同意 disagree 不同意</param>
        /// <param name="taskIds">任务串</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult AuditFlows(string operationCode, string taskIds)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.AuditFlows(operationCode, taskIds, userInfo);

            return Success("流程批量审批成功");
        }
        /// <summary>
        /// 流程加签
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">流程任务主键</param>
        /// <param name="userId">加签人员</param>
        /// <param name="des">加签说明</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult SignFlow(string processId, string taskId, string userId, string des)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.SignFlow(processId, taskId, userId, des, userInfo);
            return Success("流程加签成功");
        }


        /// <summary>
        /// 流程加签 2020-2-13
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">流程任务主键</param>
        /// <param name="userIds">加签人员</param>
        /// <param name="des">加签说明</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult SignFlowNew(string processId, string taskId, string userIds, string des)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.SignFlowNew(processId, taskId, userIds, des, userInfo);

            //根据流程进程主键获取当前审批人员集合
            var list = (List<NWFTaskEntity>)nWFTaskIBLL.GetUnFinishTaskList(processId);
            foreach (var item in list)
            {
                var taskRelationList = (List<NWFTaskRelationEntity>)nWFTaskIBLL.GetTaskUserList(list[0].F_Id);
                if (taskRelationList != null && taskRelationList.Count > 0)
                {
                    //支持多个审批人时的通知
                    foreach (NWFTaskRelationEntity taskRelation in taskRelationList)
                    {
                        if (taskRelation.F_Result == 0)
                        {
                            chatHub.Send(taskRelation.F_UserId, null);
                        }
                    }
                }
            }
            return Success("流程加签成功");
        }


        /// <summary>
        /// 流程加签审核
        /// </summary>
        /// <param name="operationCode">审核操作码</param>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">流程任务主键</param>
        /// <param name="des">加签说明</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult SignAuditFlow(string operationCode, string processId, string taskId, string des)
        {
            NWFProcessEntity entity = nWFProcessIBLL.GetEntity(processId);
            string ProjectId = entity.ProjectId;
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.SignAuditFlow(operationCode, processId, taskId, des, userInfo);
            //根据流程进程主键获取当前审批人员集合
            var taskRelationList = (List<NWFTaskRelationEntity>)nWFTaskIBLL.GetTaskUserList(taskId);
            if (taskRelationList != null && taskRelationList.Count > 0)
            {
                //支持多个审批人时的通知
                foreach (NWFTaskRelationEntity taskRelation in taskRelationList)
                {
                    if (taskRelation.F_Result == 0)
                    {
                        chatHub.Send(taskRelation.F_UserId, ProjectId);
                    }
                }
            }
            chatHub.Send(userInfo.userId, ProjectId);
            return Success("加签审批成功");
        }

        /// <summary>
        /// 确认阅读
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">流程任务主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult ReferFlow(string processId, string taskId, string des)
        {
            NWFProcessEntity entity = nWFProcessIBLL.GetEntity(processId);
            string ProjectId = entity.ProjectId;
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.ReferFlow(processId, taskId, userInfo, des);
            chatHub.Send(userInfo.userId, ProjectId);
            return Success("保存成功");
        }

        /// <summary>
        /// 催办流程
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="userInfo">当前操作人信息</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult UrgeFlow(string processId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.UrgeFlow(processId, userInfo);
            return Success("催办成功");
        }
        /// <summary>
        /// 撤销流程（只有在该流程未被处理的情况下）
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult RevokeFlow(string processId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.RevokeFlow(processId, userInfo);
            return Success("撤销成功");
        }

        /// <summary>
        /// 获取流程当前任务需要处理的人
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetTaskUserList(string processId,string ProjectId)
        {
            var userdata = userIBLL.GetCommonSelectUsers(null, "{ProjectId:'" + ProjectId + "'}");
            var selectuserdata = nWFProcessIBLL.GetTaskUserList(processId);
            var data = new
            {
                data = selectuserdata,
                userList = userdata,
            };
            return Success(data);
        }
        /// <summary>
        /// 指派流程审核人
        /// </summary>
        /// <param name="strList">任务列表</param>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult AppointUser(string strList)
        {
            IEnumerable<NWFTaskEntity> list = strList.ToObject<IEnumerable<NWFTaskEntity>>();
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.AppointUser(list, userInfo);
            return Success("指派成功");
        }
        /// <summary>
        /// 作废流程
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult DeleteFlow(string processId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            nWFProcessIBLL.DeleteFlow(processId, userInfo);
            return Success("作废成功");
        }


        /// <summary>
        /// 撤销审核
        /// </summary>
        /// <param name="processId">流程进程主键</param>
        /// <param name="taskId">任务主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult RevokeAudit(string processId, string taskId)
        {
            UserInfo userInfo = LoginUserInfo.Get();
            var res = nWFProcessIBLL.RevokeAudit(processId, taskId, userInfo);
            if (res)
            {
                return Success("撤销成功");
            }
            else
            {
                return Fail("撤销失败，当前不允许撤销！");
            }

        }
        #endregion
    }
}