using Newtonsoft.Json.Linq; using OT.COM.ArsenalDB; using OT.COM.LogisticsUtil; using OT.COM.SignalerMessage; using SoldierData; using SoldierData.syserp; using SoldierDataEntity; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; namespace CounsellorBL { public partial class AuthorityService : DBService { public class PrvilegeInfoEx : PrvilegeInfo { public bool CHECKED { get; set; } public PrvilegeInfoEx(PrvilegeInfo i_pi) { PropertyInfo[] pis = typeof(PrvilegeInfo).GetProperties(); foreach (PropertyInfo pi in pis) { pi.SetValue(this, pi.GetValue(i_pi, null), null); } CHECKED = false; } } public CResponseMessage GetNodeTreee(CRequestMessage i_crm, bool i_bFilterNonePrivilege = false) { CResponseMessage crm = null; string sMsg = null; try { do { Dictionary dicFormData = null; CResponseMessage crmCheckToken = checkTokenWithCRequestMessage(i_crm, out dicFormData); if (EResponseResult.RR_FALSE == crmCheckToken.RESULT) { sMsg = crmCheckToken.MSG; sMsg = BaseExceptionWord.ex000019; // crmCheckToken異常 break; } if (false == dicFormData.ContainsKey(BLWording.ROLEID)) { sMsg = BaseExceptionWord.ex000008; //NO ROLEID break; } object oRoleID = dicFormData[BLWording.ROLEID]; if (null == oRoleID) { sMsg = BaseExceptionWord.ex000008; //NO ROLEID break; } string nRoldID = oRoleID.ToString(); //if (false == Int32.TryParse(oRoleID.ToString(), out nRoldID)) //{ // sMsg = "INVALID ROLEID"; // break; //} CResponseMessage crmPri = this.GetPrivilege(nRoldID.Trim()); if (EResponseResult.RR_FALSE == crmPri.RESULT) { sMsg = crmPri.MSG; break; } CResponseMessage crmAllPri = GetAllPrivilege(nRoldID.Trim()); if (EResponseResult.RR_FALSE == crmAllPri.RESULT) { sMsg = crmPri.MSG; break; } crm = new CSuccessResponseMessage(null, i_crm); // TODO Merger crmAllPri/crmPri List lAllPr = crmAllPri.DATA[BLWording.PRIVILEGES] as List; List lOwnPr = crmPri.DATA[BLWording.PRIVILEGES] as List; List lRes = new List(); foreach (PrvilegeInfo piAllCur in lAllPr) { lRes.Add(new PrvilegeInfoEx(piAllCur) { CHECKED = null != lOwnPr.Where(f => f.ID.Trim() == piAllCur.ID.Trim()).FirstOrDefault() }); } if (true == i_bFilterNonePrivilege) { filterNonePrivilege(ref lRes); } //去空白處理 foreach (PrvilegeInfo pi in lRes) { pi.ID = pi.ID.Trim(); pi.PARENTID = pi.PARENTID.Trim(); pi.NAME = pi.NAME.Trim(); pi.CONTENT = pi.CONTENT.Trim(); } crm.DATA.Add(BLWording.PRIVILEGES, lRes); } while (false); } catch (Exception ex) { sMsg = new Util().GetLastExceptionMsg(ex); } if (null != sMsg) { crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg }; } return crm; } /// /// 移除沒有權限的Node /// /// protected void filterNonePrivilege(ref List i_l) { // Remove Leaf but no Prvilege Dictionary dicUncheckBranchNodeFID = new Dictionary(); Dictionary dicFIDToListIdx = new Dictionary(); for (int i = i_l.Count - 1; i >= 0; i--) { PrvilegeInfoEx piCur = i_l[i]; if (true == piCur.ISLEAF && false == piCur.CHECKED) { i_l.RemoveAt(i); } else if (false == piCur.ISLEAF) { dicUncheckBranchNodeFID.Add(piCur.ID.Trim(), piCur); } } for (int i = 0; i < i_l.Count; i++) { if (true == i_l[i].ISLEAF) { PrvilegeInfoEx piCur = i_l[i]; string nParentID = piCur.PARENTID.Trim(); while ("-1" != nParentID) { if (true == dicUncheckBranchNodeFID.ContainsKey(nParentID)) { piCur = dicUncheckBranchNodeFID[nParentID]; dicUncheckBranchNodeFID.Remove(nParentID); } else { break; } } } } foreach (string nFID in dicUncheckBranchNodeFID.Keys) { PrvilegeInfoEx piRemove = i_l.Where(f => f.ID.Trim() == nFID.Trim()).FirstOrDefault(); if (null != piRemove) { i_l.Remove(piRemove); } } } public CResponseMessage GetAllPrivilege(string i_nRoleFID) { CResponseMessage crm = null; string sMsg = null; try { do { List lqje = new List(); crm = new CSuccessResponseMessage(null); //crm.DATA.Add(BLWording.PRIVILEGES, lp); } while (false); } catch (Exception ex) { sMsg = new Util().GetLastExceptionMsg(ex); } if (null != sMsg) { crm = new CResponseMessage() { RESULT = EResponseResult.RR_FALSE, MSG = sMsg }; } return crm; } public CResponseMessage GetPrivilege(string i_nRoleFID) { CResponseMessage crm = null; string sMsg = null; try { do { List lqje = new List(); } while (false); } catch (Exception ex) { sMsg = new Util().GetLastExceptionMsg(ex); } if (null != sMsg) { crm = new CResponseMessage() { RESULT = EResponseResult.RR_FALSE, MSG = sMsg }; } return crm; } /// /// Get Privilege by user ID /// /// /// public CResponseMessage Privilege(CRequestMessage i_crm) { CResponseMessage crm = null; string sMsg = null; try { do { } while (false); } catch (Exception ex) { sMsg = new Util().GetLastExceptionMsg(ex); } if (null != sMsg) { crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg }; } return crm; } //public CResponseMessage RolePrivilegeModify(CRequestMessage i_crm) //{ // CResponseMessage crm = null; // string sMsg = null; // try // { // do // { // Dictionary dicFormData = null; // CResponseMessage crmCheckToken = checkTokenWithCRequestMessage(i_crm, out dicFormData); // if (EResponseResult.RR_FALSE == crmCheckToken.RESULT) // { // sMsg = crmCheckToken.MSG; // break; // } // int nCurUserID = (int)crmCheckToken.DATA[BLWording.SESSION_USER_ID]; // if (false == dicFormData.ContainsKey(BLWording.ROLEID)) // { // sMsg = "NO ROLEID"; // break; // } // object oRoleID = dicFormData[BLWording.ROLEID]; // if (null == oRoleID) // { // sMsg = "NULL ROLEID"; // break; // } // int nRoldID = -1; // if (false == Int32.TryParse(oRoleID.ToString(), out nRoldID)) // { // sMsg = "INVALID ROLEID"; // break; // } // List lCmds = new List(); // tb_node nSelect = new tb_node(); // nSelect.SetDirty(tb_node.CN_F_N_ID); // nSelect.SetDirty(tb_node.CN_F_S_NAME); // Command cSelectNode = Command.SetupSelectCmd(GetMasterDBTableInfo(typeof(tb_node)), nSelect); // QueryORMList lAllNode = this.adbm.RunQueryORMList(cSelectNode); // // TODO: Remove All nRoldID // WhereNode wnDelete = new WhereNode(tb_rolenode.CN_FK_N_ROLEINFO_ROLE_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_rolenode), nRoldID); // lCmds.Add(Command.SetupDeleteCmd(GetMasterDBTableInfo(typeof(tb_rolenode)), wnDelete)); // // TODO: Add // JObject jo = dicFormData[BLWording.PRIVILEGES] as JObject; // foreach (JProperty property in jo.Properties()) // { // JToken jv = property.Value; // tb_node nTar = lAllNode.DATA.FirstOrDefault(f => f.f_n_id == Int32.Parse(property.Name)); // if (null != nTar) // { // tb_rolenode rnInsert = new tb_rolenode() { fk_n_roleinfo_role_id = nRoldID }; // rnInsert.fk_n_creator_user_id = nCurUserID; // rnInsert.fk_n_modifier_user_id = nCurUserID; // rnInsert.fk_n_nodeinfo_node_id = nTar.f_n_id; // rnInsert.f_s_name = nTar.f_s_name; // lCmds.Add(Command.SetupInsertCmd(GetMasterDBTableInfo(typeof(tb_rolenode)), rnInsert)); // } // } // this.adbm.RunEditCmds(lCmds); // crm = new CSuccessResponseMessage(null, i_crm); // } // while (false); // } // catch (Exception ex) // { // sMsg = new Util().GetLastExceptionMsg(ex); // } // if (null != sMsg) // { // crm = new CResponseMessage(i_crm) { RESULT = EResponseResult.RR_FALSE, MSG = sMsg }; // } // return crm; //} } }