using learun.iapplication;
using learun.util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace EC.Web.Areas.LR_SystemModule.Controllers
{
///
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.11
/// 描 述:功能模块控制器
///
[Area("LR_SystemModule")]
public class ModuleController : MvcControllerBase
{
private readonly ModuleIBLL _moduleIBLL;
public ModuleController(ModuleIBLL moduleIBLL)
{
_moduleIBLL = moduleIBLL;
}
#region 视图方法
///
/// 主页
///
///
[HttpGet]
public IActionResult Index()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public IActionResult Form()
{
return View();
}
#endregion 视图方法
#region 功能模块
[HttpGet]
[AjaxOnly]
public async Task GetModuleList()
{
var data = await _moduleIBLL.GetModuleList();
return this.Success(data);
}
///
/// 获取功能模块数据列表
///
///
[HttpGet]
[AjaxOnly]
public async Task GetModuleByCode(string code)
{
var data = await _moduleIBLL.GetEntityByCode(code);
return this.Success(data);
}
///
/// 获取树形数据
///
///
[HttpGet]
[AjaxOnly]
public async Task GetModuleTree()
{
var data = await _moduleIBLL.GetModuleTree();
return this.Success(data);
}
///
/// 获取树形数据(带勾选框)
///
///
[HttpGet]
[AjaxOnly]
public async Task GetModuleCheckTree()
{
var data = await _moduleIBLL.GetModuleCheckTree();
return this.Success(data);
}
///
/// 获取功能列表的树形数据(只有展开项)
///
///
[HttpGet]
[AjaxOnly]
public async Task GetExpendModuleTree()
{
var data = await _moduleIBLL.GetExpendModuleTree();
return this.Success(data);
}
///
/// 获取列表数据根据父级id
///
/// 关键词
/// 功能类型
///
[HttpGet]
[AjaxOnly]
public async Task GetModuleListByParentId(string keyword, string parentId)
{
var jsondata = await _moduleIBLL.GetModuleListByParentId(keyword, parentId);
return this.Success(jsondata);
}
///
/// 获取树形数据(带勾选框)
///
/// 1 模块 2 按钮 3 列 4 表单
///
[HttpGet]
[AjaxOnly]
public async Task GetCheckTree(string type, string objectId)
{
var list = type switch
{
"1" => await _moduleIBLL.GetModuleCheckTree(),
"2" => await _moduleIBLL.GetButtonCheckTree(objectId),
"3" => await _moduleIBLL.GetColumnCheckTree(objectId),
"4" => await _moduleIBLL.GetFormCheckTree(objectId),
_ => await _moduleIBLL.GetModuleCheckTree(),
};
return this.Success(list);
}
#endregion 功能模块
#region 模块按钮
///
/// 获取功能模块按钮数据列表
///
/// 模块主键
///
[HttpGet]
[AjaxOnly]
public async Task GetButtonListNoAuthorize(string moduleId)
{
var data = await _moduleIBLL.GetButtonListNoAuthorize(moduleId);
return this.Success(data);
}
///
/// 获取功能模块按钮数据列表
///
/// 模块主键
///
[HttpGet]
[AjaxOnly]
public async Task GetButtonList(string moduleId)
{
var data = await _moduleIBLL.GetButtonList(moduleId);
return this.Success(data);
}
#endregion 模块按钮
#region 模块视图
///
/// 获取功能模块视图数据列表
///
/// 模块主键
///
[HttpGet]
[AjaxOnly]
public async Task GetColumnList(string moduleId)
{
var data = await _moduleIBLL.GetColumnList(moduleId);
return this.Success(data);
}
#endregion 模块视图
#region 获取数据
///
/// 获取表单数据
///
/// 主键
///
[HttpGet]
[AjaxOnly]
public async Task GetFormData(string keyValue)
{
var module = await _moduleIBLL.GetModuleEntity(keyValue);
var btns = await _moduleIBLL.GetButtonList(keyValue);
var cols = await _moduleIBLL.GetColumnList(keyValue);
var fields = await _moduleIBLL.GetFormList(keyValue);
var jsondata = new
{
moduleEntity = module,
moduleButtons = btns,
moduleColumns = cols,
moduleFields = fields
};
return this.Success(jsondata);
}
#endregion 获取数据
#region 提交数据
///
/// 保存功能表单
///
/// 主键值
/// 功能实体
/// 按钮实体列表
/// 视图实体列表
/// 表单字段列表
///
[HttpPost]
[AjaxOnly]
public async Task SaveForm(string keyValue, string moduleEntityJson, string moduleButtonListJson, string moduleColumnListJson, string moduleFormListJson)
{
var moduleButtonList = moduleButtonListJson.ToList();
var moduleColumnList = moduleColumnListJson.ToList();
var moduleFormList = moduleFormListJson.ToList();
var moduleEntity = moduleEntityJson.ToObject();
await _moduleIBLL.SaveEntity(keyValue, moduleEntity, moduleButtonList, moduleColumnList, moduleFormList);
return SuccessInfo("保存成功。");
}
///
/// 删除表单数据
///
/// 主键
///
[HttpPost]
[AjaxOnly]
public async Task DeleteForm(string keyValue)
{
bool res = await _moduleIBLL.Delete(keyValue);
if (res)
{
return SuccessInfo("删除成功。");
}
else
{
return Fail("有子节点无法删除。");
}
}
#endregion 提交数据
#region 权限数据
///
/// 获取权限按钮和列表信息
///
/// 菜单对应编码
///
[HttpGet]
[AjaxOnly]
public async Task GetAuthorizeButtonColumnList(string code)
{
Dictionary dicButton = new Dictionary();
Dictionary dicColumn = new Dictionary();
Dictionary dicForm = new Dictionary();
ModuleEntity moduleEntity = await _moduleIBLL.GetEntityByCode(code);
if (moduleEntity != null)
{
List buttonList = (List)await _moduleIBLL.GetButtonList(moduleEntity.F_ModuleId);
foreach (var item in buttonList)
{
if (!dicButton.ContainsKey(item.F_EnCode))
{
dicButton.Add(item.F_EnCode, item.F_FullName);
}
}
List columnList = (List)await _moduleIBLL.GetColumnList(moduleEntity.F_ModuleId);
foreach (var item in columnList)
{
if (!dicColumn.ContainsKey(item.F_EnCode.ToLower()))
{
dicColumn.Add(item.F_EnCode.ToLower(), item.F_FullName);
}
}
List formList = (List)await _moduleIBLL.GetFormList(moduleEntity.F_ModuleId);
foreach (var item in formList)
{
if (item.F_EnCode != null && !dicForm.ContainsKey(item.F_EnCode))
{
dicForm.Add(item.F_EnCode, item.F_FullName);
}
}
}
var jsonData = new
{
module = moduleEntity,
btns = dicButton,
cols = dicColumn,
forms = dicForm
};
return Success(jsonData);
}
#endregion 权限数据
}
}