重构代码
重构代码
This commit is contained in:
@@ -1,228 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Common.QueueModel;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
using Yi.Framework.WebCore.Mapper;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private readonly ILogger<UserController> _logger;
|
||||
|
||||
private IUserService _userService;
|
||||
private IMenuService _menuService;
|
||||
private RabbitMQInvoker _rabbitMQInvoker;
|
||||
private CacheClientDB _cacheClientDB;
|
||||
private IRoleService _roleService;
|
||||
private IHttpContextAccessor _httpContext;
|
||||
public AccountController(ILogger<UserController> logger, IUserService userService, IMenuService menuService, RabbitMQInvoker rabbitMQInvoker, CacheClientDB cacheClientDB, IRoleService roleService, IHttpContextAccessor httpContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
_menuService = menuService;
|
||||
_rabbitMQInvoker = rabbitMQInvoker;
|
||||
_cacheClientDB = cacheClientDB;
|
||||
_roleService = roleService;
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录方法,要返回data:{user,token} token
|
||||
/// </summary>
|
||||
/// <param name="login"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Login(loginDto login)
|
||||
{
|
||||
var _user = MapperHelper.Map<user, loginDto>(login);
|
||||
var user_data = await _userService.Login(_user);
|
||||
if (user_data == null)
|
||||
{
|
||||
return Result.Error("该用户不存在");
|
||||
}
|
||||
var menuList = await _menuService.GetTopMenuByUserId(user_data.id);
|
||||
if (user_data != null)
|
||||
{
|
||||
var token = MakeJwt.app(new jwtUser() { user = user_data, menuIds = menuList });
|
||||
JobModel.visitNum += 1;
|
||||
//同时要将api路径放置到redis中
|
||||
var menuDto = MapperHelper.MapList<menuDto,menu>(menuList);
|
||||
_userService.SaveUserApi(user_data.id, menuDto);
|
||||
return Result.Success().SetData(new { user = new { user_data.id, user_data.username, user_data.introduction, user_data.icon, user_data.nick }, token });
|
||||
}
|
||||
return Result.Error();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不用写,单纯制作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
public Result Logout()
|
||||
{
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// code为验证码,从redis中判断一下code是否正确
|
||||
/// </summary>
|
||||
/// <param name="_user"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Register(user _user, string code)
|
||||
{
|
||||
_user.username = _user.username.Trim();
|
||||
if (string.IsNullOrEmpty(_user.username))
|
||||
code = code.Trim();
|
||||
|
||||
string trueCode = _cacheClientDB.Get<string>(RedisConst.keyCode + _user.phone);
|
||||
if (code == trueCode)
|
||||
{
|
||||
//设置默认头像
|
||||
var setting = JsonHelper.StrToObj<SettingDto>(_cacheClientDB.Get<string>(RedisConst.key));
|
||||
_user.icon = setting.InitIcon;
|
||||
_user.ip = _httpContext.HttpContext?.Request.Headers["X-Real-IP"].FirstOrDefault();//通过上下文获取ip
|
||||
//设置默认角色
|
||||
if (string.IsNullOrEmpty(setting.InitRole))
|
||||
{
|
||||
return Result.Error("无默认角色,请初始化数据库");
|
||||
}
|
||||
_user.roles = new List<role>();
|
||||
_user.roles.Add(await _roleService.GetEntity(u => u.role_name == setting.InitRole));
|
||||
await _userService.Register(_user);
|
||||
|
||||
return Result.Success("恭喜,你已加入我们!");
|
||||
}
|
||||
return Result.Error("验证码有误,请重新输入!");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送短信,需要将生成的sms+code存入redis
|
||||
/// </summary>
|
||||
/// <param name="SMSAddress"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> SendSMS(string SMSAddress)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SMSAddress))
|
||||
{
|
||||
return Result.Error("请输入电话号码");
|
||||
}
|
||||
SMSAddress = SMSAddress.Trim();
|
||||
if (!await _userService.PhoneIsExsit(SMSAddress))
|
||||
{
|
||||
SMSQueueModel sMSQueueModel = new SMSQueueModel();
|
||||
sMSQueueModel.phone = SMSAddress;
|
||||
sMSQueueModel.code = RandomHelper.GenerateCheckCodeNum(6);
|
||||
|
||||
//10分钟过期
|
||||
_cacheClientDB.Set(RedisConst.keyCode + sMSQueueModel.phone, sMSQueueModel.code, TimeSpan.FromMinutes(10));
|
||||
|
||||
_rabbitMQInvoker.Send(new Common.IOCOptions.RabbitMQConsumerModel() { ExchangeName = RabbitConst.SMS_Exchange, QueueName = RabbitConst.SMS_Queue_Send }, JsonHelper.ObjToStr(sMSQueueModel));
|
||||
return Result.Success("发送短信成功,10分钟后过期,请留意短信接收");
|
||||
}
|
||||
return Result.Error("该号码已被注册");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮箱,需要先到数据库判断该邮箱是否被人注册过,到userservice写mail_exist方法,还有接口别忘了。
|
||||
/// </summary>
|
||||
/// <param name="emailAddress"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]//邮箱验证
|
||||
public async Task<Result> Email(string emailAddress)
|
||||
{
|
||||
emailAddress = emailAddress.Trim().ToLower();
|
||||
//先判断邮箱是否被注册使用过,如果被使用过,便不让操作
|
||||
if (!await _userService.EmailIsExsit(emailAddress))
|
||||
{
|
||||
string code = RandomHelper.GenerateRandomLetter(6);
|
||||
code = code.ToUpper();//全部转为大写
|
||||
EmailHelper.sendMail(code, emailAddress);
|
||||
|
||||
//我要把邮箱和对应的code加进到数据库,还有申请时间
|
||||
//设置10分钟过期
|
||||
//set不存在便添加,如果存在便替换
|
||||
//CacheHelper.SetCache<string>(emailAddress, code, TimeSpan.FromSeconds(10));
|
||||
|
||||
return Result.Success("发送邮件成功,请查看邮箱(可能在垃圾箱)");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Result.Error("该邮箱已被注册");
|
||||
}
|
||||
// 邮箱和验证码都要被记住,然后注册时候比对邮箱和验证码是不是都和现在生成的一样
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
/// <param name="pwdDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Authorize]
|
||||
public async Task<Result> ChangePassword(ChangePwdDto pwdDto)
|
||||
{
|
||||
var user_data = await _userService.GetUserById(pwdDto.user.id);
|
||||
string msg = "修改成功";
|
||||
if (!string.IsNullOrEmpty(pwdDto.newPassword))
|
||||
{
|
||||
if (user_data.password == pwdDto.user.password)
|
||||
{
|
||||
|
||||
user_data.password = pwdDto.newPassword;
|
||||
user_data.phone = pwdDto.user.phone;
|
||||
user_data.introduction = pwdDto.user.introduction;
|
||||
user_data.email = pwdDto.user.email;
|
||||
user_data.age = pwdDto.user.age;
|
||||
user_data.address = pwdDto.user.address;
|
||||
user_data.nick = pwdDto.user.nick;
|
||||
|
||||
|
||||
await _userService.UpdateAsync(user_data);
|
||||
user_data.password = null;
|
||||
return Result.Success(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "密码错误";
|
||||
return Result.Error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
user_data.phone = pwdDto.user.phone;
|
||||
user_data.introduction = pwdDto.user.introduction;
|
||||
user_data.email = pwdDto.user.email;
|
||||
user_data.age = pwdDto.user.age;
|
||||
user_data.address = pwdDto.user.address;
|
||||
user_data.nick = pwdDto.user.nick;
|
||||
|
||||
await _userService.UpdateAsync(user_data);
|
||||
|
||||
|
||||
return Result.Success(msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
private IUserService _userService;
|
||||
private readonly IHostEnvironment _env;
|
||||
public FileController(IUserService userService, IHostEnvironment env)
|
||||
{
|
||||
_userService = userService;
|
||||
_env = env;
|
||||
}
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<Result> EditIcon(IFormFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
var _user = HttpContext.GetCurrentUserInfo();
|
||||
var user_data = await _userService.GetUserById(_user.id);
|
||||
var type = "image";
|
||||
var filename = await Upload(type, file);
|
||||
user_data.icon = filename;
|
||||
await _userService.UpdateAsync(user_data);
|
||||
return Result.Success();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Result.Error();
|
||||
}
|
||||
}
|
||||
|
||||
[Route("/api/{type}/{fileName}")]
|
||||
[HttpGet]
|
||||
public IActionResult Get(string type, string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Path.Combine($"wwwroot/{type}", fileName);
|
||||
var stream = System.IO.File.OpenRead(path);
|
||||
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(fileName);
|
||||
return new FileStreamResult(stream, MimeType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该方法不对外暴露
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> Upload(string type, IFormFile file)
|
||||
{
|
||||
string filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
|
||||
using (var stream = new FileStream(Path.Combine($"wwwroot/{type}", filename), FileMode.CreateNew, FileAccess.Write))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ExportFile()
|
||||
{
|
||||
var userdata = await _userService.GetAllEntitiesTrueAsync();
|
||||
var userList = userdata.ToList();
|
||||
List<string> header = new() { "用户", "密码", "头像", "昵称", "邮箱", "ip", "年龄", "个人介绍", "地址", "手机", "角色" };
|
||||
var filename = Common.Helper.ExcelHelper.CreateExcelFromList(userList, header, _env.ContentRootPath.ToString());
|
||||
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(filename);
|
||||
return new FileStreamResult(new FileStream(Path.Combine(_env.ContentRootPath+@"/wwwroot/Excel", filename), FileMode.Open),MimeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
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;
|
||||
using Yi.Framework.Common.Const;
|
||||
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;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class JobController : Controller
|
||||
{
|
||||
private readonly ILogger<JobController> _logger;
|
||||
private QuartzInvoker _quartzInvoker;
|
||||
public JobController(ILogger<JobController> logger,QuartzInvoker quartzInvoker)
|
||||
{
|
||||
_logger = logger;
|
||||
_quartzInvoker = quartzInvoker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> startJob()
|
||||
{
|
||||
//任务1
|
||||
//await _quartzInvoker.start("*/1 * * * * ? ", new Quartz.JobKey("test", "my"), "VisitJob");
|
||||
|
||||
//任务2
|
||||
Dictionary<string, object> data = new Dictionary<string, object>()
|
||||
{
|
||||
{JobConst.method,"get" },
|
||||
{JobConst.url,"https://www.baidu.com" }
|
||||
};
|
||||
await _quartzInvoker.start("*/5 * * * * ?", new Quartz.JobKey("test", "my"), "Yi.Framework.Job", "HttpJob",data: data);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> getRunJobList()
|
||||
{
|
||||
return Result.Success().SetData(await _quartzInvoker.getRunJobList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Result getJobClass()
|
||||
{
|
||||
return Result.Success().SetData(_quartzInvoker.getJobClassList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> stopJob()
|
||||
{
|
||||
await _quartzInvoker.Stop(new Quartz.JobKey("test", "my"));
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<Result> DeleteJob()
|
||||
{
|
||||
await _quartzInvoker.Delete(new Quartz.JobKey("test", "my"));
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> ResumeJob()
|
||||
{
|
||||
await _quartzInvoker.Resume(new Quartz.JobKey("test", "my"));
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
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.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MenuController : ControllerBase
|
||||
{
|
||||
private IMenuService _menuService;
|
||||
private IUserService _userService;
|
||||
public MenuController(IMenuService menuService,IUserService userService)
|
||||
{
|
||||
_menuService = menuService;
|
||||
_userService = userService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetMenuInMould()
|
||||
{
|
||||
return Result.Success().SetData(await _menuService.GetMenuInMould());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更
|
||||
/// </summary>
|
||||
/// <param name="_menu"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateMenu(menu _menu)
|
||||
{
|
||||
await _menuService.UpdateAsync(_menu);
|
||||
return Result.Success();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// </summary>
|
||||
/// <param name="_ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<Result> DelListMenu(List<int> _ids)
|
||||
{
|
||||
await _menuService.DelListByUpdateAsync(_ids);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// 现在,top菜单只允许为一个
|
||||
/// </summary>
|
||||
/// <param name="_menu"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddTopMenu(menu _menu)
|
||||
{
|
||||
await _menuService.AddTopMenu(_menu);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给一个菜单设置一个接口,Id1为菜单id,Id2为接口id
|
||||
/// 用于给菜单设置接口
|
||||
/// </summary>
|
||||
/// <param name="idDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> SetMouldByMenu(IdDto<int> idDto)
|
||||
{
|
||||
await _menuService.SetMouldByMenu(idDto.id1, idDto.id2);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 给一个菜单添加子节点(注意:添加,不是覆盖)
|
||||
/// </summary>
|
||||
/// <param name="childrenDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddChildrenMenu(ChildrenDto<menu> childrenDto)
|
||||
{
|
||||
await _menuService.AddChildrenMenu(childrenDto.parentId, childrenDto.data);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户的目录菜单,不包含接口
|
||||
/// 用于账户信息页面,显示这个用户有哪些菜单,需要并列
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetTopMenusByHttpUser()
|
||||
{
|
||||
var menuIds = _userService.GetCurrentMenuInfo(HttpContext.GetCurrentUserInfo().id);
|
||||
return Result.Success().SetData(await _menuService.GetTopMenusByTopMenuIds(menuIds));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
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;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MouldController : ControllerBase
|
||||
{
|
||||
private IMouldService _mouldService;
|
||||
public MouldController(IMouldService mouldService)
|
||||
{
|
||||
_mouldService = mouldService;
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<Result> GetMould()
|
||||
{
|
||||
return Result.Success().SetData(await _mouldService.GetAllEntitiesTrueAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更
|
||||
/// </summary>
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateMould(mould _mould)
|
||||
{
|
||||
await _mouldService.UpdateAsync(_mould);
|
||||
return Result.Success();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// </summary>
|
||||
/// <param name="_ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<Result> DelListMould(List<int> _ids)
|
||||
{
|
||||
await _mouldService.DelListByUpdateAsync(_ids);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddMould(mould _mould)
|
||||
{
|
||||
await _mouldService.AddAsync(_mould);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class RoleController : ControllerBase
|
||||
{
|
||||
private IRoleService _roleService;
|
||||
public RoleController(IRoleService roleService)
|
||||
{
|
||||
_roleService = roleService;
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<Result> GetRole()
|
||||
{
|
||||
return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更
|
||||
/// </summary>
|
||||
/// <param name="_role"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateRole(role _role)
|
||||
{
|
||||
await _roleService.UpdateAsync(_role);
|
||||
return Result.Success();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// </summary>
|
||||
/// <param name="_ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<Result> DelListRole(List<int> _ids)
|
||||
{
|
||||
await _roleService.DelListByUpdateAsync(_ids);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
/// <param name="_role"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddRole(role _role)
|
||||
{
|
||||
await _roleService.AddAsync(_role);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户id得到该用户有哪些角色
|
||||
/// 用于显示用户详情中的角色说明
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetRolesByUserId(int userId)
|
||||
{
|
||||
|
||||
return Result.Success().SetData(await _roleService.GetRolesByUserId(userId));
|
||||
}
|
||||
/// <summary>
|
||||
/// 给角色设置菜单,多个角色与多个菜单,让每一个角色都设置,ids1为角色,ids2为菜单
|
||||
/// 用于设置角色
|
||||
/// </summary>
|
||||
/// <param name="idsListDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> SetMenuByRole(IdsListDto<int> idsListDto)
|
||||
{
|
||||
await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1);
|
||||
return Result.Success();
|
||||
}
|
||||
/// <summary>
|
||||
/// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetTopMenusByRoleId(int roleId)
|
||||
{
|
||||
|
||||
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
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.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[Authorize]
|
||||
public class SettingController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<SettingController> _logger;
|
||||
private readonly CacheClientDB _cacheClientDB;
|
||||
|
||||
public SettingController(ILogger<SettingController> logger, CacheClientDB cacheClientDB)
|
||||
{
|
||||
_logger = logger;
|
||||
_cacheClientDB = cacheClientDB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Result GetSetting()
|
||||
{
|
||||
var setDto = Common.Helper.JsonHelper.StrToObj<SettingDto>(_cacheClientDB.Get<string>(RedisConst.key));
|
||||
return Result.Success().SetData( setDto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更
|
||||
/// </summary>
|
||||
/// <param name="settingDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public Result UpdateSetting(SettingDto settingDto)
|
||||
{
|
||||
var setDto = Common.Helper.JsonHelper.ObjToStr(settingDto);
|
||||
|
||||
_cacheClientDB.Set(RedisConst.key, setDto);
|
||||
return Result.Success();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ 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.WebCore;
|
||||
@@ -21,133 +20,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
private readonly ILogger<UserController> _logger;
|
||||
|
||||
private IUserService _userService;
|
||||
public UserController(ILogger<UserController> logger, IUserService userService)
|
||||
private IUserService _iUserService;
|
||||
public UserController(ILogger<UserController> logger, IUserService iUserService)
|
||||
{
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
_iUserService = iUserService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[Authorize(PolicyName.Menu)]
|
||||
[HttpGet]
|
||||
public async Task<Result> GetUser()
|
||||
public async Task<Result> Get()
|
||||
{
|
||||
return Result.Success().SetData(await _userService.GetAllEntitiesTrueAsync());
|
||||
return Result.Success().SetData(await _iUserService.GetListAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更
|
||||
/// </summary>
|
||||
/// <param name="_user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Authorize(PolicyName.Menu)]
|
||||
public async Task<Result> UpdateUser(user _user)
|
||||
{
|
||||
await _userService.UpdateAsync(_user);
|
||||
return Result.Success();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// </summary>
|
||||
/// <param name="_ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Authorize(PolicyName.Menu)]
|
||||
public async Task<Result> DelListUser(List<int> _ids)
|
||||
{
|
||||
await _userService.DelListByUpdateAsync(_ids);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
/// <param name="_user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize(PolicyName.Menu)]
|
||||
public async Task<Result> AddUser(user _user)
|
||||
{
|
||||
await _userService.AddAsync(_user);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// SetRoleByUser
|
||||
/// 给多个用户设置多个角色,ids有用户id与 角色列表ids,多对多,ids1用户,ids2为角色
|
||||
/// 用户设置给用户设置角色
|
||||
/// </summary>
|
||||
/// <param name="idsListDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> SetRoleByUser(IdsListDto<int> idsListDto)
|
||||
{
|
||||
await _userService.SetRoleByUser(idsListDto.ids2, idsListDto.ids1);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据http上下文的用户得到该用户信息,关联角色
|
||||
/// 用于显示账号信息页中的用户信息和角色信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetUserInRolesByHttpUser()
|
||||
{
|
||||
var _user = HttpContext.GetCurrentUserInfo();
|
||||
return Result.Success().SetData( await _userService.GetUserInRolesByHttpUser(_user.id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到登录用户的递归菜单,放到导航栏
|
||||
/// 用户放到导航栏中
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetMenuByHttpUser()
|
||||
{
|
||||
var allMenuIds= _userService.GetCurrentMenuInfo(HttpContext.GetCurrentUserInfo().id);
|
||||
return Result.Success().SetData(await _userService.GetMenuByHttpUser(allMenuIds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到请求模型
|
||||
/// </summary>
|
||||
/// <param name="router"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetAxiosByRouter(string router)
|
||||
{
|
||||
var _user = HttpContext.GetCurrentUserInfo();
|
||||
var menuIds = _userService.GetCurrentMenuInfo(_user.id);
|
||||
if (menuIds == null)
|
||||
{
|
||||
return Result.Error();
|
||||
}
|
||||
var menuList= await _userService.GetAxiosByRouter(router, menuIds);
|
||||
AxiosUrlsModel urlsModel = new();
|
||||
menuList.ForEach(u =>
|
||||
{
|
||||
switch (u.menu_name)
|
||||
{
|
||||
case "get":urlsModel.get = u.mould.url;break;
|
||||
case "del": urlsModel.del = u.mould.url; break;
|
||||
case "add": urlsModel.add = u.mould.url; break;
|
||||
case "update": urlsModel.update = u.mould.url; break;
|
||||
}
|
||||
});
|
||||
|
||||
return Result.Success().SetData(urlsModel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user