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.

390 lines
12 KiB

  1. using Newtonsoft.Json.Linq;
  2. using OT.COM.ArsenalDB;
  3. using OT.COM.LogisticsUtil;
  4. using OT.COM.SignalerMessage;
  5. using SoldierData;
  6. using SoldierData.syserp;
  7. using SoldierDataEntity;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. namespace CounsellorBL
  14. {
  15. public partial class AuthorityService : DBService
  16. {
  17. public class PrvilegeInfoEx : PrvilegeInfo
  18. {
  19. public bool CHECKED { get; set; }
  20. public PrvilegeInfoEx(PrvilegeInfo i_pi)
  21. {
  22. PropertyInfo[] pis = typeof(PrvilegeInfo).GetProperties();
  23. foreach (PropertyInfo pi in pis)
  24. {
  25. pi.SetValue(this, pi.GetValue(i_pi, null), null);
  26. }
  27. CHECKED = false;
  28. }
  29. }
  30. public CResponseMessage GetNodeTreee(CRequestMessage i_crm, bool i_bFilterNonePrivilege = false)
  31. {
  32. CResponseMessage crm = null;
  33. string sMsg = null;
  34. try
  35. {
  36. do
  37. {
  38. Dictionary<string, object> dicFormData = null;
  39. CResponseMessage crmCheckToken = checkTokenWithCRequestMessage(i_crm, out dicFormData);
  40. if (EResponseResult.RR_FALSE == crmCheckToken.RESULT)
  41. {
  42. sMsg = crmCheckToken.MSG;
  43. sMsg = BaseExceptionWord.ex000019; // crmCheckToken異常
  44. break;
  45. }
  46. if (false == dicFormData.ContainsKey(BLWording.ROLEID))
  47. {
  48. sMsg = BaseExceptionWord.ex000008; //NO ROLEID
  49. break;
  50. }
  51. object oRoleID = dicFormData[BLWording.ROLEID];
  52. if (null == oRoleID)
  53. {
  54. sMsg = BaseExceptionWord.ex000008; //NO ROLEID
  55. break;
  56. }
  57. string nRoldID = oRoleID.ToString();
  58. //if (false == Int32.TryParse(oRoleID.ToString(), out nRoldID))
  59. //{
  60. // sMsg = "INVALID ROLEID";
  61. // break;
  62. //}
  63. CResponseMessage crmPri = this.GetPrivilege(nRoldID.Trim());
  64. if (EResponseResult.RR_FALSE == crmPri.RESULT)
  65. {
  66. sMsg = crmPri.MSG;
  67. break;
  68. }
  69. CResponseMessage crmAllPri = GetAllPrivilege(nRoldID.Trim());
  70. if (EResponseResult.RR_FALSE == crmAllPri.RESULT)
  71. {
  72. sMsg = crmPri.MSG;
  73. break;
  74. }
  75. crm = new CSuccessResponseMessage(null, i_crm);
  76. // TODO Merger crmAllPri/crmPri
  77. List<PrvilegeInfo> lAllPr = crmAllPri.DATA[BLWording.PRIVILEGES] as List<PrvilegeInfo>;
  78. List<PrvilegeInfo> lOwnPr = crmPri.DATA[BLWording.PRIVILEGES] as List<PrvilegeInfo>;
  79. List<PrvilegeInfoEx> lRes = new List<PrvilegeInfoEx>();
  80. foreach (PrvilegeInfo piAllCur in lAllPr)
  81. {
  82. lRes.Add(new PrvilegeInfoEx(piAllCur) { CHECKED = null != lOwnPr.Where(f => f.ID.Trim() == piAllCur.ID.Trim()).FirstOrDefault() });
  83. }
  84. if (true == i_bFilterNonePrivilege)
  85. {
  86. filterNonePrivilege(ref lRes);
  87. }
  88. //去空白處理
  89. foreach (PrvilegeInfo pi in lRes)
  90. {
  91. pi.ID = pi.ID.Trim();
  92. pi.PARENTID = pi.PARENTID.Trim();
  93. pi.NAME = pi.NAME.Trim();
  94. pi.CONTENT = pi.CONTENT.Trim();
  95. }
  96. crm.DATA.Add(BLWording.PRIVILEGES, lRes);
  97. }
  98. while (false);
  99. }
  100. catch (Exception ex)
  101. {
  102. sMsg = new Util().GetLastExceptionMsg(ex);
  103. }
  104. if (null != sMsg)
  105. {
  106. crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
  107. }
  108. return crm;
  109. }
  110. /// <summary>
  111. /// 移除沒有權限的Node
  112. /// </summary>
  113. /// <param name="i_l"></param>
  114. protected void filterNonePrivilege(ref List<PrvilegeInfoEx> i_l)
  115. {
  116. // Remove Leaf but no Prvilege
  117. Dictionary<string, PrvilegeInfoEx> dicUncheckBranchNodeFID = new Dictionary<string, PrvilegeInfoEx>();
  118. Dictionary<int, int> dicFIDToListIdx = new Dictionary<int, int>();
  119. for (int i = i_l.Count - 1; i >= 0; i--)
  120. {
  121. PrvilegeInfoEx piCur = i_l[i];
  122. if (true == piCur.ISLEAF && false == piCur.CHECKED)
  123. {
  124. i_l.RemoveAt(i);
  125. }
  126. else if (false == piCur.ISLEAF)
  127. {
  128. dicUncheckBranchNodeFID.Add(piCur.ID.Trim(), piCur);
  129. }
  130. }
  131. for (int i = 0; i < i_l.Count; i++)
  132. {
  133. if (true == i_l[i].ISLEAF)
  134. {
  135. PrvilegeInfoEx piCur = i_l[i];
  136. string nParentID = piCur.PARENTID.Trim();
  137. while ("-1" != nParentID)
  138. {
  139. if (true == dicUncheckBranchNodeFID.ContainsKey(nParentID))
  140. {
  141. piCur = dicUncheckBranchNodeFID[nParentID];
  142. dicUncheckBranchNodeFID.Remove(nParentID);
  143. }
  144. else
  145. {
  146. break;
  147. }
  148. }
  149. }
  150. }
  151. foreach (string nFID in dicUncheckBranchNodeFID.Keys)
  152. {
  153. PrvilegeInfoEx piRemove = i_l.Where(f => f.ID.Trim() == nFID.Trim()).FirstOrDefault();
  154. if (null != piRemove)
  155. {
  156. i_l.Remove(piRemove);
  157. }
  158. }
  159. }
  160. public CResponseMessage GetAllPrivilege(string i_nRoleFID)
  161. {
  162. CResponseMessage crm = null;
  163. string sMsg = null;
  164. try
  165. {
  166. do
  167. {
  168. List<QueryJsonElement> lqje = new List<QueryJsonElement>();
  169. crm = new CSuccessResponseMessage(null);
  170. //crm.DATA.Add(BLWording.PRIVILEGES, lp);
  171. }
  172. while (false);
  173. }
  174. catch (Exception ex)
  175. {
  176. sMsg = new Util().GetLastExceptionMsg(ex);
  177. }
  178. if (null != sMsg)
  179. {
  180. crm = new CResponseMessage() { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
  181. }
  182. return crm;
  183. }
  184. public CResponseMessage GetPrivilege(string i_nRoleFID)
  185. {
  186. CResponseMessage crm = null;
  187. string sMsg = null;
  188. try
  189. {
  190. do
  191. {
  192. List<QueryJsonElement> lqje = new List<QueryJsonElement>();
  193. }
  194. while (false);
  195. }
  196. catch (Exception ex)
  197. {
  198. sMsg = new Util().GetLastExceptionMsg(ex);
  199. }
  200. if (null != sMsg)
  201. {
  202. crm = new CResponseMessage() { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
  203. }
  204. return crm;
  205. }
  206. /// <summary>
  207. /// Get Privilege by user ID
  208. /// </summary>
  209. /// <param name="i_crm"></param>
  210. /// <returns></returns>
  211. public CResponseMessage Privilege(CRequestMessage i_crm)
  212. {
  213. CResponseMessage crm = null;
  214. string sMsg = null;
  215. try
  216. {
  217. do
  218. {
  219. }
  220. while (false);
  221. }
  222. catch (Exception ex)
  223. {
  224. sMsg = new Util().GetLastExceptionMsg(ex);
  225. }
  226. if (null != sMsg)
  227. {
  228. crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
  229. }
  230. return crm;
  231. }
  232. //public CResponseMessage RolePrivilegeModify(CRequestMessage i_crm)
  233. //{
  234. // CResponseMessage crm = null;
  235. // string sMsg = null;
  236. // try
  237. // {
  238. // do
  239. // {
  240. // Dictionary<string, object> dicFormData = null;
  241. // CResponseMessage crmCheckToken = checkTokenWithCRequestMessage(i_crm, out dicFormData);
  242. // if (EResponseResult.RR_FALSE == crmCheckToken.RESULT)
  243. // {
  244. // sMsg = crmCheckToken.MSG;
  245. // break;
  246. // }
  247. // int nCurUserID = (int)crmCheckToken.DATA[BLWording.SESSION_USER_ID];
  248. // if (false == dicFormData.ContainsKey(BLWording.ROLEID))
  249. // {
  250. // sMsg = "NO ROLEID";
  251. // break;
  252. // }
  253. // object oRoleID = dicFormData[BLWording.ROLEID];
  254. // if (null == oRoleID)
  255. // {
  256. // sMsg = "NULL ROLEID";
  257. // break;
  258. // }
  259. // int nRoldID = -1;
  260. // if (false == Int32.TryParse(oRoleID.ToString(), out nRoldID))
  261. // {
  262. // sMsg = "INVALID ROLEID";
  263. // break;
  264. // }
  265. // List<Command> lCmds = new List<Command>();
  266. // tb_node nSelect = new tb_node();
  267. // nSelect.SetDirty(tb_node.CN_F_N_ID);
  268. // nSelect.SetDirty(tb_node.CN_F_S_NAME);
  269. // Command cSelectNode = Command.SetupSelectCmd(GetMasterDBTableInfo(typeof(tb_node)), nSelect);
  270. // QueryORMList<tb_node> lAllNode = this.adbm.RunQueryORMList<tb_node>(cSelectNode);
  271. // // TODO: Remove All nRoldID
  272. // WhereNode wnDelete = new WhereNode(tb_rolenode.CN_FK_N_ROLEINFO_ROLE_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_rolenode), nRoldID);
  273. // lCmds.Add(Command.SetupDeleteCmd(GetMasterDBTableInfo(typeof(tb_rolenode)), wnDelete));
  274. // // TODO: Add
  275. // JObject jo = dicFormData[BLWording.PRIVILEGES] as JObject;
  276. // foreach (JProperty property in jo.Properties())
  277. // {
  278. // JToken jv = property.Value;
  279. // tb_node nTar = lAllNode.DATA.FirstOrDefault(f => f.f_n_id == Int32.Parse(property.Name));
  280. // if (null != nTar)
  281. // {
  282. // tb_rolenode rnInsert = new tb_rolenode() { fk_n_roleinfo_role_id = nRoldID };
  283. // rnInsert.fk_n_creator_user_id = nCurUserID;
  284. // rnInsert.fk_n_modifier_user_id = nCurUserID;
  285. // rnInsert.fk_n_nodeinfo_node_id = nTar.f_n_id;
  286. // rnInsert.f_s_name = nTar.f_s_name;
  287. // lCmds.Add(Command.SetupInsertCmd(GetMasterDBTableInfo(typeof(tb_rolenode)), rnInsert));
  288. // }
  289. // }
  290. // this.adbm.RunEditCmds(lCmds);
  291. // crm = new CSuccessResponseMessage(null, i_crm);
  292. // }
  293. // while (false);
  294. // }
  295. // catch (Exception ex)
  296. // {
  297. // sMsg = new Util().GetLastExceptionMsg(ex);
  298. // }
  299. // if (null != sMsg)
  300. // {
  301. // crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg };
  302. // }
  303. // return crm;
  304. //}
  305. }
  306. }