using FineUIPro; using Model; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace BLL { public static class WorkflowTodoitemsService { public enum Status:int { 待办 = 0, 已办 = 1, } public static string SysCode = "QHSE"; #region 获取列表 /// /// 记录数 /// public static int Count { get; set; } private static IQueryable GetWorkflow_TodoItemsByModle(Model.Workflow_TodoItems table) { var q = from x in Funs.DB.Workflow_TodoItems where (string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) && (string.IsNullOrEmpty(table.SysCode) || x.SysCode.Contains(table.SysCode)) && (string.IsNullOrEmpty(table.FlowId) || x.FlowId.Contains(table.FlowId)) && (string.IsNullOrEmpty(table.RequestName) || x.RequestName.Contains(table.RequestName)) && (string.IsNullOrEmpty(table.WorkflowName) || x.WorkflowName.Contains(table.WorkflowName)) && (string.IsNullOrEmpty(table.NodeName) || x.NodeName.Contains(table.NodeName)) && (string.IsNullOrEmpty(table.PCUrl) || x.PCUrl.Contains(table.PCUrl)) && (string.IsNullOrEmpty(table.AppUrl) || x.AppUrl.Contains(table.AppUrl)) && (string.IsNullOrEmpty(table.Creator) || x.Creator.Contains(table.Creator)) && (string.IsNullOrEmpty(table.Receiver) || x.Receiver.Contains(table.Receiver)) select x ; return q; } /// /// 获取分页列表 /// /// /// /// private static IEnumerable GetListData(Model.Workflow_TodoItems table, Grid grid1) { var q = GetWorkflow_TodoItemsByModle(table); Count = q.Count(); if (Count == 0) { return null; } q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize); // q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in q select new { x.Id, x.SysCode, x.FlowId, x.RequestName, x.WorkflowName, x.NodeName, x.PCUrl, x.AppUrl, x.Creator, x.CreateDateTime, x.Receiver, x.ReceiveDateTime, x.Status, }; } private static void UpdateWorkflow_TodoItems(Model.Workflow_TodoItems newtable) { Model.Workflow_TodoItems table = Funs.DB.Workflow_TodoItems.FirstOrDefault(x => x.Id == newtable.Id); if (table != null) { table.Id = newtable.Id; table.SysCode = newtable.SysCode; table.FlowId = newtable.FlowId; table.RequestName = newtable.RequestName; table.WorkflowName = newtable.WorkflowName; table.NodeName = newtable.NodeName; table.PCUrl = newtable.PCUrl; table.AppUrl = newtable.AppUrl; table.Creator = newtable.Creator; table.CreateDateTime = newtable.CreateDateTime; table.Receiver = newtable.Receiver; table.ReceiveDateTime = newtable.ReceiveDateTime; table.Status = newtable.Status; Funs.DB.SubmitChanges(); } } private static void DeleteWorkflow_TodoItemsById(string Id) { Model.Workflow_TodoItems table = Funs.DB.Workflow_TodoItems.FirstOrDefault(x => x.Id == Id); if (table != null) { Funs.DB.Workflow_TodoItems.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } #endregion public static Model.Workflow_TodoItems GetWorkflow_TodoItemsById(string id) { return Funs.DB.Workflow_TodoItems.FirstOrDefault(x => x.Id == id); } /// /// 根据接收者获取待办事项 /// /// 接收者名称 /// 待办事项列表 public static List GetWorkflow_TodoItemsByReceiver (string receiver) { return Funs.DB.Workflow_TodoItems.Where(x => x.Receiver == receiver && x.Status == (int)Status.待办).OrderByDescending(x => x.CreateDateTime).ToList(); } public static int GetWorkflow_TodoItemCountByReceiver(string receiver) { return Funs.DB.Workflow_TodoItems.Count(x => x.Receiver == receiver && x.Status == (int)Status.待办); } public static List GetWorkflow_TodoItemsByReceiver(string receiver,int state) { if (state==-1) { return Funs.DB.Workflow_TodoItems.Where(x => x.Receiver == receiver ).OrderByDescending(x=>x.CreateDateTime).ToList(); } else { return Funs.DB.Workflow_TodoItems.Where(x => x.Receiver == receiver && x.Status == state).OrderByDescending(x => x.CreateDateTime).ToList(); } } /// /// 添加待办事项 /// /// public static void AddWorkflow_TodoItems(Model.Workflow_TodoItems newtable) { Model.Workflow_TodoItems table = new Model.Workflow_TodoItems { Id = newtable.Id, SysCode = newtable.SysCode, FlowId = newtable.FlowId, RequestName = newtable.RequestName, WorkflowName = newtable.WorkflowName, NodeName = newtable.NodeName, PCUrl = newtable.PCUrl, AppUrl = newtable.AppUrl, Creator = newtable.Creator, CreateDateTime = newtable.CreateDateTime, Receiver = newtable.Receiver, ReceiveDateTime = newtable.ReceiveDateTime, Status = newtable.Status, }; Funs.DB.Workflow_TodoItems.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 增加待办事项 /// /// 流程ID /// 标题 /// 流程类型名称 /// 步骤名称(节点名称) /// PC地址 /// APP地址 /// 创建人 /// 接收人 public static void Add(string flowId, string requestName, string workflowName, string nodeName, string pcUrl, string appUrl, string creator, string receiver) { if (IsWorkflow_TodoItems( flowId, receiver, nodeName)) { return; } Model.Workflow_TodoItems table = new Model.Workflow_TodoItems { Id = SQLHelper.GetNewID(), SysCode = SysCode, FlowId = flowId, RequestName = requestName, WorkflowName = workflowName, NodeName = nodeName, PCUrl = pcUrl, AppUrl = "", Creator = creator, CreateDateTime = DateTime.Now, Receiver = receiver, ReceiveDateTime = DateTime.Now, Status = (int)Status.待办, }; Funs.DB.Workflow_TodoItems.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 删除待办事项 /// /// public static void DeleteWorkflow_TodoItemsByflowId(string flowId) { var q = from x in Funs.DB.Workflow_TodoItems where x.FlowId == flowId select x; foreach (var item in q) { Funs.DB.Workflow_TodoItems.DeleteOnSubmit(item); } Funs.DB.SubmitChanges(); } //根据flowid 和 receiver 判断是否有待办事项 public static bool IsWorkflow_TodoItems(string flowId, string receiver,string nodename) { return Funs.DB.Workflow_TodoItems.Any(x => x.FlowId == flowId && x.Receiver == receiver && x.NodeName== nodename); } /// /// 办结待办事项 /// /// /// public static void DoneWorkflow_TodoItems(string flowId,string receiver) { Model.Workflow_TodoItems table = Funs.DB.Workflow_TodoItems.FirstOrDefault(x => x.FlowId == flowId && x.Receiver == receiver); if (table != null) { table.Status = (int)Status.已办; Funs.DB.SubmitChanges(); } } } }