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.

125 lines
6.0 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. class AnnounceService : SingleDataTableTemplate<tb_sys_announce>
  16. {
  17. [Auth(false)]
  18. public new CResponseMessage Read(CRequestMessage i_crmInput) => base.Read(i_crmInput);
  19. public AnnounceService()
  20. {
  21. dgReadCommandGenerator = readCommandGenerator;
  22. }
  23. protected string readCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_c,
  24. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  25. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  26. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  27. {
  28. string sMsg;
  29. Command cRes = null;
  30. string groupUID = null;
  31. try
  32. {
  33. do
  34. {
  35. DateTime now = DateTime.Today;
  36. List<string> lsMainColumns = typeof(tb_sys_announce).GetProperties()
  37. .Where(x => x.Name != "PKNames" && x.Name != "Dirty" && x.Name != "SetNull")
  38. .Select(x => x.Name).ToList();
  39. var lsBranch = ProjectHelper.GetUserGroup(i_crmInput);
  40. Dictionary<string, string> qry_data = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
  41. List<WhereNode> lAllWhere = new List<WhereNode>();
  42. if (qry_data.Any())
  43. {
  44. if (qry_data.TryGetValue("isDisplayPeriod", out string isDisplayPeriod))
  45. {
  46. if (bool.Parse(isDisplayPeriod))
  47. {
  48. WhereNode wnA1 = new WhereNode(tb_sys_announce.CN_START_DATE, WhereNode.EColumnOperation.EOT_LTEQ, typeof(tb_sys_announce), now);
  49. WhereNode wnA2 = new WhereNode(tb_sys_announce.CN_START_DATE, WhereNode.EColumnOperation.EOT_ISNULL, typeof(tb_sys_announce));
  50. lAllWhere.Add(new WhereNode(WhereNode.ENodeOperation.ENO_OR, wnA1, wnA2));
  51. WhereNode wnB1 = new WhereNode(tb_sys_announce.CN_END_DATE, WhereNode.EColumnOperation.EOT_GT, typeof(tb_sys_announce), now.AddDays(1));
  52. WhereNode wnB2 = new WhereNode(tb_sys_announce.CN_END_DATE, WhereNode.EColumnOperation.EOT_ISNULL, typeof(tb_sys_announce));
  53. lAllWhere.Add(new WhereNode(WhereNode.ENodeOperation.ENO_OR, wnB1, wnB2));
  54. };
  55. }
  56. if (qry_data.ContainsKey(tb_meb_member.CN_GROUP_ID))
  57. {
  58. // 查詢group uid
  59. tb_grp_group cGroup = new tb_grp_group();
  60. cGroup.SetDirty(tb_grp_group.CN_UID);
  61. tb_grp_group cCon = new tb_grp_group() { fb_group_id = qry_data[tb_meb_member.CN_GROUP_ID].ToString() };
  62. Command cSelect = Command.SetupSelectCmd(cGroup, cCon);
  63. ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
  64. tb_grp_group qds = ai.RunQuerySingleORM<tb_grp_group>(cSelect);
  65. if (qds != null)
  66. {
  67. groupUID = qds.uid ?? "";
  68. Logger.Info("groupUID:" + groupUID);
  69. lAllWhere.Add(new WhereNode(tb_sys_announce.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_announce), groupUID));
  70. }
  71. }
  72. }
  73. if (string.IsNullOrEmpty(groupUID))
  74. {
  75. lAllWhere.Add(new WhereNode(tb_sys_announce.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_sys_announce), lsBranch.ToArray()));
  76. }
  77. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  78. QueryJsonElement qjeA = lBlocks.GetInst();
  79. qjeA.table = tb_sys_announce.TABLENAME;
  80. if (lAllWhere.Any())
  81. {
  82. WhereNode wnAll = new WhereNode(WhereNode.ENodeOperation.ENO_AND, lAllWhere.ToArray());
  83. qjeA.wherecols = wnAll;
  84. }
  85. qjeA.displaycols = lsMainColumns;
  86. qjeA.ordercols = new List<Tuple<QueryJsonElement, string, string>>
  87. {
  88. Tuple.Create(qjeA,tb_sys_announce.CN_CREATE_DATE, BLWording.ORDER_DESC),
  89. };
  90. if (qry_data.Any())
  91. {
  92. qjeA.dicwherecols = qry_data;
  93. }
  94. lBlocks.Add(qjeA);
  95. sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
  96. if (sMsg != null)
  97. {
  98. break;
  99. }
  100. }
  101. while (false);
  102. }
  103. catch (Exception ex)
  104. {
  105. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  106. sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  107. #if DEBUG
  108. System.Diagnostics.Debug.WriteLine(sMsg);
  109. #endif
  110. }
  111. o_c = cRes;
  112. return sMsg;
  113. }
  114. }
  115. }