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.

157 lines
7.1 KiB

  1. 
  2. using CounsellorBL.Helper;
  3. using MonumentDefine;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using OT.COM.ArsenalDB;
  7. using OT.COM.LogisticsUtil;
  8. using OT.COM.SignalerMessage;
  9. using SoldierData;
  10. using SoldierData.EnterprizeV4;
  11. using System;
  12. using System.Collections.Generic;
  13. namespace CounsellorBL.BLStructure.SYS
  14. {
  15. class PersonalInfoService : ModelDataTemplate<VMPersionalInfo>
  16. {
  17. public PersonalInfoService() : base()
  18. {
  19. dgReadCommandGenerator = readCommandGenerator;
  20. dgUpdateCommandGenerator = updateCommandGenerator;
  21. }
  22. protected string readCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_c,
  23. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  24. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  25. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  26. {
  27. string sMsg;
  28. Command cRes = null;
  29. try
  30. {
  31. do
  32. {
  33. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  34. QueryJsonElement qjeA = lBlocks.GetInst();
  35. qjeA.table = tb_sys_session.TABLENAME;
  36. qjeA.wherecols = new WhereNode(tb_sys_session.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_session), i_crmInput.token);
  37. lBlocks.Add(qjeA);
  38. QueryJsonElement qjeUser = lBlocks.GetInst();
  39. qjeUser.table = tb_sys_user.TABLENAME;
  40. qjeUser.jointype = QueryJsonElement.LEFT_JOIN;
  41. qjeUser.jointable = qjeA;
  42. qjeUser.joincols = new Dictionary<string, string>() {
  43. { tb_sys_user.CN_UID, tb_sys_session.CN_CREATE_USER_UID }};
  44. lBlocks.Add(qjeUser);
  45. QueryJsonElement qjeB = lBlocks.GetInst();
  46. qjeB.table = tb_hr_employee.TABLENAME;
  47. qjeB.jointype = QueryJsonElement.LEFT_JOIN;
  48. qjeB.displaycols = new List<string>() { tb_hr_employee.CN_EMAIL, tb_hr_employee.CN_UID };
  49. qjeB.jointable = qjeUser;
  50. qjeB.joincols = new Dictionary<string, string>() {
  51. { tb_hr_employee.CN_UID, tb_sys_user.CN_UID }};
  52. lBlocks.Add(qjeB);
  53. QueryJsonElement qjeC = lBlocks.GetInst();
  54. qjeC.table = tb_sys_user2entercode.TABLENAME;
  55. qjeC.aliascols = new Dictionary<string, List<string>>()
  56. { {tb_sys_user2entercode.CN_UID, new List<string>(){ VMPersionalInfo.CN_USER2ENTERCODE_UID } } };
  57. qjeC.displaycols = new List<string>() { tb_sys_user2entercode.CN_USER_ENTERCODE };
  58. qjeC.jointype = QueryJsonElement.LEFT_JOIN;
  59. qjeC.jointable = qjeUser;
  60. qjeC.joincols = new Dictionary<string, string>() {
  61. { tb_sys_user2entercode.CN_USER_UID, tb_sys_user.CN_UID }};
  62. lBlocks.Add(qjeC);
  63. sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
  64. if (sMsg != null)
  65. {
  66. break;
  67. }
  68. }
  69. while (false);
  70. }
  71. catch (Exception ex)
  72. {
  73. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  74. sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  75. #if DEBUG
  76. System.Diagnostics.Debug.WriteLine(sMsg);
  77. #endif
  78. }
  79. o_c = cRes;
  80. return sMsg;
  81. }
  82. protected string updateCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lResult, List<string> i_saQryContainKeys,
  83. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  84. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  85. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  86. {
  87. string sMsg = null;
  88. List<Command> lcCmd = new List<Command>();
  89. try
  90. {
  91. do
  92. {
  93. foreach (JToken joData in i_jaData)
  94. {
  95. Dictionary<string, object> dicData = joData.ToObject<Dictionary<string, object>>();
  96. string sUserID = null;
  97. if (dicData.ContainsKey(BLWording.WHEREDATA))
  98. {
  99. JObject wheredata = dicData[BLWording.WHEREDATA] as JObject;
  100. Dictionary<string, object> wheredataDic = wheredata?.ToObject<Dictionary<string, object>>();
  101. if (wheredataDic != null && wheredataDic.ContainsKey(BLWording.UID))
  102. {
  103. sUserID = wheredataDic[BLWording.UID].ToString();
  104. }
  105. }
  106. JObject joWriteData = dicData[BLWording.DATA] as JObject;
  107. Dictionary<string, object> dicWriteData = joWriteData.ToObject<Dictionary<string, object>>();
  108. if (dicWriteData.ContainsKey(tb_sys_user2entercode.CN_USER_ENTERCODE))
  109. {
  110. tb_sys_user2entercode u2p = new tb_sys_user2entercode() { user_entercode = dicWriteData[tb_sys_user2entercode.CN_USER_ENTERCODE].ToString() };
  111. Command c = Command.SetupUpdateCmd(u2p, new WhereNode(tb_sys_user2entercode.CN_USER_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_user2entercode), sUserID));
  112. lcCmd.Add(c);
  113. }
  114. if (dicWriteData.ContainsKey(tb_hr_employee.CN_EMAIL))
  115. {
  116. tb_hr_employee u = new tb_hr_employee() { email = dicWriteData[tb_hr_employee.CN_EMAIL].ToString() };
  117. Command c = Command.SetupUpdateCmd(u, new WhereNode(tb_sys_user.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_user), sUserID));
  118. lcCmd.Add(c);
  119. }
  120. }
  121. }
  122. while (false);
  123. }
  124. catch (Exception ex)
  125. {
  126. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  127. sMsg = $"{nameof(updateCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  128. #if DEBUG
  129. System.Diagnostics.Debug.WriteLine(sMsg);
  130. #endif
  131. }
  132. o_lResult = lcCmd;
  133. return sMsg;
  134. }
  135. }
  136. }