天津投入产出系统后端
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.
 
 
 
 
 
 

199 lines
6.8 KiB

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
{
/// <summary>
/// 权限查询
/// </summary>
public class PowerQueryController : QController
{
#region 权限查询
/// <summary>
/// 权限查询
/// </summary>
/// <returns></returns>
[HandleException]
public ActionResult AuthorityList(bool? callBack)
{
AuthorityModel model = new AuthorityModel();
model.url = "/PowerQuery/GetList";
return View("AuthorityList", model);
}
/// <summary>
/// 权限查询信息
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult GetList(bool? callBack)
{
AuthorityModel seachModel = null;//查询条件
PowerQyCondition condition = null;//查询条件
DataPage page = new DataPage();
PowerUtil pu = new PowerUtil();
try
{
//获取查询对象
seachModel = GetModel<AuthorityModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<AuthorityModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<AuthorityModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<PowerQyCondition, AuthorityModel>(seachModel);
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
page = agent.InvokeServiceFunction<DataPage>("QueryUserPowerBLL_GetUserPowerList", condition, page);
List<PowerQueryResult> resultList = JsonConvertHelper.GetDeserialize<List<PowerQueryResult>>(page.Result.ToString());
//获取权限信息
List<string> systemIDs = new List<string> { "Main", "FJC" };
List<PowerInfo> allPowers = new List<PowerInfo>();
foreach (string systemID in systemIDs)
{
string powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml";
List<PowerInfo> 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<PowerQueryResult> result = new DataGridResult<PowerQueryResult>();
result.Total = page.RecordCount;
result.Rows = resultList;
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出excel
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[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<AuthorityModel>();
condition = CopyToModel<PowerQyCondition, AuthorityModel>(seachModel);
//获取数据
exportDt = wcfAgent.InvokeServiceFunction<DataTable>("QueryUserPowerBLL_GetExportData", condition);
//获取权限信息
List<string> systemIDs = new List<string> { "Main", "MainData", "KB", "PLP", "Report" };
List<PowerInfo> allPowers = new List<PowerInfo>();
foreach (string systemID in systemIDs)
{
string powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml";
List<PowerInfo> 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
}
}