You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
10 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Newtonsoft.Json.Linq;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. namespace EasyBL.WEBAPP.SYS
  10. {
  11. public class AuthantedProgramsService : ServiceBase
  12. {
  13. #region 查詢系統所有程式(系統授權)
  14. /// <summary>
  15. /// 查詢系統所有程式(系統授權)
  16. /// </summary>
  17. /// <param name="i_crm"></param>
  18. /// <returns></returns>
  19. public ResponseMessage GetAuthorizeBy_(RequestMessage i_crm)
  20. {
  21. ResponseMessage rm = null;
  22. string sMsg = null;
  23. var db = SugarBase.DB;
  24. try
  25. {
  26. do
  27. {
  28. var sType = _fetchString(i_crm, @"Type");
  29. var sRuleID = _fetchString(i_crm, @"RuleID");
  30. var sChildSystem = _fetchString(i_crm, @"ChildSystem");
  31. var sModuleID = _fetchString(i_crm, @"ModuleID");
  32. var dic_SP = new Dictionary<string, string> {
  33. { "Role", "OSP_Common_GetProgramListByRuleId" },
  34. { "Dept", "OSP_Common_GetProgramListByDeptId" },
  35. { "Member", "OSP_Common_GetProgramListByMemberId" }
  36. };
  37. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  38. var spRuleID = new SugarParameter("@RuleID", sRuleID);
  39. var spChildSystem = new SugarParameter("@ChildSystem", sChildSystem);
  40. var spModuleID = new SugarParameter("@ModuleID", sModuleID);
  41. var dt = db.Ado.UseStoredProcedure().GetDataTable(dic_SP[sType], spOrgID, spRuleID, spChildSystem, spModuleID);
  42. using (var tb_new = new DataTable())
  43. {
  44. foreach (DataColumn col in dt.Columns)
  45. {
  46. tb_new.Columns.Add(col.ToString());
  47. }
  48. var saAuth = db.Queryable<OTB_SYS_Arguments>()
  49. .Where(x => x.OrgID == i_crm.ORIGID && x.ArgumentClassID == "99999" && x.Effective == "Y")
  50. .ToList();
  51. foreach (var _auth in saAuth)
  52. {
  53. tb_new.Columns.Add(_auth.ArgumentID);
  54. }
  55. foreach (DataRow row in dt.Rows)
  56. {
  57. var row_new = tb_new.NewRow();
  58. foreach (DataColumn col in dt.Columns)
  59. {
  60. row_new[col.ToString()] = row[col];
  61. }
  62. var saCanAllowRight = row["CanAllowRight"].ToString().Trim().Split(new string[] { @"|" }, StringSplitOptions.RemoveEmptyEntries);
  63. foreach (string right in saCanAllowRight)
  64. {
  65. row_new[right] = right;
  66. }
  67. tb_new.Rows.Add(row_new);
  68. }
  69. rm = new SuccessResponseMessage(null, i_crm);
  70. rm.DATA.Add(BLWording.REL, tb_new);
  71. }
  72. } while (false);
  73. }
  74. catch (Exception ex)
  75. {
  76. sMsg = Util.GetLastExceptionMsg(ex);
  77. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AuthantedProgramsService), "", @"GetAuthorizeBy_(查詢系統所有程式(系統授權))", @"", @"", @"");
  78. }
  79. finally
  80. {
  81. if (null != sMsg)
  82. {
  83. rm = new ErrorResponseMessage(sMsg, i_crm);
  84. }
  85. }
  86. return rm;
  87. }
  88. #endregion 查詢系統所有程式(系統授權)
  89. #region 修改(系統授權)
  90. /// <summary>
  91. /// 修改(系統授權)
  92. /// </summary>
  93. /// <param name="i_crm"></param>
  94. /// <returns></returns>
  95. public ResponseMessage UpdateAuthorize(RequestMessage i_crm)
  96. {
  97. ResponseMessage rm = null;
  98. string sMsg = null;
  99. try
  100. {
  101. rm = SugarBase.ExecTran(db =>
  102. {
  103. do
  104. {
  105. var sType = _fetchString(i_crm, @"Type");
  106. var sRuleID = _fetchString(i_crm, @"RuleID");
  107. var sChildSystem = _fetchString(i_crm, @"ChildSystem");
  108. var sModuleID = _fetchString(i_crm, @"ModuleID");
  109. var dic_SP_Del = new Dictionary<string, string> {
  110. { "Role", "[dbo].[OSP_OTB_SYS_Authorize_Delete]" },
  111. { "Dept", "OSP_OTB_SYS_AuthorizeForDept_Delete" },
  112. { "Member", "OSP_OTB_SYS_AuthorizeForMember_Delete" }
  113. };
  114. var dic_SP_Add = new Dictionary<string, string> {
  115. { "Role", "OSP_OTB_SYS_Authorize_ADD" },
  116. { "Dept", "OSP_OTB_SYS_AuthorizeForDept_Add" },
  117. { "Member", "OSP_OTB_SYS_AuthorizeForMember_Add" }
  118. };
  119. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  120. var spRuleID = new SugarParameter("@RuleID", sRuleID);
  121. var spChildSystem = new SugarParameter("@ChildSystem", sChildSystem);
  122. var spModuleID = new SugarParameter("@ModuleID", sModuleID);
  123. var iRel = db.Ado.UseStoredProcedure().ExecuteCommand(dic_SP_Del[sType], spOrgID, spRuleID, spChildSystem, spModuleID);
  124. var saAuth = i_crm.DATA["add"] as JArray;
  125. foreach (JObject jo in saAuth)
  126. {
  127. var saSp = new List<SugarParameter>();
  128. foreach (var auth in jo)
  129. {
  130. saSp.Add(new SugarParameter(auth.Key, auth.Value));
  131. }
  132. var iRel_Add = db.Ado.UseStoredProcedure().ExecuteCommand(dic_SP_Add[sType], saSp);
  133. }
  134. rm = new SuccessResponseMessage(null, i_crm);
  135. rm.DATA.Add(BLWording.REL, iRel);
  136. } while (false);
  137. return rm;
  138. });
  139. }
  140. catch (Exception ex)
  141. {
  142. sMsg = Util.GetLastExceptionMsg(ex);
  143. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AuthantedProgramsService), "", @"UpdateAuthorize(修改(系統授權))", @"", @"", @"");
  144. }
  145. finally
  146. {
  147. if (null != sMsg)
  148. {
  149. rm = new ErrorResponseMessage(sMsg, i_crm);
  150. }
  151. }
  152. return rm;
  153. }
  154. #endregion 修改(系統授權)
  155. #region 獲取系統角色(系統授權)
  156. /// <summary>
  157. /// 獲取系統角色(系統授權)
  158. /// </summary>
  159. /// <param name="i_crm"></param>
  160. /// <returns></returns>
  161. public ResponseMessage GetRules(RequestMessage i_crm)
  162. {
  163. ResponseMessage rm = null;
  164. string sMsg = null;
  165. var db = SugarBase.DB;
  166. try
  167. {
  168. do
  169. {
  170. var saRules = db.Queryable<OTB_SYS_Rules>().Where(x => x.OrgID == i_crm.ORIGID && x.DelStatus == "N").ToList();
  171. rm = new SuccessResponseMessage(null, i_crm);
  172. rm.DATA.Add(BLWording.REL, saRules);
  173. } while (false);
  174. }
  175. catch (Exception ex)
  176. {
  177. sMsg = Util.GetLastExceptionMsg(ex);
  178. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AuthantedProgramsService), "", @"GetRules(獲取系統角色(系統授權))", @"", @"", @"");
  179. }
  180. finally
  181. {
  182. if (null != sMsg)
  183. {
  184. rm = new ErrorResponseMessage(sMsg, i_crm);
  185. }
  186. }
  187. return rm;
  188. }
  189. #endregion 獲取系統角色(系統授權)
  190. #region 獲取系統模組(系統授權)
  191. /// <summary>
  192. /// 獲取系統模組(系統授權)
  193. /// </summary>
  194. /// <param name="i_crm"></param>
  195. /// <returns></returns>
  196. public ResponseMessage GetModulelist(RequestMessage i_crm)
  197. {
  198. ResponseMessage rm = null;
  199. string sMsg = null;
  200. var db = SugarBase.DB;
  201. try
  202. {
  203. do
  204. {
  205. var bParentID = _fetchBool(i_crm, @"ParentID");
  206. var bIncludeParent = _fetchBool(i_crm, @"IncludeParent");
  207. var saRules = db.Queryable<OTB_SYS_ModuleList>()
  208. .Where(x => x.OrgID == i_crm.ORIGID)
  209. .WhereIF(!bParentID && !bIncludeParent, x => SqlFunc.HasValue(x.ParentID))
  210. .WhereIF(bParentID && !bIncludeParent, x => !SqlFunc.HasValue(x.ParentID))
  211. .OrderBy(x => x.OrderByValue)
  212. .ToList();
  213. rm = new SuccessResponseMessage(null, i_crm);
  214. rm.DATA.Add(BLWording.REL, saRules);
  215. } while (false);
  216. }
  217. catch (Exception ex)
  218. {
  219. sMsg = Util.GetLastExceptionMsg(ex);
  220. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AuthantedProgramsService), "", @"GetModulelist(獲取系統模組(系統授權))", @"", @"", @"");
  221. }
  222. finally
  223. {
  224. if (null != sMsg)
  225. {
  226. rm = new ErrorResponseMessage(sMsg, i_crm);
  227. }
  228. }
  229. return rm;
  230. }
  231. #endregion 獲取系統模組(系統授權)
  232. }
  233. }