From 1d9dc084870ab8bf5c46d577b822afeae3e98b7d Mon Sep 17 00:00:00 2001 From: ddlucky Date: Wed, 1 Feb 2023 14:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BD=86=E6=9C=AA=E5=81=9A=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E3=80=82=EF=BC=88GetWorkFlowmb=EF=BC=89=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=8C=89companyid=E8=8E=B7=E5=8F=96=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DSWeb.Common/DB/Comm.cs | 87 ++++++++++++ DSWeb.Common/DB/CommonDataContext.cs | 6 + DSWeb/Areas/CommMng/DAL/WorkFlowDAL.cs | 188 +++++++++++++++++++++++++ HcDBUtility/Comm/DBResult.cs | 14 +- 4 files changed, 292 insertions(+), 3 deletions(-) diff --git a/DSWeb.Common/DB/Comm.cs b/DSWeb.Common/DB/Comm.cs index 2b982164..7e5ebcdc 100644 --- a/DSWeb.Common/DB/Comm.cs +++ b/DSWeb.Common/DB/Comm.cs @@ -2257,6 +2257,93 @@ namespace DSWeb.Common.DB public string GOODSNAME_OUT { get; set; } } + + + [Table("workflow_type")] + public class workflow_type_md + { + [Key] + public string GID { get; set; } + /// + /// 英文名 + /// + public string NAME { get; set; } + public string DESCRIPTION { get; set; } + /// + /// 类型序列号 数字 + /// + public int? TYPENO { get; set; } + public string CREATEUSER { get; set; } + public DateTime? CREATETIME { get; set; } + public string MODIFIEDUSER { get; set; } + public DateTime? MODIFIEDTIME { get; set; } + } + + [Table("workflow")] + public partial class workflow_md + { + [Key] + public string GID { get; set; } + public string NAME { get; set; } + public string DESCRIPTION { get; set; } + public string MODULEID { get; set; } + public int? TYPE { get; set; } + public string CREATEUSER { get; set; } + public DateTime? CREATETIME { get; set; } + public string MODIFIEDUSER { get; set; } + public DateTime? MODIFIEDTIME { get; set; } + public int? STATE { get; set; } + public int? SORT { get; set; } + public int? ISDELETE { get; set; } + public string COMPANYID { get; set; } + public string DEPTGID { get; set; } + public string TASKURL { get; set; } + public Byte ISDEFAULT { get; set; } + public bool ISCONDITION { get; set; } + public string CONDITIONSQL { get; set; } + public Byte? SORTNO { get; set; } + } + + [Table("workflow_step")] + public partial class workflow_step_md + { + [Key] + public string GID { get; set; } + public string NAME { get; set; } + public string DESCRIPTION { get; set; } + public string WORKFLOWID { get; set; } + public int? STEPNO { get; set; } + public string DEFAULTAUDITOR { get; set; } + public string AUDITOR { get; set; } + public string CONDITIONID { get; set; } + public bool? NEEDALLPASS { get; set; } + public bool? ISMUST { get; set; } + public bool? ISLAST { get; set; } + public string GROUPID { get; set; } + public string NextGROUP { get; set; } + public string NextSTEPNO { get; set; } + public string CREATEUSER { get; set; } + public DateTime? CREATETIME { get; set; } + public string MODIFIEDUSER { get; set; } + public DateTime? MODIFIEDTIME { get; set; } + public string REMARK { get; set; } + public bool? ISPARALLEL { get; set; } + public bool? ISDEPARTMENT { get; set; } + public string DEPARTMENTID { get; set; } + public string TASKURL { get; set; } + } + + [Table("workflow_UserPath")] + public partial class workflow_UserPath_md + { + [Key] + public Int32 id { get; set; } + public string USERID { get; set; } + public string workflowTypeNO { get; set; } + public string workflowID { get; set; } + } + + public static class StrHelper { #region 将一个dictionary转化为用;;和::隔开的文本 diff --git a/DSWeb.Common/DB/CommonDataContext.cs b/DSWeb.Common/DB/CommonDataContext.cs index 4bf60de0..63bddbac 100644 --- a/DSWeb.Common/DB/CommonDataContext.cs +++ b/DSWeb.Common/DB/CommonDataContext.cs @@ -74,6 +74,12 @@ namespace DSWeb.Common.DB public DbSet wms_out { get; set; } public DbSet wms_out_detail { get; set; } public DbSet VW_WMS_OUT_DETAIL { get; set; } + + + public DbSet workflow_type { get; set; } + public DbSet workflow { get; set; } + public DbSet workflow_step { get; set; } + public DbSet workflow_UserPath { get; set; } } diff --git a/DSWeb/Areas/CommMng/DAL/WorkFlowDAL.cs b/DSWeb/Areas/CommMng/DAL/WorkFlowDAL.cs index 2ee5d7be..be3e9c3e 100644 --- a/DSWeb/Areas/CommMng/DAL/WorkFlowDAL.cs +++ b/DSWeb/Areas/CommMng/DAL/WorkFlowDAL.cs @@ -22,6 +22,7 @@ using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.Areas.MvcShipping.Helper; using DSWeb.Areas.SysMng.DAL.SysTask; +using DSWeb.Common.DB; namespace DSWeb.Areas.CommMng.DAL { @@ -407,6 +408,193 @@ namespace DSWeb.Areas.CommMng.DAL return result; } + /// + /// 根据工作流名字、用户ID、公司ID 判定该使用哪个或哪些工作流 + /// + /// + /// + /// + /// + static public DBResult GetWorkFlowmb(string NAME, string BILLNO, string USERID, string COMPANYID = "") + { + var result = new DBResult(); + try + { + + var cdc = new CommonDataContext(); + + var vwuser = new VW_user_md(); + var vwuserList = cdc.VW_user.Where(x => x.USERID == USERID).ToList(); + if (vwuserList == null || vwuserList.Count == 0) + { + + result.SetErrorInfo($"未找到可用用户ID:{USERID}"); + return result; + } + else + { + vwuser = vwuserList[0]; + if (string.IsNullOrWhiteSpace(COMPANYID)) + COMPANYID = vwuser.COMPANYID; + } + + + //1 看该用户是否出现在该种工作流的【管辖范围workflow_UserPath】内 + //1.1 如有 看是否多条 如是多条 分别依据条件判断使用哪一个工作流 + // 如多条符合 或 多条无条件 或 无符合条件 则返回错误 + // 如仅一条符合 返回该工作流 + + //1.2 如无(出现在该种工作流的【管辖范围workflow_UserPath】内) + // 则根据公司(如公司为空则使用用户所在公司id) 、isdefault 判断是否只有一条工作流 + // 如无,则根据公司(如公司为空则使用用户所在公司id) 判断是否只有一条工作流 + // 如仅一条符合 返回该工作流 + // 否则 返回错误 + + var 工作流type = cdc.workflow_type.Where(x => x.NAME == NAME).ToList(); + + if (工作流type == null || 工作流type.Count == 0) + { + result.SetErrorInfo($"未找到工作流{NAME}"); + return result; + } + if (工作流type == null || 工作流type.Count == 0) + { + result.SetErrorInfo($"未找到工作流{NAME}"); + return result; + } + var typenostr = 工作流type[0].TYPENO.ToString(); + var 受管辖范围List = cdc.workflow_UserPath.Where(x => x.USERID == USERID && x.workflowTypeNO == typenostr).ToList(); + if (!(受管辖范围List == null || 受管辖范围List.Count == 0)) + { //1.1 + + result = 根据管辖范围获取工作流(受管辖范围List, BILLNO, USERID, COMPANYID); + + } + else + { + //1.2 + var typeno = 工作流type[0].TYPENO; + var workflowidlist = cdc.workflow.Where(x => x.TYPE == typeno).Select(s => s.GID).ToList(); + result = 无管辖范围获取工作流(workflowidlist, BILLNO, USERID, COMPANYID); + } + + return result; + } + catch (Exception ex) + { + result.SetErrorInfo(ex.Message); + return result; + } + } + + private static DBResult 根据管辖范围获取工作流(List 受管辖范围List, string BILLNO, string USERID, string COMPANYID = "") + { + //1 看该用户是否出现在该种工作流的【管辖范围workflow_UserPath】内 + //1.1 如有 看是否多条 如是多条 分别依据条件condition判断使用哪一个工作流 + // 如多条符合 或 多条无条件 或 无符合条件 则返回错误 + // 如仅一条符合 返回该工作流 + var result = new DBResult(); + var resultdata = new workflow_md(); + var cdc = new CommonDataContext(); + + if (受管辖范围List.Count == 1) + { + var workflowid = 受管辖范围List[0].workflowID; + resultdata = cdc.workflow.FirstOrDefault(x => x.GID == workflowid); + result.OK("", resultdata); + return result; + } + else + { + var workflowidlist = 受管辖范围List.Select(s => s.workflowID).Distinct().ToList(); + + result = 无管辖范围获取工作流(workflowidlist, BILLNO, USERID, COMPANYID); + } + + return result; + } + + private static DBResult 无管辖范围获取工作流(List workflowidlist, string BILLNO, string USERID, string COMPANYID = "") + { + var result = new DBResult(); + + var cdc = new CommonDataContext(); + + var workflowlist = cdc.workflow.Where(x => workflowidlist.Contains(x.GID) && x.COMPANYID == COMPANYID).ToList(); + + if (workflowlist.Exists(x => x.ISCONDITION)) + { + //如果有条件工作流 先看有没有符合条件的 + var 条件工作流List = workflowlist.Where(x => x.ISCONDITION == true).ToList(); + foreach (var 条件工作流 in 条件工作流List) + { + var CONDITIONSQL = 条件工作流.CONDITIONSQL.Replace("[业务编号]", "'" + BILLNO + "'"); + T_ALL_DA T_ALL_DA = new T_ALL_DA(); + var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL); + if (strCOUNT != "0") + { + result.OK("", 条件工作流); + return result; + } + } + //如果 条件工作流中无符合条件的 那就看有没有无条件的 + //如无 返回无符合条件的工作流 + //如有且仅有一个 返回它 + //如有多个且其中有一个isdefault的 返回它 + //如有多个且其中无默认工作流的 返回错误 + var 无条件工作流 = workflowlist.Where(x => x.ISCONDITION != true).ToList(); + if (无条件工作流 == null || 无条件工作流.Count == 0) + { + result.SetErrorInfo("无符合条件的工作流"); + return result; + } + + if (无条件工作流.Count == 1) + { + result.OK("", 无条件工作流[0]); + return result; + } + + if (无条件工作流.Count > 1 && 无条件工作流.Exists(x => x.ISDEFAULT == 1)) + { + result.OK("", 无条件工作流.First(x => x.ISDEFAULT == 1)); + return result; + } + if (无条件工作流.Count > 1 && !无条件工作流.Exists(x => x.ISDEFAULT == 1)) + { + result.SetErrorInfo("无符合条件的工作流(多条无条件工作流,且其中无默认工作流)"); + return result; + } + result.SetErrorInfo("无符合条件的工作流(其他情况)"); + return result; + } + else + { + if (workflowlist.Count == 1) + { + result.OK("", workflowlist[0]); + return result; + } + + if (workflowlist.Count > 1) + { + if (workflowlist.Exists(x => x.ISDEFAULT == 1)) + { + result.OK("", workflowlist.First(x => x.ISDEFAULT == 1)); + return result; + } + else + { + result.SetErrorInfo("无符合条件的工作流(多条无条件工作流,且其中无默认工作流)"); + return result; + } + } + } + + return result; + } + + #endregion #region [查询]通过WORKFLOWID查找workflow_step的内容 diff --git a/HcDBUtility/Comm/DBResult.cs b/HcDBUtility/Comm/DBResult.cs index be199659..68ca7acf 100644 --- a/HcDBUtility/Comm/DBResult.cs +++ b/HcDBUtility/Comm/DBResult.cs @@ -60,11 +60,19 @@ namespace HcUtility.Comm OK(""); return this; } - public DBResult OK( string _message) + public void OK(string _message) { success = true; - message += _message + ";"; - return this; + if (!string.IsNullOrWhiteSpace(message) && !string.IsNullOrWhiteSpace(_message)) + { + message += ";"; + } + message += _message; + } + public void OK(string _message, object data = null) + { + OK(_message); + Data = data; } public DBResult SetErrorInfo(string message, bool success = false, object data = null)