using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.Attribute;
using QMFrameWork.Data;
using QMAPP.ServicesAgent;
using QMFrameWork.Common.Serialization;
using QMFrameWork.WebUI.DataSource;
using QMAPP.Common.Web.Util;
using QMAPP.Web.Models.Report;
using QMAPP.Entity.Sys;
using QMAPP.Entity.Report;
namespace QMAPP.Web.Controllers
{
///
/// 权限查询
///
public class PowerQueryController : QController
{
#region 权限查询
///
/// 权限查询
///
///
[HandleException]
public ActionResult AuthorityList(bool? callBack)
{
AuthorityModel model = new AuthorityModel();
model.url = "/PowerQuery/GetList";
return View("AuthorityList", model);
}
///
/// 权限查询信息
///
/// 结果
[HandleException]
public ActionResult GetList(bool? callBack)
{
AuthorityModel seachModel = null;//查询条件
PowerQyCondition condition = null;//查询条件
DataPage page = new DataPage();
PowerUtil pu = new PowerUtil();
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
page = agent.InvokeServiceFunction("QueryUserPowerBLL_GetUserPowerList", condition, page);
List resultList = JsonConvertHelper.GetDeserialize>(page.Result.ToString());
//获取权限信息
List systemIDs = new List { "Main", "FJC" };
List allPowers = new List();
foreach (string systemID in systemIDs)
{
string powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml";
List powers = pu.GetPowerList(powerFile);
allPowers.AddRange(powers);
}
//匹配权限名称
foreach (PowerQueryResult r in resultList)
{
PowerInfo pi = allPowers.Find(p => p.PowerID == r.AUTHORITYID);
if (pi != null)
{
r.AUTHORITYNAME = pi.PowerDes;
if (pi.PowerType.ToLower() == "button")
{
PowerInfo parentPi = allPowers.Find(p => p.PowerID == pi.SuperID);
if (parentPi == null)
continue;
r.AUTHORITYNAME = parentPi.PowerDes + "-" + r.AUTHORITYNAME;
}
}
else
{
r.AUTHORITYNAME="";
}
}
//数据格式转换
DataGridResult result = new DataGridResult();
result.Total = page.RecordCount;
result.Rows = resultList;
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出excel
///
/// 导出excel
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult ExpertExcel()
{
AuthorityModel seachModel = null;
PowerQyCondition condition = null;
DataTable exportDt = new DataTable();
ServiceAgent wcfAgent = this.GetServiceAgent();
PowerUtil pu = new PowerUtil();
string selectKey = Request.Form["selectKey"];
try
{
//获取查询对象
seachModel = GetModel();
condition = CopyToModel(seachModel);
//获取数据
exportDt = wcfAgent.InvokeServiceFunction("QueryUserPowerBLL_GetExportData", condition);
//获取权限信息
List systemIDs = new List { "Main", "MainData", "KB", "PLP", "Report" };
List allPowers = new List();
foreach (string systemID in systemIDs)
{
string powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml";
List powers = pu.GetPowerList(powerFile);
allPowers.AddRange(powers);
}
//匹配权限名称
foreach (DataRow r in exportDt.Rows)
{
PowerInfo pi = allPowers.Find(p => p.PowerID == r["AUTHORITYID"].ToString());
if (pi != null)
{
r["AUTHORITYNAME"] = pi.PowerDes;
if (pi.PowerType.ToLower() == "button")
{
PowerInfo parentPi = allPowers.Find(p => p.PowerID == pi.SuperID);
if (parentPi == null)
continue;
r["AUTHORITYNAME"] = parentPi.PowerDes + "-" + r["AUTHORITYNAME"].ToString();
}
}
else
{
r["AUTHORITYNAME"] = "";
}
}
//导出
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
return efTool.GetExcelFileResult("UserPowerList", "权限信息" + System.DateTime.Now.ToString("yyyy-MM-dd") + ".xls", exportDt);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}