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.
 
 

328 lines
11 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Log;
using Znyc.Cloudcar.Admin.Commons.Mapping;
using Znyc.Cloudcar.Admin.Security.Dtos;
using Znyc.Cloudcar.Admin.Security.Entitys;
using Znyc.Cloudcar.Admin.Security.IServices;
namespace Znyc.Cloudcar.Admin.WebApi.Controllers
{
/// <summary>
/// 功能菜单接口
/// </summary>
[ApiController]
[Route("api/Security/[controller]")]
public class MenuController : AreaApiController<MenuEntity, MenuOutputDto, MenuInputDto, IMenuService, long>
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="service"></param>
public MenuController(IMenuService service) : base(service)
{
_service = service;
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(MenuEntity info)
{
info.Id = 0;
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
if (info.SortCode == null)
{
info.SortCode = 99;
}
if (string.IsNullOrEmpty(info.ParentId.ToString()))
{
info.Layers = 1;
info.ParentId = 0;
}
else
{
info.Layers = _service.Get(info.ParentId).Layers + 1;
}
if (info.MenuType == "F")
{
info.IsFrame = false;
info.Component = "";
info.UrlAddress = "";
}
}
/// <summary>
/// 新增
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost("Insert")]
[FunctionAuthorize("Add")]
public async Task<IActionResult> InsertAsync(MenuInputDto info)
{
CommonResult result = new CommonResult();
MenuEntity menu = info.MapTo<MenuEntity>();
long ln = 0;
if (info.IsBatch)
{
string strEnCode = info.EnCode;
MenuEntity listInfo = new MenuEntity();
listInfo = menu;
listInfo.FullName = "列表";
listInfo.EnCode = strEnCode + "/List";
listInfo.Icon = "list";
OnBeforeInsert(listInfo);
long listId = info.ParentId;
ln = _service.Insert(listInfo);
MenuEntity addInfo = new MenuEntity();
addInfo = menu;
addInfo.Id = 0;
addInfo.FullName = "新增";
addInfo.EnCode = strEnCode + "/Add";
addInfo.ParentId = listId;
addInfo.Icon = "add";
addInfo.SortCode = 1;
OnBeforeInsert(addInfo);
ln = _service.Insert(addInfo);
MenuEntity viewInfo = new MenuEntity();
viewInfo = menu;
viewInfo.Id = 0;
viewInfo.FullName = "查看";
viewInfo.EnCode = strEnCode + "/View";
viewInfo.ParentId = listId;
viewInfo.Icon = "eye-open";
viewInfo.SortCode = 1;
OnBeforeInsert(viewInfo);
ln = _service.Insert(viewInfo);
MenuEntity editnfo = new MenuEntity();
editnfo = menu;
editnfo.Id = 0;
editnfo.FullName = "修改";
editnfo.EnCode = strEnCode + "/Edit";
editnfo.ParentId = listId;
editnfo.Icon = "write";
editnfo.SortCode = 2;
OnBeforeInsert(editnfo);
ln = _service.Insert(editnfo);
MenuEntity enableInfo = new MenuEntity();
enableInfo = menu;
enableInfo.Id = 0;
enableInfo.FullName = "禁用";
enableInfo.EnCode = strEnCode + "/Enable";
enableInfo.ParentId = listId;
enableInfo.Icon = "pause";
enableInfo.SortCode = 3;
OnBeforeInsert(enableInfo);
ln = _service.Insert(enableInfo);
MenuEntity enableInfo1 = new MenuEntity();
enableInfo1 = menu;
enableInfo1.Id = 0;
enableInfo1.FullName = "启用";
enableInfo1.EnCode = strEnCode + "/Enable";
enableInfo1.ParentId = listId;
enableInfo1.Icon = "play";
enableInfo1.SortCode = 4;
OnBeforeInsert(enableInfo1);
ln = _service.Insert(enableInfo1);
MenuEntity deleteSoftInfo = new MenuEntity();
deleteSoftInfo = menu;
deleteSoftInfo.Id = 0;
deleteSoftInfo.FullName = "软删除";
deleteSoftInfo.EnCode = strEnCode + "/DeleteSoft";
deleteSoftInfo.ParentId = listId;
deleteSoftInfo.Icon = "remove";
deleteSoftInfo.SortCode = 5;
OnBeforeInsert(deleteSoftInfo);
ln = _service.Insert(deleteSoftInfo);
MenuEntity deleteInfo = new MenuEntity();
deleteInfo = menu;
deleteInfo.Id = 0;
deleteInfo.FullName = "删除";
deleteInfo.EnCode = strEnCode + "/Delete";
deleteInfo.ParentId = listId;
deleteInfo.Icon = "remove";
deleteInfo.SortCode = 6;
OnBeforeInsert(deleteInfo);
ln = _service.Insert(deleteInfo);
}
else
{
OnBeforeInsert(menu);
ln = await _service.InsertAsync(menu);
}
if (ln >= 0)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrCode = "43001";
}
return ToJsonContent(result);
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(MenuEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
if (info.SortCode == null)
{
info.SortCode = 99;
}
if (string.IsNullOrEmpty(info.ParentId.ToString()))
{
info.Layers = 1;
info.ParentId = 0;
}
else
{
info.Layers = _service.Get(info.ParentId).Layers + 1;
}
}
/// <summary>
/// 在软删除数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeSoftDelete(MenuEntity info)
{
info.IsDeleted = true;
}
/// <summary>
/// 异步更新数据
/// </summary>
/// <param name="tinfo"></param>
/// <returns></returns>
[HttpPost("Update")]
[FunctionAuthorize("Edit")]
public async Task<IActionResult> UpdateAsync(MenuInputDto tinfo)
{
CommonResult result = new CommonResult();
MenuEntity info = _service.Get(tinfo.Id);
info.FullName = tinfo.FullName;
info.EnCode = tinfo.EnCode;
info.SystemTypeId = tinfo.SystemTypeId;
info.ParentId = tinfo.ParentId;
info.Icon = tinfo.Icon;
info.SortCode = tinfo.SortCode;
info.Description = tinfo.Description;
info.MenuType = tinfo.MenuType;
info.ActiveMenu = tinfo.ActiveMenu;
if (info.MenuType == "F")
{
info.IsFrame = false;
info.Component = "";
info.UrlAddress = "";
}
else
{
info.Component = tinfo.Component;
info.IsFrame = tinfo.IsFrame;
info.UrlAddress = tinfo.UrlAddress;
}
info.IsShow = tinfo.IsShow;
OnBeforeUpdate(info);
bool bl = await _service.UpdateAsync(info, tinfo.Id).ConfigureAwait(false);
if (bl)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
/// <summary>
/// 获取功能菜单适用于Vue 树形列表
/// </summary>
/// <param name="systemTypeId">子系统Id</param>
/// <returns></returns>
[HttpGet("GetAllMenuTreeTable")]
[FunctionAuthorize("List")]
public async Task<IActionResult> GetAllMenuTreeTable(string systemTypeId)
{
CommonResult result = new CommonResult();
try
{
System.Collections.Generic.List<MenuTreeTableOutputDto> list = await _service.GetAllMenuTreeTable(systemTypeId);
result.Success = true;
result.ErrCode = ErrCode.successCode;
result.ResData = list;
}
catch (Exception ex)
{
Log4NetHelper.Error("获取菜单异常", ex);
result.ErrMsg = ErrCode.err40110;
result.ErrCode = "40110";
}
return ToJsonContent(result);
}
///// <summary>
///// 异步批量物理删除
///// </summary>
///// <param name="info"></param>
//[HttpDelete("DeleteBatchAsync")]
//[FunctionAuthorize("Delete")]
//public override async Task<IActionResult> DeleteBatchAsync(DeletesInputDto info)
//{
// var result = new CommonResult();
// if (info.Ids.Length > 0)
// {
// result = await _service.DeleteBatchWhereAsync(info).ConfigureAwait(false);
// if (result.Success)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrCode = "43003";
// }
// }
// return ToJsonContent(result);
//}
}
}