From 14529793198ea4c8ff1dcb62dce4c9a3a515e267 Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Wed, 13 Oct 2021 23:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 15 ++++- .../Controllers/MenuController.cs | 65 +++++++++++++++++++ .../Controllers/MouldController.cs | 65 +++++++++++++++++++ .../Controllers/RoleController.cs | 65 +++++++++++++++++++ .../Controllers/UserController.cs | 4 +- .../Yi.Framework.Interface/IMenuService.cs | 6 -- .../Yi.Framework.Interface/IRoleService.cs | 6 -- .../Yi.Framework.Interface/IUserService.cs | 1 + .../Yi.Framework.Service/MenuService.cs | 10 --- .../Yi.Framework.Service/MouldService.cs | 7 +- .../Yi.Framework.Service/RoleService.cs | 12 +--- .../Yi.Framework.Service/UserService.cs | 11 ++++ 12 files changed, 227 insertions(+), 40 deletions(-) create mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs create mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs create mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index 78a8d044..4dcba658 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -33,6 +33,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task Login(user _user) { + if( await _userService.Login(_user)) + { + return Result.Success().SetData(new { _user, token = 123456789 }); + } + return Result.Error(); } /// @@ -53,8 +58,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [HttpPost] public async Task Register(user _user, string code) - { - + { + if (code!=null) + { + await _userService.Register(_user); + } + return Result.Error(); } /// @@ -67,7 +76,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers { emailAddress = emailAddress.Trim().ToLower(); //先判断邮箱是否被注册使用过,如果被使用过,便不让操作 - if (!await _userService.mail_exist(emailAddress)) + if (!await _userService.EmailIsExsit(emailAddress)) { string code = RandomHelper.GenerateRandomLetter(6); code = code.ToUpper();//全部转为大写 diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs new file mode 100644 index 00000000..bd7a3695 --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -0,0 +1,65 @@ +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]")] + [ApiController] + public class MenuController : ControllerBase + { + private IMenuService _menuService; + public MenuController(IMenuService menuService) + { + _menuService = menuService; + } + [HttpGet] + public async Task GetMenu() + { + return Result.Success().SetData(await _menuService.GetAllEntitiesTrueAsync()); + } + + /// + /// 更 + /// + /// + /// + [HttpPut] + public async Task UpdateMenu(menu _menu) + { + await _menuService.UpdateAsync(_menu); + return Result.Success(); + + } + + /// + /// 删 + /// + /// + /// + [HttpDelete] + public async Task DelListMenu(List _ids) + { + await _menuService.DelListByUpdateAsync(_ids); + return Result.Success(); + } + + /// + /// 增 + /// + /// + /// + [HttpPost] + public async Task AddMenu(menu _menu) + { + await _menuService.AddAsync(_menu); + return Result.Success(); + } + } +} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs new file mode 100644 index 00000000..57b9af6f --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MouldController.cs @@ -0,0 +1,65 @@ +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]")] + [ApiController] + public class MouldController : ControllerBase + { + private IMouldService _mouldService; + public MouldController(IMouldService mouldService) + { + _mouldService = mouldService; + } + [HttpGet] + public async Task GetMould() + { + return Result.Success().SetData(await _mouldService.GetAllEntitiesTrueAsync()); + } + + /// + /// 更 + /// + /// + /// + [HttpPut] + public async Task UpdateMould(mould _mould) + { + await _mouldService.UpdateAsync(_mould); + return Result.Success(); + + } + + /// + /// 删 + /// + /// + /// + [HttpDelete] + public async Task DelListMould(List _ids) + { + await _mouldService.DelListByUpdateAsync(_ids); + return Result.Success(); + } + + /// + /// 增 + /// + /// + /// + [HttpPost] + public async Task AddMould(mould _mould) + { + await _mouldService.AddAsync(_mould); + return Result.Success(); + } + } +} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs new file mode 100644 index 00000000..94571487 --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -0,0 +1,65 @@ +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]")] + [ApiController] + public class RoleController : ControllerBase + { + private IRoleService _roleService; + public RoleController(IRoleService roleService) + { + _roleService = roleService; + } + [HttpGet] + public async Task GetURole() + { + return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync()); + } + + /// + /// 更 + /// + /// + /// + [HttpPut] + public async Task UpdateRole(role _role) + { + await _roleService.UpdateAsync(_role); + return Result.Success(); + + } + + /// + /// 删 + /// + /// + /// + [HttpDelete] + public async Task DelListRole(List _ids) + { + await _roleService.DelListByUpdateAsync(_ids); + return Result.Success(); + } + + /// + /// 增 + /// + /// + /// + [HttpPost] + public async Task AddRole(role _role) + { + await _roleService.AddAsync(_role); + return Result.Success(); + } + } +} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index fd7ce24b..3472ddd1 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -78,7 +78,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task GetMenuMould() { - var _user= this.HttpContext.GetCurrentUserInfo(); + var _user= this.HttpContext.GetCurrentUserInfo(); + var menu_data = await _userService.GetMenusByUser(_user); + return Result.Success().SetData(menu_data); } } } diff --git a/Yi.Framework/Yi.Framework.Interface/IMenuService.cs b/Yi.Framework/Yi.Framework.Interface/IMenuService.cs index cc13c920..a39e9b6e 100644 --- a/Yi.Framework/Yi.Framework.Interface/IMenuService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IMenuService.cs @@ -41,12 +41,6 @@ namespace Yi.Framework.Interface /// Task SetMouldByMenu(int mouldId,int menuId); /// - /// 添加菜单 - /// - /// - /// - Task AddMenu(menu _menu); - /// /// 添加子菜单 /// /// diff --git a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs index 943ae5c5..6d9a47a7 100644 --- a/Yi.Framework/Yi.Framework.Interface/IRoleService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IRoleService.cs @@ -33,12 +33,6 @@ namespace Yi.Framework.Interface /// /// Task SetMenusByRolesId(List menuIds, int roleId); - /// - /// 添加角色 - /// - /// - /// - Task AddRole(role _role); } } diff --git a/Yi.Framework/Yi.Framework.Interface/IUserService.cs b/Yi.Framework/Yi.Framework.Interface/IUserService.cs index ba356f07..6e86b4fa 100644 --- a/Yi.Framework/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IUserService.cs @@ -52,6 +52,7 @@ namespace Yi.Framework.Interface /// /// Task SetRolesByUserId(List roleIds,int userId); + Task EmailIsExsit(string emailAddress); } } diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 7b479a58..c0bf6d9d 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -24,16 +24,6 @@ namespace Yi.Framework.Service return await AddAsync(_menu); } - public async Task AddMenu(menu _menu) - { - var menu_data = await GetEntityById(_menu.id); - if (menu_data == null) - { - return false; - } - return await AddAsync(_menu); - } - public async Task DelListByUpdateAsync(List _ids) { var menuList = await GetEntitiesAsync(u=>_ids.Contains(u.id)); diff --git a/Yi.Framework/Yi.Framework.Service/MouldService.cs b/Yi.Framework/Yi.Framework.Service/MouldService.cs index ff64a8e2..7746b640 100644 --- a/Yi.Framework/Yi.Framework.Service/MouldService.cs +++ b/Yi.Framework/Yi.Framework.Service/MouldService.cs @@ -27,9 +27,10 @@ namespace Yi.Framework.Service public async Task GetMenuByMould(mould _mould) { - throw new Exception(); - //var mould_data= await _Db.Set().Include(u=>u.menu).Where(u => u.id == _mould.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); - // return mould_data.menu; + + var menu_data = await _Db.Set().Include(u => u.mould) + .Where(u => u.mould == _mould && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + return menu_data; } } } diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index 79a62af8..d0450289 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -13,17 +13,7 @@ namespace Yi.Framework.Service { public RoleService(DbContext Db):base(Db) { - } - - public async Task AddRole(role _role) - { - var role_data = await GetEntityById(_role.id); - if(role_data==null) - { - return false; - } - return await AddAsync(_role); - } + } public async Task DelListByUpdateAsync(List _ids) { diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index ea563c57..35567401 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -23,6 +23,17 @@ namespace Yi.Framework.Service return await UpdateListAsync(userList); } + public async Task EmailIsExsit(string emailAddress) + { + var userList=await GetAllEntitiesTrueAsync(); + var is_email= userList.Where(u=>u.email==emailAddress).FirstOrDefault(); + if (is_email == null) + { + return true; + } + return false; + } + public async Task> GetAllEntitiesTrueAsync() { return await GetEntitiesAsync(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);