|
|
|
@ -9,6 +9,7 @@ using DS.WMS.Core.Code.Interface;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using LanguageExt;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Hubs;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
@ -190,6 +191,217 @@ namespace DS.WMS.Core.Code.Method
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
|
|
|
|
|
}
|
|
|
|
|
public async Task<DataResult> UserVisibleDataRuleScopeApply(UserDataRuleScopeApplyReq req)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var rule = await tenantDb.Queryable<CodeDataRule>().Where(x=>x.Id == req.RuleId).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (rule.IsNull()) {
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("数据权限信息不存在!"));
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(rule.VisibleRuleScope))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("请维护该数据权限信息的可视范围!"));
|
|
|
|
|
}
|
|
|
|
|
var userId = req.UserId;
|
|
|
|
|
|
|
|
|
|
var userInfo = await db.Queryable<SysUser>().Where(x => x.Id == userId).FirstAsync();
|
|
|
|
|
var roleIds = await db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync();
|
|
|
|
|
if (roleIds.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("该用户未绑定角色!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
|
|
|
|
|
.Select(x => x.PermissionId).Distinct().ToListAsync();
|
|
|
|
|
|
|
|
|
|
var perlist = await db.Queryable<SysPermissionTenant>()
|
|
|
|
|
.Where(x => x.MenuType == 2 && x.IsHidden == false && permissions.Contains(x.PermissionId) && x.PermissionId!= rule.PermissionId &&
|
|
|
|
|
(x.PermissionType == 1 || x.PermissionType == 0))
|
|
|
|
|
.OrderBy(x => x.SortCode)
|
|
|
|
|
.Select(a => new RouteItem
|
|
|
|
|
{
|
|
|
|
|
Id = a.Id,
|
|
|
|
|
ParentId = a.PermissionId,
|
|
|
|
|
Path = a.Url,
|
|
|
|
|
Name = a.PermissionName,
|
|
|
|
|
EnName = a.PermissionEnName,
|
|
|
|
|
Component = a.Component,
|
|
|
|
|
Redirect = a.Redirect,
|
|
|
|
|
SortCode = a.SortCode,
|
|
|
|
|
Meta = new RouteMeta()
|
|
|
|
|
{
|
|
|
|
|
Title = a.Title,
|
|
|
|
|
Icon = a.Icon,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
var newRules = new List<CodeDataRule>();
|
|
|
|
|
var updateRules = new List<CodeDataRule>();
|
|
|
|
|
foreach (var item in perlist)
|
|
|
|
|
{
|
|
|
|
|
var currentTemplate = await tenantDb.Queryable<CodeDataRuleTemplate>().Where(x => x.PermissionId == item.ParentId && x.RuleScope == rule.VisibleRuleScope).FirstAsync();
|
|
|
|
|
var currentRule = await tenantDb.Queryable<CodeDataRule>().Where(x => x.PermissionId == item.ParentId && x.UserId == req.UserId).FirstAsync();
|
|
|
|
|
if (currentRule.IsNull())
|
|
|
|
|
{
|
|
|
|
|
if (currentTemplate.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
newRules.Add(new CodeDataRule()
|
|
|
|
|
{
|
|
|
|
|
UserId = userInfo.Id,
|
|
|
|
|
UserName = userInfo.UserName,
|
|
|
|
|
VisibleTemplateId = currentTemplate.Id,
|
|
|
|
|
VisibleRuleScope = currentTemplate.RuleScope,
|
|
|
|
|
VisibleRuleScopeName = currentTemplate.RuleScopeName,
|
|
|
|
|
PermissionEntity = currentTemplate.PermissionEntity,
|
|
|
|
|
PermissionId = currentTemplate.PermissionId,
|
|
|
|
|
Description = currentTemplate.Description,
|
|
|
|
|
Status = currentTemplate.Status,
|
|
|
|
|
Note = currentTemplate.Note,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
currentRule.VisibleTemplateId = currentTemplate.Id;
|
|
|
|
|
currentRule.VisibleRuleScope = currentTemplate.RuleScope;
|
|
|
|
|
currentRule.VisibleRuleScopeName = currentTemplate.RuleScopeName;
|
|
|
|
|
|
|
|
|
|
updateRules.Add(currentRule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (newRules.Count>0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Insertable(newRules).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
if (updateRules.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Updateable(updateRules).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<DataResult> UserOperateDataRuleScopeApply(UserDataRuleScopeApplyReq req)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var rule = await tenantDb.Queryable<CodeDataRule>().Where(x => x.Id == req.RuleId).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (rule.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("数据权限信息不存在!"));
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(rule.OperateRuleScope))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("请维护该数据权限信息的操作范围!"));
|
|
|
|
|
}
|
|
|
|
|
var userId = req.UserId;
|
|
|
|
|
|
|
|
|
|
var userInfo = await db.Queryable<SysUser>().Where(x => x.Id == userId).FirstAsync();
|
|
|
|
|
var roleIds = await db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync();
|
|
|
|
|
if (roleIds.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("该用户未绑定角色!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
|
|
|
|
|
.Select(x => x.PermissionId).Distinct().ToListAsync();
|
|
|
|
|
|
|
|
|
|
var perlist = await db.Queryable<SysPermissionTenant>()
|
|
|
|
|
.Where(x => x.MenuType == 2 && x.IsHidden == false && permissions.Contains(x.PermissionId) && x.PermissionId != rule.PermissionId &&
|
|
|
|
|
(x.PermissionType == 1 || x.PermissionType == 0))
|
|
|
|
|
.OrderBy(x => x.SortCode)
|
|
|
|
|
.Select(a => new RouteItem
|
|
|
|
|
{
|
|
|
|
|
Id = a.Id,
|
|
|
|
|
ParentId = a.PermissionId,
|
|
|
|
|
Path = a.Url,
|
|
|
|
|
Name = a.PermissionName,
|
|
|
|
|
EnName = a.PermissionEnName,
|
|
|
|
|
Component = a.Component,
|
|
|
|
|
Redirect = a.Redirect,
|
|
|
|
|
SortCode = a.SortCode,
|
|
|
|
|
Meta = new RouteMeta()
|
|
|
|
|
{
|
|
|
|
|
Title = a.Title,
|
|
|
|
|
Icon = a.Icon,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
var newRules = new List<CodeDataRule>();
|
|
|
|
|
var updateRules = new List<CodeDataRule>();
|
|
|
|
|
foreach (var item in perlist)
|
|
|
|
|
{
|
|
|
|
|
var currentTemplate = await tenantDb.Queryable<CodeDataRuleTemplate>().Where(x => x.PermissionId == item.ParentId && x.RuleScope == rule.OperateRuleScope).FirstAsync();
|
|
|
|
|
var currentRule = await tenantDb.Queryable<CodeDataRule>().Where(x => x.PermissionId == item.ParentId && x.UserId == req.UserId).FirstAsync();
|
|
|
|
|
if (currentRule.IsNull())
|
|
|
|
|
{
|
|
|
|
|
if (currentTemplate.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
newRules.Add(new CodeDataRule()
|
|
|
|
|
{
|
|
|
|
|
UserId = userInfo.Id,
|
|
|
|
|
UserName = userInfo.UserName,
|
|
|
|
|
OperateTemplateId = currentTemplate.Id,
|
|
|
|
|
OperateRuleScope = currentTemplate.RuleScope,
|
|
|
|
|
OperateRuleScopeName = currentTemplate.RuleScopeName,
|
|
|
|
|
PermissionEntity = currentTemplate.PermissionEntity,
|
|
|
|
|
PermissionId = currentTemplate.PermissionId,
|
|
|
|
|
Description = currentTemplate.Description,
|
|
|
|
|
Status = currentTemplate.Status,
|
|
|
|
|
Note = currentTemplate.Note,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRule.OperateTemplateId = currentTemplate.Id;
|
|
|
|
|
currentRule.OperateRuleScope = currentTemplate.RuleScope;
|
|
|
|
|
currentRule.OperateRuleScopeName = currentTemplate.RuleScopeName;
|
|
|
|
|
|
|
|
|
|
updateRules.Add(currentRule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (newRules.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Insertable(newRules).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
if (updateRules.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Updateable(updateRules).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|