620 lines
28 KiB

  1. namespace CounsellorBL.BLStructure.SYS
  2. {
  3. using CounsellorBL.Common;
  4. using CounsellorBL.Helper;
  5. using MonumentDefine;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using OT.COM.ArsenalDB;
  9. using OT.COM.LogisticsUtil;
  10. using OT.COM.SignalerMessage;
  11. using SoldierData.EnterprizeV4;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using static CounsellorBL.Common.EntityBaseExtension;
  16. public class AuthManageService : SingleDataTableTemplate<tb_sys_program>
  17. {
  18. public AuthManageService()
  19. {
  20. dgReadCommandGenerator = readCommandGenerator;
  21. dgReadCommandPostDataHandler = readCommandPostDataHandler;
  22. dgUpdateCommandGenerator = updateCommandGenerator;
  23. }
  24. private class ResViewModel
  25. {
  26. public string uid { get; set; } = null;
  27. public string name { get; set; } = null;
  28. public string module_name { get; set; } = null;
  29. public string parent { get; set; } = null;
  30. public string module_UID { get; set; } = null;
  31. public string action_name { get; set; } = null;
  32. public string action_UID { get; set; } = null;
  33. public int sequence { get; set; } = 0;
  34. }
  35. protected string readCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_c,
  36. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  37. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  38. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  39. {
  40. Command cRes = null;
  41. string sMsg;
  42. try
  43. {
  44. do
  45. {
  46. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  47. QueryJsonElement qjeA = lBlocks.GetInst();
  48. qjeA.table = tb_sys_program.TABLENAME;
  49. qjeA.displaycols = new List<string>() { tb_sys_program.CN_UID, tb_sys_program.CN_NAME, tb_sys_program.CN_SEQ };
  50. QueryJsonElement qjeB = lBlocks.GetInst();
  51. qjeB.table = tb_sys_module.TABLENAME;
  52. qjeB.jointype = QueryJsonElement.JOIN;
  53. qjeB.jointable = qjeA;
  54. qjeB.joincols = new Dictionary<string, string>() {
  55. { tb_sys_module.CN_UID,tb_sys_program.CN_MODULE_UID }};
  56. qjeB.aliascols = new Dictionary<string, List<string>>()
  57. { { tb_sys_module .CN_UID, new List<string>(){ "module_UID" } } ,{ tb_sys_module.CN_NAME, new List<string>(){ "module_name" } }};
  58. qjeB.displaycols = new List<string>() { tb_sys_module.CN_CODE, tb_sys_module.CN_SEQ, tb_sys_module.CN_PARENT };
  59. QueryJsonElement qjeC = lBlocks.GetInst();
  60. qjeC.table = tb_sys_program2action.TABLENAME;
  61. qjeC.jointype = QueryJsonElement.JOIN;
  62. qjeC.jointable = qjeA;
  63. qjeC.joincols = new Dictionary<string, string>() {
  64. { tb_sys_program2action.CN_PROGRAM_UID,tb_sys_program.CN_UID }};
  65. qjeC.aliascols = new Dictionary<string, List<string>>()
  66. { { tb_sys_program2action .CN_UID, new List<string>(){ "action_UID" } } };
  67. qjeC.displaycols = new List<string>() { tb_sys_program2action.CN_ACTION_NAME, tb_sys_program2action.CN_SEQUENCE };
  68. lBlocks.Add(qjeA);
  69. lBlocks.Add(qjeB);
  70. lBlocks.Add(qjeC);
  71. sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
  72. }
  73. while (false);
  74. }
  75. catch (Exception ex)
  76. {
  77. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  78. sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  79. #if DEBUG
  80. System.Diagnostics.Debug.WriteLine(sMsg);
  81. #endif
  82. }
  83. o_c = cRes;
  84. return sMsg;
  85. }
  86. protected string readCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
  87. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  88. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  89. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  90. {
  91. string sMsg = null;
  92. object oResultData = null;
  93. try
  94. {
  95. do
  96. {
  97. List<ResViewModel> qds = i_aiArsenal.RunQueryList<ResViewModel>(i_cCmd);
  98. if (!i_cCmd.IsSuccess)
  99. {
  100. sMsg = i_cCmd.LastErrorCode;
  101. break;
  102. }
  103. string[] saCrudArray = { "btnQry", "btnAdd", "btnUpd", "btnDel" };
  104. List<tb_sys_action> lActionList = GetAction();
  105. oResultData = qds
  106. .Select(x => new
  107. {
  108. x.uid,
  109. x.name,
  110. modulename = x.module_name,
  111. moduleparent = x.parent,
  112. moduleuid = x.module_UID,
  113. actionname = x.action_name,
  114. action = lActionList.Where(c => c.uid == x.action_name).Select(c => c.name).SingleOrDefault(),
  115. action_id = x.action_UID,
  116. x.sequence
  117. })
  118. .GroupBy(x => new { x.uid, x.name, x.moduleuid, x.modulename, x.moduleparent })
  119. .Select(x => new
  120. {
  121. x.Key.uid,
  122. x.Key.name,
  123. x.Key.moduleuid,
  124. x.Key.modulename,
  125. x.Key.moduleparent,
  126. view = x.Where(c => c.actionname.Trim() == saCrudArray[0]).Select(c => c.action_id).SingleOrDefault(),
  127. create = x.Where(c => c.actionname.Trim() == saCrudArray[1]).Select(c => c.action_id).SingleOrDefault(),
  128. edit = x.Where(c => c.actionname.Trim() == saCrudArray[2]).Select(c => c.action_id).SingleOrDefault(),
  129. delete = x.Where(c => c.actionname.Trim() == saCrudArray[3]).Select(c => c.action_id).SingleOrDefault(),
  130. other = x.Where(c => !saCrudArray.Contains(c.actionname.Trim()))
  131. .OrderBy(c => c.sequence)
  132. .Select(c => new { c.action, c.action_id })
  133. }).ToList();
  134. }
  135. while (false);
  136. }
  137. catch (Exception ex)
  138. {
  139. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  140. sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  141. #if DEBUG
  142. System.Diagnostics.Debug.WriteLine(sMsg);
  143. #endif
  144. }
  145. o_oReault = oResultData;
  146. return sMsg;
  147. }
  148. private List<tb_sys_action> GetAction()
  149. {
  150. // 查詢action
  151. tb_sys_action cData = new tb_sys_action();
  152. cData.SetFullDirtyEx(EColumnFilter.ES_NO);
  153. Command cSelect = Command.SetupSelectCmd(cData);
  154. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
  155. List<tb_sys_action> qdAction = ai.RunQueryList<tb_sys_action>(cSelect);
  156. return qdAction;
  157. }
  158. private QueryJsonElementCollection getProgramActionQJE(out QueryJsonElement o_qjeA, out QueryJsonElement o_qjeB)
  159. {
  160. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  161. o_qjeA = lBlocks.GetInst();
  162. o_qjeA.table = tb_sys_program.TABLENAME;
  163. o_qjeA.displaycols = new List<string>() { tb_sys_program.CN_UID, tb_sys_program.CN_NAME };
  164. o_qjeB = lBlocks.GetInst();
  165. o_qjeB.table = tb_sys_program2action.TABLENAME;
  166. o_qjeB.jointype = QueryJsonElement.LEFT_JOIN;
  167. o_qjeB.jointable = o_qjeA;
  168. o_qjeB.joincols = new Dictionary<string, string>() {
  169. { tb_sys_program2action.CN_PROGRAM_UID,tb_sys_program.CN_UID }};
  170. o_qjeB.displaycols = new List<string>() { tb_sys_program2action.CN_ACTION_NAME };
  171. lBlocks.Add(o_qjeA);
  172. lBlocks.Add(o_qjeB);
  173. return lBlocks;
  174. }
  175. protected string getRoleAuthCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
  176. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  177. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  178. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  179. {
  180. return getAuthCommandGeneratorBase(BLWording.ROLE_ID, i_jaData[0][BLWording.ROLE_ID].ToObject<string>(), out o_cCmd);
  181. }
  182. public CResponseMessage GetRoleAuth(CRequestMessage i_crmInput)
  183. {
  184. return simpleQuery(i_crmInput, BLWording.QRY_MASTER, getRoleAuthCommandGenerator, actionsPostDataHandler);
  185. }
  186. protected string getUserAuthCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
  187. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  188. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  189. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  190. {
  191. return getAuthCommandGeneratorBase(BLWording.USER_ID, i_jaData[0][BLWording.USER_ID].ToObject<string>(), out o_cCmd);
  192. }
  193. protected string actionsPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
  194. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  195. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  196. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  197. {
  198. string sMsg = null;
  199. object oResultData = null;
  200. try
  201. {
  202. do
  203. {
  204. List<ResViewModel> qds = i_aiArsenal.RunQueryList<ResViewModel>(i_cCmd);
  205. if (!i_cCmd.IsSuccess)
  206. {
  207. sMsg = i_cCmd.LastErrorCode;
  208. break;
  209. }
  210. string[] saCrudArray = { "btnQry", "btnAdd", "btnUpd", "btnDel" };
  211. List<tb_sys_action> lActionList = GetAction();
  212. oResultData = qds.Select(x => new
  213. {
  214. x.uid,
  215. x.name,
  216. actionname = x.action_name,
  217. })
  218. .GroupBy(x => x.uid)
  219. .Select(x => new
  220. {
  221. uid = x.Key,
  222. view = x.Any(c => c.actionname == saCrudArray[0]),
  223. create = x.Any(c => c.actionname == saCrudArray[1]),
  224. edit = x.Any(c => c.actionname == saCrudArray[2]),
  225. delete = x.Any(c => c.actionname == saCrudArray[3]),
  226. other = x.Where(c => !saCrudArray.Contains(c.actionname)).Select(c => lActionList.Where(z => z.uid == c.actionname).Select(z => z.name))
  227. }).ToList();
  228. }
  229. while (false);
  230. }
  231. catch (Exception ex)
  232. {
  233. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  234. sMsg = $"{nameof(actionsPostDataHandler)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  235. #if DEBUG
  236. System.Diagnostics.Debug.WriteLine(sMsg);
  237. #endif
  238. }
  239. o_oReault = oResultData;
  240. return sMsg;
  241. }
  242. public CResponseMessage GetUserAuth(CRequestMessage i_crmInput)
  243. {
  244. return simpleQuery(i_crmInput, BLWording.QRY_MASTER, getUserAuthCommandGenerator, actionsPostDataHandler);
  245. }
  246. protected string getAuthCommandGeneratorBase(string i_sGrandType, string i_sGrandUID, out Command o_cCmd,
  247. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  248. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  249. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  250. {
  251. Command cRes = null;
  252. string sMsg;
  253. try
  254. {
  255. do
  256. {
  257. QueryJsonElementCollection lBlocks = getProgramActionQJE(out QueryJsonElement qjeA, out QueryJsonElement qjeB);
  258. QueryJsonElement qjeC = lBlocks.GetInst();
  259. qjeC.table = tb_sys_program2action_grant.TABLENAME;
  260. qjeC.jointype = QueryJsonElement.LEFT_JOIN;
  261. qjeC.jointable = qjeB;
  262. qjeC.joincols = new Dictionary<string, string>() {
  263. { tb_sys_program2action_grant.CN_PROGRAM2ACTION_UID,tb_sys_program2action.CN_UID }
  264. };
  265. qjeC.displaycols = new List<string>() { tb_sys_program2action_grant.CN_PROGRAM2ACTION_UID };
  266. qjeC.wherecols = new WhereNode(WhereNode.ENodeOperation.ENO_AND,
  267. new WhereNode(tb_sys_program2action_grant.CN_GRANT_TYPE, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_program2action_grant), i_sGrandType),
  268. new WhereNode(tb_sys_program2action_grant.CN_GRANT_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_program2action_grant), i_sGrandUID)
  269. );
  270. lBlocks.Add(qjeC);
  271. sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
  272. }
  273. while (false);
  274. }
  275. catch (Exception ex)
  276. {
  277. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  278. sMsg = $"{nameof(getAuthCommandGeneratorBase)} unknwon exception. i_sGrandType={i_sGrandType}, i_sGrandUID={i_sGrandUID}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  279. #if DEBUG
  280. System.Diagnostics.Debug.WriteLine(sMsg);
  281. #endif
  282. }
  283. o_cCmd = cRes;
  284. return sMsg;
  285. }
  286. protected string getDepAuthCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
  287. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  288. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  289. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  290. {
  291. return getAuthCommandGeneratorBase(BLWording.DEPT_ID, i_jaData[0][BLWording.DEPT_ID].ToObject<string>(), out o_cCmd);
  292. }
  293. // 部門權限
  294. public CResponseMessage GetDepAuth(CRequestMessage i_crmInput)
  295. {
  296. return simpleQuery(i_crmInput, BLWording.QRY_MASTER, getDepAuthCommandGenerator, actionsPostDataHandler);
  297. }
  298. protected string updateCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcResult, List<string> i_saQryContainKeys,
  299. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  300. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  301. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  302. {
  303. string sMsg = null;
  304. List<Command> lCmds = new List<Command>();
  305. try
  306. {
  307. do
  308. {
  309. List<string> data = new List<string>();
  310. foreach (JToken jtk in i_jaData)
  311. {
  312. data.Add(jtk[BLWording.DATA].ToString());
  313. }
  314. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  315. QueryJsonElement qjeOrigin = lBlocks.GetInst();
  316. ArsenalInterface ai;
  317. string sGrand_type = null;
  318. if (i_crmInput.param.ContainsKey(BLWording.ROLE_ID))
  319. {
  320. sGrand_type = BLWording.ROLE_ID;
  321. }
  322. else if (i_crmInput.param.ContainsKey(BLWording.DEPT_ID))
  323. {
  324. sGrand_type = BLWording.DEPT_ID;
  325. }
  326. else if (i_crmInput.param.ContainsKey(BLWording.USER_ID))
  327. {
  328. sGrand_type = BLWording.USER_ID;
  329. }
  330. if (sGrand_type == null)
  331. {
  332. sMsg = MessageWording.PARAM_NOT_EXPECTED;
  333. break;
  334. }
  335. string sGrand_id = i_crmInput.param[sGrand_type] as string;
  336. // 查詢原始資料
  337. qjeOrigin.table = tb_sys_program2action_grant.TABLENAME;
  338. qjeOrigin.displaycols = new List<string>() { tb_sys_program2action_grant.CN_UID, tb_sys_program2action_grant.CN_GRANT_TYPE, tb_sys_program2action_grant.CN_GRANT_UID, tb_sys_program2action_grant.CN_PROGRAM2ACTION_UID };
  339. qjeOrigin.wherecols = new WhereNode(WhereNode.ENodeOperation.ENO_AND,
  340. new WhereNode(tb_sys_program2action_grant.CN_GRANT_TYPE, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_program2action_grant), sGrand_type),
  341. new WhereNode(tb_sys_program2action_grant.CN_GRANT_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_program2action_grant), sGrand_id));
  342. lBlocks.Add(qjeOrigin);
  343. sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRes);
  344. if (sMsg != null)
  345. {
  346. break;
  347. }
  348. ai = ArsenalDBMgr.GetInst(cRes);
  349. List<tb_sys_program2action_grant> qds = ai.RunQueryList<tb_sys_program2action_grant>(cRes);
  350. if (!cRes.IsSuccess)
  351. {
  352. sMsg = cRes.LastErrorCode;
  353. break;
  354. }
  355. if (data.Any())
  356. {
  357. var origin = qds.Select(x => x.program2action_uid).ToList();
  358. var addIDs = data.Except(origin);
  359. var delIDs = origin.Except(data);
  360. if (addIDs.Any())
  361. {
  362. foreach (string sUID in addIDs)
  363. {
  364. tb_sys_program2action_grant cNew = new tb_sys_program2action_grant()
  365. {
  366. grant_type = sGrand_type,
  367. grant_uid = sGrand_id,
  368. program2action_uid = sUID
  369. };
  370. lCmds.Add(Command.SetupInsertCmd(cNew));
  371. }
  372. }
  373. if (delIDs.Any())
  374. {
  375. foreach (string sUID in delIDs)
  376. {
  377. tb_sys_program2action_grant cCond = new tb_sys_program2action_grant()
  378. {
  379. grant_type = sGrand_type,
  380. grant_uid = sGrand_id,
  381. program2action_uid = sUID
  382. };
  383. lCmds.Add(Command.SetupDeleteCmd(cCond));
  384. }
  385. }
  386. }
  387. else
  388. {
  389. tb_sys_program2action_grant cCond = new tb_sys_program2action_grant()
  390. {
  391. grant_type = sGrand_type,
  392. grant_uid = sGrand_id
  393. };
  394. lCmds.Add(Command.SetupDeleteCmd(cCond));
  395. }
  396. }
  397. while (false);
  398. }
  399. catch (Exception ex)
  400. {
  401. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  402. sMsg = $"{nameof(updateCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  403. #if DEBUG
  404. System.Diagnostics.Debug.WriteLine(sMsg);
  405. #endif
  406. }
  407. o_lcResult = lCmds;
  408. return sMsg;
  409. }
  410. protected string getRoleCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
  411. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  412. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  413. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  414. {
  415. Command cRes = null;
  416. string sMsg = null;
  417. try
  418. {
  419. do
  420. {
  421. tb_sys_role cData = new tb_sys_role();
  422. cData.SetFullDirty();
  423. cRes = Command.SetupSelectCmd(cData);
  424. }
  425. while (false);
  426. }
  427. catch (Exception ex)
  428. {
  429. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  430. sMsg = $"{nameof(getRoleCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  431. #if DEBUG
  432. System.Diagnostics.Debug.WriteLine(sMsg);
  433. #endif
  434. }
  435. o_cCmd = cRes;
  436. return sMsg;
  437. }
  438. protected string getRoleCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
  439. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  440. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  441. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = ""
  442. )
  443. {
  444. string sMsg = null;
  445. object oResultData = null;
  446. try
  447. {
  448. do
  449. {
  450. List<tb_sys_role> qdRole = i_aiArsenal.RunQueryList<tb_sys_role>(i_cCmd);
  451. Dictionary<object, string> resp = new Dictionary<object, string>();
  452. foreach (var role in qdRole)
  453. {
  454. resp.Add(role.uid, role.name);
  455. }
  456. oResultData = resp;
  457. }
  458. while (false);
  459. }
  460. catch (Exception ex)
  461. {
  462. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  463. sMsg = $"{nameof(getRoleCommandPostDataHandler)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  464. #if DEBUG
  465. System.Diagnostics.Debug.WriteLine(sMsg);
  466. #endif
  467. }
  468. o_oReault = oResultData;
  469. return sMsg;
  470. }
  471. /// <summary>
  472. /// 取得角色
  473. /// </summary>
  474. /// <param name="i_crmInput"></param>
  475. /// <returns></returns>
  476. [Auth(false)]
  477. public CResponseMessage GetRole(CRequestMessage i_crmInput)
  478. {
  479. return simpleQuery(i_crmInput, null, getRoleCommandGenerator, getRoleCommandPostDataHandler);
  480. }
  481. protected string getUserCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
  482. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  483. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  484. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  485. {
  486. Command cRes = null;
  487. string sMsg = null;
  488. try
  489. {
  490. do
  491. {
  492. tb_sys_user cData = new tb_sys_user();
  493. cData.SetFullDirty();
  494. cRes = Command.SetupSelectCmd(cData);
  495. }
  496. while (false);
  497. }
  498. catch (Exception ex)
  499. {
  500. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  501. sMsg = $"{nameof(getUserCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  502. #if DEBUG
  503. System.Diagnostics.Debug.WriteLine(sMsg);
  504. #endif
  505. }
  506. o_cCmd = cRes;
  507. return sMsg;
  508. }
  509. protected string getUserCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
  510. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  511. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  512. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = ""
  513. )
  514. {
  515. string sMsg = null;
  516. object oResultData = null;
  517. try
  518. {
  519. do
  520. {
  521. List<tb_sys_user> qdUser = i_aiArsenal.RunQueryList<tb_sys_user>(i_cCmd);
  522. if (qdUser.Count > 0)
  523. {
  524. Dictionary<object, string> resp = new Dictionary<object, string>();
  525. foreach (var user in qdUser)
  526. {
  527. resp.Add(user.uid, user.account);
  528. }
  529. oResultData = resp;
  530. }
  531. }
  532. while (false);
  533. }
  534. catch (Exception ex)
  535. {
  536. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  537. sMsg = $"{nameof(getUserCommandPostDataHandler)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  538. #if DEBUG
  539. System.Diagnostics.Debug.WriteLine(sMsg);
  540. #endif
  541. }
  542. o_oReault = oResultData;
  543. return sMsg;
  544. }
  545. [Auth(false)]
  546. public CResponseMessage GetUser(CRequestMessage i_crmInput)
  547. {
  548. return simpleQuery(i_crmInput, null, getUserCommandGenerator, getUserCommandPostDataHandler);
  549. }
  550. }
  551. }