namespace CounsellorBL.BLStructure.SYS { using CounsellorBL.Common; using CounsellorBL.Helper; using MonumentDefine; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OT.COM.ArsenalDB; using OT.COM.LogisticsUtil; using OT.COM.SignalerMessage; using SoldierData.EnterprizeV4; using System; using System.Collections.Generic; using System.Linq; class AnnounceService : SingleDataTableTemplate { [Auth(false)] public new CResponseMessage Read(CRequestMessage i_crmInput) => base.Read(i_crmInput); public AnnounceService() { dgReadCommandGenerator = readCommandGenerator; } protected string readCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_c, [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0, [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "", [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "") { string sMsg; Command cRes = null; string groupUID = null; try { do { DateTime now = DateTime.Today; List lsMainColumns = typeof(tb_sys_announce).GetProperties() .Where(x => x.Name != "PKNames" && x.Name != "Dirty" && x.Name != "SetNull") .Select(x => x.Name).ToList(); var lsBranch = ProjectHelper.GetUserGroup(i_crmInput); Dictionary qry_data = GetQueryMasterFirstQJEDicwherecols(i_crmInput); List lAllWhere = new List(); if (qry_data.Any()) { if (qry_data.TryGetValue("isDisplayPeriod", out string isDisplayPeriod)) { if (bool.Parse(isDisplayPeriod)) { WhereNode wnA1 = new WhereNode(tb_sys_announce.CN_START_DATE, WhereNode.EColumnOperation.EOT_LTEQ, typeof(tb_sys_announce), now); WhereNode wnA2 = new WhereNode(tb_sys_announce.CN_START_DATE, WhereNode.EColumnOperation.EOT_ISNULL, typeof(tb_sys_announce)); lAllWhere.Add(new WhereNode(WhereNode.ENodeOperation.ENO_OR, wnA1, wnA2)); WhereNode wnB1 = new WhereNode(tb_sys_announce.CN_END_DATE, WhereNode.EColumnOperation.EOT_GT, typeof(tb_sys_announce), now.AddDays(1)); WhereNode wnB2 = new WhereNode(tb_sys_announce.CN_END_DATE, WhereNode.EColumnOperation.EOT_ISNULL, typeof(tb_sys_announce)); lAllWhere.Add(new WhereNode(WhereNode.ENodeOperation.ENO_OR, wnB1, wnB2)); }; } if (qry_data.ContainsKey(tb_meb_member.CN_GROUP_ID)) { // 查詢group uid tb_grp_group cGroup = new tb_grp_group(); cGroup.SetDirty(tb_grp_group.CN_UID); tb_grp_group cCon = new tb_grp_group() { fb_group_id = qry_data[tb_meb_member.CN_GROUP_ID].ToString() }; Command cSelect = Command.SetupSelectCmd(cGroup, cCon); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect); tb_grp_group qds = ai.RunQuerySingleORM(cSelect); if (qds != null) { groupUID = qds.uid ?? ""; Logger.Info("groupUID:" + groupUID); lAllWhere.Add(new WhereNode(tb_sys_announce.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_announce), groupUID)); } } } if (string.IsNullOrEmpty(groupUID)) { lAllWhere.Add(new WhereNode(tb_sys_announce.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_sys_announce), lsBranch.ToArray())); } QueryJsonElementCollection lBlocks = new QueryJsonElementCollection(); QueryJsonElement qjeA = lBlocks.GetInst(); qjeA.table = tb_sys_announce.TABLENAME; if (lAllWhere.Any()) { WhereNode wnAll = new WhereNode(WhereNode.ENodeOperation.ENO_AND, lAllWhere.ToArray()); qjeA.wherecols = wnAll; } qjeA.displaycols = lsMainColumns; qjeA.ordercols = new List> { Tuple.Create(qjeA,tb_sys_announce.CN_CREATE_DATE, BLWording.ORDER_DESC), }; if (qry_data.Any()) { qjeA.dicwherecols = qry_data; } lBlocks.Add(qjeA); sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes); if (sMsg != null) { break; } } while (false); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath); sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine})."; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } o_c = cRes; return sMsg; } } }