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.
265 lines
12 KiB
265 lines
12 KiB
using MonumentDefine;
|
|
using OT.COM.ArsenalDB;
|
|
using OT.COM.SignalerMessage;
|
|
using SoldierData.EnterprizeV4;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace CounsellorBL.Helper
|
|
{
|
|
public class ProjectHelper : DBService
|
|
{
|
|
public override string MainTable => null;
|
|
|
|
#region 使用者資訊
|
|
/// <summary>
|
|
/// 取得使用者資訊
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <returns></returns>
|
|
public static tb_hr_employee GetLoginUser(CRequestMessage i_crmInput)
|
|
{
|
|
tb_hr_employee loginUser = null;
|
|
if (i_crmInput == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(i_crmInput));
|
|
}
|
|
var token = i_crmInput.token;
|
|
if (!string.IsNullOrEmpty(token))
|
|
{
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
|
|
QueryJsonElement qjeSession = lBlocks.GetInst();
|
|
qjeSession.table = tb_sys_session.TABLENAME;
|
|
qjeSession.wherecols = new WhereNode(tb_sys_session.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_session), token);
|
|
|
|
// 人員資訊
|
|
QueryJsonElement qjeEmployee = lBlocks.GetInst();
|
|
qjeEmployee.table = tb_hr_employee.TABLENAME;
|
|
qjeEmployee.jointype = QueryJsonElement.JOIN;
|
|
qjeEmployee.joincols = new Dictionary<string, string>() { { tb_hr_employee.CN_UID, tb_sys_session.CN_CREATE_USER_UID } };
|
|
qjeEmployee.jointable = qjeSession;
|
|
qjeEmployee.displaycols = new List<string>() {
|
|
tb_hr_employee.CN_UID,
|
|
tb_hr_employee.CN_RECEIVE_BRANCH_UID
|
|
};
|
|
lBlocks.Add(qjeSession);
|
|
lBlocks.Add(qjeEmployee);
|
|
var sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRes);
|
|
if (sMsg != null)
|
|
{
|
|
return loginUser;
|
|
}
|
|
cRes.ReadLevel = Command.EReadLevel.ERL_DIRTY;
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
loginUser = ai.RunQuerySingleORM<tb_hr_employee>(cRes);
|
|
}
|
|
return loginUser;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判斷是否為admin角色
|
|
/// </summary>
|
|
/// <param name="i_sUserUID"></param>
|
|
/// <returns></returns>
|
|
private static bool CheckIsAdmin(string i_sUserUID)
|
|
{
|
|
bool isAdmin = false;
|
|
|
|
tb_sys_user2role cRole = new tb_sys_user2role();
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
|
|
QueryJsonElement qjUser2eRole = lBlocks.GetInst();
|
|
qjUser2eRole.table = tb_sys_user2role.TABLENAME;
|
|
qjUser2eRole.wherecols = new WhereNode(tb_sys_user2role.CN_USER_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_sys_user2role), i_sUserUID);
|
|
lBlocks.Add(qjUser2eRole);
|
|
|
|
QueryJsonElement qjeRole = lBlocks.GetInst();
|
|
qjeRole.table = tb_sys_role.TABLENAME;
|
|
qjeRole.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeRole.joincols = new Dictionary<string, string>() { { tb_sys_role.CN_UID, tb_sys_user2role.CN_ROLE_UID } };
|
|
qjeRole.jointable = qjUser2eRole;
|
|
qjeRole.displaycols = new List<string>() { tb_sys_role.CN_NAME };
|
|
lBlocks.Add(qjeRole);
|
|
|
|
// 查詢資料
|
|
MakeSelectJoinByBlocks(lBlocks, out Command cSelect);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_sys_role> lRes = ai.RunQueryList<tb_sys_role>(cSelect, null);
|
|
|
|
var lsRoleName = lRes.Select(x => x.name).ToList();
|
|
if (CustomizeDBMgr.SettingData.ContainsKey(BLWording.ADMIN_NAME))
|
|
{
|
|
if (lsRoleName.Contains(CustomizeDBMgr.SettingData[BLWording.ADMIN_NAME]))
|
|
{
|
|
isAdmin = true;
|
|
}
|
|
}
|
|
return isAdmin;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得登入者所屬社團
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <returns></returns>
|
|
public static List<string> GetUserGroup(CRequestMessage i_crmInput)
|
|
{
|
|
var userUID = GetLoginUser(i_crmInput)?.uid;
|
|
|
|
if (!string.IsNullOrEmpty(userUID))
|
|
{
|
|
ArsenalInterface ai = null;
|
|
bool isAdmin = CheckIsAdmin(userUID); // 判斷admin
|
|
|
|
var lsGroup = new List<string>();
|
|
if (isAdmin)
|
|
{
|
|
// 取得所有社團
|
|
tb_grp_group cGroup = new tb_grp_group();
|
|
cGroup.SetDirty(tb_grp_group.CN_UID);
|
|
tb_grp_group cGroupCon = new tb_grp_group() { status_flag = (int)Enums.Flag.Enable };
|
|
Command cGroupSelect = Command.SetupSelectCmd(cGroup, cGroupCon);
|
|
ai = ArsenalDBMgr.GetInst(cGroupSelect);
|
|
List<tb_grp_group> qdsGroup = ai.RunQueryList<tb_grp_group>(cGroupSelect);
|
|
lsGroup = qdsGroup.Select(x => x.uid).ToList();
|
|
}
|
|
else
|
|
{
|
|
// 所屬社團
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeEmp2Branch = lBlocks.GetInst();
|
|
qjeEmp2Branch.table = tb_hr_employee2branch.TABLENAME;
|
|
qjeEmp2Branch.wherecols = new WhereNode(tb_hr_employee2branch.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_hr_employee2branch), userUID);
|
|
lBlocks.Add(qjeEmp2Branch);
|
|
|
|
QueryJsonElement qjeBranch = lBlocks.GetInst();
|
|
qjeBranch.table = tb_grp_branch.TABLENAME;
|
|
qjeBranch.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeBranch.joincols = new Dictionary<string, string>() { { tb_grp_branch.CN_UID, tb_hr_employee2branch.CN_BRANCH_UID } };
|
|
qjeBranch.jointable = qjeEmp2Branch;
|
|
qjeBranch.wherecols = new WhereNode(tb_grp_branch.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_branch), (int)Enums.Flag.Enable);
|
|
lBlocks.Add(qjeBranch);
|
|
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroup.joincols = new Dictionary<string, string>() { { tb_grp_group.CN_UID, tb_grp_branch.CN_GROUP_UID } };
|
|
qjeGroup.jointable = qjeBranch;
|
|
qjeGroup.displaycols = new List<string>() { tb_grp_group.CN_UID };
|
|
qjeGroup.wherecols = new WhereNode(tb_grp_group.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), (int)Enums.Flag.Enable);
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
// 查詢資料
|
|
MakeSelectJoinByBlocks(lBlocks, out Command cBranchSelect);
|
|
ai = ArsenalDBMgr.GetInst(cBranchSelect);
|
|
List<tb_grp_group> lResGroup = ai.RunQueryList<tb_grp_group>(cBranchSelect, null);
|
|
|
|
// 自行建立的社團
|
|
tb_grp_group cGroup = new tb_grp_group();
|
|
cGroup.SetDirty(tb_grp_group.CN_UID);
|
|
tb_grp_group cGroupCon = new tb_grp_group()
|
|
{
|
|
create_user_uid = userUID,
|
|
status_flag = (int)Enums.Flag.Enable
|
|
};
|
|
Command cGroupSelect = Command.SetupSelectCmd(cGroup, cGroupCon);
|
|
ai = ArsenalDBMgr.GetInst(cGroupSelect);
|
|
List<tb_grp_group> qdsGroup = ai.RunQueryList<tb_grp_group>(cGroupSelect);
|
|
|
|
lsGroup = lResGroup.Union(qdsGroup).Select(x => x.uid).ToList();
|
|
}
|
|
|
|
return lsGroup;
|
|
}
|
|
else
|
|
{
|
|
return new List<string>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得登入者人員管理所設定之所屬分店
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <returns></returns>
|
|
public static List<string> GetUserBranch(CRequestMessage i_crmInput)
|
|
{
|
|
var userUID = GetLoginUser(i_crmInput)?.uid;
|
|
|
|
if (!string.IsNullOrEmpty(userUID))
|
|
{
|
|
ArsenalInterface ai = null;
|
|
bool isAdmin = CheckIsAdmin(userUID); // 判斷admin
|
|
var lsBranch = new List<string>();
|
|
if (isAdmin)
|
|
{
|
|
// 取得所有分店
|
|
tb_grp_branch cBranch = new tb_grp_branch();
|
|
cBranch.SetDirty(tb_grp_branch.CN_UID);
|
|
tb_grp_branch cBranchCon = new tb_grp_branch() { status_flag = (int)Enums.Flag.Enable };
|
|
Command cSelect = Command.SetupSelectCmd(cBranch, cBranchCon);
|
|
ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_grp_branch> qdsBranch = ai.RunQueryList<tb_grp_branch>(cSelect);
|
|
lsBranch = qdsBranch.Select(x => x.uid).ToList();
|
|
}
|
|
else
|
|
{
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
|
|
QueryJsonElement qjeEmp2Branch = lBlocks.GetInst();
|
|
qjeEmp2Branch.table = tb_hr_employee2branch.TABLENAME;
|
|
qjeEmp2Branch.wherecols = new WhereNode(tb_hr_employee2branch.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_hr_employee2branch), userUID);
|
|
qjeEmp2Branch.displaycols = new List<string>() { tb_hr_employee2branch.CN_BRANCH_UID };
|
|
lBlocks.Add(qjeEmp2Branch);
|
|
|
|
// 查詢資料
|
|
MakeSelectJoinByBlocks(lBlocks, out Command cBranchSelect);
|
|
ai = ArsenalDBMgr.GetInst(cBranchSelect);
|
|
List<tb_hr_employee2branch> lRes = ai.RunQueryList<tb_hr_employee2branch>(cBranchSelect, null);
|
|
lsBranch = lRes.Select(x => x.branch_uid).ToList();
|
|
|
|
}
|
|
|
|
return lsBranch;
|
|
}
|
|
else
|
|
{
|
|
return new List<string>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得登入者人員管理所設定之所屬分店Key與分店名稱, 權限綁定
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <returns></returns>
|
|
public static List<(string Uid, string BranchName)> GetUserBranchAndName(CRequestMessage i_crmInput)
|
|
{
|
|
var branch = GetUserBranch(i_crmInput);
|
|
var branchAndName = new List<(string, string)>();
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMain = lBlocks.GetInst();
|
|
qjeMain.table = tb_grp_branch.TABLENAME;
|
|
qjeMain.displaycols = new List<string>() {
|
|
tb_grp_branch.CN_UID,
|
|
tb_grp_branch.CN_BRANCH_NAME
|
|
};
|
|
qjeMain.wherecols = new WhereNode(tb_grp_branch.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_branch), branch.ToArray());
|
|
|
|
lBlocks.Add(qjeMain);
|
|
|
|
var sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cSelect);
|
|
var ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_grp_branch> qdsBranch = ai.RunQueryList<tb_grp_branch>(cSelect);
|
|
branchAndName = qdsBranch.Select(x => (x.uid, x.branch_name)).ToList();
|
|
|
|
return branchAndName;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|