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.
 
 
 
 
 
 

441 lines
20 KiB

namespace CounsellorBL.BLStructure.SYS
{
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 RoleManageService : SingleDataTableTemplate<tb_sys_role>
{
public RoleManageService() : base()
{
dgReadCommandGenerator = readCommandGenerator;
dgCreateCommandGenerator = createCommandGenerator;
dgDeleteCommandGenerator = deleteCommandGenerator;
dgUpdateCommandGenerator = updateCommandGenerator;
}
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<string> lsColumns = EntityBase.GetAllColumnName(typeof(tb_sys_role));
// 取得condition
Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
var lsGroup = ProjectHelper.GetUserGroup(i_crmInput);
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
QueryJsonElement qjeRole = lBlocks.GetInst();
qjeRole.table = tb_sys_role.TABLENAME;
qjeRole.displaycols = lsColumns;
qjeRole.wherecols = new WhereNode(tb_sys_role.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_group), lsGroup.ToArray());
if (dicCondition != null && dicCondition.Any())
{
qjeRole.dicwherecols = dicCondition;
}
lBlocks.Add(qjeRole);
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;
}
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 roleid = Guid.NewGuid().ToString();
tb_sys_role cInsert = new tb_sys_role()
{
uid = roleid,
group_uid = dicInput[tb_sys_role.CN_GROUP_UID]?.ToString(),
code = (dicInput[tb_sys_role.CN_CODE] ?? "").ToString(),
name = dicInput[tb_sys_role.CN_NAME].ToString(),
memo = (dicInput[tb_sys_role.CN_MEMO] ?? "").ToString(),
remark = (dicInput[tb_sys_role.CN_REMARK] ?? "").ToString(),
};
Command c = Command.SetupInsertCmd(cInsert);
lCmds.Add(c);
tb_sys_role2org cData = new tb_sys_role2org()
{
org_uid = i_sSessionUser.update_org_uid,
role_uid = roleid,
};
Command d = Command.SetupInsertCmd(cData);
lCmds.Add(d);
//if (dicInput.ContainsKey(BLWording.UID))
//{
// string[] lsRole = dicInput[BLWording.UID].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// lsRole = lsRole.Distinct().ToArray();
// foreach (var role in lsRole)
// {
// tb_sys_user2role cNew = new tb_sys_user2role()
// {
// user_uid = role,
// role_uid = roleid
// };
// lCmds.Add(Command.SetupInsertCmd(cNew));
// }
//}
}
}
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 role_id = null;
if (dicData.ContainsKey(BLWording.WHEREDATA) && dicData[BLWording.WHEREDATA] is JObject wheredata)
{
wheredataDic = wheredata.ToObject<Dictionary<string, object>>();
if (wheredataDic.ContainsKey(BLWording.UID))
{
role_id = wheredataDic[BLWording.UID].ToString();
}
}
tb_sys_user2role ur = new tb_sys_user2role()
{
role_uid = role_id
};
lCmds.Add(Command.SetupDeleteCmd(ur));
tb_sys_role2org r = new tb_sys_role2org()
{
role_uid = role_id
};
lCmds.Add(Command.SetupDeleteCmd(r));
tb_sys_role d = new tb_sys_role()
{
uid = role_id
};
lCmds.Add(Command.SetupDeleteCmd(d));
}
}
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;
}
protected string updateCommandGenerator(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;
List<Command> lCmds = new List<Command>();
try
{
do
{
string role_id = null;
foreach (JToken joData in i_jaData)
{
Dictionary<string, object> dicData = joData.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))
{
role_id = wheredataDic[BLWording.UID].ToString();
}
}
tb_sys_role u = new tb_sys_role();
sMsg = valueAssignment(i_crmInput, u, dicData[BLWording.DATA] as JObject, out List<Command> lcAddInsert, i_bIsCreate: false);
if (sMsg != null)
{
break;
}
Command c = Command.SetupUpdateCmd(u, new WhereNode(tb_sys_role.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_role), role_id));
lCmds.Add(c);
tb_sys_role2org udro = new tb_sys_role2org() { };
Command udr = Command.SetupUpdateCmd(udro, new WhereNode(tb_sys_role2org.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_role2org), role_id));
lCmds.Add(udr);
}
// 查詢原始資料
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
QueryJsonElement qjeOrigin = lBlocks.GetInst();
qjeOrigin.table = tb_sys_user2role.TABLENAME;
qjeOrigin.displaycols = new List<string>() { tb_sys_user2role.CN_USER_UID };
qjeOrigin.wherecols = new WhereNode(tb_sys_user2role.CN_ROLE_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_user2role), role_id);
lBlocks.Add(qjeOrigin);
sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRes);
if (sMsg != null)
{
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_lResult = lCmds;
return sMsg;
}
protected string getUserNameHandler(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_cCmd,
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
{
Command cRes = null;
string sMsg;
try
{
do
{
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
QueryJsonElement qjeUser = lBlocks.GetInst();
qjeUser.table = tb_sys_user.TABLENAME;
qjeUser.displaycols = new List<string>() { tb_sys_user.CN_ACCOUNT, tb_sys_user.CN_UID };
QueryJsonElement qjeEmp = lBlocks.GetInst();
qjeEmp.table = tb_hr_employee.TABLENAME;
qjeEmp.jointype = QueryJsonElement.LEFT_JOIN;
qjeEmp.jointable = qjeUser;
qjeEmp.joincols = new Dictionary<string, string>() {
{ tb_hr_employee.CN_UID,tb_sys_user.CN_UID }};
qjeEmp.displaycols = new List<string>() { tb_hr_employee.CN_NAME };
lBlocks.Add(qjeUser);
lBlocks.Add(qjeEmp);
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
}
while (false);
}
catch (Exception ex)
{
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
sMsg = $"{nameof(getUserNameHandler)} 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_cCmd = cRes;
return sMsg;
}
/// <summary>
/// 所有人員的資料
/// </summary>
/// <param name="i_crmInput"></param>
/// <returns></returns>
public CResponseMessage GetUserName(CRequestMessage i_crmInput)
{
return simpleQuery(i_crmInput, null, getUserNameHandler);
}
protected string getRole2UserCommand(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 = "")
{
Command cRes = null;
string sMsg;
try
{
do
{
string role_id = null;
object i_dicData = i_crmInput.param[BLWording.QRY_MASTER];
if (i_dicData is JArray)
{
JArray jaData = i_dicData as JArray;
foreach (JToken joData in jaData)
{
Dictionary<string, object> dicData = joData.ToObject<Dictionary<string, object>>();
role_id = dicData[BLWording.ROLE_ID].ToString();
}
}
// 查詢原始資料
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
QueryJsonElement qjeOrigin = lBlocks.GetInst();
qjeOrigin.table = tb_sys_user2role.TABLENAME;
qjeOrigin.displaycols = new List<string>() { tb_sys_user2role.CN_USER_UID };
qjeOrigin.aliascols = new Dictionary<string, List<string>>()
{ {tb_sys_user2role.CN_USER_UID, new List<string>(){ tb_sys_user.CN_UID } } };
qjeOrigin.wherecols = new WhereNode(tb_sys_user2role.CN_ROLE_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_user2role), role_id);
lBlocks.Add(qjeOrigin);
QueryJsonElement qjeRole = lBlocks.GetInst();
qjeRole.table = tb_sys_user.TABLENAME;
qjeRole.displaycols = new List<string>() { tb_sys_user.CN_ACCOUNT };
qjeRole.jointype = QueryJsonElement.LEFT_JOIN;
qjeRole.jointable = qjeOrigin;
qjeRole.joincols = new Dictionary<string, string>() {
{ tb_sys_user.CN_UID, tb_sys_user2role.CN_USER_UID}
};
lBlocks.Add(qjeRole);
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
}
while (false);
}
catch (Exception ex)
{
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
sMsg = $"{nameof(getRole2UserCommand)} 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;
}
protected string getRole2UserPostHandleData(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 = null;
object oResultData = null;
try
{
do
{
List<tb_sys_user> qdRole = i_aiArsenal.RunQueryList<tb_sys_user>(i_cCmd);
Dictionary<object, string> dicResultData = new Dictionary<object, string>();
if (qdRole.Count > 0)
{
foreach (var role in qdRole)
{
dicResultData.Add(role.account, role.uid);
}
}
oResultData = dicResultData;
}
while (false);
}
catch (Exception ex)
{
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
sMsg = $"{nameof(getRole2UserPostHandleData)} 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;
}
public CResponseMessage GetRole2User(CRequestMessage i_crmInput)
{
return simpleQuery(i_crmInput, null, getRole2UserCommand, getRole2UserPostHandleData);
}
}
}