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.
624 lines
29 KiB
624 lines
29 KiB
namespace CounsellorBL.BLStructure.GROUP
|
|
{
|
|
using CounsellorBL.Common;
|
|
using CounsellorBL.GROUP.Helper;
|
|
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;
|
|
using System.Text;
|
|
using static CounsellorBL.GROUP.Helper.FbHelper;
|
|
|
|
public class GroupManageService : SingleDataTableTemplate<tb_grp_group>
|
|
{
|
|
private class GroupViewModel
|
|
{
|
|
public string uid { get; set; }
|
|
public string name { get; set; }
|
|
public string fb_group_id { get; set; }
|
|
public string description { get; set; }
|
|
public int seq { get; set; }
|
|
public string user_token { get; set; }
|
|
public int status_flag { get; set; }
|
|
public string announcement { get; set; }
|
|
|
|
}
|
|
public GroupManageService()
|
|
{
|
|
dgReadCommandPostDataHandler = readCommandPostDataHandler;
|
|
|
|
dgCreateCommandGenerator = createCommandGenerator;
|
|
|
|
dgDeleteCommandGenerator = deleteCommandGenerator;
|
|
|
|
dgUpdateCommandGenerator = updateCommandGenerator;
|
|
}
|
|
[Auth(false)]
|
|
public new CResponseMessage Read(CRequestMessage i_crmInput) => base.Read(i_crmInput);
|
|
protected string readCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
|
|
[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;
|
|
object oResultData = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
// 取得condition
|
|
Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
|
|
|
|
// 登入者所屬社團
|
|
var lsBranch = ProjectHelper.GetUserGroup(i_crmInput);
|
|
|
|
/**開始組指令**/
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.displaycols = new List<string>()
|
|
{
|
|
tb_grp_group.CN_UID,
|
|
tb_grp_group.CN_NAME,
|
|
tb_grp_group.CN_FB_GROUP_ID,
|
|
tb_grp_group.CN_DESCRIPTION,
|
|
tb_grp_group.CN_SEQ,
|
|
tb_grp_group.CN_STATUS_FLAG,
|
|
tb_grp_group.CN_POST_USER_UID,
|
|
tb_grp_group.CN_ANNOUNCEMENT,
|
|
tb_grp_group.CN_CLIENT_SECRET,
|
|
tb_grp_group.CN_PAGE_ID,
|
|
tb_grp_group.CN_APP_ID,
|
|
tb_grp_group.CN_PAGES_TOKEN
|
|
};
|
|
List<WhereNode> wnQuery = new List<WhereNode>();
|
|
if (lsBranch.Any())
|
|
{
|
|
wnQuery.Add(new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_group), lsBranch.ToArray()));
|
|
}
|
|
if (wnQuery.Any())
|
|
{
|
|
qjeGroup.wherecols = new WhereNode(WhereNode.ENodeOperation.ENO_AND, wnQuery.ToArray());
|
|
}
|
|
if (dicCondition != null && dicCondition.Any())
|
|
{
|
|
qjeGroup.dicwherecols = dicCondition;
|
|
}
|
|
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
List<tb_grp_group> qds = ai.RunQueryList<tb_grp_group>(cRes);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRead);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
oResultData = qds.OrderBy(x => x.seq);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(readCommandPostDataHandler)} 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_oReault = oResultData;
|
|
return sMsg;
|
|
}
|
|
|
|
protected string updateCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcResult, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
string sMsg = null;
|
|
List<Command> lCmds = new List<Command>();
|
|
string uid = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
List<string> data = new List<string>();
|
|
|
|
foreach (JToken jtk in i_jaData)
|
|
{
|
|
Dictionary<string, object> dicData = jtk.ToObject<Dictionary<string, object>>();
|
|
Dictionary<string, object> dicData2 = jtk[BLWording.DATA].ToObject<Dictionary<string, object>>();
|
|
|
|
//取得user_uid
|
|
if (dicData.ContainsKey(BLWording.WHEREDATA))
|
|
{
|
|
JObject wheredata = dicData[BLWording.WHEREDATA] as JObject;
|
|
Dictionary<string, object> wheredataDic = wheredata.ToObject<Dictionary<string, object>>();
|
|
if (wheredataDic.ContainsKey(BLWording.UID))
|
|
{
|
|
uid = wheredataDic[BLWording.UID].ToString();
|
|
}
|
|
}
|
|
|
|
var joData = dicData[BLWording.DATA] as JObject;
|
|
if (joData != null)
|
|
{
|
|
if (joData.ContainsKey(tb_grp_group.CN_POST_USER_UID))
|
|
{
|
|
joData[tb_grp_group.CN_POST_USER_UID] = joData[tb_grp_group.CN_POST_USER_UID].ToString().Contains("new_add") ? Guid.NewGuid().ToString() : joData[tb_grp_group.CN_POST_USER_UID].ToString();
|
|
}
|
|
}
|
|
|
|
tb_grp_group u = new tb_grp_group();
|
|
sMsg = valueAssignment(i_crmInput, u, joData, out List<Command> lcAddInsert, i_bIsCreate: false);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
Command c = Command.SetupUpdateCmd(u, new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), uid));
|
|
lCmds.Add(c);
|
|
|
|
bool hasUser = false;
|
|
if (dicData2.ContainsKey("tb_grp_group2user"))
|
|
{
|
|
var user = dicData2["tb_grp_group2user"] as JArray;
|
|
if (user.Any())
|
|
{
|
|
hasUser = true;
|
|
var updData = new List<string>();
|
|
foreach (var item in user)
|
|
{
|
|
Dictionary<string, object> dicUserData = new Dictionary<string, object>();
|
|
if (item.Any())
|
|
{
|
|
dicUserData = item.ToObject<Dictionary<string, object>>();
|
|
}
|
|
dicUserData.Remove(tb_grp_group2user.CN_UID);
|
|
if (Guid.TryParse(item[tb_grp_group2user.CN_UID].ToString(), out var id))
|
|
{
|
|
updData.Add(id.ToString());
|
|
// 修改
|
|
tb_grp_group2user cUpdUser = new tb_grp_group2user();
|
|
tb_grp_group2user cUpdCon = new tb_grp_group2user() { uid = id.ToString() };
|
|
cUpdUser.FillData(dicUserData);
|
|
|
|
lCmds.Add(Command.SetupUpdateCmd(cUpdUser, cUpdCon));
|
|
}
|
|
else
|
|
{
|
|
// 新增
|
|
tb_grp_group2user cNewUser = new tb_grp_group2user();
|
|
cNewUser.FillData(dicUserData);
|
|
cNewUser.uid = Guid.NewGuid().ToString();
|
|
cNewUser.create_date = DateTime.Now;// Set dirty column value
|
|
cNewUser.group_uid = uid;
|
|
|
|
lCmds.Add(Command.SetupInsertCmd(cNewUser));
|
|
}
|
|
}
|
|
|
|
tb_grp_group2user cRecord = new tb_grp_group2user();
|
|
cRecord.SetFullDirty();
|
|
tb_grp_group2user cCon = new tb_grp_group2user() { group_uid = uid };
|
|
Command cSelect = Command.SetupSelectCmd(cRecord, cCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_grp_group2user> qds = ai.RunQueryList<tb_grp_group2user>(cSelect);
|
|
|
|
var delData = qds.Select(x => x.uid.ToString()).ToList().Except(updData);
|
|
foreach (var del in delData)
|
|
{
|
|
tb_grp_group2user cCond = new tb_grp_group2user() { uid = del };
|
|
lCmds.Add(Command.SetupDeleteCmd(cCond));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!hasUser)
|
|
{
|
|
sMsg = "至少一位發文者!";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(updateCommandGenerator)} 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_lcResult = lCmds;
|
|
return sMsg;
|
|
}
|
|
|
|
protected string createCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lResult, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
string sMsg = null;
|
|
List<Command> lCmds = new List<Command>();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
foreach (JToken joData in i_jaData)
|
|
{
|
|
Dictionary<string, object> dicData = joData.ToObject<Dictionary<string, object>>();
|
|
JObject jdata = dicData[BLWording.DATA] as JObject;
|
|
Dictionary<string, object> dicInput = jdata.ToObject<Dictionary<string, object>>();
|
|
|
|
//取得新增的帳號uid
|
|
string uid = Guid.NewGuid().ToString();
|
|
tb_grp_group cInsert = new tb_grp_group()
|
|
{
|
|
uid = uid,
|
|
fb_group_id = (dicInput[tb_grp_group.CN_FB_GROUP_ID] ?? "").ToString(),
|
|
name = dicInput[tb_grp_group.CN_NAME].ToString(),
|
|
app_id = dicInput[tb_grp_group.CN_APP_ID].ToString(),
|
|
page_id = dicInput[tb_grp_group.CN_PAGE_ID].ToString(),
|
|
pages_token = dicInput[tb_grp_group.CN_PAGES_TOKEN].ToString(),
|
|
client_secret = dicInput[tb_grp_group.CN_CLIENT_SECRET].ToString(),
|
|
seq = Convert.ToInt32(dicInput[tb_grp_group.CN_SEQ] ?? 0),
|
|
status_flag = Convert.ToInt32(dicInput[tb_grp_group.CN_STATUS_FLAG] ?? 0)
|
|
};
|
|
if (dicInput.ContainsKey(tb_grp_group.CN_DESCRIPTION) && !string.IsNullOrEmpty(dicInput[tb_grp_group.CN_DESCRIPTION]?.ToString()))
|
|
{
|
|
cInsert.description = dicInput[tb_grp_group.CN_DESCRIPTION].ToString();
|
|
}
|
|
|
|
if (dicInput.ContainsKey(tb_grp_group.CN_POST_USER_UID) && !string.IsNullOrEmpty(dicInput[tb_grp_group.CN_POST_USER_UID]?.ToString()))
|
|
{
|
|
cInsert.post_user_uid = dicInput[tb_grp_group.CN_POST_USER_UID].ToString().Contains("new_add") ? Guid.NewGuid().ToString() : dicInput[tb_grp_group.CN_POST_USER_UID].ToString();
|
|
}
|
|
|
|
Command c = Command.SetupInsertCmd(cInsert);
|
|
lCmds.Add(c);
|
|
|
|
bool hasUser = false;
|
|
if (dicInput.ContainsKey("tb_grp_group2user"))
|
|
{
|
|
var user = dicInput["tb_grp_group2user"] as JArray;
|
|
if (user.Any())
|
|
{
|
|
hasUser = true;
|
|
// 新增user
|
|
foreach (var item in user)
|
|
{
|
|
tb_grp_group2user cNewUser = new tb_grp_group2user()
|
|
{
|
|
uid = cInsert.post_user_uid,
|
|
group_uid = uid,
|
|
fb_account = item[tb_grp_group2user.CN_FB_ACCOUNT].ToString(),
|
|
fb_password = item[tb_grp_group2user.CN_FB_PASSWORD].ToString(),
|
|
user_token = item[tb_grp_group2user.CN_USER_TOKEN].ToString(),
|
|
status_flag = (int)item[tb_grp_group2user.CN_STATUS_FLAG],
|
|
};
|
|
lCmds.Add(Command.SetupInsertCmd(cNewUser));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!hasUser)
|
|
{
|
|
sMsg = "至少一位發文者!";
|
|
break;
|
|
}
|
|
// 新增現場銷貨會員資料
|
|
tb_meb_member cNewDefaultUser = new tb_meb_member()
|
|
{
|
|
uid = Guid.NewGuid().ToString(),
|
|
group_id = cInsert.fb_group_id,
|
|
group_user_id = "0000000000000000",
|
|
name = "現貨銷售",
|
|
};
|
|
lCmds.Add(Command.SetupInsertCmd(cNewDefaultUser));
|
|
}
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(createCommandGenerator)} 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_lResult = lCmds;
|
|
return sMsg;
|
|
}
|
|
protected string deleteCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lResult, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
string sMsg = null;
|
|
List<Command> lCmds = new List<Command>();
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
foreach (JToken joData in i_jaData)
|
|
{
|
|
Dictionary<string, object> dicData = joData.ToObject<Dictionary<string, object>>();
|
|
|
|
Dictionary<string, object> wheredataDic;
|
|
string uid = null;
|
|
if (dicData.ContainsKey(BLWording.WHEREDATA) && dicData[BLWording.WHEREDATA] is JObject wheredata)
|
|
{
|
|
wheredataDic = wheredata.ToObject<Dictionary<string, object>>();
|
|
if (wheredataDic.ContainsKey(BLWording.UID))
|
|
{
|
|
uid = wheredataDic[BLWording.UID].ToString();
|
|
}
|
|
}
|
|
tb_grp_branch ur = new tb_grp_branch()
|
|
{
|
|
group_uid = uid
|
|
};
|
|
lCmds.Add(Command.SetupDeleteCmd(ur));
|
|
|
|
tb_grp_group2user dUser = new tb_grp_group2user()
|
|
{
|
|
group_uid = uid
|
|
};
|
|
lCmds.Add(Command.SetupDeleteCmd(dUser));
|
|
|
|
tb_grp_group r = new tb_grp_group()
|
|
{
|
|
uid = uid
|
|
};
|
|
lCmds.Add(Command.SetupDeleteCmd(r));
|
|
}
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(deleteCommandGenerator)} 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_lResult = lCmds;
|
|
return sMsg;
|
|
}
|
|
public CResponseMessage GetAnnouncemnet(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg;
|
|
CResponseMessage crmRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
List<string> lsEmpColumns = EntityBase.GetAllColumnName(typeof(tb_grp_group));
|
|
|
|
// 取得condition
|
|
Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.displaycols = lsEmpColumns;
|
|
if (dicCondition.Any())
|
|
{
|
|
qjeGroup.dicwherecols = dicCondition;
|
|
}
|
|
lBlocks.Add(qjeGroup);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRead);
|
|
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRead);
|
|
var qds = ai.RunQueryList<GroupViewModel>(cRead);
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add(BLWording.DATA, qds);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetAnnouncemnet)} 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 RefreshUserAccessToken(CRequestMessage i_crmInput)
|
|
{
|
|
int prepare_token_counnt = 0, success_refresh_count = 0;
|
|
StringBuilder fbErrorString = new StringBuilder();
|
|
List<Command> commands = new List<Command>();
|
|
|
|
try
|
|
{
|
|
var groupsAndUsers = GetEnableGroupsAndGroup2Users();
|
|
List<tb_grp_group> groups = groupsAndUsers.groups;
|
|
List<tb_grp_group2user> group2users = groupsAndUsers.group2users;
|
|
|
|
var FbHelp = new FbHelper();
|
|
|
|
foreach (var group in groups)
|
|
{
|
|
var AppId = group.app_id;
|
|
var AppSecret = group.client_secret;
|
|
|
|
foreach (var user in group2users.Where(x => x.group_uid == group.uid))
|
|
{
|
|
prepare_token_counnt++;
|
|
var UserToken = user.user_token;
|
|
|
|
FbHelp.GetUserAccessToken(ref UserToken, ref AppId, ref AppSecret,
|
|
(response) =>
|
|
{
|
|
success_refresh_count++;
|
|
|
|
var content = JsonConvert.DeserializeObject<FbGetTokenEntity>(response.Content.ReadAsStringAsync().Result);
|
|
commands.Add(Command.SetupUpdateCmd(new tb_grp_group2user() { user_token = content.access_token }, new tb_grp_group2user() { uid = user.uid }));
|
|
},
|
|
(response, error_code) =>
|
|
{
|
|
|
|
fbErrorString.AppendLine(error_code);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
if (commands.Any())
|
|
{
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(commands.FirstOrDefault(), GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(commands);
|
|
}
|
|
|
|
if (prepare_token_counnt != success_refresh_count || fbErrorString.Length > 0)
|
|
{
|
|
var err = $"Prepare and success token count not same, FB response: {fbErrorString.ToString()}";
|
|
Logger.Error(err);
|
|
return new CErrorResponseMessage(err, null);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(ex.ToString());
|
|
return new CErrorResponseMessage(ex.ToString(), null);
|
|
}
|
|
|
|
Logger.Info($"Prepare refresh access token count={prepare_token_counnt}, success refresh count= {success_refresh_count}");
|
|
return new CSuccessResponseMessage($"{nameof(RefreshUserAccessToken)} success", i_crmInput);
|
|
}
|
|
|
|
|
|
private (List<tb_grp_group> groups, List<tb_grp_group2user> group2users) GetEnableGroupsAndGroup2Users()
|
|
{
|
|
string sMsg = "";
|
|
List<tb_grp_group> groups = new List<tb_grp_group>();
|
|
List<tb_grp_group2user> group2users = new List<tb_grp_group2user>();
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qje_groups = lBlocks.GetInst();
|
|
qje_groups.table = tb_grp_group.TABLENAME;
|
|
qje_groups.displaycols = EntityBase.GetAllColumnName(typeof(tb_grp_group));
|
|
qje_groups.wherecols = new WhereNode(tb_grp_group.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), BLWording.STATUS_FLAG_ON);
|
|
lBlocks.Add(qje_groups);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
groups = ai.RunQueryList<tb_grp_group>(cRes);
|
|
|
|
lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qje_group2user = lBlocks.GetInst();
|
|
qje_group2user.table = tb_grp_group2user.TABLENAME;
|
|
qje_group2user.displaycols = EntityBase.GetAllColumnName(typeof(tb_grp_group2user));
|
|
qje_group2user.wherecols = new WhereNode(tb_grp_group2user.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group2user), BLWording.STATUS_FLAG_ON);
|
|
lBlocks.Add(qje_group2user);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ai = ArsenalDBMgr.GetInst(cRes);
|
|
group2users = ai.RunQueryList<tb_grp_group2user>(cRes);
|
|
|
|
return (groups, group2users);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得群組的隱私狀態, 只有屬於這群組的人或社團管理人可以查到群組狀態
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <returns></returns>
|
|
[Auth(false)]
|
|
public CResponseMessage GetGroupPrivacy(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg;
|
|
CResponseMessage crmRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
|
|
string group_id = dicCondition[tb_grp_group.CN_FB_GROUP_ID];
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
|
|
QueryJsonElement group2user = lBlocks.GetInst();
|
|
group2user.table = tb_grp_group2user.TABLENAME;
|
|
group2user.displaycols = new List<string> { tb_grp_group2user.CN_USER_TOKEN };
|
|
group2user.wherecols = new WhereNode(tb_grp_group2user.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group2user), BLWording.STATUS_FLAG_ON);
|
|
lBlocks.Add(group2user);
|
|
|
|
QueryJsonElement groups = lBlocks.GetInst();
|
|
groups.table = tb_grp_group.TABLENAME;
|
|
groups.displaycols = new List<string>();
|
|
groups.jointype = QueryJsonElement.LEFT_JOIN;
|
|
groups.jointable = group2user;
|
|
groups.joincols = new Dictionary<string, string>() { { tb_grp_group.CN_UID, tb_grp_group2user.CN_GROUP_UID } };
|
|
if (dicCondition.Any())
|
|
{
|
|
groups.dicwherecols = dicCondition;
|
|
}
|
|
lBlocks.Add(groups);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRead);
|
|
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRead);
|
|
GroupViewModel qds = ai.RunQuerySingleORM<GroupViewModel>(cRead);
|
|
|
|
var FbHelp = new FbHelper();
|
|
FbHelp.GetGroupPublicDescription(group_id, qds.user_token,
|
|
(response)=>{
|
|
var content = JsonConvert.DeserializeObject<FbGroupEntity>(response.Content.ReadAsStringAsync().Result);
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add(BLWording.DATA, content);
|
|
},
|
|
(response, error_code) =>
|
|
{
|
|
throw new Exception(error_code);
|
|
}
|
|
);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetAnnouncemnet)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
return new CErrorResponseMessage(sMsg, i_crmInput);
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
}
|
|
}
|