Merge branch 'sqlsugar-dev' of https://gitee.com/ccnetcore/Yi into sqlsugar-dev
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
using Hei.Captcha;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 账户管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AccountController : ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
private JwtInvoker _jwtInvoker;
|
||||
private ILogger _logger;
|
||||
private SecurityCodeHelper _securityCode;
|
||||
private IRepository<UserEntity> _repository;
|
||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker, SecurityCodeHelper securityCode)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_jwtInvoker = jwtInvoker;
|
||||
_logger = logger;
|
||||
_securityCode = securityCode;
|
||||
_repository = iUserService._repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置管理员CC的密码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<Result> RestCC()
|
||||
{
|
||||
var user = await _iUserService._repository.GetFirstAsync(u => u.UserName == "cc");
|
||||
user.Password = "123456";
|
||||
user.BuildPassword();
|
||||
await _iUserService._repository.UpdateIgnoreNullAsync(user);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,登录
|
||||
/// </summary>
|
||||
/// <param name="loginDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Login(LoginDto loginDto)
|
||||
{
|
||||
//跳过,需要redis缓存获取uuid与code的关系,进行比较即可
|
||||
//先效验验证码和UUID
|
||||
//登录还需要进行登录日志的落库
|
||||
|
||||
var loginInfo = HttpContext.GetLoginLogInfo();
|
||||
loginInfo.LoginUser = loginDto.UserName;
|
||||
loginInfo.LogMsg = "登录成功!";
|
||||
var loginLogRepository = _repository.ChangeRepository<Repository<LoginLogEntity>>();
|
||||
UserEntity user = new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
|
||||
{
|
||||
var userRoleMenu = await _iUserService.GetUserAllInfo(user.Id);
|
||||
await loginLogRepository.InsertReturnSnowflakeIdAsync(loginInfo);
|
||||
return Result.Success(loginInfo.LogMsg).SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User, userRoleMenu.Menus) });
|
||||
}
|
||||
loginInfo.LogMsg = "登录失败!用户名或者密码错误!";
|
||||
await loginLogRepository.InsertReturnSnowflakeIdAsync(loginInfo);
|
||||
return Result.Error(loginInfo.LogMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,注册
|
||||
/// </summary>
|
||||
/// <param name="registerDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Register(RegisterDto registerDto)
|
||||
{
|
||||
UserEntity user = new();
|
||||
if (await _iUserService.Register(WebCore.Mapper.MapperHelper.Map<UserEntity, RegisterDto>(registerDto), o => user = o))
|
||||
{
|
||||
return Result.Success("注册成功!").SetData(user);
|
||||
}
|
||||
return Result.SuccessError("注册失败!用户名已存在!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,登出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public Result Logout()
|
||||
{
|
||||
return Result.Success("安全登出成功!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过已登录的用户获取用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//[Authorize]
|
||||
public async Task<Result> GetUserAllInfo()
|
||||
{
|
||||
//通过鉴权jwt获取到用户的id
|
||||
var userId = HttpContext.GetUserIdInfo();
|
||||
var data = await _iUserService.GetUserAllInfo(userId);
|
||||
//系统用户数据被重置,老前端访问重新授权
|
||||
if (data is null)
|
||||
{
|
||||
return Result.UnAuthorize();
|
||||
}
|
||||
|
||||
data.Menus.Clear();
|
||||
return Result.Success().SetData(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户的前端路由
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetRouterInfo()
|
||||
{
|
||||
var userId = HttpContext.GetUserIdInfo();
|
||||
var data = await _iUserService.GetUserAllInfo(userId);
|
||||
var menus = data.Menus.ToList();
|
||||
|
||||
//为超级管理员直接给全部路由
|
||||
if (SystemConst.Admin.Equals(data.User.UserName))
|
||||
{
|
||||
menus = await _iUserService._repository.ChangeRepository<Repository<MenuEntity>>().GetListAsync();
|
||||
}
|
||||
//将后端菜单转换成前端路由,组件级别需要过滤
|
||||
List<VueRouterModel> routers = MenuEntity.RouterBuild(menus);
|
||||
return Result.Success().SetData(routers);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 更新已登录用户的用户信息
|
||||
///// </summary>
|
||||
///// <param name="user"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpPut]
|
||||
//public async Task<Result> UpdateUserByHttp(UserEntity user)
|
||||
//{
|
||||
// //当然,密码是不能给他修改的
|
||||
// user.Password = null;
|
||||
// user.Salt = null;
|
||||
|
||||
// //修改需要赋值上主键哦
|
||||
// user.Id = HttpContext.GetUserIdInfo();
|
||||
// return Result.Success().SetStatus(await _iUserService._repository.UpdateIgnoreNullAsync(user));
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 自己更新密码
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdatePassword(UpdatePasswordDto dto)
|
||||
{
|
||||
long userId = HttpContext.GetUserIdInfo();
|
||||
|
||||
if (await _iUserService.UpdatePassword(dto, userId))
|
||||
{
|
||||
return Result.Success();
|
||||
}
|
||||
return Result.Error("更新失败!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public Result CaptchaImage()
|
||||
{
|
||||
var uuid = Guid.NewGuid();
|
||||
var code = _securityCode.GetRandomEnDigitalText(4);
|
||||
//将uuid与code,Redis缓存中心化保存起来,登录根据uuid比对即可
|
||||
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
|
||||
return Result.Success().SetData(new { uuid = uuid, img = imgbyte });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class ConfigController : BaseSimpleCrudController<ConfigEntity>
|
||||
{
|
||||
private IConfigService _iConfigService;
|
||||
public ConfigController(ILogger<ConfigEntity> logger, IConfigService iConfigService) : base(logger, iConfigService)
|
||||
{
|
||||
_iConfigService = iConfigService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] ConfigEntity dic, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iConfigService.SelctPageList(dic, page));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class DeptController : BaseSimpleCrudController<DeptEntity>
|
||||
{
|
||||
private IDeptService _iDeptService;
|
||||
public DeptController(ILogger<DeptEntity> logger, IDeptService iDeptService) : base(logger, iDeptService)
|
||||
{
|
||||
_iDeptService = iDeptService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件查询
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> SelctGetList([FromQuery] DeptEntity dept)
|
||||
{
|
||||
return Result.Success().SetData(await _iDeptService.SelctGetList(dept));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<Result> Add(DeptEntity entity)
|
||||
{
|
||||
return await base.Add(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<Result> Update(DeptEntity entity)
|
||||
{
|
||||
return await base.Update(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色id获取该角色下全部部门
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result> GetListByRoleId(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iDeptService.GetListByRoleId(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class DictionaryController :BaseSimpleCrudController<DictionaryEntity>
|
||||
{
|
||||
private IDictionaryService _iDictionaryService;
|
||||
public DictionaryController(ILogger<DictionaryEntity> logger, IDictionaryService iDictionaryService):base(logger, iDictionaryService)
|
||||
{
|
||||
_iDictionaryService = iDictionaryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] DictionaryEntity dic, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryService.SelctPageList(dic, page));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class DictionaryInfoController:BaseSimpleCrudController<DictionaryInfoEntity>
|
||||
{
|
||||
private IDictionaryInfoService _iDictionaryInfoService;
|
||||
public DictionaryInfoController(ILogger<DictionaryInfoEntity> logger, IDictionaryInfoService iDictionaryInfoService):base(logger, iDictionaryInfoService)
|
||||
{
|
||||
_iDictionaryInfoService = iDictionaryInfoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="dicInfo"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] DictionaryInfoEntity dicInfo, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryInfoService.SelctPageList(dicInfo, page));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类别获取字典信息
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{type}")]
|
||||
public async Task<Result> GetListByType([FromRoute] string type)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryInfoService._repository.GetListAsync(u=>u.DictType==type&&u.IsDeleted==false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
private IFileService _iFileService;
|
||||
private readonly IHostEnvironment _env;
|
||||
private ThumbnailSharpInvoer _thumbnailSharpInvoer;
|
||||
|
||||
/// <summary>
|
||||
/// 文件上传下载
|
||||
/// </summary>
|
||||
/// <param name="iFileService"></param>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="thumbnailSharpInvoer"></param>
|
||||
public FileController(IFileService iFileService, IHostEnvironment env, ThumbnailSharpInvoer thumbnailSharpInvoer)
|
||||
{
|
||||
_iFileService = iFileService;
|
||||
_env = env;
|
||||
_thumbnailSharpInvoer = thumbnailSharpInvoer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载,只需用文件code即可,可选择是否为缩略图
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="isThumbnail"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/file/{code}/{isThumbnail?}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(long code, bool? isThumbnail)
|
||||
{
|
||||
var file = await _iFileService._repository.GetByIdAsync(code);
|
||||
if (file is null)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
try
|
||||
{
|
||||
//如果为缩略图
|
||||
if (isThumbnail is true)
|
||||
{
|
||||
file.FilePath = PathEnum.Thumbnail.ToString();
|
||||
}
|
||||
//路径为: 文件路径/文件id+文件扩展名
|
||||
var path = Path.Combine($"{PathConst.wwwroot}/{file.FilePath}", file.Id.ToString() + Path.GetExtension(file.FileName));
|
||||
var stream = System.IO.File.OpenRead(path);
|
||||
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(file.FileName);
|
||||
return File(stream, MimeType, file.FileName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 多文件上传,type可空,默认上传至File文件夹下,swagger返回雪花id精度是有问题的,同时如果时图片类型,还需要进行缩略图制作
|
||||
/// </summary>
|
||||
/// <param name="type">文件类型,可空</param>
|
||||
/// <param name="file">多文件表单</param>
|
||||
/// <param name="remark">描述</param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/file/Upload/{type?}")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Upload([FromRoute] string? type, [FromForm] IFormFileCollection file, [FromQuery] string? remark)
|
||||
{
|
||||
type = type ?? PathEnum.File.ToString();
|
||||
|
||||
type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type.ToLower());
|
||||
if (!Enum.IsDefined(typeof(PathEnum), type))
|
||||
{
|
||||
//后续类型可从字典表中获取
|
||||
return Result.Error("上传失败!文件类型不支持!");
|
||||
}
|
||||
|
||||
|
||||
if (file.Count() == 0)
|
||||
{
|
||||
return Result.Error("未选择文件");
|
||||
}
|
||||
//批量插入
|
||||
List<FileEntity> datas = new();
|
||||
|
||||
//返回的codes
|
||||
List<long> codes = new();
|
||||
try
|
||||
{
|
||||
foreach (var f in file)
|
||||
{
|
||||
FileEntity data = new();
|
||||
data.Id = SnowFlakeSingle.Instance.NextId();
|
||||
data.FileSize = ((decimal)f.Length) / 1024;
|
||||
data.FileName = f.FileName;
|
||||
data.FileType = Common.Helper.MimeHelper.GetMimeMapping(f.FileName);
|
||||
data.FilePath = type;
|
||||
data.Remark = remark;
|
||||
data.IsDeleted = false;
|
||||
|
||||
//落盘文件,文件名为雪花id+自己的扩展名
|
||||
string filename = data.Id.ToString() + Path.GetExtension(f.FileName);
|
||||
string typePath = $"{PathConst.wwwroot}/{type}";
|
||||
if (!Directory.Exists(typePath))
|
||||
{
|
||||
Directory.CreateDirectory(typePath);
|
||||
}
|
||||
|
||||
//生成文件
|
||||
using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
{
|
||||
await f.CopyToAsync(stream);
|
||||
|
||||
//如果是图片类型,还需要生成缩略图,当然,如果图片很小,直接复制过去即可
|
||||
if (PathEnum.Image.ToString().Equals(type))
|
||||
{
|
||||
string thumbnailPath = $"{PathConst.wwwroot}/{PathEnum.Thumbnail}";
|
||||
if (!Directory.Exists(thumbnailPath))
|
||||
{
|
||||
Directory.CreateDirectory(thumbnailPath);
|
||||
}
|
||||
//保存至缩略图路径
|
||||
byte[] result=null!;
|
||||
try
|
||||
{
|
||||
result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
|
||||
imageStream: stream,
|
||||
imageFormat: Format.Jpeg);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = new byte[stream.Length];
|
||||
stream.Read(result, 0, result.Length);
|
||||
// 设置当前流的位置为流的开始
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
//将文件信息添加到数据库
|
||||
datas.Add(data);
|
||||
codes.Add(data.Id);
|
||||
}
|
||||
return Result.Success().SetData(codes).SetStatus(await _iFileService._repository.InsertRangeAsync(datas));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Result.Error();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 一键同步图片到缩略图
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> ThumbnailSync()
|
||||
{
|
||||
string typePath = $"{PathConst.wwwroot}/{PathEnum.Image}";
|
||||
string thumbnailPath = $"{PathConst.wwwroot}/{PathEnum.Thumbnail}";
|
||||
List<string> fileNames = FileHelper.GetAllFileNames(typePath);
|
||||
foreach (var filename in fileNames)
|
||||
{
|
||||
if (System.IO.File.Exists(Path.Combine(thumbnailPath, filename)))
|
||||
{
|
||||
//如果缩略图存在,直接跳过
|
||||
continue;
|
||||
}
|
||||
if (!Directory.Exists(typePath))
|
||||
{
|
||||
Directory.CreateDirectory(typePath);
|
||||
}
|
||||
|
||||
|
||||
using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
byte[] result=null!;
|
||||
try
|
||||
{
|
||||
|
||||
//保存至缩略图路径
|
||||
result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
|
||||
imageStream: stream,
|
||||
imageFormat: Format.Jpeg);
|
||||
|
||||
if (!Directory.Exists(thumbnailPath))
|
||||
{
|
||||
Directory.CreateDirectory(thumbnailPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = new byte[stream.Length];
|
||||
stream.Read(result, 0, result.Length);
|
||||
// 设置当前流的位置为流的开始
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
////如果当前文件同步失败,就跳转到下一个
|
||||
}
|
||||
finally {
|
||||
|
||||
await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class LogController : ControllerBase
|
||||
{
|
||||
private ILogService _iLogService;
|
||||
//大量日志,将采用自动分表形式,默认1年分一次表
|
||||
public LogController(ILogger<LogEntity> logger, ILogService iLogService)
|
||||
{
|
||||
_iLogService = iLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动分表,日志添加
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Add()
|
||||
{
|
||||
Random random = new Random();
|
||||
var logList = new List<LogEntity>() {
|
||||
new LogEntity() { CreateTime = Convert.ToDateTime("2019-12-1"), Message = "jack"+random.Next() } ,
|
||||
new LogEntity() { CreateTime = Convert.ToDateTime("2022-02-1"), Message = "jack"+random.Next() },
|
||||
new LogEntity() { CreateTime = Convert.ToDateTime("2020-02-1"), Message = "jack"+random.Next() },
|
||||
new LogEntity() { CreateTime = Convert.ToDateTime("2021-12-1"), Message = "jack"+random.Next() } };
|
||||
return Result.Success().SetData(await _iLogService.AddListTest(logList));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询近20年与21年的日志表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _iLogService.GetListTest());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class LoginLogController : BaseSimpleCrudController<LoginLogEntity>
|
||||
{
|
||||
private ILoginLogService _iLoginLogService;
|
||||
public LoginLogController(ILogger<LoginLogEntity> logger, ILoginLogService iLoginLogService) : base(logger, iLoginLogService)
|
||||
{
|
||||
_iLoginLogService = iLoginLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="loginLog"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] LoginLogEntity loginLog, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iLoginLogService.SelctPageList(loginLog, page));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class MenuController: BaseSimpleRdController<MenuEntity>
|
||||
{
|
||||
private IMenuService _iMenuService;
|
||||
public MenuController(ILogger<MenuEntity> logger, IMenuService iMenuService):base(logger,iMenuService)
|
||||
{
|
||||
_iMenuService = iMenuService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件查询全部
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> SelctGetList([FromQuery] MenuEntity menu)
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService.SelctGetList(menu));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(MenuEntity menu)
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService._repository.InsertReturnSnowflakeIdAsync(menu));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(MenuEntity menu)
|
||||
{
|
||||
//注意,这里如果是主目录,还需要判断/,需要以/开头
|
||||
return Result.Success().SetData(await _iMenuService._repository.UpdateIgnoreNullAsync(menu));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到树形菜单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetMenuTree()
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService.GetMenuTreeAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色id获取该角色下全部菜单
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result> GetListByRoleId(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService.GetListByRoleId(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using Hei.Captcha;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
using Yi.Framework.WebCore.SignalRHub;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 在线管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class OnlineController : ControllerBase
|
||||
{
|
||||
private ILogger<OnlineController> _logger;
|
||||
private IHubContext<MainHub> _hub;
|
||||
public OnlineController(ILogger<OnlineController> logger, IHubContext<MainHub> hub)
|
||||
{
|
||||
_logger = logger;
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件获取当前在线用户
|
||||
/// </summary>
|
||||
/// <param name="online"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Result PageList([FromQuery] OnlineUser online, [FromQuery] PageParModel page)
|
||||
{
|
||||
var data = MainHub.clientUsers;
|
||||
IEnumerable<OnlineUser> dataWhere = data.AsEnumerable();
|
||||
|
||||
if (!string.IsNullOrEmpty(online.Ipaddr))
|
||||
{
|
||||
dataWhere = dataWhere.Where((u) => u.Ipaddr.Contains(online.Ipaddr));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(online.UserName))
|
||||
{
|
||||
dataWhere = dataWhere.Where((u) => u.UserName.Contains(online.UserName));
|
||||
}
|
||||
return Result.Success().SetData(new PageModel<List<OnlineUser>>() { Total = data.Count, Data = dataWhere.ToList() });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 强制退出用户
|
||||
/// </summary>
|
||||
/// <param name="connnectionId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("{connnectionId}")]
|
||||
public async Task<Result> ForceOut(string connnectionId)
|
||||
{
|
||||
if (MainHub.clientUsers.Exists(u => u.ConnnectionId == connnectionId))
|
||||
{
|
||||
//前端接受到这个事件后,触发前端自动退出
|
||||
await _hub.Clients.Client(connnectionId).SendAsync(HubTypeEnum.forceOut.ToString(),"你已被强制退出!");
|
||||
return Result.Success();
|
||||
}
|
||||
return Result.Error("操作失败!未发现该连接!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class OperationLogController : BaseSimpleCrudController<OperationLogEntity>
|
||||
{
|
||||
private IOperationLogService _iOperationLogService;
|
||||
public OperationLogController(ILogger<OperationLogEntity> logger, IOperationLogService iOperationLogService) : base(logger, iOperationLogService)
|
||||
{
|
||||
_iOperationLogService = iOperationLogService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="operationLog"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] OperationLogEntity operationLog, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iOperationLogService.SelctPageList(operationLog, page));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class PostController : BaseSimpleCrudController<PostEntity>
|
||||
{
|
||||
private IPostService _iPostService;
|
||||
public PostController(ILogger<PostEntity> logger, IPostService iPostService) : base(logger, iPostService)
|
||||
{
|
||||
_iPostService = iPostService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="post"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] PostEntity post, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iPostService.SelctPageList(post, page));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override async Task<Result> Add(PostEntity entity)
|
||||
{
|
||||
return await base.Add(entity);
|
||||
}
|
||||
|
||||
public override async Task<Result> Update(PostEntity entity)
|
||||
{
|
||||
return await base.Update(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class RoleController : BaseSimpleRdController<RoleEntity>
|
||||
{
|
||||
private IRoleService _iRoleService;
|
||||
public RoleController(ILogger<RoleEntity> logger, IRoleService iRoleService) : base(logger, iRoleService)
|
||||
{
|
||||
_iRoleService = iRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> PageList([FromQuery] RoleEntity role, [FromQuery] PageParModel page)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.SelctPageList(role, page));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 给多用户设置多角色
|
||||
/// </summary>
|
||||
/// <param name="giveRoleSetMenuDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> GiveRoleSetMenu(GiveRoleSetMenuDto giveRoleSetMenuDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色包含菜单
|
||||
/// </summary>
|
||||
/// <param name="roleDto"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.AddInfo(roleDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.UpdateInfo(roleDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改角色状态
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="isDel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateStatus(long roleId, bool isDel)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService._repository.UpdateIgnoreNullAsync(new RoleEntity() { Id = roleId, IsDeleted = isDel }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///更改角色数据权限
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateDataScpoce(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.UpdateDataScpoce(roleDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Attribute;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class UserController : BaseSimpleRdController<UserEntity>
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
|
||||
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="deptId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Permission("system:user:query")]
|
||||
public async Task<Result> PageList([FromQuery] UserEntity user, [FromQuery] PageParModel page, [FromQuery] long? deptId)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.SelctPageList(user, page, deptId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改用户状态
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="isDel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission("system:user:edit")]
|
||||
[Log("用户模块", OperEnum.Update)]
|
||||
public async Task<Result> UpdateStatus(long userId, bool isDel)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.UpdateIgnoreNullAsync(new UserEntity() { Id = userId, IsDeleted = isDel }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给多用户设置多角色
|
||||
/// </summary>
|
||||
/// <param name="giveUserSetRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission("system:user:edit")]
|
||||
[Log("用户模块", OperEnum.Update)]
|
||||
public async Task<Result> GiveUserSetRole(GiveUserSetRoleDto giveUserSetRoleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.GiveUserSetRole(giveUserSetRoleDto.UserIds, giveUserSetRoleDto.RoleIds));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到用户信息关联部门、岗位、角色
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
[Permission("system:user:query")]
|
||||
public override async Task<Result> GetById([FromRoute] long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetInfoById(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission("system:user:edit")]
|
||||
[Log("用户模块", OperEnum.Update)]
|
||||
public async Task<Result> Update(UserInfoDto userDto)
|
||||
{
|
||||
if (await _repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id)))
|
||||
{
|
||||
return Result.Error("用户名已存在,修改失败!");
|
||||
}
|
||||
return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新个人中心信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission("system:user:edit")]
|
||||
[Log("用户模块", OperEnum.Update)]
|
||||
public async Task<Result> UpdateProfile(UserInfoDto userDto)
|
||||
{
|
||||
//修改需要赋值上主键哦
|
||||
userDto.User.Id = HttpContext.GetUserIdInfo();
|
||||
return Result.Success().SetStatus(await _iUserService.UpdateProfile(userDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Permission("system:user:add")]
|
||||
[Log("用户模块", OperEnum.Insert)]
|
||||
public async Task<Result> Add(UserInfoDto userDto)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userDto.User.Password))
|
||||
{
|
||||
return Result.Error("密码为空,添加失败!");
|
||||
}
|
||||
if (await _repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName)))
|
||||
{
|
||||
return Result.Error("用户已经存在,添加失败!");
|
||||
}
|
||||
|
||||
return Result.Success().SetStatus(await _iUserService.AddInfo(userDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission("system:user:edit")]
|
||||
[Log("用户模块", OperEnum.Update)]
|
||||
public async Task<Result> RestPassword(UserEntity user)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.RestPassword(user.Id, user.Password));
|
||||
}
|
||||
[Permission("system:user:query")]
|
||||
public override Task<Result> GetList()
|
||||
{
|
||||
return base.GetList();
|
||||
}
|
||||
[Permission("system:user:remove")]
|
||||
[Log("用户模块", OperEnum.Delete)]
|
||||
public override Task<Result> DelList(List<long> ids)
|
||||
{
|
||||
return base.DelList(ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user