Merge branch 'sqlsugar-dev' into sqlsugar
This commit is contained in:
@@ -91,6 +91,12 @@
|
|||||||
<param name="giveRoleSetMenuDto"></param>
|
<param name="giveRoleSetMenuDto"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GetInMenuByRoleId(System.Int64)">
|
||||||
|
<summary>
|
||||||
|
通过角色id来获取菜单列表
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
||||||
<summary>
|
<summary>
|
||||||
测试控制器
|
测试控制器
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
_iMenuService = iMenuService;
|
_iMenuService = iMenuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 得到树形菜单
|
/// 得到树形菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色id来获取菜单列表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Result> GetInMenuByRoleId(long RoleId)
|
||||||
|
{
|
||||||
|
return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
//不建议操作,直接切换其他仓储
|
//不建议操作,直接切换其他仓储
|
||||||
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
||||||
|
|
||||||
//直接操作Db对象???恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
|
//最好不要直接操作Db对象
|
||||||
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||||
|
|
||||||
return Result.Success().SetData(await _iUserService.DbTest());
|
return Result.Success().SetData(await _iUserService.DbTest());
|
||||||
|
|||||||
Binary file not shown.
@@ -13,6 +13,13 @@ namespace Yi.Framework.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<RoleEntity>> DbTest();
|
Task<List<RoleEntity>> DbTest();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色id获取角色实体包含菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<RoleEntity> GetInMenuByRoleId(long roleId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 给角色设置菜单,多角色,多菜单
|
/// 给角色设置菜单,多角色,多菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -10,5 +10,7 @@ namespace Yi.Framework.Model.Models
|
|||||||
{
|
{
|
||||||
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
||||||
//public List<UserEntity> Users { get; set; }
|
//public List<UserEntity> Users { get; set; }
|
||||||
|
[Navigate(typeof(RoleMenuEntity),nameof(RoleMenuEntity.RoleId),nameof(RoleMenuEntity.MenuId))]
|
||||||
|
public List<MenuEntity> Menus { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
using SqlSugar;
|
//using SqlSugar;
|
||||||
using Yi.Framework.Common.Models;
|
//using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.Model.Models;
|
//using Yi.Framework.Model.Models;
|
||||||
|
|
||||||
namespace Yi.Framework.Repository
|
//namespace Yi.Framework.Repository
|
||||||
{
|
//{
|
||||||
public class DataContext<T> : SimpleClient<T> where T : class, IBaseModelEntity, new()
|
// public class DataContext<T> : SimpleClient<T> where T : class, IBaseModelEntity, new()
|
||||||
{
|
// {
|
||||||
public DataContext(ISqlSugarClient context) : base(context)
|
// public DataContext(ISqlSugarClient context) : base(context)
|
||||||
{
|
// {
|
||||||
Db =base.Context;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public ISqlSugarClient Db;
|
// }
|
||||||
}
|
//}
|
||||||
}
|
//简化已被弃用
|
||||||
|
|||||||
@@ -12,16 +12,15 @@ namespace Yi.Framework.Repository
|
|||||||
/// 仓储模式
|
/// 仓储模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class Repository<T> : DataContext<T>, IRepository<T> where T : class, IBaseModelEntity, new()
|
public class Repository<T> : SimpleClient<T>, IRepository<T> where T : class, IBaseModelEntity, new()
|
||||||
{
|
{
|
||||||
public ISqlSugarClient _Db { get; set; }
|
public ISqlSugarClient _Db { get { return base.Context; } set { } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
||||||
{
|
{
|
||||||
_Db = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -31,7 +30,8 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UseTranAsync(Func<Task> func)
|
public async Task<bool> UseTranAsync(Func<Task> func)
|
||||||
{
|
{
|
||||||
var res = await Db.AsTenant().UseTranAsync(func);
|
var con = Context;
|
||||||
|
var res = await _Db.AsTenant().UseTranAsync(func);
|
||||||
return res.IsSuccess;
|
return res.IsSuccess;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<S>> UseSqlAsync<S>(string sql)
|
public async Task<List<S>> UseSqlAsync<S>(string sql)
|
||||||
{
|
{
|
||||||
return await Db.Ado.SqlQueryAsync<S>(sql);
|
return await _Db.Ado.SqlQueryAsync<S>(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UseSqlAsync(string sql)
|
public async Task<bool> UseSqlAsync(string sql)
|
||||||
{
|
{
|
||||||
return await Db.Ado.ExecuteCommandAsync(sql)>0;
|
return await _Db.Ado.ExecuteCommandAsync(sql)>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ namespace Yi.Framework.Repository
|
|||||||
public async Task<T> InsertReturnEntityAsync(T entity)
|
public async Task<T> InsertReturnEntityAsync(T entity)
|
||||||
{
|
{
|
||||||
entity.Id =SnowFlakeSingle.instance.getID();
|
entity.Id =SnowFlakeSingle.instance.getID();
|
||||||
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
|
return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -78,7 +78,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UpdateIgnoreNullAsync(T entity)
|
public async Task<bool> UpdateIgnoreNullAsync(T entity)
|
||||||
{
|
{
|
||||||
return await Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
return await _Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,9 +88,9 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> DeleteByLogicAsync(List<long> ids)
|
public async Task<bool> DeleteByLogicAsync(List<long> ids)
|
||||||
{
|
{
|
||||||
var entitys = await Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
var entitys = await _Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
||||||
entitys.ForEach(u=>u.IsDeleted=true);
|
entitys.ForEach(u=>u.IsDeleted=true);
|
||||||
return await Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
||||||
{
|
{
|
||||||
return await Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
return await _Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ namespace Yi.Framework.Repository
|
|||||||
FieldName = it.Key,
|
FieldName = it.Key,
|
||||||
FieldValue = it.Value
|
FieldValue = it.Value
|
||||||
}).ToList();
|
}).ToList();
|
||||||
var query = Db.Queryable<T>();
|
var query = _Db.Queryable<T>();
|
||||||
if (pars.OrderBys != null)
|
if (pars.OrderBys != null)
|
||||||
{
|
{
|
||||||
foreach (var item in pars.OrderBys)
|
foreach (var item in pars.OrderBys)
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
|
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
|
||||||
{
|
{
|
||||||
var _repositoryRoleMenu = _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
var _repositoryRoleMenu= _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
||||||
|
|
||||||
//多次操作,需要事务确保原子性
|
//多次操作,需要事务确保原子性
|
||||||
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
||||||
{
|
{
|
||||||
@@ -35,12 +34,17 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
//一次性批量添加
|
//一次性批量添加
|
||||||
await _repositoryRoleMenu.InsertRangeAsync(roleMenuEntity);
|
await _repositoryRoleMenu.InsertReturnSnowflakeIdAsync(roleMenuEntity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<RoleEntity> GetInMenuByRoleId(long roleId)
|
||||||
|
{
|
||||||
|
return await _repository._Db.Queryable<RoleEntity>().Includes(u => u.Menus).InSingleAsync(roleId);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
//一次性批量添加
|
//一次性批量添加
|
||||||
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
|
await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,5 @@ export default {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
},
|
|
||||||
|
|
||||||
GetTopMenusByHttpUser() {
|
|
||||||
return myaxios({
|
|
||||||
url: '/Menu/GetTopMenusByHttpUser',
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,36 @@
|
|||||||
import myaxios from '@/util/myaxios'
|
import myaxios from '@/util/myaxios'
|
||||||
export default {
|
export default {
|
||||||
getRole() {
|
getList() {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: '/Role/getRole',
|
url: '/Role/GetList',
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
setMenuByRole(roleList, menuList) {
|
|
||||||
return myaxios({
|
|
||||||
url: '/Role/setMenuByRole',
|
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: { ids1: roleList, ids2: menuList }
|
data: {
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
key: "isDeleted",
|
||||||
|
value: "0",
|
||||||
|
type: 0
|
||||||
|
|
||||||
|
}
|
||||||
|
],
|
||||||
|
orderBys: [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
GetTopMenusByRoleId(roleId) {
|
giveRoleSetMenu(roleList, menuList) {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: `/Role/GetTopMenusByRoleId?roleId=${roleId}`,
|
url: '/Role/GiveRoleSetMenu',
|
||||||
method: 'get'
|
method: 'put',
|
||||||
|
data: { RoleIds: roleList, menuIds: menuList }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getInMenuByRoleId(roleId) {
|
||||||
|
return myaxios({
|
||||||
|
url: `/Role/GetInMenuByRoleId?roleId=${roleId}`,
|
||||||
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,30 +6,28 @@
|
|||||||
角色菜单分配管理 —
|
角色菜单分配管理 —
|
||||||
<small class="text-body-1"
|
<small class="text-body-1"
|
||||||
>你可以在这里多角色分配多菜单/选中一个可查看</small
|
>你可以在这里多角色分配多菜单/选中一个可查看</small
|
||||||
> </template
|
>
|
||||||
>
|
</template>
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
<app-btn dark class="ma-4" @click="showAll"> 展开全部</app-btn>
|
<app-btn dark class="ma-4" @click="showAll"> 展开全部</app-btn>
|
||||||
<app-btn class="my-4 mr-4" @click="setMenu">确定分配</app-btn
|
<app-btn class="my-4 mr-4" @click="setMenu">确定分配</app-btn>
|
||||||
>
|
|
||||||
|
<app-btn class="my-4" color="secondary" @click="clear"
|
||||||
<app-btn class="my-4" color="secondary" @click="clear">清空选择</app-btn></material-card
|
>清空选择</app-btn
|
||||||
|
></material-card
|
||||||
>
|
>
|
||||||
|
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
<v-col cols="12" md="4" lg="4">
|
<v-col cols="12" md="4" lg="4">
|
||||||
<v-card class="mx-auto" width="100%">
|
<v-card class="mx-auto" width="100%">
|
||||||
<v-treeview
|
<v-treeview
|
||||||
|
|
||||||
|
|
||||||
selectable
|
selectable
|
||||||
:items="RoleItems"
|
:items="RoleItems"
|
||||||
v-model="selectionRole"
|
v-model="selectionRole"
|
||||||
return-object
|
return-object
|
||||||
open-all
|
open-all
|
||||||
hoverable
|
hoverable
|
||||||
item-text="role_name"
|
item-text="roleName"
|
||||||
>
|
>
|
||||||
</v-treeview>
|
</v-treeview>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -38,7 +36,7 @@
|
|||||||
<v-col cols="12" md="8" lg="8">
|
<v-col cols="12" md="8" lg="8">
|
||||||
<v-card class="mx-auto" width="100%">
|
<v-card class="mx-auto" width="100%">
|
||||||
<v-treeview
|
<v-treeview
|
||||||
ref="tree"
|
ref="tree"
|
||||||
open-on-click
|
open-on-click
|
||||||
selectable
|
selectable
|
||||||
:items="Menuitems"
|
:items="Menuitems"
|
||||||
@@ -47,7 +45,7 @@
|
|||||||
return-object
|
return-object
|
||||||
open-all
|
open-all
|
||||||
hoverable
|
hoverable
|
||||||
item-text="menu_name"
|
item-text="menuName"
|
||||||
>
|
>
|
||||||
<template v-slot:append="{ item }">
|
<template v-slot:append="{ item }">
|
||||||
<v-btn>id:{{ item.id }}</v-btn>
|
<v-btn>id:{{ item.id }}</v-btn>
|
||||||
@@ -68,8 +66,12 @@ export default {
|
|||||||
selectionRole: {
|
selectionRole: {
|
||||||
handler(val, oldVal) {
|
handler(val, oldVal) {
|
||||||
if (val.length == 1) {
|
if (val.length == 1) {
|
||||||
roleApi.GetTopMenusByRoleId(val[0].id).then((resp) => {
|
roleApi.getInMenuByRoleId(val[0].id).then((resp) => {
|
||||||
this.selectionMenu = resp.data;
|
if (resp.data.menus == null) {
|
||||||
|
this.selectionMenu = [];
|
||||||
|
} else {
|
||||||
|
this.selectionMenu = resp.data.menus;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -77,9 +79,9 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showAll(){
|
showAll() {
|
||||||
this.$refs.tree.updateAll(true);
|
this.$refs.tree.updateAll(true);
|
||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
this.selectionMenu = [];
|
this.selectionMenu = [];
|
||||||
this.selectionRole = [];
|
this.selectionRole = [];
|
||||||
@@ -93,20 +95,20 @@ export default {
|
|||||||
this.selectionMenu.forEach((ele) => {
|
this.selectionMenu.forEach((ele) => {
|
||||||
menuIds.push(ele.id);
|
menuIds.push(ele.id);
|
||||||
});
|
});
|
||||||
roleApi.setMenuByRole(roleIds, menuIds).then((resp) => {
|
roleApi.giveRoleSetMenu(roleIds, menuIds).then((resp) => {
|
||||||
this.$dialog.notify.info(resp.msg, {
|
this.$dialog.notify.info(resp.message, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
roleApi.getRole().then((resp) => {
|
roleApi.getList().then((resp) => {
|
||||||
this.RoleItems = resp.data;
|
this.RoleItems = resp.data;
|
||||||
});
|
});
|
||||||
|
|
||||||
menuApi.GetMenuInMould().then((resp) => {
|
menuApi.getMenuTree().then((resp) => {
|
||||||
this.Menuitems = [resp.data];
|
this.Menuitems = resp.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user