namespace CounsellorBL.GROUP { using CounsellorBL.Common; using CounsellorBL.Helper; using MonumentDefine; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OT.COM.ArsenalDB; using OT.COM.SignalerMessage; using SoldierData.EnterprizeV4; using System; using System.Collections.Generic; using System.Linq; using Util = OT.COM.LogisticsUtil.Util; class BranchService : SingleDataTableTemplate { public BranchService() { dgReadCommandGenerator = readCommandGenerator; } public new CResponseMessage Read(CRequestMessage i_crmInput) => base.Read(i_crmInput); 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; try { do { List lsColumns = EntityBase.GetAllColumnName(typeof(tb_grp_branch)); Dictionary dicWhereData = i_jaData[0][BLWording.WHEREDATA].ToObject>(); Dictionary dicCondition = new Dictionary(); foreach (var data in dicWhereData) { if (data.Key != tb_grp_branch.CN_GROUP_UID) { dicCondition.Add(data.Key, data.Value.ToString()); } } QueryJsonElementCollection lBlocks = new QueryJsonElementCollection(); QueryJsonElement qjeBranch = lBlocks.GetInst(); qjeBranch.table = tb_grp_branch.TABLENAME; qjeBranch.displaycols = lsColumns; List wnQuery = new List(); if (dicWhereData.ContainsKey(tb_grp_branch.CN_GROUP_UID)) { var lsGroupUID = new List(); foreach (var uid in dicWhereData[tb_grp_branch.CN_GROUP_UID] as JArray) { lsGroupUID.Add(uid.ToString()); } wnQuery.Add(new WhereNode(tb_grp_branch.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_branch), lsGroupUID.ToArray())); } if (wnQuery.Any()) { qjeBranch.wherecols = new WhereNode(WhereNode.ENodeOperation.ENO_AND, wnQuery.ToArray()); } qjeBranch.dicwherecols = dicCondition; lBlocks.Add(qjeBranch); QueryJsonElement qjeGroup = lBlocks.GetInst(); qjeGroup.aliascols = new Dictionary>() { { tb_grp_group.CN_NAME, new List(){ "group_name" } } }; qjeGroup.jointype = QueryJsonElement.JOIN; qjeGroup.jointable = qjeBranch; qjeGroup.joincols = new Dictionary() { {tb_grp_group.CN_UID, tb_grp_branch.CN_GROUP_UID } }; lBlocks.Add(qjeGroup); sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRead); if (sMsg != null) { break; } cRes = cRead; } 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; } public CResponseMessage GetBranchName(CRequestMessage i_crmInput) { string sMsg; Command cRes = null; CResponseMessage crmRes = null; try { do { Dictionary dicCondition = GetQueryMasterFirstWhereData(i_crmInput); // 取得condition QueryJsonElementCollection lBlocks = new QueryJsonElementCollection(); QueryJsonElement qjeA = lBlocks.GetInst(); qjeA.table = tb_grp_branch.TABLENAME; qjeA.displaycols = new List() { tb_grp_branch.CN_UID, tb_grp_branch.CN_BRANCH_NAME, tb_grp_branch.CN_GROUP_UID, tb_grp_branch.CN_ADDRESS, tb_grp_branch.CN_IP_ADDRESS, tb_grp_branch.CN_PHONE_NUMBER, tb_grp_branch.CN_QRCODE_PAYTYPE, tb_grp_branch.CN_PUBLIC_STATUS, tb_grp_branch.CN_CONTACT_PERSON, tb_grp_branch.CN_SEQ }; lBlocks.Add(qjeA); QueryJsonElement qjeB = lBlocks.GetInst(); qjeB.table = tb_grp_group.TABLENAME; qjeB.jointype = QueryJsonElement.JOIN; qjeB.jointable = qjeA; qjeB.aliascols = new Dictionary>() { { tb_grp_group.CN_NAME, new List(){ "group_name" } } }; qjeB.joincols = new Dictionary() { { tb_grp_group.CN_UID,tb_grp_branch.CN_GROUP_UID }}; if (dicCondition.ContainsKey(tb_grp_branch.CN_GROUP_UID)) { qjeB.wherecols = new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), dicCondition[tb_grp_branch.CN_GROUP_UID]); } if (dicCondition.ContainsKey(tb_grp_group.CN_FB_GROUP_ID)) { qjeB.wherecols = new WhereNode(tb_grp_group.CN_FB_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), dicCondition[tb_grp_group.CN_FB_GROUP_ID]); } lBlocks.Add(qjeB); sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes); if (sMsg != null) { break; } ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes); QueryDataSet qds = ai.RunQueryDataSet(cRes); if (cRes.IsSuccess == false) { sMsg = cRes.LastErrorCode; break; } crmRes = new CSuccessResponseMessage(null, i_crmInput); crmRes.param.Add(BLWording.DATA, qds); } while (false); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex)); sMsg = $"{nameof(GetBranchName)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. "; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } if (null != sMsg) { crmRes = new CErrorResponseMessage(sMsg, i_crmInput); } return crmRes; } /// /// 取得登入帳號人員管理裡設訂所屬分店的資料 /// /// /// public CResponseMessage GetBranchAuth(CRequestMessage i_crmInput) { string sMsg = null; CResponseMessage crmRes = null; try { do { var lsBranch = ProjectHelper.GetUserBranch(i_crmInput); tb_grp_branch cBranch = new tb_grp_branch(); cBranch.SetFullDirty(); WhereNode wn1 = new WhereNode(tb_grp_branch.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_branch), lsBranch.ToArray()); WhereNode wn2 = new WhereNode(tb_grp_branch.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_branch), (int)Enums.Flag.Enable); Command cSelect = Command.SetupSelectCmd(cBranch, new WhereNode(WhereNode.ENodeOperation.ENO_AND, wn1, wn2)); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect); List qdsBranch = ai.RunQueryList(cSelect); crmRes = new CSuccessResponseMessage(null, i_crmInput); crmRes.param.Add(BLWording.DATA, qdsBranch); } while (false); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex)); sMsg = $"{nameof(GetBranchAuth)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. "; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } if (null != sMsg) { crmRes = new CErrorResponseMessage(sMsg, i_crmInput); } return crmRes; } [Auth(false)] public CResponseMessage GetPayType(CRequestMessage i_crmInput) { string sMsg = null; CResponseMessage crmRes = null; try { do { // var lsBranch = ProjectHelper.GetLoginUser(i_crmInput).receive_branch_uid; tb_grp_branch cBranch = new tb_grp_branch(); cBranch.SetFullDirty(); var session = ProjectHelper.GetLoginUser(i_crmInput); if (session == null) { sMsg = "Session error!!"; Logger.Error($"Session error!! i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. "); } WhereNode wn1 = new WhereNode(tb_grp_branch.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_branch), session.receive_branch_uid); WhereNode wn2 = new WhereNode(tb_grp_branch.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_branch), (int)Enums.Flag.Enable); Command cSelect = Command.SetupSelectCmd(cBranch, new WhereNode(WhereNode.ENodeOperation.ENO_AND, wn1, wn2)); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect); List qdsBranch = ai.RunQueryList(cSelect); crmRes = new CSuccessResponseMessage(null, i_crmInput); crmRes.param.Add(BLWording.DATA, qdsBranch); } while (false); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex)); sMsg = $"{nameof(GetPayType)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. "; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } if (null != sMsg) { crmRes = new CErrorResponseMessage(sMsg, i_crmInput); } return crmRes; } } }