first commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
[LogActionFilter]
|
||||
public class BaseController : ControllerBase
|
||||
{
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
|
||||
public static string TIME_FORMAT_FULL_2 = "MM-dd HH:mm:ss";
|
||||
|
||||
protected IActionResult SUCCESS(object data, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(GetApiResult(data != null ? ResultCode.SUCCESS : ResultCode.FAIL, data), timeFormatStr);
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// json输出带时间格式的
|
||||
/// </summary>
|
||||
/// <param name="apiResult"></param>
|
||||
/// <param name="timeFormatStr"></param>
|
||||
/// <returns></returns>
|
||||
protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(apiResult, timeFormatStr);
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected IActionResult OutputJson(long rows, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr);
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected string SerializeObject(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应返回结果
|
||||
/// </summary>
|
||||
/// <param name="rows">受影响行数</param>
|
||||
/// <returns></returns>
|
||||
protected ApiResult ToJson(long rows)
|
||||
{
|
||||
return rows > 0 ? GetApiResult(ResultCode.SUCCESS) : GetApiResult(ResultCode.FAIL);
|
||||
}
|
||||
protected ApiResult ToJson(long rows, object data)
|
||||
{
|
||||
return rows > 0 ? GetApiResult(ResultCode.SUCCESS, data) : GetApiResult(ResultCode.FAIL);
|
||||
}
|
||||
/// <summary>
|
||||
/// 全局Code使用
|
||||
/// </summary>
|
||||
/// <param name="resultCode"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
protected ApiResult GetApiResult(ResultCode resultCode, object data = null)
|
||||
{
|
||||
var apiResult = new ApiResult((int)resultCode, resultCode.ToString())
|
||||
{
|
||||
Data = data
|
||||
};
|
||||
|
||||
return apiResult;
|
||||
}
|
||||
protected ApiResult GetApiResult(ResultCode resultCode, string msg)
|
||||
{
|
||||
return new ApiResult((int)resultCode, msg);
|
||||
}
|
||||
private static string GetJsonStr(ApiResult apiResult, string timeFormatStr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(timeFormatStr))
|
||||
{
|
||||
timeFormatStr = TIME_FORMAT_FULL;
|
||||
}
|
||||
var serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
// 设置为驼峰命名
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
DateFormatString = timeFormatStr
|
||||
};
|
||||
|
||||
return JsonConvert.SerializeObject(apiResult, Formatting.Indented, serializerSettings);
|
||||
}
|
||||
|
||||
protected IActionResult CustomError(ResultCode resultCode, string msg = "")
|
||||
{
|
||||
return OutputJson(GetApiResult(resultCode, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 心跳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("health/index")]
|
||||
[Log()]
|
||||
public IActionResult Health()
|
||||
{
|
||||
return SUCCESS(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult Encrypt(string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
throw new Exception("content不能为空");
|
||||
}
|
||||
string key = ConfigUtils.Instance.GetConfig("DbKey");
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESEncrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult Decrypt(string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
throw new Exception("content不能为空");
|
||||
}
|
||||
string key = ConfigUtils.Instance.GetConfig("DbKey");
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESDecrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码已从模板生成。
|
||||
//
|
||||
// 手动更改此文件可能导致应用程序出现意外的行为。
|
||||
// 如果重新生成代码,将覆盖对此文件的手动更改。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using Mapster;
|
||||
using ZR.Model.Dto.System;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// T4代码自动生成
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("article")]
|
||||
public class ArticleController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章接口
|
||||
/// </summary>
|
||||
private readonly IArticleService _ArticleService;
|
||||
private readonly IArticleCategoryService _ArticleCategoryService;
|
||||
|
||||
public ArticleController(IArticleService ArticleService, IArticleCategoryService articleCategoryService)
|
||||
{
|
||||
_ArticleService = ArticleService;
|
||||
_ArticleCategoryService = articleCategoryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "system:article:list")]
|
||||
public IActionResult Query([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<Article>();
|
||||
|
||||
//搜索条件
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Title), m => m.Title.Contains(parm.Title));
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status);
|
||||
|
||||
var response = _ArticleService.GetPages(predicate.ToExpression(), parm, f => f.Cid, "Desc");
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文章目录,前端没用到
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CategoryList")]
|
||||
public IActionResult CategoryList()
|
||||
{
|
||||
var response = _ArticleCategoryService.GetAll();
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文章目录树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CategoryTreeList")]
|
||||
public IActionResult CategoryTreeList()
|
||||
{
|
||||
var response = _ArticleCategoryService.BuildCategoryTree(_ArticleCategoryService.GetAll());
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章详情
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var response = _ArticleService.GetId(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("add")]
|
||||
[ActionPermissionFilter(Permission = "system:article:add")]
|
||||
[Log(Title = "文章添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] Article parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||
addModel.AuthorName = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_ArticleService.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
[ActionPermissionFilter(Permission = "system:article:update")]
|
||||
[Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] Article parm)
|
||||
{
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||
addModel.AuthorName = User.Identity.Name;
|
||||
|
||||
var response = _ArticleService.Update(it => it.Cid == addModel.Cid,
|
||||
f => new Article
|
||||
{
|
||||
Title = addModel.Title,
|
||||
Content = addModel.Content,
|
||||
Tags = addModel.Tags,
|
||||
Category_id = addModel.Category_id,
|
||||
UpdateTime = addModel.UpdateTime
|
||||
}).ToCreate();
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ActionPermissionFilter(Permission = "system:article:delete")]
|
||||
[Log(Title = "文章删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"删除失败Id 不能为空"));
|
||||
}
|
||||
|
||||
// 删除文章
|
||||
var response = _ArticleService.Delete(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置文件
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/config")]
|
||||
public class SysConfigController : BaseController
|
||||
{
|
||||
[HttpGet("list")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return SUCCESS(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 部门
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/dept")]
|
||||
public class SysDeptController : BaseController
|
||||
{
|
||||
public ISysDeptService DeptService;
|
||||
public ISysUserService UserService;
|
||||
public SysDeptController(ISysDeptService deptService
|
||||
, ISysUserService userService)
|
||||
{
|
||||
DeptService = deptService;
|
||||
UserService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取部门列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dept:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysDept dept)
|
||||
{
|
||||
return SUCCESS(DeptService.GetSysDepts(dept), TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询部门列表(排除节点)
|
||||
/// </summary>
|
||||
/// <param name="deptId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list/exclude/{deptId}")]
|
||||
public IActionResult ExcludeChild(long deptId)
|
||||
{
|
||||
var depts = DeptService.GetSysDepts(new SysDept());
|
||||
|
||||
for (int i = 0; i < depts.Count; i++)
|
||||
{
|
||||
SysDept d = depts[i];
|
||||
long[] deptIds = Tools.SpitLongArrary(d.Ancestors);
|
||||
if (d.DeptId == deptId || ((IList)deptIds).Contains(deptId))
|
||||
{
|
||||
depts.Remove(d);
|
||||
}
|
||||
}
|
||||
return SUCCESS(depts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取部门下拉树列表
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeselect")]
|
||||
public IActionResult TreeSelect(SysDept dept)
|
||||
{
|
||||
var depts = DeptService.GetSysDepts(dept);
|
||||
|
||||
return SUCCESS(DeptService.BuildDeptTreeSelect(depts), TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据部门编号获取详细信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{deptId}")]
|
||||
[ActionPermissionFilter(Permission = "system:dept:query")]
|
||||
public IActionResult GetInfo(long deptId)
|
||||
{
|
||||
var info = DeptService.GetFirst(f => f.DeptId == deptId);
|
||||
return SUCCESS(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增部门
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Log(Title = "部门管理", BusinessType = BusinessType.INSERT)]
|
||||
[ActionPermissionFilter(Permission = "system:dept:add")]
|
||||
public IActionResult Add([FromBody] SysDept dept)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
|
||||
{
|
||||
return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在"));
|
||||
}
|
||||
dept.Create_by = User.Identity.Name;
|
||||
return OutputJson(ToJson(DeptService.InsertDept(dept)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改部门
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Log(Title = "部门管理", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:dept:update")]
|
||||
public IActionResult Update([FromBody] SysDept dept)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
|
||||
{
|
||||
return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在"));
|
||||
}
|
||||
else if (dept.ParentId.Equals(dept.DeptId))
|
||||
{
|
||||
return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己"));
|
||||
}
|
||||
dept.Update_by = User.Identity.Name;
|
||||
return OutputJson(ToJson(DeptService.UpdateDept(dept)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除部门
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{deptId}")]
|
||||
[ActionPermissionFilter(Permission = "system:dept:remove")]
|
||||
[Log(Title = "部门管理", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Remove(long deptId)
|
||||
{
|
||||
if (DeptService.GetCount(it => it.ParentId == deptId && it.DelFlag == "0") > 0)
|
||||
{
|
||||
return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除"));
|
||||
}
|
||||
if (UserService.GetCount(it => it.DeptId == deptId && it.DelFlag == "0") > 0)
|
||||
{
|
||||
return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除"));
|
||||
}
|
||||
|
||||
return SUCCESS(DeptService.Delete(deptId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据字典信息
|
||||
/// @author zr
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/dict/data")]
|
||||
public class SysDictDataController : BaseController
|
||||
{
|
||||
private readonly ISysDictDataService SysDictDataService;
|
||||
private readonly ISysDictService SysDictService;
|
||||
|
||||
public SysDictDataController(ISysDictService sysDictService, ISysDictDataService sysDictDataService)
|
||||
{
|
||||
SysDictService = sysDictService;
|
||||
SysDictDataService = sysDictDataService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysDictData dictData, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = SysDictDataService.SelectDictDataList(dictData);
|
||||
pagerInfo.TotalNum = list.Count;
|
||||
var vm = new VMPageResult<SysDictData>(list, pagerInfo);
|
||||
return SUCCESS(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类型查询字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="dictType"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("type/{dictType}")]
|
||||
public IActionResult DictType(string dictType)
|
||||
{
|
||||
return SUCCESS(SysDictDataService.SelectDictDataByType(dictType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典数据详细
|
||||
/// </summary>
|
||||
/// <param name="dictCode"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("info/{dictCode}")]
|
||||
public IActionResult GetInfo(long dictCode)
|
||||
{
|
||||
return SUCCESS(SysDictDataService.SelectDictDataById(dictCode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:add")]
|
||||
[Log(Title = "字典数据", BusinessType = BusinessType.INSERT)]
|
||||
[HttpPost()]
|
||||
public IActionResult Add([FromBody] SysDictData dict)
|
||||
{
|
||||
dict.Create_by = User.Identity.Name;
|
||||
dict.Create_time = DateTime.Now;
|
||||
return SUCCESS(SysDictDataService.InsertDictData(dict));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:edit")]
|
||||
[Log(Title = "字典数据", BusinessType = BusinessType.UPDATE)]
|
||||
[HttpPut()]
|
||||
public IActionResult Edit([FromBody] SysDictData dict)
|
||||
{
|
||||
dict.Update_by = User.Identity.Name;
|
||||
return SUCCESS(SysDictDataService.UpdateDictData(dict));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典类型
|
||||
/// </summary>
|
||||
/// <param name="dictCode"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:remove")]
|
||||
[Log(Title = "字典类型", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{dictCode}")]
|
||||
public IActionResult Remove(string dictCode)
|
||||
{
|
||||
long[] dictCodes = ZR.Common.Tools.SpitLongArrary(dictCode);
|
||||
|
||||
return SUCCESS(SysDictDataService.DeleteDictDataByIds(dictCodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据字典信息
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/dict/type")]
|
||||
public class SysDictTypeController : BaseController
|
||||
{
|
||||
private readonly ISysDictService SysDictService;
|
||||
|
||||
public SysDictTypeController(ISysDictService sysDictService)
|
||||
{
|
||||
SysDictService = sysDictService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysDictType dict, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = SysDictService.SelectDictTypeList(dict);
|
||||
pagerInfo.TotalNum = list.Count;
|
||||
var vm = new VMPageResult<SysDictType>(list, pagerInfo);
|
||||
return SUCCESS(vm, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典类型详细
|
||||
/// </summary>
|
||||
/// <param name="dictId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{dictId}")]
|
||||
[ActionPermissionFilter(Permission = "system:dict:query")]
|
||||
public IActionResult GetInfo(long dictId = 0)
|
||||
{
|
||||
return SUCCESS(SysDictService.SelectDictTypeById(dictId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加字典类型
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:add")]
|
||||
[Log(Title = "字典操作", BusinessType = BusinessType.INSERT)]
|
||||
[HttpPost("edit")]
|
||||
public IActionResult Add([FromBody] SysDictType dict)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在"));
|
||||
}
|
||||
//设置添加人
|
||||
dict.Create_by = HttpContext.User.Identity.Name;
|
||||
dict.Create_time = DateTime.Now;
|
||||
return SUCCESS(SysDictService.InsertDictType(dict));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改字典类型
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:edit")]
|
||||
[Log(Title = "字典操作", BusinessType = BusinessType.UPDATE)]
|
||||
[Route("edit")]
|
||||
[HttpPut]
|
||||
public IActionResult Edit([FromBody] SysDictType dict)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在"));
|
||||
}
|
||||
//设置添加人
|
||||
dict.Update_by = HttpContext.User.Identity.Name;
|
||||
return SUCCESS(SysDictService.UpdateDictType(dict));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:dict:remove")]
|
||||
[Log(Title = "删除字典类型", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{ids}")]
|
||||
public IActionResult Remove(string ids)
|
||||
{
|
||||
long[] idss = Tools.SpitLongArrary(ids);
|
||||
|
||||
return SUCCESS(SysDictService.DeleteDictTypeByIds(idss));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Framework;
|
||||
using Infrastructure.Model;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Service.IService;
|
||||
using Hei.Captcha;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
public class SysLoginController : BaseController
|
||||
{
|
||||
static readonly NLog.Logger logger = NLog.LogManager.GetLogger("LoginController");
|
||||
private readonly IHttpContextAccessor httpContextAccessor;
|
||||
private readonly ISysUserService sysUserService;
|
||||
private readonly ISysMenuService sysMenuService;
|
||||
private readonly ISysLoginService sysLoginService;
|
||||
private readonly ISysPermissionService permissionService;
|
||||
private readonly SecurityCodeHelper SecurityCodeHelper;
|
||||
|
||||
public SysLoginController(
|
||||
IHttpContextAccessor contextAccessor,
|
||||
ISysMenuService sysMenuService,
|
||||
ISysUserService sysUserService,
|
||||
ISysLoginService sysLoginService,
|
||||
ISysPermissionService permissionService,
|
||||
SecurityCodeHelper captcha)
|
||||
{
|
||||
httpContextAccessor = contextAccessor;
|
||||
SecurityCodeHelper = captcha;
|
||||
this.sysMenuService = sysMenuService;
|
||||
this.sysUserService = sysUserService;
|
||||
this.sysLoginService = sysLoginService;
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="loginBody">登录对象</param>
|
||||
/// <returns></returns>
|
||||
[Route("login")]
|
||||
[HttpPost]
|
||||
[Log(Title = "登录")]
|
||||
public IActionResult Login([FromBody] LoginBodyDto loginBody)
|
||||
{
|
||||
if (loginBody == null) { throw new CustomException("请求参数错误"); }
|
||||
loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext);
|
||||
if (CacheHelper.Get(loginBody.Uuid) is string str && !str.ToLower().Equals(loginBody.Code.ToLower()))
|
||||
{
|
||||
throw new CustomException(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
||||
}
|
||||
|
||||
var user = sysLoginService.Login(loginBody, AsyncFactory.RecordLogInfo(httpContextAccessor.HttpContext, "0", "login"));
|
||||
#region 存入cookie Action校验权限使用
|
||||
//角色集合 eg: admin,yunying,common
|
||||
List<string> roles = permissionService.GetRolePermission(user);
|
||||
//权限集合 eg *:*:*,system:user:list
|
||||
List<string> permissions = permissionService.GetMenuPermission(user);
|
||||
#endregion
|
||||
LoginUser loginUser = new LoginUser(user.UserId, user.UserName, roles, permissions);
|
||||
|
||||
return SUCCESS(JwtUtil.GenerateJwtToken(HttpContext.WriteCookies(loginUser)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注销
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "注销")]
|
||||
[HttpPost("logout")]
|
||||
public IActionResult LogOut()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
//注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut
|
||||
await HttpContext.SignOutAsync();
|
||||
}).Wait();
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Verify]
|
||||
[HttpGet("getInfo")]
|
||||
public IActionResult GetUserInfo()
|
||||
{
|
||||
long userid = HttpContext.GetUId();
|
||||
var user = sysUserService.SelectUserById(userid);
|
||||
|
||||
//前端校验按钮权限使用
|
||||
//角色集合 eg: admin,yunying,common
|
||||
List<string> roles = permissionService.GetRolePermission(user);
|
||||
//权限集合 eg *:*:*,system:user:list
|
||||
List<string> permissions = permissionService.GetMenuPermission(user);
|
||||
|
||||
return SUCCESS(new { user, roles, permissions });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取路由信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Verify]
|
||||
[HttpGet("getRouters")]
|
||||
public IActionResult GetRouters()
|
||||
{
|
||||
long uid = HttpContext.GetUId();
|
||||
var menus = sysMenuService.SelectMenuTreeByUserId(uid);
|
||||
|
||||
return OutputJson(ToJson(1, sysMenuService.BuildMenus(menus)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成图片验证码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("captchaImage")]
|
||||
public ApiResult CaptchaImage()
|
||||
{
|
||||
string uuid = Guid.NewGuid().ToString().Replace("-", "");
|
||||
var code = SecurityCodeHelper.GetRandomEnDigitalText(4);
|
||||
var imgByte = SecurityCodeHelper.GetGifEnDigitalCodeByte(code);
|
||||
string base64Str = Convert.ToBase64String(imgByte);
|
||||
CacheHelper.SetCache(uuid, code);
|
||||
var obj = new { uuid, img = base64Str };// File(stream, "image/png")
|
||||
|
||||
return ToJson(1, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Verify]
|
||||
[Route("/system/menu")]
|
||||
public class SysMenuController : BaseController
|
||||
{
|
||||
private readonly ISysRoleService sysRoleService;
|
||||
private readonly ISysMenuService sysMenuService;
|
||||
|
||||
public SysMenuController(
|
||||
ISysRoleService sysRoleService,
|
||||
ISysMenuService sysMenuService)
|
||||
{
|
||||
this.sysRoleService = sysRoleService;
|
||||
this.sysMenuService = sysMenuService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单列表 √
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:menu:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult MenuList([FromQuery] SysMenu menu)
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
return SUCCESS(sysMenuService.SelectMenuList(menu, userId), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据菜单编号获取详细信息 √
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{menuId}")]
|
||||
[ActionPermissionFilter(Permission = "system:menu:query")]
|
||||
public IActionResult GetMenuInfo(int menuId = 0)
|
||||
{
|
||||
return SUCCESS(sysMenuService.GetMenuByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单下拉树列表(分配角色所需菜单)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeSelect")]
|
||||
public IActionResult TreeSelect()
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var list = sysMenuService.SelectMenuList(new SysMenu(), userId).FindAll(f => f.visible == "0");
|
||||
var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
|
||||
|
||||
return SUCCESS(treeMenus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色菜单信息
|
||||
/// 加载对应角色菜单列表树
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("roleMenuTreeselect/{roleId}")]
|
||||
public IActionResult RoleMenuTreeselect(int roleId)
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var menus = sysMenuService.SelectMenuList(userId);
|
||||
var checkedKeys = sysRoleService.SelectUserRoleMenus(roleId);
|
||||
return SUCCESS(new
|
||||
{
|
||||
checkedKeys,
|
||||
menus = sysMenuService.BuildMenuTreeSelect(menus),
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改菜单 √
|
||||
/// </summary>
|
||||
/// <param name="MenuDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("edit")]
|
||||
[Log(Title = "菜单管理", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:menu:edit")]
|
||||
public IActionResult MenuEdit([FromBody] SysMenu MenuDto)
|
||||
{
|
||||
if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
//if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto)))
|
||||
//{
|
||||
// return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在"));
|
||||
//}
|
||||
if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http"))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头"));
|
||||
}
|
||||
if (MenuDto.menuId.Equals(MenuDto.parentId))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,上级菜单不能选择自己"));
|
||||
}
|
||||
MenuDto.Update_by = User.Identity.Name;
|
||||
int result = sysMenuService.EditMenu(MenuDto);
|
||||
|
||||
return OutputJson(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加菜单 √
|
||||
/// </summary>
|
||||
/// <param name="MenuDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("add")]
|
||||
[Log(Title = "菜单管理", BusinessType = BusinessType.INSERT)]
|
||||
[ActionPermissionFilter(Permission = "system:menu:add")]
|
||||
public IActionResult MenuAdd([FromBody] SysMenu MenuDto)
|
||||
{
|
||||
if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,菜单名称已存在"));
|
||||
}
|
||||
if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http"))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头"));
|
||||
}
|
||||
|
||||
MenuDto.Create_by = User.Identity.Name;
|
||||
int result = sysMenuService.AddMenu(MenuDto);
|
||||
|
||||
return OutputJson(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜单删除 √
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{menuId}")]
|
||||
[Log(Title = "菜单管理", BusinessType = BusinessType.DELETE)]
|
||||
[ActionPermissionFilter(Permission = "system:menu:remove")]
|
||||
public IActionResult Remove(int menuId = 0)
|
||||
{
|
||||
if (sysMenuService.HasChildByMenuId(menuId))
|
||||
{
|
||||
return CustomError(ResultCode.CUSTOM_ERROR, "存在子菜单,不允许删除");
|
||||
}
|
||||
if (sysMenuService.CheckMenuExistRole(menuId))
|
||||
{
|
||||
return CustomError(ResultCode.CUSTOM_ERROR, "菜单已分配,不允许删除");
|
||||
}
|
||||
int result = sysMenuService.DeleteMenuById(menuId);
|
||||
|
||||
return OutputJson(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存排序
|
||||
/// </summary>
|
||||
/// <param name="MenuDto"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:menu:update")]
|
||||
[HttpPost("ChangeSort")]
|
||||
[Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult ChangeSort([FromBody] MenuDto MenuDto)
|
||||
{
|
||||
if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
|
||||
int result = sysMenuService.ChangeSortMenu(MenuDto);
|
||||
return OutputJson(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Route("system/notice")]
|
||||
public class SysNoticeController : BaseController
|
||||
{
|
||||
[HttpGet("list")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return SUCCESS(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 岗位管理
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/post")]
|
||||
public class SysPostController : BaseController
|
||||
{
|
||||
private readonly ISysPostService PostService;
|
||||
public SysPostController(ISysPostService postService)
|
||||
{
|
||||
PostService = postService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位列表查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "system:post:list")]
|
||||
public IActionResult List([FromQuery] SysPost post, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<SysPost>();
|
||||
predicate = predicate.AndIF(post.Status.IfNotEmpty(), it => it.Status == post.Status);
|
||||
var list = PostService.GetPages(predicate.ToExpression(), pagerInfo);
|
||||
|
||||
return SUCCESS(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位查询
|
||||
/// </summary>
|
||||
/// <param name="postId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{postId}")]
|
||||
[ActionPermissionFilter(Permission = "system:post:query")]
|
||||
public IActionResult Query(long postId = 0)
|
||||
{
|
||||
return SUCCESS(PostService.GetId(postId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位管理
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "system:post:add")]
|
||||
[Log(Title = "岗位添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add([FromBody] SysPost post)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
|
||||
{
|
||||
throw new CustomException($"修改岗位{post.PostName}失败,岗位名已存在");
|
||||
}
|
||||
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
|
||||
{
|
||||
throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在");
|
||||
}
|
||||
post.Update_by = User.Identity.Name;
|
||||
return OutputJson(ToJson(PostService.Add(post)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位管理
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "system:post:edit")]
|
||||
[Log(Title = "岗位编辑", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] SysPost post)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
|
||||
{
|
||||
throw new CustomException($"修改岗位{post.PostName}失败,岗位名已存在");
|
||||
}
|
||||
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
|
||||
{
|
||||
throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在");
|
||||
}
|
||||
post.Update_by = User.Identity.Name;
|
||||
return OutputJson(ToJson(PostService.Update(post)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ActionPermissionFilter(Permission = "system:post:remove")]
|
||||
[Log(Title = "岗位删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
return OutputJson(ToJson(PostService.Delete(id)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取岗位选择框列表
|
||||
/// </summary>
|
||||
[HttpGet("optionselect")]
|
||||
public IActionResult Optionselect()
|
||||
{
|
||||
List<SysPost> posts = PostService.GetAll();
|
||||
return SUCCESS(posts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Verify]
|
||||
[Route("system/user/profile")]
|
||||
public class SysProfileController : BaseController
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly ISysUserService UserService;
|
||||
private readonly ISysRoleService RoleService;
|
||||
private readonly ISysUserPostService UserPostService;
|
||||
private readonly ISysDeptService DeptService;
|
||||
private OptionsSetting OptionsSetting;
|
||||
private IWebHostEnvironment hostEnvironment;
|
||||
|
||||
public SysProfileController(
|
||||
ISysUserService userService,
|
||||
ISysRoleService roleService,
|
||||
ISysUserPostService postService,
|
||||
ISysDeptService deptService,
|
||||
IOptions<OptionsSetting> options,
|
||||
IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
UserService = userService;
|
||||
RoleService = roleService;
|
||||
UserPostService = postService;
|
||||
DeptService = deptService;
|
||||
OptionsSetting = options.Value;
|
||||
this.hostEnvironment = hostEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 个人中心用户信息获取
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Profile()
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var user = UserService.SelectUserById(userId);
|
||||
|
||||
user.Roles = RoleService.SelectUserRoleListByUserId(userId);
|
||||
var roles = RoleService.SelectUserRoleNames(userId);
|
||||
var postGroup = UserPostService.GetPostsStrByUserId(userId);
|
||||
var deptInfo = DeptService.GetFirst(f => f.DeptId == user.DeptId);
|
||||
user.DeptName = deptInfo?.DeptName;
|
||||
|
||||
return SUCCESS(new { user, roles, postGroup }, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
[Log(Title = "修改信息", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateProfile([FromBody] SysUserDto userDto)
|
||||
{
|
||||
if (userDto == null)
|
||||
{
|
||||
throw new CustomException(ResultCode.PARAM_ERROR, "请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var user = userDto.Adapt<SysUser>();
|
||||
user.Update_by = User.Identity.Name;
|
||||
user.Update_time = DateTime.Now;
|
||||
|
||||
int result = UserService.ChangeUser(user);
|
||||
return OutputJson(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("updatePwd")]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
[Log(Title = "修改密码", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdatePwd(string oldPassword, string newPassword)
|
||||
{
|
||||
LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext);
|
||||
|
||||
SysUser user = UserService.SelectUserById(loginUser.UserId);
|
||||
string oldMd5 = NETCore.Encrypt.EncryptProvider.Md5(oldPassword);
|
||||
string newMd5 = NETCore.Encrypt.EncryptProvider.Md5(newPassword);
|
||||
if (user.Password != oldMd5)
|
||||
{
|
||||
return OutputJson(ApiResult.Error("修改密码失败,旧密码错误"));
|
||||
}
|
||||
if (user.Password == newMd5)
|
||||
{
|
||||
return OutputJson(ApiResult.Error("新密码不能和旧密码相同"));
|
||||
}
|
||||
if (UserService.ResetPwd(loginUser.UserId, newMd5) > 0)
|
||||
{
|
||||
//TODO 更新缓存
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
return OutputJson(ApiResult.Error("修改密码异常,请联系管理员"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改头像
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Avatar")]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
//[Log(Title = "修改头像", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Avatar([FromForm(Name = "picture")] IFormFile formFile)
|
||||
{
|
||||
LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext);
|
||||
|
||||
if (formFile == null) throw new CustomException("请选择文件");
|
||||
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string savePath = Path.Combine("wwwroot", FileUtil.GetdirPath("uploads"));
|
||||
|
||||
Console.WriteLine(savePath);
|
||||
if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }
|
||||
|
||||
string fileName = FileUtil.HashFileName() + fileExt;
|
||||
string finalFilePath = savePath + fileName;
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyToAsync(stream);
|
||||
}
|
||||
string accessUrl = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads")}{fileName}";
|
||||
|
||||
UserService.UpdatePhoto(new SysUser() { Avatar = accessUrl, UserId = loginUser.UserId });
|
||||
logger.Info("修改头像:" + accessUrl);
|
||||
return SUCCESS(new { imgUrl = accessUrl });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Common;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色信息
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("system/role")]
|
||||
public class SysRoleController : BaseController
|
||||
{
|
||||
readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly ISysRoleService sysRoleService;
|
||||
|
||||
public SysRoleController(
|
||||
ISysRoleService sysRoleService)
|
||||
{
|
||||
this.sysRoleService = sysRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统角色管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:role:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysRole role, [FromQuery] PagerInfo pager)
|
||||
{
|
||||
var list = sysRoleService.SelectRoleList(role);
|
||||
|
||||
VMPageResult<SysRole> vMPageResult = new(list, pager);
|
||||
|
||||
return SUCCESS(vMPageResult, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色编号获取详细信息
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{roleId}")]
|
||||
public IActionResult GetInfo(long roleId = 0)
|
||||
{
|
||||
var info = sysRoleService.SelectRoleById(roleId);
|
||||
|
||||
return SUCCESS(info, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色 √
|
||||
/// </summary>
|
||||
/// <param name="sysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "system:role:add")]
|
||||
[Log(Title = "角色管理", BusinessType = BusinessType.INSERT)]
|
||||
[Route("edit")]
|
||||
public IActionResult RoleAdd([FromBody] SysRole sysRoleDto)
|
||||
{
|
||||
if (sysRoleDto == null) return OutputJson(ApiResult.Error(101, "请求参数错误"));
|
||||
|
||||
if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
|
||||
}
|
||||
|
||||
sysRoleDto.Create_by = User.Identity.Name;
|
||||
long roleId = sysRoleService.InsertRole(sysRoleDto);
|
||||
|
||||
return OutputJson(ToJson(roleId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改角色 √
|
||||
/// </summary>
|
||||
/// <param name="sysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "system:role:edit")]
|
||||
[Log(Title = "角色管理", BusinessType = BusinessType.UPDATE)]
|
||||
[Route("edit")]
|
||||
public IActionResult RoleEdit([FromBody] SysRole sysRoleDto)
|
||||
{
|
||||
if (sysRoleDto == null || sysRoleDto.RoleId <= 0 || string.IsNullOrEmpty(sysRoleDto.RoleKey))
|
||||
{
|
||||
return OutputJson(ApiResult.Error(101, "请求参数错误"));
|
||||
}
|
||||
sysRoleService.CheckRoleAllowed(sysRoleDto);
|
||||
var info = sysRoleService.SelectRoleById(sysRoleDto.RoleId);
|
||||
if (info != null && info.RoleKey != sysRoleDto.RoleKey)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
|
||||
}
|
||||
}
|
||||
|
||||
sysRoleDto.Update_by = User.Identity.Name;
|
||||
int upResult = sysRoleService.UpdateRole(sysRoleDto);
|
||||
if (upResult > 0)
|
||||
{
|
||||
//TODO 更新缓存用户权限信息
|
||||
|
||||
return SUCCESS(upResult);
|
||||
}
|
||||
return OutputJson(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色分配菜单
|
||||
/// </summary>
|
||||
/// <param name="sysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("dataScope")]
|
||||
[ActionPermissionFilter(Permission = "system:role:update")]
|
||||
[Log(Title = "角色管理", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult DataScope([FromBody] SysRole sysRoleDto)
|
||||
{
|
||||
if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return OutputJson(ApiResult.Error(101, "请求参数错误"));
|
||||
|
||||
sysRoleDto.Create_by = HttpContextExtension.GetName(HttpContext);
|
||||
//删除角色菜单
|
||||
sysRoleService.DeleteRoleMenuByRoleId(sysRoleDto.RoleId);
|
||||
sysRoleService.InsertRoleMenu(sysRoleDto);
|
||||
|
||||
return SUCCESS(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色删除 √
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{roleId}")]
|
||||
[Log(Title = "角色管理", BusinessType = BusinessType.DELETE)]
|
||||
[ActionPermissionFilter(Permission = "system:role:remove")]
|
||||
public IActionResult Remove(string roleId)
|
||||
{
|
||||
long[] roleIds = Tools.SpitLongArrary(roleId);
|
||||
int result = sysRoleService.DeleteRoleByRoleId(roleIds);
|
||||
|
||||
return OutputJson(ToJson(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改角色状态 √
|
||||
/// </summary>
|
||||
/// <param name="roleDto">角色对象</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("changeStatus")]
|
||||
[Log(Title = "修改角色状态", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:role:update")]
|
||||
public IActionResult ChangeStatus([FromBody] SysRole roleDto)
|
||||
{
|
||||
int result = sysRoleService.UpdateRoleStatus(roleDto);
|
||||
|
||||
return OutputJson(ToJson(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Npoi.Mapper;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Verify]
|
||||
[Route("system/user")]
|
||||
public class SysUserController : BaseController
|
||||
{
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly ISysUserService UserService;
|
||||
private readonly ISysRoleService RoleService;
|
||||
private readonly ISysPostService PostService;
|
||||
private readonly ISysUserPostService UserPostService;
|
||||
|
||||
public SysUserController(
|
||||
ISysUserService userService,
|
||||
ISysRoleService roleService,
|
||||
ISysPostService postService,
|
||||
ISysUserPostService userPostService)
|
||||
{
|
||||
UserService = userService;
|
||||
RoleService = roleService;
|
||||
PostService = postService;
|
||||
UserPostService = userPostService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户管理 -> 获取用户
|
||||
/// /system/user/list
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "system:user:list")]
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysUser user, PagerInfo pager)
|
||||
{
|
||||
var list = UserService.SelectUserList(user, pager);
|
||||
|
||||
var vm = new VMPageResult<SysUser>(list, pager);
|
||||
|
||||
return SUCCESS(vm, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户管理 -> 编辑、添加用户获取用户,信息查询
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("")]
|
||||
[HttpGet("{userId:int=0}")]
|
||||
public IActionResult GetInfo(int userId)
|
||||
{
|
||||
Dictionary<string, object> dic = new();
|
||||
var roles = RoleService.SelectRoleAll();
|
||||
dic.Add("roles", roles);
|
||||
dic.Add("posts", PostService.GetAll());
|
||||
|
||||
//编辑
|
||||
if (userId > 0)
|
||||
{
|
||||
dic.Add("user", UserService.SelectUserById(userId));
|
||||
dic.Add("postIds", UserPostService.GetUserPostsByUserId(userId));
|
||||
dic.Add("roleIds", RoleService.SelectUserRoles(userId));
|
||||
}
|
||||
|
||||
return OutputJson(ApiResult.Success(dic));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("edit")]
|
||||
[Log(Title = "用户管理", BusinessType = BusinessType.INSERT)]
|
||||
[ActionPermissionFilter(Permission = "system:user:add")]
|
||||
public IActionResult AddUser([FromBody] SysUser user)
|
||||
{
|
||||
if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
if (UserConstants.NOT_UNIQUE.Equals(UserService.CheckUserNameUnique(user.UserName)))
|
||||
{
|
||||
return OutputJson(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在"));
|
||||
}
|
||||
|
||||
user.Create_by = User.Identity.Name;
|
||||
user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password);
|
||||
|
||||
return OutputJson(UserService.InsertUser(user));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
[Log(Title = "用户管理", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:user:edit")]
|
||||
public IActionResult UpdateUser([FromBody] SysUser user)
|
||||
{
|
||||
if (user == null || user.UserId <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
|
||||
user.Update_by = User.Identity.Name;
|
||||
int upResult = UserService.UpdateUser(user);
|
||||
|
||||
return OutputJson(upResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 改变用户状态
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("changeStatus")]
|
||||
[Log(Title = "修改用户状态", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:user:update")]
|
||||
public IActionResult ChangeStatus([FromBody] SysUser user)
|
||||
{
|
||||
if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
|
||||
int result = UserService.ChangeUserStatus(user);
|
||||
return OutputJson(ToJson(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{userId}")]
|
||||
[Log(Title = "用户管理", BusinessType = BusinessType.DELETE)]
|
||||
[ActionPermissionFilter(Permission = "system:user:remove")]
|
||||
public IActionResult Remove(int userid = 0)
|
||||
{
|
||||
if (userid <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); }
|
||||
|
||||
int result = UserService.DeleteUser(userid);
|
||||
|
||||
return OutputJson(ToJson(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("resetPwd")]
|
||||
[Log(Title = "重置密码", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:user:update")]
|
||||
public IActionResult ResetPwd([FromBody] SysUser sysUser)
|
||||
{
|
||||
//密码md5
|
||||
sysUser.Password = NETCore.Encrypt.EncryptProvider.Md5(sysUser.Password);
|
||||
|
||||
int result = UserService.ResetPwd(sysUser.UserId, sysUser.Password);
|
||||
return OutputJson(ToJson(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入 ok
|
||||
/// </summary>
|
||||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "用户导入", BusinessType = BusinessType.IMPORT)]
|
||||
[ActionPermissionFilter(Permission = "system:user:import")]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
var mapper = new Mapper(formFile.OpenReadStream());// 从流获取
|
||||
//读取的sheet信息
|
||||
var rows = mapper.Take<SysUser>(0);
|
||||
foreach (var item in rows)
|
||||
{
|
||||
SysUser u = item.Value;
|
||||
}
|
||||
//TODO 业务逻辑
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户模板 ok
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "用户模板", BusinessType = BusinessType.EXPORT)]
|
||||
[ActionPermissionFilter(Permission = "system:user:export")]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
List<SysUser> user = new List<SysUser>();
|
||||
var mapper = new Mapper();
|
||||
MemoryStream stream = new MemoryStream();
|
||||
mapper.Save(stream, user, "sheel1", overwrite: true, xlsx: true);
|
||||
//Response.Headers.Append("content-disposition", "attachment;filename=sysUser.xlsx");
|
||||
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "sysUser.xlsx");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Verify]
|
||||
[Route("system/userRole")]
|
||||
public class SysUserRoleController : BaseController
|
||||
{
|
||||
private readonly ISysUserRoleService SysUserRoleService;
|
||||
private readonly ISysUserService UserService;
|
||||
|
||||
public SysUserRoleController(
|
||||
ISysUserRoleService sysUserRoleService,
|
||||
ISysUserService userService)
|
||||
{
|
||||
SysUserRoleService = sysUserRoleService;
|
||||
UserService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色编号获取已分配的用户
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("get/{roleId}")]
|
||||
[ActionPermissionFilter(Permission = "system:roleusers:query")]
|
||||
public IActionResult GetList(long roleId = 0)
|
||||
{
|
||||
var list = SysUserRoleService.GetSysUsersByRoleId(roleId);
|
||||
|
||||
return SUCCESS(list, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("create")]
|
||||
[ActionPermissionFilter(Permission = "system:roleusers:add")]
|
||||
[Log(Title = "添加角色用户", BusinessType = Infrastructure.Enums.BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] RoleUsersCreateDto roleUsersCreateDto)
|
||||
{
|
||||
var response = SysUserRoleService.InsertRoleUser(roleUsersCreateDto);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色用户
|
||||
/// </summary>
|
||||
/// <param name="roleUsersCreateDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("delete")]
|
||||
[ActionPermissionFilter(Permission = "system:roleusers:del")]
|
||||
[Log(Title = "删除角色用户", BusinessType = Infrastructure.Enums.BusinessType.DELETE)]
|
||||
public IActionResult Delete([FromBody] RoleUsersCreateDto roleUsersCreateDto)
|
||||
{
|
||||
return SUCCESS(SysUserRoleService.DeleteRoleUserByUserIds(roleUsersCreateDto.RoleId, roleUsersCreateDto.UserIds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未分配用户角色
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetExcludeUsers")]
|
||||
public IActionResult GetExcludeUsers(long roleId = 0)
|
||||
{
|
||||
if (roleId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.PARAM_ERROR, "roleId不能为空");
|
||||
}
|
||||
// 取得该角色所有添加的用户
|
||||
var userIds = SysUserRoleService.GetSysUsersByRoleId(roleId).Select(f => f.UserId);
|
||||
|
||||
SysUser userQuery = new();
|
||||
userQuery.Status = "0";
|
||||
PagerInfo pager = new(1, 50);
|
||||
|
||||
// 获取未添加用户
|
||||
var list = UserService.SelectUserList(userQuery, pager).Where(m => !userIds.Contains(m.UserId));
|
||||
return SUCCESS(list, TIME_FORMAT_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Quartz;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 计划任务
|
||||
/// </summary>
|
||||
//[Verify]
|
||||
[Route("system/Tasks")]
|
||||
public class TasksController : BaseController
|
||||
{
|
||||
private ISysTasksQzService _tasksQzService;
|
||||
private ITaskSchedulerServer _schedulerServer;
|
||||
|
||||
public TasksController(
|
||||
ISysTasksQzService sysTasksQzService,
|
||||
ITaskSchedulerServer taskScheduler)
|
||||
{
|
||||
_tasksQzService = sysTasksQzService;
|
||||
_schedulerServer = taskScheduler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询计划任务列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "system:task:list")]
|
||||
public IActionResult Query([FromQuery] TasksQueryDto parm, [FromQuery] PagerInfo pager)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<SysTasksQz>();
|
||||
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.QueryText),
|
||||
m => m.Name.Contains(parm.QueryText) ||
|
||||
m.JobGroup.Contains(parm.QueryText) ||
|
||||
m.AssemblyName.Contains(parm.QueryText));
|
||||
|
||||
var response = _tasksQzService.GetPages(predicate.ToExpression(), pager, f => f.IsStart, "Desc");
|
||||
|
||||
return SUCCESS(response, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询单个计划任务
|
||||
/// </summary>
|
||||
/// <param name="id">编码</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(string id)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
return SUCCESS(_tasksQzService.GetId(id));
|
||||
}
|
||||
return SUCCESS(_tasksQzService.GetAll());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("create")]
|
||||
[ActionPermissionFilter(Permission = "system:task:add")]
|
||||
[Log(Title = "添加任务", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] TasksCreateDto parm)
|
||||
{
|
||||
//判断是否已经存在
|
||||
if (_tasksQzService.Any(m => m.Name == parm.Name))
|
||||
{
|
||||
throw new CustomException($"添加 {parm.Name} 失败,该用任务存在,不能重复!");
|
||||
}
|
||||
if (string.IsNullOrEmpty(parm.Cron) || !CronExpression.IsValidExpression(parm.Cron))
|
||||
{
|
||||
throw new CustomException($"cron表达式不正确");
|
||||
}
|
||||
|
||||
//从 Dto 映射到 实体
|
||||
var tasksQz = parm.Adapt<SysTasksQz>().ToCreate();
|
||||
tasksQz.IsStart = false;
|
||||
tasksQz.Create_by = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_tasksQzService.Add(tasksQz));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("update")]
|
||||
[ActionPermissionFilter(Permission = "system:task:edit")]
|
||||
[Log(Title = "修改任务", BusinessType = BusinessType.UPDATE)]
|
||||
public async Task<IActionResult> Update([FromBody] TasksUpdateDto parm)
|
||||
{
|
||||
//判断是否已经存在
|
||||
if (_tasksQzService.Any(m => m.Name == parm.Name && m.ID != parm.ID))
|
||||
{
|
||||
throw new CustomException($"更新 {parm.Name} 失败,该用任务存在,不能重复!");
|
||||
}
|
||||
if (string.IsNullOrEmpty(parm.Cron))
|
||||
{
|
||||
throw new CustomException($"触发器 Corn 模式下,运行时间表达式必须填写");
|
||||
}
|
||||
if (!CronExpression.IsValidExpression(parm.Cron))
|
||||
{
|
||||
throw new CustomException($"cron表达式不正确");
|
||||
}
|
||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == parm.ID);
|
||||
|
||||
if (tasksQz.IsStart)
|
||||
{
|
||||
throw new CustomException($"该任务正在运行中,请先停止在更新");
|
||||
}
|
||||
|
||||
var response = _tasksQzService.Update(m => m.ID == parm.ID, m => new SysTasksQz
|
||||
{
|
||||
Name = parm.Name,
|
||||
JobGroup = parm.JobGroup,
|
||||
Cron = parm.Cron,
|
||||
AssemblyName = parm.AssemblyName,
|
||||
ClassName = parm.ClassName,
|
||||
Remark = parm.Remark,
|
||||
TriggerType = parm.TriggerType,
|
||||
IntervalSecond = parm.IntervalSecond,
|
||||
JobParams = parm.JobParams,
|
||||
Update_by = User.Identity.Name,
|
||||
Update_time = DateTime.Now
|
||||
});
|
||||
if (response > 0)
|
||||
{
|
||||
//先暂停原先的任务
|
||||
var respon = await _schedulerServer.UpdateTaskScheduleAsync(tasksQz, tasksQz.JobGroup);
|
||||
}
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("delete")]
|
||||
[ActionPermissionFilter(Permission = "system:task:delete")]
|
||||
[Log(Title = "删除任务", BusinessType = BusinessType.DELETE)]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new CustomException("删除任务 Id 不能为空");
|
||||
}
|
||||
|
||||
if (!_tasksQzService.Any(m => m.ID == id))
|
||||
{
|
||||
throw new CustomException("任务不存在");
|
||||
}
|
||||
|
||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);
|
||||
|
||||
if (taskResult.Code == 200)
|
||||
{
|
||||
_tasksQzService.Delete(id);
|
||||
}
|
||||
return OutputJson(taskResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("start")]
|
||||
[ActionPermissionFilter(Permission = "system:task:start")]
|
||||
[Log(Title = "启动任务", BusinessType = BusinessType.OTHER)]
|
||||
public async Task<IActionResult> Start(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new CustomException("启动任务 Id 不能为空");
|
||||
}
|
||||
|
||||
if (!_tasksQzService.Any(m => m.ID == id))
|
||||
{
|
||||
throw new CustomException("任务不存在");
|
||||
}
|
||||
|
||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||
var taskResult = await _schedulerServer.AddTaskScheduleAsync(tasksQz);
|
||||
|
||||
if (taskResult.Code == 200)
|
||||
{
|
||||
tasksQz.IsStart = true;
|
||||
_tasksQzService.Update(tasksQz);
|
||||
}
|
||||
|
||||
return OutputJson(taskResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("stop")]
|
||||
[ActionPermissionFilter(Permission = "system:task:stop")]
|
||||
[Log(Title = "停止任务", BusinessType = BusinessType.OTHER)]
|
||||
public async Task<IActionResult> Stop(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new CustomException("停止任务 Id 不能为空");
|
||||
}
|
||||
|
||||
if (!_tasksQzService.Any(m => m.ID == id))
|
||||
{
|
||||
throw new CustomException("任务不存在");
|
||||
}
|
||||
|
||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);//await _schedulerServer.PauseTaskScheduleAsync(tasksQz);
|
||||
|
||||
if (taskResult.Code == 200)
|
||||
{
|
||||
tasksQz.IsStart = false;
|
||||
_tasksQzService.Update(tasksQz);
|
||||
}
|
||||
|
||||
return OutputJson(taskResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务立即执行一次
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("run")]
|
||||
[ActionPermissionFilter(Permission = "system:task:run")]
|
||||
[Log(Title = "执行任务", BusinessType = BusinessType.OTHER)]
|
||||
public async Task<IActionResult> Run(string id)
|
||||
{
|
||||
if (!_tasksQzService.Any(m => m.ID == id))
|
||||
{
|
||||
throw new CustomException("任务不存在");
|
||||
}
|
||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||
var taskResult = await _schedulerServer.RunTaskScheduleAsync(tasksQz);
|
||||
|
||||
if (taskResult.Code == 200)
|
||||
{
|
||||
//_tasksQzService.Update(tasksQz);
|
||||
}
|
||||
|
||||
return OutputJson(taskResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Enums;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Route("/monitor/jobLog")]
|
||||
public class TasksLogController : BaseController
|
||||
{
|
||||
private readonly ISysTasksLogService tasksLogService;
|
||||
|
||||
public TasksLogController(ISysTasksLogService tasksLogService)
|
||||
{
|
||||
this.tasksLogService = tasksLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询日志
|
||||
/// </summary>
|
||||
/// <param name="queryDto"></param>
|
||||
/// <param name="pager"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult GetList([FromQuery] PagerInfo pager, [FromQuery] TasksLogQueryDto queryDto)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
queryDto.BeginTime = DateTimeHelper.GetBeginTime(queryDto.BeginTime, -1);
|
||||
queryDto.EndTime = DateTimeHelper.GetBeginTime(queryDto.EndTime, 1);
|
||||
|
||||
var predicate = Expressionable.Create<SysTasksLog>().And(it => it.CreateTime >= queryDto.BeginTime && it.CreateTime <= queryDto.EndTime);
|
||||
predicate = predicate.AndIF(queryDto.JobName.IfNotEmpty(), m => m.JobName.Contains(queryDto.JobName));
|
||||
predicate = predicate.AndIF(queryDto.JobGroup.IfNotEmpty(), m => m.JobGroup == queryDto.JobGroup);
|
||||
predicate = predicate.AndIF(queryDto.Status.IfNotEmpty(), m => m.Status == queryDto.Status);
|
||||
predicate = predicate.AndIF(queryDto.JobId.IfNotEmpty(), m => m.JobId == queryDto.JobId);
|
||||
|
||||
var response = tasksLogService.GetPages(predicate.ToExpression(), pager, m => m.CreateTime, "Desc");
|
||||
|
||||
return SUCCESS(response, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除定时任务调用日志
|
||||
/// </summary>
|
||||
/// <param name="jobIds"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{jobIds}")]
|
||||
[ActionPermissionFilter(Permission = "PRIV_JOBLOG_DELETE")]
|
||||
[Log(Title = "删除任务日志", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(string jobIds)
|
||||
{
|
||||
long[] jobIdArr = Tools.SpitLongArrary(jobIds);
|
||||
|
||||
int result = tasksLogService.Delete(jobIdArr);
|
||||
|
||||
return OutputJson(ToJson(result, result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("clean")]
|
||||
[ActionPermissionFilter(Permission = "PRIV_JOBLOG_REMOVE")]
|
||||
[Log(Title = "清空任务日志", BusinessType = BusinessType.CLEAN)]
|
||||
public IActionResult Clean()
|
||||
{
|
||||
tasksLogService.DeleteTable();
|
||||
return SUCCESS(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
//[Verify]
|
||||
public class MonitorController : BaseController
|
||||
{
|
||||
private OptionsSetting Options;
|
||||
private IWebHostEnvironment HostEnvironment;
|
||||
|
||||
public MonitorController(IOptions<OptionsSetting> options, IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
this.HostEnvironment = hostEnvironment;
|
||||
this.Options = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存监控数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("monitor/cache")]
|
||||
public ApiResult GetCache()
|
||||
{
|
||||
string redis_connString = Options.Redis;
|
||||
var rs = new CSRedis.CSRedisClient(redis_connString);
|
||||
|
||||
RedisHelper.Initialization(rs);//初始化Redis
|
||||
|
||||
return ToJson(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("monitor/server")]
|
||||
//[AllowAnonymous]
|
||||
public IActionResult Server()
|
||||
{
|
||||
//核心数
|
||||
int cpuNum = Environment.ProcessorCount;
|
||||
string computerName = Environment.MachineName;
|
||||
string osName = RuntimeInformation.OSDescription;
|
||||
string osArch = RuntimeInformation.OSArchitecture.ToString();
|
||||
string version = RuntimeInformation.FrameworkDescription;
|
||||
string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB";
|
||||
string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string runTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string serverIP = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort);//获取服务器IP
|
||||
|
||||
var data = new
|
||||
{
|
||||
cpu = ComputerHelper.GetComputerInfo(),
|
||||
sys = new { cpuNum, computerName, osName, osArch, serverIP },
|
||||
app = new
|
||||
{
|
||||
name = HostEnvironment.EnvironmentName,
|
||||
rootPath = HostEnvironment.ContentRootPath,
|
||||
webRootPath = HostEnvironment.WebRootPath,
|
||||
version,
|
||||
appRAM,
|
||||
startTime,
|
||||
runTime,
|
||||
host = serverIP
|
||||
}
|
||||
};
|
||||
|
||||
return SUCCESS(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统访问记录
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("/monitor/logininfor")]
|
||||
public class SysLogininforController : BaseController
|
||||
{
|
||||
private ISysLoginService sysLoginService;
|
||||
|
||||
public SysLogininforController(ISysLoginService sysLoginService)
|
||||
{
|
||||
this.sysLoginService = sysLoginService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询登录日志
|
||||
/// /monitor/logininfor/list
|
||||
/// </summary>
|
||||
/// <param name="sysLogininfoDto"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult LoignLogList([FromQuery] SysLogininfor sysLogininfoDto, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = sysLoginService.GetLoginLog(sysLogininfoDto, pagerInfo);
|
||||
var vMPage = new VMPageResult<SysLogininfor>(list, pagerInfo);
|
||||
|
||||
return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空登录日志
|
||||
/// /monitor/logininfor/clean
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "清空登录日志")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
[HttpDelete("clean")]
|
||||
public IActionResult CleanLoginInfo()
|
||||
{
|
||||
sysLoginService.TruncateLogininfo();
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /monitor/logininfor/1
|
||||
/// </summary>
|
||||
/// <param name="infoIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "删除登录日志")]
|
||||
[HttpDelete("{infoIds}")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
public IActionResult Remove(string infoIds)
|
||||
{
|
||||
long[] infoIdss = Tools.SpitLongArrary(infoIds);
|
||||
return SUCCESS(sysLoginService.DeleteLogininforByIds(infoIdss));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
[Verify]
|
||||
[Route("/monitor/operlog")]
|
||||
public class SysOperlogController : BaseController
|
||||
{
|
||||
private ISysOperLogService sysOperLogService;
|
||||
|
||||
public SysOperlogController(ISysOperLogService sysOperLogService)
|
||||
{
|
||||
this.sysOperLogService = sysOperLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="sysOperLog"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult OperList([FromQuery] SysOperLogDto sysOperLog)
|
||||
{
|
||||
PagerInfo pagerInfo = new PagerInfo(sysOperLog.pageNum);
|
||||
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog, pagerInfo);
|
||||
var vMPage = new VMPageResult<SysOperLog>(list, pagerInfo);
|
||||
|
||||
return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除操作日志
|
||||
/// </summary>
|
||||
/// <param name="operIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "操作日志", BusinessType = BusinessType.DELETE)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:delete")]
|
||||
[HttpDelete("{operIds}")]
|
||||
public IActionResult Remove(string operIds)
|
||||
{
|
||||
long[] operIdss = Tools.SpitLongArrary(operIds);
|
||||
return SUCCESS(sysOperLogService.DeleteOperLogByIds(operIdss));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "清空操作日志", BusinessType = BusinessType.CLEAN)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:delete")]
|
||||
[HttpDelete("clean")]
|
||||
public ApiResult ClearOperLog()
|
||||
{
|
||||
sysOperLogService.CleanOperLog();
|
||||
|
||||
return ToJson(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
[Verify]
|
||||
[Route("monitor/online")]
|
||||
public class SysUserOnlineController : BaseController
|
||||
{
|
||||
[HttpGet("list")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return SUCCESS(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
public class UploadController : BaseController
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private OptionsSetting OptionsSetting;
|
||||
|
||||
public UploadController(IOptions<OptionsSetting> optionsSetting)
|
||||
{
|
||||
OptionsSetting = optionsSetting.Value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult SaveFile([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传图片不能为空");
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string savePath = Path.Combine("wwwroot", FileUtil.GetdirPath("uploads"));
|
||||
|
||||
if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }
|
||||
|
||||
string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt;
|
||||
string finalFilePath = Path.Combine(savePath, fileName);
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{finalFilePath.Replace("wwwroot", "").Replace("\\", "/")}";
|
||||
return OutputJson(ToJson(1, accessPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user