重构代码
重构代码
This commit is contained in:
4
Yi.Framework.Net6/.editorconfig
Normal file
4
Yi.Framework.Net6/.editorconfig
Normal file
@@ -0,0 +1,4 @@
|
||||
[*.cs]
|
||||
|
||||
# SYSLIB0014: 类型或成员已过时
|
||||
dotnet_diagnostic.SYSLIB0014.severity = none
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Yi.Framework.OcelotGateway</name>
|
||||
<name>Yi.Framework.ApiMicroservice</name>
|
||||
</assembly>
|
||||
<members>
|
||||
</members>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Yi.Framework.WebCore.BuilderExtend;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.WebCore.MiddlewareExtend;
|
||||
using Yi.Framework.WebCore.Utility;
|
||||
using Autofac;
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -70,10 +70,6 @@ builder.Services.AddJwtService();
|
||||
#endregion
|
||||
builder.Services.AddAuthorizationService();
|
||||
#region
|
||||
//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddDbService();
|
||||
#region
|
||||
//Redis<69><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddRedisService();
|
||||
@@ -95,6 +91,11 @@ builder.Services.AddSMSService();
|
||||
builder.Services.AddCAPService<Program>();
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
var app = builder.Build();
|
||||
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
ServiceLocator.Instance = app.Services;
|
||||
//if (app.Environment.IsDevelopment())
|
||||
{
|
||||
#region
|
||||
@@ -110,7 +111,6 @@ var app = builder.Build();
|
||||
//<2F><><EFBFBD><EFBFBD>ץȡ<D7A5><C8A1><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseErrorHandlingService();
|
||||
|
||||
#region
|
||||
//<2F><>̬<EFBFBD>ļ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
@@ -144,10 +144,6 @@ app.UseAuthorization();
|
||||
#endregion
|
||||
app.UseConsulService();
|
||||
#region
|
||||
//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseDbSeedInitService(app.Services.GetService<IDbContextFactory>());
|
||||
#region
|
||||
//redis<69><73><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseRedisSeedInitService(app.Services.GetService<CacheClientDB>());
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Yi.Framework.ApiMicroservice</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.loginDto)">
|
||||
<summary>
|
||||
登录方法,要返回data:{user,token} token
|
||||
</summary>
|
||||
<param name="login"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Logout">
|
||||
<summary>
|
||||
不用写,单纯制作日志
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Register(Yi.Framework.Model.Models.user,System.String)">
|
||||
<summary>
|
||||
code为验证码,从redis中判断一下code是否正确
|
||||
</summary>
|
||||
<param name="_user"></param>
|
||||
<param name="code"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.SendSMS(System.String)">
|
||||
<summary>
|
||||
发送短信,需要将生成的sms+code存入redis
|
||||
</summary>
|
||||
<param name="SMSAddress"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Email(System.String)">
|
||||
<summary>
|
||||
发送邮箱,需要先到数据库判断该邮箱是否被人注册过,到userservice写mail_exist方法,还有接口别忘了。
|
||||
</summary>
|
||||
<param name="emailAddress"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.ChangePassword(Yi.Framework.DTOModel.ChangePwdDto)">
|
||||
<summary>
|
||||
修改密码
|
||||
</summary>
|
||||
<param name="pwdDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.Upload(System.String,Microsoft.AspNetCore.Http.IFormFile)">
|
||||
<summary>
|
||||
该方法不对外暴露
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="file"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.startJob">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.getRunJobList">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.getJobClass">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.stopJob">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.DeleteJob">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.JobController.ResumeJob">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.GetMenuInMould">
|
||||
<summary>
|
||||
这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.UpdateMenu(Yi.Framework.Model.Models.menu)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="_menu"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.DelListMenu(System.Collections.Generic.List{System.Int32})">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="_ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.AddTopMenu(Yi.Framework.Model.Models.menu)">
|
||||
<summary>
|
||||
增
|
||||
现在,top菜单只允许为一个
|
||||
</summary>
|
||||
<param name="_menu"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.SetMouldByMenu(Yi.Framework.DTOModel.IdDto{System.Int32})">
|
||||
<summary>
|
||||
给一个菜单设置一个接口,Id1为菜单id,Id2为接口id
|
||||
用于给菜单设置接口
|
||||
</summary>
|
||||
<param name="idDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.AddChildrenMenu(Yi.Framework.DTOModel.ChildrenDto{Yi.Framework.Model.Models.menu})">
|
||||
<summary>
|
||||
给一个菜单添加子节点(注意:添加,不是覆盖)
|
||||
</summary>
|
||||
<param name="childrenDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.GetTopMenusByHttpUser">
|
||||
<summary>
|
||||
获取用户的目录菜单,不包含接口
|
||||
用于账户信息页面,显示这个用户有哪些菜单,需要并列
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MouldController.UpdateMould(Yi.Framework.Model.Models.mould)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="_mould"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MouldController.DelListMould(System.Collections.Generic.List{System.Int32})">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="_ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MouldController.AddMould(Yi.Framework.Model.Models.mould)">
|
||||
<summary>
|
||||
增
|
||||
</summary>
|
||||
<param name="_mould"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.UpdateRole(Yi.Framework.Model.Models.role)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="_role"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.DelListRole(System.Collections.Generic.List{System.Int32})">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="_ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.AddRole(Yi.Framework.Model.Models.role)">
|
||||
<summary>
|
||||
增
|
||||
</summary>
|
||||
<param name="_role"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GetRolesByUserId(System.Int32)">
|
||||
<summary>
|
||||
根据用户id得到该用户有哪些角色
|
||||
用于显示用户详情中的角色说明
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.SetMenuByRole(Yi.Framework.DTOModel.IdsListDto{System.Int32})">
|
||||
<summary>
|
||||
给角色设置菜单,多个角色与多个菜单,让每一个角色都设置,ids1为角色,ids2为菜单
|
||||
用于设置角色
|
||||
</summary>
|
||||
<param name="idsListDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GetTopMenusByRoleId(System.Int32)">
|
||||
<summary>
|
||||
用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
|
||||
</summary>
|
||||
<param name="roleId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.SettingController.GetSetting">
|
||||
<summary>
|
||||
查
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.SettingController.UpdateSetting(Yi.Framework.DTOModel.SettingDto)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="settingDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetUser">
|
||||
<summary>
|
||||
查
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.UpdateUser(Yi.Framework.Model.Models.user)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="_user"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.DelListUser(System.Collections.Generic.List{System.Int32})">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="_ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.AddUser(Yi.Framework.Model.Models.user)">
|
||||
<summary>
|
||||
增
|
||||
</summary>
|
||||
<param name="_user"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.SetRoleByUser(Yi.Framework.DTOModel.IdsListDto{System.Int32})">
|
||||
<summary>
|
||||
SetRoleByUser
|
||||
给多个用户设置多个角色,ids有用户id与 角色列表ids,多对多,ids1用户,ids2为角色
|
||||
用户设置给用户设置角色
|
||||
</summary>
|
||||
<param name="idsListDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetUserInRolesByHttpUser">
|
||||
<summary>
|
||||
根据http上下文的用户得到该用户信息,关联角色
|
||||
用于显示账号信息页中的用户信息和角色信息
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetMenuByHttpUser">
|
||||
<summary>
|
||||
得到登录用户的递归菜单,放到导航栏
|
||||
用户放到导航栏中
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetAxiosByRouter(System.String)">
|
||||
<summary>
|
||||
得到请求模型
|
||||
</summary>
|
||||
<param name="router"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
@@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>D:\CC.Yi\CC.Yi\Yi.Framework.Net6\Yi.Framework.ApiMicroservice\SwaggerDoc.xml</DocumentationFile>
|
||||
<DocumentationFile>./Config/SwaggerDoc.xml</DocumentationFile>
|
||||
<NoWarn>1701;1702;CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -20,14 +20,6 @@
|
||||
<None Remove="wwwrooot\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace Yi.Framework.Common.Helper
|
||||
{
|
||||
public static string HttpGet(string Url, string postDataStr="")
|
||||
{
|
||||
#pragma warning disable SYSLIB0014 // 类型或成员已过时
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
|
||||
#pragma warning restore SYSLIB0014 // 类型或成员已过时
|
||||
request.Method = "GET";
|
||||
request.ContentType = "text/html;charset=UTF-8";
|
||||
|
||||
@@ -52,7 +54,9 @@ namespace Yi.Framework.Common.Helper
|
||||
public static string HttpPost(string Url, string postDataStr="")
|
||||
{
|
||||
CookieContainer cookie = new CookieContainer();
|
||||
#pragma warning disable SYSLIB0014 // 类型或成员已过时
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
|
||||
#pragma warning restore SYSLIB0014 // 类型或成员已过时
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace Yi.Framework.Common.Helper
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt16(string password)
|
||||
{
|
||||
#pragma warning disable SYSLIB0021 // 类型或成员已过时
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
#pragma warning restore SYSLIB0021 // 类型或成员已过时
|
||||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
|
||||
t2 = t2.Replace("-", string.Empty);
|
||||
return t2;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Common.IOCOptions
|
||||
{
|
||||
public class AuthorizationOptions
|
||||
{
|
||||
public string Refresh { get; set; }
|
||||
public List<string> WhiteList { get; set; }
|
||||
public List<string> AccountList { get; set; }
|
||||
public List<string> UserList { get; set; }
|
||||
|
||||
public List<string> TenantList { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Common.IOCOptions
|
||||
{
|
||||
public class JWTTokenOptions
|
||||
{
|
||||
public string Audience
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string SecurityKey
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
//public SigningCredentials Credentials
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
public string Issuer
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string Audience { get; set; }
|
||||
|
||||
public string Issuer { get; set; }
|
||||
|
||||
public string SecurityKey { get; set; }
|
||||
|
||||
public string DefaultScheme { get; set; }
|
||||
public int Expiration { get; set; }
|
||||
|
||||
public int ReExpiration { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Common.Models.Enum
|
||||
{
|
||||
public enum ResultCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作成功。
|
||||
/// </summary>
|
||||
Success = 200,
|
||||
|
||||
/// <summary>
|
||||
/// 操作不成功
|
||||
/// </summary>
|
||||
NotSuccess = 500,
|
||||
|
||||
/// <summary>
|
||||
/// 无权限
|
||||
/// </summary>
|
||||
NoPermission = 401,
|
||||
|
||||
/// <summary>
|
||||
/// Access过期
|
||||
/// </summary>
|
||||
AccessTokenExpire = 1001,
|
||||
|
||||
/// <summary>
|
||||
/// Refresh过期
|
||||
/// </summary>
|
||||
RefreshTokenExpire = 1002,
|
||||
|
||||
/// <summary>
|
||||
/// 没有角色登录
|
||||
/// </summary>
|
||||
NoRoleLogin = 1003,
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yi.Framework.Common.Models.Enum;
|
||||
using Yi.Framework.Language;
|
||||
|
||||
namespace Yi.Framework.Common.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果数据
|
||||
/// </summary>
|
||||
public class Result
|
||||
{
|
||||
public static IStringLocalizer<LocalLanguage> _local;
|
||||
public ResultCode code { get; set; }
|
||||
|
||||
public bool status { get; set; }
|
||||
public int code { get; set; }
|
||||
public string msg { get; set; }
|
||||
public string message { get; set; }
|
||||
public object data { get; set; }
|
||||
public static Result Instance(bool status, string msg)
|
||||
public static Result Expire(ResultCode code, string msg="")
|
||||
{
|
||||
return new Result() { status = status, code = 500, msg = msg };
|
||||
return new Result() { code = code, status=false, message = Get(msg, "token_expiration") };
|
||||
}
|
||||
public static Result Error(string msg = "fail")
|
||||
public static Result Error(string msg = "")
|
||||
{
|
||||
return new Result() { status = false, code = 500, msg = msg };
|
||||
return new Result() { code = ResultCode.NotSuccess,status=false, message =Get(msg, "fail") };
|
||||
}
|
||||
public static Result Success(string msg = "succeed")
|
||||
public static Result Success(string msg = "")
|
||||
{
|
||||
return new Result() { status = true, code = 200, msg = msg };
|
||||
return new Result() { code = ResultCode.Success,status=true, message =Get( msg, "succeed" )};
|
||||
}
|
||||
public static Result UnAuthorize(string msg = "unAuthorize")
|
||||
public static Result SuccessError(string msg = "")
|
||||
{
|
||||
return new Result() { status = false, code = 401, msg = msg };
|
||||
return new Result() { code = ResultCode.Success, status = false, message = Get(msg, "fail") };
|
||||
}
|
||||
|
||||
|
||||
public static Result UnAuthorize(string msg = "")
|
||||
{
|
||||
return new Result() { code = ResultCode.NoPermission,status=false, message = Get(msg, "unAuthorize") };
|
||||
}
|
||||
public Result SetStatus(bool _status)
|
||||
{
|
||||
this.status = _status;
|
||||
return this;
|
||||
}
|
||||
public Result SetData(object obj)
|
||||
{
|
||||
this.data = obj;
|
||||
return this;
|
||||
}
|
||||
public Result SetCode(int Code)
|
||||
public Result SetCode(ResultCode Code)
|
||||
{
|
||||
this.code = Code;
|
||||
return this;
|
||||
}
|
||||
public Result StatusFalse()
|
||||
{
|
||||
this.status = false;
|
||||
return this;
|
||||
}
|
||||
public Result StatusTrue()
|
||||
{
|
||||
this.status = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static string Get(string msg,string msg2)
|
||||
{
|
||||
if (msg=="")
|
||||
{
|
||||
msg = _local[msg2];
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
public class Result<T>
|
||||
{
|
||||
public bool status { get; set; }
|
||||
public int code { get; set; }
|
||||
public string msg { get; set; }
|
||||
public ResultCode code { get; set; }
|
||||
public string message { get; set; }
|
||||
public T data { get; set; }
|
||||
|
||||
public static Result<T> Instance(bool status, string msg)
|
||||
{
|
||||
return new Result<T>() { status = status, code = 500, msg = msg };
|
||||
}
|
||||
public static Result<T> Error(string msg = "fail")
|
||||
{
|
||||
return new Result<T> { status = false, code = 500, msg = msg };
|
||||
return new Result<T>() { code = ResultCode.NotSuccess, message = msg };
|
||||
}
|
||||
public static Result<T> Success(string msg = "succeed")
|
||||
{
|
||||
return new Result<T> { status = true, code = 200, msg = msg };
|
||||
return new Result<T>() { code = ResultCode.Success, message = msg };
|
||||
}
|
||||
|
||||
public static Result<T> UnAuthorize(string msg = "unAuthorize")
|
||||
{
|
||||
return new Result<T>{ status = false, code = 401, msg = msg };
|
||||
return new Result<T>() { code = ResultCode.NoPermission, message = msg };
|
||||
}
|
||||
|
||||
public Result<T> SetData(T TValue)
|
||||
@@ -72,6 +92,11 @@ namespace Yi.Framework.Common.Models
|
||||
this.data = TValue;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Result<T> SetCode(ResultCode Code)
|
||||
{
|
||||
this.code = Code;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Yi.Framework.Common.Models
|
||||
{
|
||||
public static class ServiceLocator
|
||||
{
|
||||
public static IServiceProvider Instance { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EPPlus" Version="5.8.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Language\Yi.Framework.Language.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,10 +14,9 @@ using JwtRegisteredClaimNames = Microsoft.IdentityModel.JsonWebTokens.JwtRegiste
|
||||
namespace Yi.Framework.Core
|
||||
{
|
||||
|
||||
public class jwtUser
|
||||
public class JwtUser
|
||||
{
|
||||
public user user { get; set; }
|
||||
public List<menu> menuIds { get; set; }
|
||||
public User user { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -29,23 +28,23 @@ namespace Yi.Framework.Core
|
||||
/// </summary>
|
||||
/// <param name="_user"></param>
|
||||
/// <returns></returns>
|
||||
public static string app(jwtUser _user)
|
||||
public static string app(JwtUser _user)
|
||||
{
|
||||
//通过查询权限,把所有权限加入进令牌中
|
||||
List<Claim> claims = new List<Claim>();
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}"));
|
||||
claims.Add(new Claim(ClaimTypes.Name, _user.user.username));
|
||||
claims.Add(new Claim(ClaimTypes.Sid, _user.user.id.ToString()));
|
||||
claims.Add(new Claim(ClaimTypes.Name, _user.user.Username));
|
||||
claims.Add(new Claim(ClaimTypes.Sid, _user.user.Id.ToString()));
|
||||
//现在不存放在jwt中,而存放在redis中
|
||||
//foreach (var k in _user?.menuIds)
|
||||
//{
|
||||
// claims.Add(new Claim("menuIds",k.id.ToString()));
|
||||
//}
|
||||
foreach (var k in _user.user.roles)
|
||||
{
|
||||
claims.Add(new Claim(ClaimTypes.Role, k.role_name));
|
||||
}
|
||||
//foreach (var k in _user.user.roles)
|
||||
//{
|
||||
// claims.Add(new Claim(ClaimTypes.Role, k.role_name));
|
||||
//}
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
|
||||
<PackageReference Include="Consul" Version="1.6.10.3" />
|
||||
<PackageReference Include="CSRedisCore" Version="3.6.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
|
||||
@@ -40,4 +41,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Library\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class ChangePwdDto
|
||||
{
|
||||
public user user { get; set; }
|
||||
public string newPassword { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class ChildrenDto<T>
|
||||
{
|
||||
public int parentId { get; set; }
|
||||
public T data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class IdDto<T>
|
||||
{
|
||||
public T id1 { get; set; }
|
||||
public T id2 { get; set; }
|
||||
}
|
||||
|
||||
public class IdsDto<T>
|
||||
{
|
||||
public T id{ get; set; }
|
||||
public List<T> ids { get; set; }
|
||||
}
|
||||
|
||||
public class IdsListDto<T>
|
||||
{
|
||||
public List<T> ids1 { get; set; }
|
||||
public List<T> ids2 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class SettingDto
|
||||
{
|
||||
public string InitIcon { get; set; }
|
||||
public string InitRole { get; set; }
|
||||
public string Title { get; set; }
|
||||
public List<string> ImageList { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,10 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class loginDto
|
||||
{
|
||||
public string username { get; set; }
|
||||
public string password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class menuDto
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string icon { get; set; }
|
||||
public string router { get; set; }
|
||||
public string menu_name { get; set; }
|
||||
|
||||
public mould mould { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="configuration.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="Log4net.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public interface IBaseService<T> where T : class, new()
|
||||
{
|
||||
#region
|
||||
//通过id得到实体
|
||||
#endregion
|
||||
Task<T> GetEntityById(int id);
|
||||
|
||||
#region
|
||||
//通过表达式得到实体
|
||||
#endregion
|
||||
Task<T> GetEntity(Expression<Func<T, bool>> whereLambda);
|
||||
|
||||
#region
|
||||
//得到全部实体
|
||||
#endregion
|
||||
Task<IEnumerable<T>> GetAllEntitiesAsync();
|
||||
|
||||
#region
|
||||
//通过表达式得到实体
|
||||
#endregion
|
||||
Task<IEnumerable<T>> GetEntitiesAsync(Expression<Func<T, bool>> whereLambda);
|
||||
|
||||
#region
|
||||
//通过表达式得到实体,分页版本
|
||||
#endregion
|
||||
Task<int> GetCountAsync(Expression<Func<T, bool>> whereLambda);
|
||||
|
||||
#region
|
||||
//通过表达式统计数量
|
||||
#endregion
|
||||
IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda);
|
||||
|
||||
#region
|
||||
//通过表达式分组
|
||||
#endregion
|
||||
Task<Tuple<IEnumerable<T>, int>> GetPageEntities<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc);
|
||||
|
||||
#region
|
||||
//添加实体
|
||||
#endregion
|
||||
Task<bool> AddAsync(T entity);
|
||||
|
||||
#region
|
||||
//添加多个实体
|
||||
#endregion
|
||||
Task<bool> AddAsync(IEnumerable<T> entities);
|
||||
|
||||
#region
|
||||
//更新实体
|
||||
#endregion
|
||||
Task<bool> UpdateAsync(T entity);
|
||||
|
||||
#region
|
||||
//更新多个实体
|
||||
#endregion
|
||||
Task<bool> UpdateListAsync(IEnumerable<T> entities);
|
||||
|
||||
#region
|
||||
//更新实体部分属性
|
||||
#endregion
|
||||
Task<bool> DeleteAsync(T entity);
|
||||
|
||||
#region
|
||||
//删除实体
|
||||
#endregion
|
||||
Task<bool> DeleteAsync(int id);
|
||||
|
||||
#region
|
||||
//通过id删除实体
|
||||
#endregion
|
||||
Task<bool> DeleteAsync(IEnumerable<int> ids);
|
||||
|
||||
#region
|
||||
//通过id列表删除多个实体
|
||||
#endregion
|
||||
Task<bool> DeleteAsync(Expression<Func<T, bool>> where);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IMenuService:IBaseService<menu>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有菜单,关联接口
|
||||
/// 这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<menu> GetMenuInMould();
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// 现在,top菜单只允许为一个
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddTopMenu(menu _menu);
|
||||
/// <summary>
|
||||
/// 给一个菜单设置一个接口,Id1为菜单id,Id2为接口id
|
||||
/// 用于给菜单设置接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<menu> SetMouldByMenu(int id1, int id2);
|
||||
/// <summary>
|
||||
/// 给一个菜单添加子节点(注意:添加,不是覆盖)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<menu> AddChildrenMenu(int menu_id, menu _children);
|
||||
/// <summary>
|
||||
/// 获取用户的目录菜单,不包含接口
|
||||
/// 用于账户信息页面,显示这个用户有哪些菜单,需要并列
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetTopMenusByTopMenuIds(List<int> menuIds);
|
||||
Task<List<menu>> GetTopMenuByUserId(int userId);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IMouldService : IBaseService<mould>
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到该接口属于哪个菜单的
|
||||
/// </summary>
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
Task<menu> GetMenuByMould(mould _mould);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IRoleService:IBaseService<role>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取该角色的所有菜单
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetMenusByRole(int roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 给多个角色设置多个菜单
|
||||
/// </summary>
|
||||
/// <param name="menuIds"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SetMenusByRolesId(List<int> menuIds, List<int> roleIds);
|
||||
/// <summary>
|
||||
/// 获取多个用户的菜单,并列,不包含子菜单
|
||||
/// </summary>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetMenusByRoleId(List<int> roleIds);
|
||||
/// <summary>
|
||||
/// 获取用户的角色
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<role>> GetRolesByUserId(int userId);
|
||||
/// <summary>
|
||||
/// 获取该角色的top菜单
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetTopMenusByRoleId(int roleId);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,84 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IUserService:IBaseService<user>
|
||||
public partial interface IUserService: IRepository<User>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 登录,传入_user需包含用户名与密码/角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<user> Login(user _user);
|
||||
|
||||
/// <summary>
|
||||
/// 注册,需要检测是否用户名重复
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> Register(user _user);
|
||||
/// <summary>
|
||||
/// 给多个用户设置多个角色
|
||||
/// </summary>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SetRoleByUser(List<int> roleIds, List<int> userIds);
|
||||
/// <summary>
|
||||
/// 通过id获取用户信息,关联角色、菜单、子菜单、接口
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<user> GetUserById(int userId);
|
||||
/// <summary>
|
||||
/// email验证
|
||||
/// </summary>
|
||||
/// <param name="emailAddress"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> EmailIsExsit(string emailAddress);
|
||||
|
||||
/// <summary>
|
||||
/// sms验证
|
||||
/// </summary>
|
||||
/// <param name="smsAddress"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> PhoneIsExsit(string smsAddress);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id,得到该用户的所有信息,关联角色
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<user> GetUserInRolesByHttpUser(int userId);
|
||||
/// <summary>
|
||||
/// 通过http获取用户id,得到该用户所有的菜单(递归的那种),把所有children为[]的值全部过滤成null,不要绑定mould
|
||||
/// </summary>
|
||||
/// <param name="allMenuIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<menu> GetMenuByHttpUser(List<int> allMenuIds);
|
||||
/// <summary>
|
||||
/// 根据路由获取菜单
|
||||
/// </summary>
|
||||
/// <param name="router"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetAxiosByRouter(string router, List<int> menuIds);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将登录用户的api保存的redis中
|
||||
/// </summary>
|
||||
/// <param name="_user"></param>
|
||||
/// <returns></returns>
|
||||
public bool SaveUserApi(int userId, List<menuDto> menus);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到redis中菜单列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<int> GetCurrentMenuInfo(int userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
|
||||
public partial interface IMenuService:IBaseService<menu>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<menu>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
|
||||
public partial interface IMouldService:IBaseService<mould>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<mould>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
|
||||
public partial interface IRoleService:IBaseService<role>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<role>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
|
||||
public partial interface IUserService:IBaseService<user>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<user>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
|
||||
public partial interface IVisitService:IBaseService<visit>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<visit>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string dirPath= Path.Combine(solutionsPath,@"Yi.Framework.Model\Models\");
|
||||
DirectoryInfo dir = new DirectoryInfo(dirPath);
|
||||
FileInfo[] finfo = dir.GetFiles();
|
||||
string filenames = string.Empty;
|
||||
List<string> filenameList = new List<string>();
|
||||
for (int i = 0; i < finfo.Length; i++)
|
||||
{
|
||||
filenames = finfo[i].Name ;
|
||||
string[] fname=filenames.Split('.');
|
||||
filenameList.Add(fname[0]);
|
||||
}
|
||||
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
<# foreach(string k in filenameList){
|
||||
string fn= k.Substring(0,1).ToUpper()+k.Substring(1);
|
||||
#>
|
||||
|
||||
public partial interface I<#= fn #>Service:IBaseService<<#= k #>>
|
||||
{
|
||||
Task<bool> DelListByUpdateAsync(List<int> _ids);
|
||||
Task<IEnumerable<<#= k #>>> GetAllEntitiesTrueAsync();
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
@@ -11,25 +11,11 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4IService.tt">
|
||||
<LastGenOutput>T4Iservice.cs</LastGenOutput>
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
</None>
|
||||
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4IService.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4IService.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
7
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.cs
Normal file
7
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.Language
|
||||
{
|
||||
public class LocalLanguage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
171
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.en.resx
Normal file
171
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.en.resx
Normal file
@@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="error" xml:space="preserve">
|
||||
<value>Internal interaction error</value>
|
||||
</data>
|
||||
<data name="fail" xml:space="preserve">
|
||||
<value>fail</value>
|
||||
</data>
|
||||
<data name="login_error" xml:space="preserve">
|
||||
<value>Login failed, please check your user name and password</value>
|
||||
</data>
|
||||
<data name="login_successful" xml:space="preserve">
|
||||
<value>Login successful</value>
|
||||
</data>
|
||||
<data name="logout" xml:space="preserve">
|
||||
<value>Logout successful</value>
|
||||
</data>
|
||||
<data name="menu_already_exists" xml:space="preserve">
|
||||
<value>The current menu already exists</value>
|
||||
</data>
|
||||
<data name="no_role_login" xml:space="preserve">
|
||||
<value>Login failed! The user does not have any roles</value>
|
||||
</data>
|
||||
<data name="original_password_error" xml:space="preserve">
|
||||
<value>Original password error</value>
|
||||
</data>
|
||||
<data name="role_already_exists" xml:space="preserve">
|
||||
<value>The current role already exists</value>
|
||||
</data>
|
||||
<data name="succeed" xml:space="preserve">
|
||||
<value>success</value>
|
||||
</data>
|
||||
<data name="token_error" xml:space="preserve">
|
||||
<value>Refreshtoken expired, refresh failed!</value>
|
||||
</data>
|
||||
<data name="token_expiration" xml:space="preserve">
|
||||
<value>Token expiration</value>
|
||||
</data>
|
||||
<data name="token_success" xml:space="preserve">
|
||||
<value>Accesstoken and refreshtoken are refreshed successfully!</value>
|
||||
</data>
|
||||
<data name="unauthorize" xml:space="preserve">
|
||||
<value>Unauthorized</value>
|
||||
</data>
|
||||
<data name="user_changed" xml:space="preserve">
|
||||
<value>User changed</value>
|
||||
</data>
|
||||
<data name="user_not_exist" xml:space="preserve">
|
||||
<value>user does not exist</value>
|
||||
</data>
|
||||
<data name="user_registered" xml:space="preserve">
|
||||
<value>User already registered</value>
|
||||
</data>
|
||||
</root>
|
||||
171
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.zh.resx
Normal file
171
Yi.Framework.Net6/Yi.Framework.Language/LocalLanguage.zh.resx
Normal file
@@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="error" xml:space="preserve">
|
||||
<value>内部交互错误</value>
|
||||
</data>
|
||||
<data name="fail" xml:space="preserve">
|
||||
<value>失败</value>
|
||||
</data>
|
||||
<data name="login_error" xml:space="preserve">
|
||||
<value>登录失败,请检查你的用户名与密码</value>
|
||||
</data>
|
||||
<data name="login_successful" xml:space="preserve">
|
||||
<value>登录成功</value>
|
||||
</data>
|
||||
<data name="logout" xml:space="preserve">
|
||||
<value>登出成功</value>
|
||||
</data>
|
||||
<data name="menu_already_exists" xml:space="preserve">
|
||||
<value>当前菜单已存在</value>
|
||||
</data>
|
||||
<data name="no_role_login" xml:space="preserve">
|
||||
<value>登录失败!该用户未拥有任何角色</value>
|
||||
</data>
|
||||
<data name="original_password_error" xml:space="preserve">
|
||||
<value>原密码错误</value>
|
||||
</data>
|
||||
<data name="role_already_exists" xml:space="preserve">
|
||||
<value>当前角色已存在</value>
|
||||
</data>
|
||||
<data name="succeed" xml:space="preserve">
|
||||
<value>成功</value>
|
||||
</data>
|
||||
<data name="token_error" xml:space="preserve">
|
||||
<value>RefreshToken过期,刷新失败!</value>
|
||||
</data>
|
||||
<data name="token_expiration" xml:space="preserve">
|
||||
<value>令牌过期</value>
|
||||
</data>
|
||||
<data name="token_success" xml:space="preserve">
|
||||
<value>AccessToken, RefreshToken刷新成功!</value>
|
||||
</data>
|
||||
<data name="unauthorize" xml:space="preserve">
|
||||
<value>未授权</value>
|
||||
</data>
|
||||
<data name="user_changed" xml:space="preserve">
|
||||
<value>用户已更改</value>
|
||||
</data>
|
||||
<data name="user_not_exist" xml:space="preserve">
|
||||
<value>用户不存在</value>
|
||||
</data>
|
||||
<data name="user_registered" xml:space="preserve">
|
||||
<value>用户已经注册</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class baseModel<T>
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
|
||||
public T id { get; set; }
|
||||
public int is_delete { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class loopModel<T>:baseModel<int>
|
||||
{
|
||||
public int is_top { get; set; }
|
||||
public int sort { get; set; }
|
||||
public int is_show { get; set; }
|
||||
public int parentId { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IList<T> children { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
//Add-Migration yi-1
|
||||
//Update-Database yi-1
|
||||
public partial class DataContext : DbContext
|
||||
{
|
||||
//private readonly IOptionsMonitor<MySqlConnOptions> _optionsMonitor;
|
||||
public static string _connStr;
|
||||
public static string DbSelect = DbConst.Mysql;
|
||||
//public DataContext(IOptionsMonitor<MySqlConnOptions> optionsMonitor)
|
||||
//{
|
||||
// _optionsMonitor = optionsMonitor;
|
||||
// _connStr = _optionsMonitor.CurrentValue.WriteUrl;
|
||||
//}
|
||||
public DbContext ToWriteOrRead(string connstr)
|
||||
{
|
||||
_connStr = connstr;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
switch (DbSelect)
|
||||
{
|
||||
case DbConst.Mysql:
|
||||
var serverVersion = new MySqlServerVersion(new Version(8, 0, 21));
|
||||
optionsBuilder.UseMySql(_connStr, serverVersion); break;
|
||||
case DbConst.Sqlite:
|
||||
optionsBuilder.UseSqlite(_connStr); break;
|
||||
case DbConst.Sqlserver:
|
||||
optionsBuilder.UseSqlServer(_connStr);break;
|
||||
case DbConst.Oracle:
|
||||
optionsBuilder.UseOracle(_connStr);break;
|
||||
default:
|
||||
Console.WriteLine("错误!请确保你选择了正确的数据库!");break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Yi.Framework.Model;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20220221034128_yi-1")]
|
||||
partial class yi1
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.Property<int>("menusid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("menusid", "rolesid");
|
||||
|
||||
b.HasIndex("rolesid");
|
||||
|
||||
b.ToTable("menurole");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("usersid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("rolesid", "usersid");
|
||||
|
||||
b.HasIndex("usersid");
|
||||
|
||||
b.ToTable("roleuser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_show")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_top")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("menu_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("mouldid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("parentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("router")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("sort")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("mouldid");
|
||||
|
||||
b.ToTable("menu");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.mould", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("mould_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("url")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("mould");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.role", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("introduce")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("role_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.user", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("address")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("age")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("email")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("introduction")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("ip")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("nick")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("password")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("phone")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("username")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.visit", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("num")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("visit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.menu", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("menusid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.user", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("usersid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.mould", "mould")
|
||||
.WithMany()
|
||||
.HasForeignKey("mouldid");
|
||||
|
||||
b.Navigation("mould");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
public partial class yi1 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "mould",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
mould_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
url = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_mould", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "role",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
role_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
introduce = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_role", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "user",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
username = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
password = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
icon = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
nick = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
email = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
ip = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
age = table.Column<int>(type: "int", nullable: true),
|
||||
introduction = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
address = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
phone = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_user", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "visit",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
time = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
num = table.Column<int>(type: "int", nullable: false),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_visit", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "menu",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
icon = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
router = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
menu_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
mouldid = table.Column<int>(type: "int", nullable: true),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false),
|
||||
is_top = table.Column<int>(type: "int", nullable: false),
|
||||
sort = table.Column<int>(type: "int", nullable: false),
|
||||
is_show = table.Column<int>(type: "int", nullable: false),
|
||||
parentId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_menu", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_menu_mould_mouldid",
|
||||
column: x => x.mouldid,
|
||||
principalTable: "mould",
|
||||
principalColumn: "id");
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "roleuser",
|
||||
columns: table => new
|
||||
{
|
||||
rolesid = table.Column<int>(type: "int", nullable: false),
|
||||
usersid = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_roleuser", x => new { x.rolesid, x.usersid });
|
||||
table.ForeignKey(
|
||||
name: "FK_roleuser_role_rolesid",
|
||||
column: x => x.rolesid,
|
||||
principalTable: "role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_roleuser_user_usersid",
|
||||
column: x => x.usersid,
|
||||
principalTable: "user",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "menurole",
|
||||
columns: table => new
|
||||
{
|
||||
menusid = table.Column<int>(type: "int", nullable: false),
|
||||
rolesid = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_menurole", x => new { x.menusid, x.rolesid });
|
||||
table.ForeignKey(
|
||||
name: "FK_menurole_menu_menusid",
|
||||
column: x => x.menusid,
|
||||
principalTable: "menu",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_menurole_role_rolesid",
|
||||
column: x => x.rolesid,
|
||||
principalTable: "role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_menu_mouldid",
|
||||
table: "menu",
|
||||
column: "mouldid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_menurole_rolesid",
|
||||
table: "menurole",
|
||||
column: "rolesid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_roleuser_usersid",
|
||||
table: "roleuser",
|
||||
column: "usersid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "menurole");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "roleuser");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "visit");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "menu");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "role");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "user");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "mould");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Yi.Framework.Model;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
partial class DataContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.Property<int>("menusid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("menusid", "rolesid");
|
||||
|
||||
b.HasIndex("rolesid");
|
||||
|
||||
b.ToTable("menurole");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("usersid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("rolesid", "usersid");
|
||||
|
||||
b.HasIndex("usersid");
|
||||
|
||||
b.ToTable("roleuser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_show")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_top")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("menu_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("mouldid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("parentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("router")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("sort")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("mouldid");
|
||||
|
||||
b.ToTable("menu");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.mould", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("mould_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("url")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("mould");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.role", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("introduce")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("role_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.user", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("address")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("age")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("email")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("introduction")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("ip")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("nick")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("password")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("phone")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("username")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.visit", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("num")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("visit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.menu", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("menusid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.user", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("usersid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.mould", "mould")
|
||||
.WithMany()
|
||||
.HasForeignKey("mouldid");
|
||||
|
||||
b.Navigation("mould");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public static class DbContextExtend
|
||||
{
|
||||
public static DbContext ToWriteOrRead(this DbContext dbContext, string conn)
|
||||
{
|
||||
if (dbContext is DataContext)
|
||||
{
|
||||
|
||||
var context= (DataContext)dbContext; // context 是 EFCoreContext 实例;
|
||||
|
||||
return context.ToWriteOrRead(conn);
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public class DbContextFactory : IDbContextFactory
|
||||
{
|
||||
|
||||
private DbContext _Context = null;
|
||||
|
||||
private DbConnOptions _readAndWrite = null;
|
||||
|
||||
public static bool MutiDB_Enabled = false;
|
||||
//private static int _iSeed = 0;//应该long
|
||||
|
||||
/// <summary>
|
||||
///能把链接信息也注入进来
|
||||
///需要IOptionsMonitor
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public DbContextFactory(DbContext context, IOptionsMonitor<DbConnOptions> options)
|
||||
{
|
||||
_readAndWrite = options.CurrentValue;
|
||||
this._Context = context;
|
||||
}
|
||||
public DbContext ConnWriteOrRead(WriteAndReadEnum writeAndRead)
|
||||
{
|
||||
//判断枚举,不同的枚举可以创建不同的Context 或者更换Context链接;
|
||||
if (MutiDB_Enabled)
|
||||
{
|
||||
switch (writeAndRead)
|
||||
{
|
||||
case WriteAndReadEnum.Write:
|
||||
ToWrite();
|
||||
break; //选择链接//更换_Context链接 //选择链接
|
||||
case WriteAndReadEnum.Read:
|
||||
ToRead();
|
||||
break; //选择链接//更换_Context链接
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ToWrite();
|
||||
}
|
||||
|
||||
return _Context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更换成主库连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void ToWrite()
|
||||
{
|
||||
string conn = _readAndWrite.WriteUrl;
|
||||
//_Context.Database.GetDbConnection().;
|
||||
_Context.ToWriteOrRead(conn);
|
||||
}
|
||||
|
||||
|
||||
private static int _iSeed = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 更换成主库连接
|
||||
///
|
||||
/// ///策略---数据库查询的负载均衡
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void ToRead()
|
||||
{
|
||||
string conn = string.Empty;
|
||||
{
|
||||
// //随机
|
||||
//int Count= _readAndWrite.ReadConnectionList.Count;
|
||||
//int index= new Random().Next(0, Count);
|
||||
//conn = _readAndWrite.ReadConnectionList[index];
|
||||
}
|
||||
{
|
||||
//来一个轮询
|
||||
conn = this._readAndWrite.ReadUrl[_iSeed++ % this._readAndWrite.ReadUrl.Count];//轮询;
|
||||
}
|
||||
{
|
||||
///是不是可以直接配置到配置文件里面
|
||||
}
|
||||
_Context.ToWriteOrRead(conn);
|
||||
}
|
||||
|
||||
//public DbContext CreateContext()
|
||||
//{
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public interface IDbContextFactory
|
||||
{
|
||||
public DbContext ConnWriteOrRead(WriteAndReadEnum writeAndRead);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class menu :loopModel<menu>,ITreeModel<menu>
|
||||
{
|
||||
public string icon { get; set; }
|
||||
public string router { get; set; }
|
||||
public string menu_name { get; set; }
|
||||
|
||||
public List<role> roles { get; set; }
|
||||
public mould mould { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class mould:baseModel<int>
|
||||
{
|
||||
public string mould_name { get; set; }
|
||||
public string url { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class role:baseModel<int>
|
||||
{
|
||||
public string role_name { get; set; }
|
||||
public string introduce { get; set; }
|
||||
|
||||
|
||||
public List<menu> menus { get; set; }
|
||||
public List<user> users { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,21 +7,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class user:baseModel<int>
|
||||
public class User
|
||||
{
|
||||
public string username { get; set; }
|
||||
public string password { get; set; }
|
||||
public string icon { get; set; }
|
||||
public string nick { get; set; }
|
||||
public string email { get; set; }
|
||||
public string ip { get; set; }
|
||||
public int? age { get; set; }
|
||||
public string introduction { get; set; }
|
||||
public string address { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public string Nick { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Ip { get; set; }
|
||||
public int? Age { get; set; }
|
||||
public string Introduction { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string Phone { get; set; }
|
||||
|
||||
public List<role> roles { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class visit:baseModel<int>
|
||||
{
|
||||
public DateTime time { get; set; }
|
||||
public int num { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
public partial class DataContext :DbContext
|
||||
{
|
||||
public DbSet<menu> menu { get; set; }
|
||||
public DbSet<mould> mould { get; set; }
|
||||
public DbSet<role> role { get; set; }
|
||||
public DbSet<user> user { get; set; }
|
||||
public DbSet<visit> visit { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string dirPath= Path.Combine(solutionsPath,@"Yi.Framework.Model\Models\");
|
||||
DirectoryInfo dir = new DirectoryInfo(dirPath);
|
||||
FileInfo[] finfo = dir.GetFiles();
|
||||
string filenames = string.Empty;
|
||||
List<string> filenameList = new List<string>();
|
||||
for (int i = 0; i < finfo.Length; i++)
|
||||
{
|
||||
filenames = finfo[i].Name ;
|
||||
string[] f=filenames.Split('.');
|
||||
filenameList.Add(f[0]);
|
||||
}
|
||||
|
||||
|
||||
#>
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
public partial class DataContext :DbContext
|
||||
{
|
||||
<# foreach(string k in filenameList){
|
||||
#>
|
||||
public DbSet<<#=k #>> <#=k #> { get; set; }
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NEST" Version="7.16.0" />
|
||||
<PackageReference Include="Oracle.EntityFrameworkCore" Version="6.21.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -25,10 +17,6 @@
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DaraContext.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4DataContext.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DataContext.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -41,11 +29,11 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DaraContext.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="T4DataContext.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DataContext.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BaseModels\" />
|
||||
<Folder Include="ModelFactory\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public abstract class AbstractBuilder
|
||||
{
|
||||
|
||||
public abstract void Invoke(DataContext data);
|
||||
|
||||
private AbstractBuilder? NextBuilder=null;
|
||||
|
||||
|
||||
public void SetNext(AbstractBuilder? nextBuilder)
|
||||
{
|
||||
this.NextBuilder = nextBuilder;
|
||||
}
|
||||
|
||||
public void Next( DataContext data)
|
||||
{
|
||||
if (NextBuilder != null)
|
||||
{
|
||||
this.NextBuilder!.Invoke(data!);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class AccoutBuilder : AbstractBuilder
|
||||
{
|
||||
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//直接放行,并需要鉴权
|
||||
if (data!.AccountPathList!.Contains(data.Path!))
|
||||
{
|
||||
data.Result = Result.Success();
|
||||
}
|
||||
else//剩下的这个,就是最后真正的业务判断
|
||||
{
|
||||
base.Next(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class DataContext
|
||||
{
|
||||
//访问路径
|
||||
public string? Path { get; set; }
|
||||
|
||||
//是否为用于刷新的token
|
||||
public bool? IsRe { get; set; } = false;
|
||||
|
||||
//刷新令牌的路径
|
||||
public string? RefreshPath { get; set; }
|
||||
|
||||
//用户白名单
|
||||
public List<string>? UserWhitePathList { get; set; }
|
||||
|
||||
//白名单路径
|
||||
public List<string>? WhitePathList { get; set; }
|
||||
|
||||
//直接放行但是需要鉴权
|
||||
public List<string>? AccountPathList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户白名单
|
||||
/// </summary>
|
||||
public List<string>? TenantPathList { get; set; }
|
||||
|
||||
//public UserRoleMenuEntity? UserRoleMenuEntity { get; set; }
|
||||
|
||||
//最终的结果
|
||||
public Result Result { get; set; } = Result.UnAuthorize();
|
||||
|
||||
public HttpContext? Context { get; set; }
|
||||
|
||||
public CacheClientDB? DB { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public static class GateStartBuilder
|
||||
{
|
||||
public static void Run(DataContext dataContext)
|
||||
{
|
||||
Handler(dataContext);
|
||||
//基础
|
||||
AbstractBuilder whitelistBuilder = new WhiteListBuilder();
|
||||
AbstractBuilder tokenBuilder = new TokenBuilder();
|
||||
AbstractBuilder refreshBuilder = new RefreshBuilder();
|
||||
AbstractBuilder accoutBuilder = new AccoutBuilder();
|
||||
|
||||
//额外
|
||||
AbstractBuilder tenantBuilder = new TenantBuilder();
|
||||
AbstractBuilder userWhitelist = new UserWhitelistBuilder();
|
||||
|
||||
//最终
|
||||
AbstractBuilder menuBuilder = new MenuBuilder();
|
||||
|
||||
|
||||
whitelistBuilder.SetNext(tokenBuilder);
|
||||
tokenBuilder.SetNext(refreshBuilder);
|
||||
refreshBuilder.SetNext(accoutBuilder);
|
||||
accoutBuilder.SetNext(tenantBuilder);
|
||||
tenantBuilder.SetNext(userWhitelist);
|
||||
userWhitelist.SetNext(menuBuilder);
|
||||
whitelistBuilder.Invoke(dataContext);
|
||||
}
|
||||
|
||||
public static void Handler(DataContext dataContext)
|
||||
{
|
||||
dataContext.Path = dataContext.Path!.ToUpper();
|
||||
dataContext.RefreshPath = dataContext.RefreshPath!.ToUpper();
|
||||
dataContext.WhitePathList = dataContext.WhitePathList!.Select(white => white.ToUpper()).ToList();
|
||||
dataContext.AccountPathList = dataContext.AccountPathList!.Select(white => white.ToUpper()).ToList();
|
||||
dataContext.TenantPathList = dataContext.TenantPathList!.Select(white => white.ToUpper()).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class MenuBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//var redisData = data!.DB!.Get<UserRoleMenuEntity>(RedisConst.GetStr(RedisConst.UserRoleMenu, data.UserRoleMenuEntity!.user.Account));
|
||||
//if (redisData.IsNotNull())
|
||||
//{
|
||||
// var menus = redisData.menus;
|
||||
// if (menus.Where(u=> u.TypeCode == (short)MenuTypeEnum.Hide).Select(u => u.UrlControl.ToUpper()).Contains(data.Path))
|
||||
// {
|
||||
|
||||
// data.Result = Result.Success();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// data.Result = Result.SuccessError("当前令牌无接口权限");
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// data.Result = Result.UnAuthorize("用户信息已经过期");
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class RefreshBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//如果是刷新令牌
|
||||
if ((bool)data!.IsRe!)
|
||||
{
|
||||
//且访问路径还是正确的
|
||||
if (data.Path == data.RefreshPath)
|
||||
{
|
||||
data.Result = Result.Success();
|
||||
}
|
||||
}
|
||||
else//表示不是刷新的token,就要去redis里面判断了
|
||||
{
|
||||
|
||||
base.Next(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class TenantBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
|
||||
if (data!.TenantPathList!.Contains(""/*data.UserRoleMenuEntity!.tenant.TenantName*/))
|
||||
{
|
||||
data.Result = Result.Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Next(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class TokenBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//先鉴权
|
||||
//var userRoleMenuEntity = data!.Context.GetCurrentUserInfo();
|
||||
|
||||
|
||||
|
||||
|
||||
////鉴权失败表示没有带token
|
||||
//if (userRoleMenuEntity.IsNull())
|
||||
//{
|
||||
// //访问的路径是刷新令牌的,失败了直接返回令牌刷新失败
|
||||
// if (data.Path == data.RefreshPath)
|
||||
// {
|
||||
// data.Result = Result.Expire(ResultCode.RefreshTokenExpire);
|
||||
// }
|
||||
|
||||
//}
|
||||
//else//鉴权成功,访问含有token
|
||||
//{
|
||||
// //将数据存入上下文对象中
|
||||
// data.UserRoleMenuEntity = userRoleMenuEntity;
|
||||
// if (userRoleMenuEntity.RefreshToken == "true")
|
||||
// {
|
||||
// data.IsRe = true;
|
||||
// }
|
||||
// data.Context!.Request.Headers.Add("Account", userRoleMenuEntity.user.Account);
|
||||
// data.Context!.Request.Headers.Add("Id", userRoleMenuEntity.user.Id.ToString());
|
||||
// data.Context!.Request.Headers.Add("Name", userRoleMenuEntity.user.Name);
|
||||
// data.Context!.Request.Headers.Add("TenantId", userRoleMenuEntity.user.TenantId.ToString());
|
||||
// data.Context!.Request.Headers.Add("TenantLevel", userRoleMenuEntity.tenant.TenantLevel.ToString());
|
||||
base.Next(data);
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class UserWhitelistBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//if (data!.UserWhitePathList!.Contains(data.UserRoleMenuEntity!.user.Account))
|
||||
//{
|
||||
// data.Result = Result.Success();
|
||||
//}
|
||||
//else
|
||||
{
|
||||
base.Next(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.Builder
|
||||
{
|
||||
public class WhiteListBuilder : AbstractBuilder
|
||||
{
|
||||
public override void Invoke(DataContext data)
|
||||
{
|
||||
//如果在白名单,直接通行
|
||||
if (data!.WhitePathList!.Contains(data.Path!))
|
||||
{
|
||||
|
||||
data.Result = Result.Success();
|
||||
}
|
||||
//访问的是swagger
|
||||
else if (data.Path!.Split("/")[1].ToUpper() == "swagger".ToUpper())
|
||||
{
|
||||
data.Result = Result.Success();
|
||||
}
|
||||
else//否则进入下一个管道处理
|
||||
{
|
||||
|
||||
base.Next(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Yi.Framework.OcelotGateway</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="P:Yi.Framework.OcelotGateway.Builder.DataContext.TenantPathList">
|
||||
<summary>
|
||||
租户白名单
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
@@ -0,0 +1,65 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.OcelotGateway.Builder;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway.WebCore
|
||||
{
|
||||
public class OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate next;
|
||||
private CacheClientDB _cacheClientDB;
|
||||
public OcelotMiddleware(RequestDelegate next, CacheClientDB cacheClientDB)
|
||||
{
|
||||
this.next = next;
|
||||
this._cacheClientDB = cacheClientDB;
|
||||
|
||||
}
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
//--------------------------------------访问路径--------------------------------------------
|
||||
var path = context.Request.Path.Value!;
|
||||
var authorizationOptions= Appsettings.app<AuthorizationOptions>("AuthorizationOptions");
|
||||
//-------------------------------------刷新令牌路径-----------------------------------------------
|
||||
string refresh = authorizationOptions.Refresh;
|
||||
//-------------------------------------白名单------------------------------------------------
|
||||
List<string> whiteList = authorizationOptions.WhiteList;
|
||||
//------------------------------------白名单需鉴权------------------------------------------
|
||||
List<string> accountList = authorizationOptions.AccountList;
|
||||
//------------------------------------用户白名单------------------------------------------
|
||||
List<string> userList = authorizationOptions.UserList;
|
||||
//------------------------------------租户白名单------------------------------------------
|
||||
List<string> tenantList = authorizationOptions.TenantList;
|
||||
|
||||
|
||||
//--------------------------------------开始组装管道---------------------------------------------
|
||||
DataContext dataContext = new() {TenantPathList= tenantList, Context = context,UserWhitePathList=userList, AccountPathList = accountList, WhitePathList = whiteList, RefreshPath = refresh, Path = path, DB = _cacheClientDB };
|
||||
//--------------------------------------管道执行---------------------------------------------
|
||||
GateStartBuilder.Run(dataContext);
|
||||
//--------------------------------------处理结果---------------------------------------------
|
||||
if (dataContext.Result.status)
|
||||
{
|
||||
//--------------------------------------中间件执行---------------------------------------------
|
||||
await next(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(Common.Helper.JsonHelper.ObjToStr(dataContext.Result));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class OcelotExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseOcelotExtensionService(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<OcelotMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>D:\CC.Yi\CC.Yi\Yi.Framework.Net6\Yi.Framework.OcelotGateway\SwaggerDoc.xml</DocumentationFile>
|
||||
<DocumentationFile>./Config/SwaggerDoc.xml</DocumentationFile>
|
||||
<NoWarn>1701;1702;CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
70
Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs
Normal file
70
Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Yi.Framework.Repository
|
||||
{
|
||||
public class DataContext<T> : SimpleClient<T> where T : class, new()
|
||||
{
|
||||
public DataContext(ISqlSugarClient context = null!) : base(context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
base.Context = Db;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// SqlSugarScope操作数据库是线程安的可以单例
|
||||
/// </summary>
|
||||
public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.MySql,
|
||||
//ConnectionString = Appsettings.app("ConnectionStrings","mysqlConnection") ,
|
||||
IsAutoCloseConnection = true
|
||||
},
|
||||
db =>
|
||||
{
|
||||
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
//var httpcontext = ServiceLocator.Instance.GetService<IHttpContextAccessor>().HttpContext;
|
||||
switch (entityInfo.OperationType)
|
||||
{
|
||||
case DataFilterType.InsertByObject:
|
||||
if (entityInfo.PropertyName == "CreateUser")
|
||||
{
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
|
||||
}
|
||||
|
||||
if (entityInfo.PropertyName == "TenantId")
|
||||
{
|
||||
//现在不能直接给了,要根据判断一下租户等级,如果租户等级是1,不给,需要自己去赋值,如果租户等级是0,就执行下面的。
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["TenantId"].ToString()));
|
||||
//查询的时候,也需要判断一下,如果是租户等级,不要租户条件,如果是超级租户,就返回所有
|
||||
}
|
||||
break;
|
||||
case DataFilterType.UpdateByObject:
|
||||
if (entityInfo.PropertyName == "ModifyTime")
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
if (entityInfo.PropertyName == "ModifyUser")
|
||||
{
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
//inset生效
|
||||
|
||||
};
|
||||
//如果用单例配置要统一写在这儿
|
||||
db.Aop.OnLogExecuting = (s, p) =>
|
||||
{
|
||||
|
||||
Console.WriteLine("_______________________________________________");
|
||||
Console.WriteLine(s);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
31
Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
Normal file
31
Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Repository
|
||||
{
|
||||
public interface IRepository<T> : ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
public Task<T> InsertReturnEntityAsync(T entity);
|
||||
public object CommonPage(QueryParameters pars, int pageIndex, int pageSize);
|
||||
public object CommonPage(QueryParameters pars, int pageIndex, int pageSize, bool whereBool, Expression<Func<T, bool>> where);
|
||||
|
||||
public object CommonPageMapper<T2, TT>(Expression<Func<TT, ManyToMany>> expression, QueryParameters pars, int pageIndex, int pageSize, bool whereBool, Expression<Func<T, bool>> where);
|
||||
|
||||
public Task<T> FirstMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression, bool isTenant = true);
|
||||
|
||||
public Task<List<T>> ToListMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression, bool isTenant = true);
|
||||
|
||||
public Task<List<T>> ToListMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression, bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true);
|
||||
|
||||
public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true);
|
||||
|
||||
public Task<List<T>> GetListAsync(bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true);
|
||||
public Task<List<S>> StoreAsync<S>(string storeName, object para);
|
||||
|
||||
}
|
||||
}
|
||||
321
Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
Normal file
321
Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using SqlSugar;
|
||||
using System.Data;
|
||||
using System.Linq.Expressions;
|
||||
using static Yi.Framework.Repository.QueryParametersExtensions;
|
||||
|
||||
/***这里面写的代码不会给覆盖,如果要重新生成请删除 Repository.cs ***/
|
||||
namespace Yi.Framework.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 仓储模式
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class Repository<T> : DataContext<T> ,IRepository<T> where T : class, new()
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
base.Context = Db;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<T> InsertReturnEntityAsync(T entity)
|
||||
{
|
||||
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// whereif与where混搭,多租户
|
||||
/// </summary>
|
||||
/// <param name="whereExpression"></param>
|
||||
/// <param name="whereBool"></param>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true)
|
||||
{
|
||||
return await Db.Queryable<T>().WhereIF(whereBool, where).Where(whereExpression).WhereTenant(isTenant).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// where重载,多租户
|
||||
/// </summary>
|
||||
/// <param name="whereBool"></param>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> GetListAsync(bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true)
|
||||
{
|
||||
return await Db.Queryable<T>().WhereIF(whereBool, where).WhereTenant(isTenant). ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 左连接,三表连接,返回最右边的列表,多租户
|
||||
/// </summary>
|
||||
/// <typeparam name="M"></typeparam>
|
||||
/// <typeparam name="R"></typeparam>
|
||||
/// <param name="joinQueryable1"></param>
|
||||
/// <param name="joinQueryable12"></param>
|
||||
/// <param name="whereLambda"></param>
|
||||
/// <param name="selectLambda"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<R>> LeftJoinListAsync<M, R>(Expression<Func<T, M, bool>> joinQueryable1, Expression<Func<T, M, R, bool>> joinQueryable12, Expression<Func<T, bool>> whereLambda, Expression<Func<T, M, R>> selectLambda, bool isTenant = true)
|
||||
{
|
||||
return await Db.Queryable<T>().LeftJoin<M>(joinQueryable1)
|
||||
.LeftJoin<R>(joinQueryable12)
|
||||
.Where(whereLambda)
|
||||
.WhereTenant(isTenant)
|
||||
.Select(selectLambda)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
||||
{
|
||||
return await Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用sql
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="para"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<DataTable> SqlDataTableAsync(string sql, object para = null)
|
||||
{
|
||||
return await Db.Ado.GetDataTableAsync(sql, para);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性mapper返回一个,多租户
|
||||
/// </summary>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> FirstMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression,bool isTenant=true)
|
||||
{
|
||||
return await Db.Queryable<T>().Mapper<T, T2, TT>(expression).WhereTenant(isTenant).FirstAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性mapper返回一组,多租户
|
||||
/// </summary>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> ToListMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression, bool isTenant = true)
|
||||
{
|
||||
return await Db.Queryable<T>() .Mapper<T, T2, TT>(expression).WhereTenant(isTenant).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性mapper返回一组.同时添加条件,多租户
|
||||
/// </summary>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="expression"></param>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> ToListMapperAsync<T2, TT>(Expression<Func<TT, ManyToMany>> expression, bool whereBool, Expression<Func<T, bool>> where, bool isTenant = true)
|
||||
{
|
||||
return await Db.Queryable<T>().Mapper<T, T2, TT>(expression).WhereIF(whereBool,where).WhereTenant(isTenant).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 仓储扩展方法:单表查询通用分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object CommonPage(QueryParameters pars, int pageIndex, int pageSize)
|
||||
{
|
||||
int tolCount = 0;
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
}).ToList();
|
||||
var query = Db.Queryable<T>();
|
||||
if (pars.OrderBys != null)
|
||||
{
|
||||
foreach (var item in pars.OrderBys)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter());//格式 id asc或者 id desc
|
||||
}
|
||||
}
|
||||
var result = query.Where(sugarParamters).ToPageList(pageIndex, pageSize, ref tolCount);
|
||||
return new
|
||||
{
|
||||
count = tolCount,
|
||||
data = result
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 额外添加动态条件拼接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object CommonPage(QueryParameters pars, int pageIndex, int pageSize, bool whereBool, Expression<Func<T, bool>> where)
|
||||
{
|
||||
int tolCount = 0;
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
}).ToList();
|
||||
var query = Db.Queryable<T>();
|
||||
if (pars.OrderBys != null)
|
||||
{
|
||||
foreach (var item in pars.OrderBys)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter());//格式 id asc或者 id desc
|
||||
}
|
||||
}
|
||||
var result = query.WhereIF(whereBool, where).Where(sugarParamters).ToPageList(pageIndex, pageSize, ref tolCount);
|
||||
return new
|
||||
{
|
||||
count = tolCount,
|
||||
data = result
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性mapper分页多条件
|
||||
/// </summary>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
public object CommonPageMapper<T2, TT>(Expression<Func<TT, ManyToMany>> expression, QueryParameters pars, int pageIndex, int pageSize,bool whereBool, Expression<Func<T, bool>> where)
|
||||
{
|
||||
int tolCount = 0;
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
}).ToList();
|
||||
var query = Db.Queryable<T>();
|
||||
if (pars.OrderBys != null)
|
||||
{
|
||||
foreach (var item in pars.OrderBys)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter());//格式 id asc或者 id desc
|
||||
}
|
||||
}
|
||||
var result = query.Mapper < T, T2, TT>(expression).WhereIF(whereBool, where). Where(sugarParamters).ToPageList(pageIndex, pageSize, ref tolCount);
|
||||
return new
|
||||
{
|
||||
count = tolCount,
|
||||
data = result
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用查询参数
|
||||
/// </summary>
|
||||
public class QueryParameters
|
||||
{
|
||||
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
|
||||
public List<string> OrderBys { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
public static class QueryParametersExtensions
|
||||
{
|
||||
|
||||
public static ISugarQueryable<T,M,R> WhereTenant<T, M, R>(this ISugarQueryable<T, M, R> db, bool isTenant = true)
|
||||
{
|
||||
if (isTenant)
|
||||
{
|
||||
var sugarParamters = new QueryParameters().SetParameters(new Dictionary<string, string>()).Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
}).ToList();
|
||||
return db.Where(sugarParamters);
|
||||
}
|
||||
|
||||
|
||||
return db;
|
||||
|
||||
}
|
||||
public static ISugarQueryable<T> WhereTenant<T>(this ISugarQueryable<T> db, bool isTenant = true)
|
||||
{
|
||||
if (isTenant)
|
||||
{
|
||||
var sugarParamters = new QueryParameters().SetParameters(new Dictionary<string, string>()).Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
}).ToList();
|
||||
return db.Where(sugarParamters);
|
||||
}
|
||||
|
||||
return db;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static QueryParameters SetParameters(this QueryParameters queryParameters, Dictionary<string, string> dic,bool IsTenant=true)
|
||||
{
|
||||
//var httpcontext = ServiceLocator.Instance.GetService<IHttpContextAccessor>().HttpContext;
|
||||
queryParameters.OrderBys = new List<string> { "CreateTime" };
|
||||
|
||||
|
||||
foreach (var p in dic)
|
||||
{
|
||||
QueryParameter qp = null;
|
||||
if (p.Key == "IsDeleted" || p.Key=="Id")
|
||||
{
|
||||
qp= new QueryParameter() { FieldName = p.Key, FieldValue = p.Value, ConditionalType = ConditionalType.Equal };
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qp= new QueryParameter() { FieldName = p.Key, FieldValue = p.Value };
|
||||
|
||||
}
|
||||
queryParameters.Parameters.Add(qp);
|
||||
}
|
||||
if (IsTenant)
|
||||
{
|
||||
//if (httpcontext.Request.Headers["TenantLevel"].ToString() == "0")
|
||||
//{
|
||||
// queryParameters.Parameters.Add(new QueryParameter() { ConditionalType = ConditionalType.Equal, FieldName = "TenantId", FieldValue = httpcontext.Request.Headers["TenantId"].ToString() });
|
||||
//}
|
||||
}
|
||||
|
||||
return queryParameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用查询参数
|
||||
/// </summary>
|
||||
public class QueryParameter
|
||||
{
|
||||
public string FieldName { get; set; }
|
||||
public string FieldValue { get; set; }
|
||||
public ConditionalType ConditionalType { get; set; } = ConditionalType.Like;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SqlSugarCore" Version="5.0.6.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,136 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class BaseService<T> : IBaseService<T> where T : class, new()
|
||||
{
|
||||
public DbContext _Db;
|
||||
public DbContext _DbRead;
|
||||
public IDbContextFactory _DbFactory;
|
||||
public BaseService(IDbContextFactory DbFactory)
|
||||
{
|
||||
_DbFactory = DbFactory;
|
||||
_Db = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Write);
|
||||
_DbRead = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Read);
|
||||
}
|
||||
|
||||
public async Task<T> GetEntityById(int id)
|
||||
{
|
||||
return await _Db.Set<T>().FindAsync(id);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<T>> GetAllEntitiesAsync()
|
||||
{
|
||||
return await _Db.Set<T>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetEntitiesAsync(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return await _Db.Set<T>().Where(whereLambda).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> GetCountAsync(Expression<Func<T, bool>> whereLambda) //统计数量
|
||||
{
|
||||
return await _Db.Set<T>().CountAsync(whereLambda);
|
||||
}
|
||||
|
||||
public IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda) //分组
|
||||
{
|
||||
return _Db.Set<T>().Where(whereLambda).GroupBy(groupByLambda).AsQueryable();
|
||||
}
|
||||
|
||||
public async Task<Tuple<IEnumerable<T>, int>> GetPageEntities<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
||||
{
|
||||
int total = await GetCountAsync(whereLambda);
|
||||
|
||||
IEnumerable<T> pageData;
|
||||
if (isAsc)
|
||||
{
|
||||
pageData = await _Db.Set<T>().Where(whereLambda)
|
||||
.OrderBy<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
pageData = await _Db.Set<T>().Where(whereLambda)
|
||||
.OrderByDescending<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).ToListAsync();
|
||||
}
|
||||
|
||||
return Tuple.Create<IEnumerable<T>, int>(pageData, total);
|
||||
}
|
||||
|
||||
public async Task<bool> AddAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Add(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> AddAsync(IEnumerable<T> entities)
|
||||
{
|
||||
_Db.Set<T>().AddRange(entities);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Update(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateListAsync(IEnumerable<T> entities)
|
||||
{
|
||||
_Db.Set<T>().UpdateRange(entities);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Remove(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
_Db.Set<T>().Remove(await GetEntityById(id));
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(IEnumerable<int> ids)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
_Db.Set<T>().RemoveRange(await GetEntityById(id));
|
||||
}
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
public async Task<bool> DeleteAsync(Expression<Func<T, bool>> where)
|
||||
{
|
||||
IEnumerable<T> entities = await GetEntitiesAsync(where);
|
||||
if (entities != null)
|
||||
{
|
||||
_Db.Set<T>().RemoveRange(entities);
|
||||
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<T> GetEntity(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return await _Db.Set<T>().Where(whereLambda).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MenuService:BaseService<menu>, IMenuService
|
||||
{
|
||||
short Normal = (short)DelFlagEnum.Normal;
|
||||
public async Task<menu> AddChildrenMenu(int menu_id, menu _children)
|
||||
{
|
||||
_children.parentId = menu_id;
|
||||
_children.is_top = (short)TopFlagEnum.Children;
|
||||
_children.is_delete = (short)DelFlagEnum.Normal;
|
||||
await AddAsync(_children);
|
||||
return _children;
|
||||
}
|
||||
|
||||
public async Task<bool> AddTopMenu(menu _menu)
|
||||
{
|
||||
_menu.is_top = (short)TopFlagEnum.Children;
|
||||
|
||||
return await AddAsync(_menu);
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuInMould()
|
||||
{
|
||||
var menu_data = await _DbRead.Set<menu>().Include(u => u.mould).Where(u=>u.is_delete==(short)DelFlagEnum.Normal).ToListAsync();
|
||||
return TreeHelper.SetTree(menu_data, null)[0]; ;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<menu>> GetTopMenusByTopMenuIds(List<int> menuIds)
|
||||
{
|
||||
return await _DbRead.Set<menu>().AsNoTracking().Where(u => menuIds.Contains(u.id)).OrderBy(u=>u.sort).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<menu> SetMouldByMenu(int id1,int id2)
|
||||
{
|
||||
var menu_data = await _DbRead.Set<menu>().Include(u => u.mould).Where(u => u.id == id1).FirstOrDefaultAsync();
|
||||
var mould_data = await _DbRead.Set<mould>().Where(u => u.id == id1).FirstOrDefaultAsync();
|
||||
menu_data.mould = mould_data;
|
||||
_Db.Update(menu_data);
|
||||
return menu_data;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<menu>> GetTopMenuByUserId(int userId)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).Where(u=>u.id==userId).FirstOrDefaultAsync();
|
||||
List<menu> menuList = new();
|
||||
user_data.roles.ForEach(u =>
|
||||
{
|
||||
var m = u.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
menuList = menuList.Union(m).ToList();
|
||||
});
|
||||
|
||||
var menuIds=menuList.Select(u => u.id).ToList();
|
||||
|
||||
return await _DbRead.Set<menu>().Include(u => u.mould).Where(u => menuIds.Contains(u.id)).ToListAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MouldService:BaseService<mould>, IMouldService
|
||||
{
|
||||
/// <summary>
|
||||
/// 这个获取的是菜单,用的是菜单表,应该放到菜单service里面,像这种只用到id的,就传一个id就可以了
|
||||
/// </summary>
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<menu> GetMenuByMould(mould _mould)
|
||||
{
|
||||
var menu_data = await _Db.Set<menu>().Include(u => u.mould).Where(u => u.mould == _mould && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync();
|
||||
return menu_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService : BaseService<role>, IRoleService
|
||||
{
|
||||
short Normal = (short)Common.Enum.DelFlagEnum.Normal;
|
||||
|
||||
public async Task<List<role>> GetRolesByUserId(int userId)
|
||||
{
|
||||
var user_data = await _Db.Set<user>().Include(u => u.roles).Where(u => u.id == userId).FirstOrDefaultAsync();
|
||||
var roleList = user_data.roles.Where(u => u.is_delete == Normal).ToList();
|
||||
roleList.ForEach(u => u.users = null);
|
||||
return roleList;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> SetMenusByRolesId(List<int> menuIds, List<int> roleIds)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => roleIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
var menuList = await _Db.Set<menu>().Where(u => menuIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
foreach (var role in role_data)
|
||||
{
|
||||
role.menus = menuList;
|
||||
}
|
||||
return await UpdateListAsync(role_data);
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByRoleId(List<int> roleIds)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => roleIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
List<menu> menuList = new();
|
||||
role_data.ForEach(u =>
|
||||
{
|
||||
var m = u.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
menuList = menuList.Union(m).ToList();
|
||||
});
|
||||
return menuList;
|
||||
}
|
||||
public async Task<List<menu>> GetTopMenusByRoleId(int roleId)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => u.id == roleId).FirstOrDefaultAsync();
|
||||
var menuList = role_data.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
|
||||
menuList.ForEach(u => u.roles = null);
|
||||
|
||||
return menuList;
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByRole(int roleId)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => u.id == roleId).FirstOrDefaultAsync();
|
||||
var menuList = role_data.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
return menuList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
|
||||
public partial class MenuService:BaseService<menu>,IMenuService
|
||||
{
|
||||
public MenuService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var menuList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
menuList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(menuList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<menu>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class MouldService:BaseService<mould>,IMouldService
|
||||
{
|
||||
public MouldService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var mouldList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
mouldList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(mouldList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<mould>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class RoleService:BaseService<role>,IRoleService
|
||||
{
|
||||
public RoleService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var roleList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
roleList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(roleList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<role>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class UserService:BaseService<user>,IUserService
|
||||
{
|
||||
public UserService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var userList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
userList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(userList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<user>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class VisitService:BaseService<visit>,IVisitService
|
||||
{
|
||||
public VisitService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var visitList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
visitList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(visitList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<visit>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string dirPath= Path.Combine(solutionsPath,@"Yi.Framework.Model\Models\");
|
||||
DirectoryInfo dir = new DirectoryInfo(dirPath);
|
||||
FileInfo[] finfo = dir.GetFiles();
|
||||
string filenames = string.Empty;
|
||||
List<string> filenameList = new List<string>();
|
||||
for (int i = 0; i < finfo.Length; i++)
|
||||
{
|
||||
filenames = finfo[i].Name ;
|
||||
string[] fname=filenames.Split('.');
|
||||
filenameList.Add(fname[0]);
|
||||
}
|
||||
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
<# foreach(string k in filenameList){
|
||||
string fn= k.Substring(0,1).ToUpper()+k.Substring(1);
|
||||
#>
|
||||
|
||||
public partial class <#= fn #>Service:BaseService<<#= k #>>,I<#= fn #>Service
|
||||
{
|
||||
public <#= fn #>Service(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var <#= k #>List = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
<#= k #>List.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(<#= k #>List);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<<#= k #>>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@@ -8,106 +7,15 @@ using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class UserService : BaseService<user>, IUserService
|
||||
public partial class UserService : Repository<User>, IUserService
|
||||
{
|
||||
CacheClientDB _cacheClientDB;
|
||||
public UserService(CacheClientDB cacheClientDB, IDbContextFactory DbFactory) : base(DbFactory)
|
||||
{
|
||||
_cacheClientDB = cacheClientDB;
|
||||
}
|
||||
short Normal = (short)Common.Enum.DelFlagEnum.Normal;
|
||||
public async Task<bool> PhoneIsExsit(string smsAddress)
|
||||
{
|
||||
var userList = await GetEntity(u => u.phone == smsAddress);
|
||||
if (userList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> EmailIsExsit(string emailAddress)
|
||||
{
|
||||
var userList = await GetEntity(u => u.email == emailAddress);
|
||||
if (userList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<user> GetUserById(int userId)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).ThenInclude(u => u.mould).Where(u => u.id == userId).FirstOrDefaultAsync();
|
||||
return user_data;
|
||||
|
||||
}
|
||||
public async Task<List<menu>> GetAxiosByRouter(string router, List<int> menuIds)
|
||||
{
|
||||
var menu_data= await _DbRead.Set<menu>().Where(u => u.router.Trim().ToUpper() == router.Trim().ToUpper() && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync();
|
||||
return await _DbRead.Set<menu>().Include(u=>u.mould).Where(u => u.parentId == menu_data.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuByHttpUser(List<int> allMenuIds)
|
||||
{
|
||||
var topMenu = await _DbRead.Set<menu>().Where(u => allMenuIds.Contains(u.id)&& u.is_show == (short)Common.Enum.ShowFlagEnum.Show && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
//现在要开始关联菜单了
|
||||
return TreeHelper.SetTree(topMenu)[0];
|
||||
}
|
||||
public async Task<user> GetUserInRolesByHttpUser(int userId)
|
||||
{
|
||||
var data = await GetUserById(userId);
|
||||
data.roles?.ForEach(u =>
|
||||
{
|
||||
u.users = null;
|
||||
u.menus = null;
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<user> Login(user _user)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).Where(u => u.username == _user.username && u.password == _user.password && u.is_delete == Normal).FirstOrDefaultAsync();
|
||||
return user_data;
|
||||
}
|
||||
|
||||
public async Task<bool> Register(user _user)
|
||||
{
|
||||
var user_data = await GetEntity(u => u.username == _user.username);
|
||||
if (user_data != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return await UpdateAsync(_user);
|
||||
}
|
||||
|
||||
public async Task<bool> SetRoleByUser(List<int> roleIds, List<int> userIds)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).Where(u => userIds.Contains(u.id)).ToListAsync();
|
||||
var roleList = await _DbRead.Set<role>().Where(u => roleIds.Contains(u.id)).ToListAsync();
|
||||
user_data.ForEach(u => u.roles = roleList);
|
||||
return await UpdateListAsync(user_data);
|
||||
}
|
||||
|
||||
public bool SaveUserApi(int userId, List<menuDto> menus)
|
||||
{
|
||||
return _cacheClientDB.Set(RedisConst.userMenusApi + ":" + userId.ToString(), menus, new TimeSpan(0, 30, 0));
|
||||
}
|
||||
public List<int> GetCurrentMenuInfo(int userId)
|
||||
{
|
||||
return _cacheClientDB.Get<List<menuDto>>(RedisConst.userMenusApi + ":" + userId).Select(u => u.id).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,11 @@
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4Service.tt">
|
||||
<LastGenOutput>T4Service.cs</LastGenOutput>
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
</None>
|
||||
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4Service.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4Service.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using System;
|
||||
@@ -7,7 +6,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Job
|
||||
@@ -15,11 +13,9 @@ namespace Yi.Framework.Job
|
||||
public class VisitJob : IJob
|
||||
{
|
||||
private ILogger<VisitJob> _logger;
|
||||
private DbContext _DBWrite;
|
||||
public VisitJob(ILogger<VisitJob> logger, IDbContextFactory DbFactory)
|
||||
public VisitJob(ILogger<VisitJob> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_DBWrite = DbFactory.ConnWriteOrRead(Common.Enum.WriteAndReadEnum.Write);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,8 +27,6 @@ namespace Yi.Framework.Job
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_DBWrite.Set<visit>().Add(new visit() { num = JobModel.visitNum, time = DateTime.Now });
|
||||
_DBWrite.SaveChanges();
|
||||
_logger.LogWarning("定时任务开始调度:" + nameof(VisitJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问总数为:{JobModel.visitNum}");
|
||||
JobModel.visitNum = 0;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.WebCore.AuthorizationPolicy
|
||||
@@ -45,15 +44,15 @@ namespace Yi.Framework.WebCore.AuthorizationPolicy
|
||||
//现在只需要登录的时候把用户的api路径添加到redis去
|
||||
//每次访问的时候进行redis判断一下即可
|
||||
//注意一下,redis不能一直保存,和jwt一样搞一个期限
|
||||
var menuList=_cacheClientDB.Get<List<menuDto>>(RedisConst.userMenusApi+":"+currentUserId);
|
||||
foreach (var k in menuList)
|
||||
{
|
||||
if (k.mould != null)
|
||||
{
|
||||
dicMenueDictionary.Add(k.mould?.id.ToString(), "/api"+ k.mould?.url);
|
||||
}
|
||||
//var menuList=_cacheClientDB.Get<List<menuDto>>(RedisConst.userMenusApi+":"+currentUserId);
|
||||
//foreach (var k in menuList)
|
||||
//{
|
||||
// if (k.mould != null)
|
||||
// {
|
||||
// dicMenueDictionary.Add(k.mould?.id.ToString(), "/api"+ k.mould?.url);
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
if (dicMenueDictionary.ContainsValue(httpcontext.Request.Path))
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Yi.Framework.WebCore
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
public static user GetCurrentUserInfo(this HttpContext httpContext, out List<int> menuIds)
|
||||
public static User GetCurrentUserInfo(this HttpContext httpContext, out List<int> menuIds)
|
||||
{
|
||||
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
||||
|
||||
@@ -40,22 +40,22 @@ namespace Yi.Framework.WebCore
|
||||
menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => Convert.ToInt32(u.Value)).ToList();
|
||||
|
||||
|
||||
return new user()
|
||||
return new User()
|
||||
{
|
||||
id = resId,
|
||||
username = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value ?? "匿名"
|
||||
Id = resId,
|
||||
Username = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value ?? "匿名"
|
||||
};
|
||||
}
|
||||
public static user GetCurrentUserInfo(this HttpContext httpContext)
|
||||
public static User GetCurrentUserInfo(this HttpContext httpContext)
|
||||
{
|
||||
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
||||
|
||||
Int32.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value, out int resId);
|
||||
|
||||
return new user()
|
||||
return new User()
|
||||
{
|
||||
id = resId,
|
||||
username = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value ?? "匿名"
|
||||
Id = resId,
|
||||
Username = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value ?? "匿名"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.WebCore.Init
|
||||
{
|
||||
public class DataSeed
|
||||
{
|
||||
public async static Task SeedAsync(IDbContextFactory _DbFactory)
|
||||
{
|
||||
var _Db = _DbFactory.ConnWriteOrRead(Common.Enum.WriteAndReadEnum.Write);
|
||||
if (!_Db.Set<user>().Any())
|
||||
{
|
||||
List<menu> menus = new List<menu>{
|
||||
|
||||
new menu{ id=1, menu_name="根",is_show=1,is_top=1},
|
||||
new menu{ id=2,icon="mdi-view-dashboard", menu_name="首页",is_show=1,is_top=0,router="/",parentId=1},
|
||||
new menu{id=3,icon="mdi-account-box-multiple", menu_name="用户角色管理",is_show=1,is_top=0,parentId=1},
|
||||
|
||||
new menu{id=4,icon="mdi-account-box", menu_name="用户管理",router="/AdmUser/",is_show=1,is_top=0,parentId=3},
|
||||
new menu{id=5, menu_name="get",is_show=0,is_top=0,parentId=4,mould=new mould{mould_name="get",url="/user/getuser" } },
|
||||
new menu{id=6, menu_name="update",is_show=0,is_top=0,parentId=4,mould=new mould{mould_name="update",url="/user/updateuser" } },
|
||||
new menu{id=7, menu_name="del",is_show=0,is_top=0,parentId=4,mould=new mould{mould_name="del",url="/user/dellistUser" } },
|
||||
new menu{id=8, menu_name="add",is_show=0,is_top=0,parentId=4,mould=new mould{mould_name="add",url="/role/adduser" } },
|
||||
|
||||
new menu{ id=9,icon="mdi-account-circle", menu_name="角色管理",router="/admrole/",is_show=1,is_top=0,parentId=3},
|
||||
new menu{id=10, menu_name="get",is_show=0,is_top=0,parentId=9,mould=new mould{mould_name="get",url="/role/getrole" } },
|
||||
new menu{id=11, menu_name="update",is_show=0,is_top=0,parentId=9,mould=new mould{mould_name="update",url="/role/updaterole" } },
|
||||
new menu{id=12, menu_name="del",is_show=0,is_top=0,parentId=9,mould=new mould{mould_name="del",url="/role/dellistrole" } },
|
||||
new menu{id=13, menu_name="add",is_show=0,is_top=0,parentId=9,mould=new mould{mould_name="add",url="/role/addrole" } },
|
||||
|
||||
|
||||
new menu{ id=14,icon="mdi-account-cash", menu_name="角色接口管理",is_show=1,is_top=0,parentId=1},
|
||||
|
||||
|
||||
new menu{ id=15,icon="mdi-clipboard-check-multiple", menu_name="菜单管理",router="/AdmMenu/",is_show=1,is_top=0,parentId=14},
|
||||
new menu{id=16, menu_name="get",is_show=0,is_top=0,parentId=15,mould=new mould{mould_name="get",url="/menu/getmenu" } },
|
||||
new menu{id=17, menu_name="update",is_show=0,is_top=0,parentId=15,mould=new mould{mould_name="update",url="/menu/updatemenu" } },
|
||||
new menu{id=18, menu_name="del",is_show=0,is_top=0,parentId=15,mould=new mould{mould_name="del",url="/menu/dellistmenu" } },
|
||||
new menu{id=19, menu_name="add",is_show=0,is_top=0,parentId=15,mould=new mould{mould_name="add",url="/menu/addmenu" } },
|
||||
|
||||
|
||||
|
||||
new menu{ id=20,icon="mdi-circle-slice-8", menu_name="接口管理",router="/admMould/",is_show=1,is_top=0,parentId=14},
|
||||
new menu{id=21, menu_name="get",is_show=0,is_top=0,parentId=20,mould=new mould{mould_name="get",url="/Mould/getMould" } },
|
||||
new menu{id=22, menu_name="update",is_show=0,is_top=0,parentId=20,mould=new mould{mould_name="update",url="/Mould/updateMould" } },
|
||||
new menu{id=23, menu_name="del",is_show=0,is_top=0,parentId=20,mould=new mould{mould_name="del",url="/Mould/dellistMould" } },
|
||||
new menu{id=24, menu_name="add",is_show=0,is_top=0,parentId=20,mould=new mould{mould_name="add",url="/Mould/addMould" } },
|
||||
|
||||
new menu{ id=25,icon="mdi-clipboard-account", menu_name="角色菜单分配管理",router="/admRoleMenu/",is_show=1,is_top=0,parentId=14},
|
||||
|
||||
new menu{ id=26,icon="mdi-clipboard-flow-outline", menu_name="路由管理",is_show=1,is_top=0,parentId=1},
|
||||
new menu{ id=27,icon="mdi-account-eye", menu_name="用户信息",router="/userinfo/",is_show=1,is_top=0,parentId=26},
|
||||
|
||||
};
|
||||
|
||||
|
||||
List<role> roles = new List<role>() {
|
||||
new role(){role_name="普通用户" },
|
||||
new role(){role_name="管理员",menus= menus}
|
||||
};
|
||||
|
||||
List<user> users = new List<user>() {
|
||||
new user(){ username="admin",password="123",roles=roles}
|
||||
};
|
||||
|
||||
await _Db.Set<user>().AddRangeAsync(users);
|
||||
await _Db.SaveChangesAsync();
|
||||
Console.WriteLine(nameof(DbContext) + ":数据库初始成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
|
||||
namespace Yi.Framework.WebCore.Init
|
||||
{
|
||||
public class RedisInit
|
||||
{
|
||||
public static void Seed(CacheClientDB _cacheClientDB)
|
||||
{
|
||||
var setDto = Common.Helper.JsonHelper.ObjToStr(new SettingDto()
|
||||
{
|
||||
ImageList =new List<string> { "默认图片", "默认图片" },
|
||||
InitRole = "普通用户",
|
||||
Title = "YiFramework",
|
||||
InitIcon = "默认头像"
|
||||
});
|
||||
if (_cacheClientDB.Get<SettingDto>(RedisConst.key)==null)
|
||||
{
|
||||
_cacheClientDB.Add(RedisConst.key,setDto) ;
|
||||
}
|
||||
|
||||
Console.WriteLine(nameof(RedisInit) + ":Redis初始成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Model;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
public static class DbExtend
|
||||
{
|
||||
public static IServiceCollection AddDbService(this IServiceCollection services)
|
||||
{
|
||||
DbContextFactory.MutiDB_Enabled = Appsettings.appBool("MutiDB_Enabled");
|
||||
DataContext.DbSelect = Appsettings.app("DbSelect");
|
||||
DataContext._connStr = Appsettings.app("DbConn", "WriteUrl");
|
||||
services.Configure<DbConnOptions>(Appsettings.appConfiguration("DbConn"));
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using log4net;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.WebCore.Init;
|
||||
|
||||
namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
public static class DbSeedInitExtend
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(DbSeedInitExtend));
|
||||
public static void UseDbSeedInitService(this IApplicationBuilder app, IDbContextFactory _DbFactory)
|
||||
{
|
||||
|
||||
if (Appsettings.appBool("DbSeed_Enabled"))
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
try
|
||||
{
|
||||
DataSeed.SeedAsync(_DbFactory).Wait();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error($"Error occured seeding the Database.\n{e.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user