wet 2 years ago
parent f86fe6d979
commit e8b819deb4

@ -1,5 +1,6 @@
using Furion; using Furion;
using Furion.DataEncryption; using Furion.DataEncryption;
using Furion.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -12,6 +13,7 @@ using RabbitMQ.Client.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -38,15 +40,18 @@ namespace Myshipping.Core.MQ
private readonly SqlSugarRepository<SysRole> _sysRoleRep; private readonly SqlSugarRepository<SysRole> _sysRoleRep;
private readonly SqlSugarRepository<SysMenu> _sysMenuRep; private readonly SqlSugarRepository<SysMenu> _sysMenuRep;
private readonly ISysRoleMenuService _sysRoleMenuService; private readonly ISysRoleMenuService _sysRoleMenuService;
private readonly IAuthService _IAuthService;
private IConnection mqConn; private IConnection mqConn;
private IModel model; private IModel model;
public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory, ISysUserService serviceUser, ISysRoleMenuService sysRoleMenuService) public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory, ISysUserService serviceUser, ISysRoleMenuService sysRoleMenuService,IAuthService IAuthService)
{ {
_scopeFactory = scopeFactory; _scopeFactory = scopeFactory;
//通过这个注入DBContext //通过这个注入DBContext
_serviceScope = _scopeFactory.CreateScope(); _serviceScope = _scopeFactory.CreateScope();
_serviceUser = serviceUser; _serviceUser = serviceUser;
_IAuthService = IAuthService;
_sysRoleMenuService = sysRoleMenuService; _sysRoleMenuService = sysRoleMenuService;
_logger = _serviceScope.ServiceProvider.GetService<ILogger<RecCompanyUserChangeService>>(); _logger = _serviceScope.ServiceProvider.GetService<ILogger<RecCompanyUserChangeService>>();
_tenantService = _serviceScope.ServiceProvider.GetService<ISysTenantService>(); _tenantService = _serviceScope.ServiceProvider.GetService<ISysTenantService>();
@ -103,26 +108,16 @@ namespace Myshipping.Core.MQ
private async void Consumer_Received(object ch, BasicDeliverEventArgs ea) private async void Consumer_Received(object ch, BasicDeliverEventArgs ea)
{ {
//授权---------- (用超级管理员的权限) //获取授权---------- (用超级管理员的权限)
var httpContext = App.HttpContext; LoginInput login = new LoginInput();
var sysTenant = _sysTenantRep.AsQueryable().Filter(null, true).First(x => x.TenantType == TenantTypeEnum.SYSTEM); login.Account = "superAdmin";
var systemtenantid = sysTenant.Id; login.Password = "123456";
var userauth = _sysUserRep.AsQueryable().Filter(null, true).First(x => x.Account == "superAdmin" && x.TenantId == systemtenantid); var rtn = "http://localhost:5000/login".SetHttpMethod(HttpMethod.Post).SetContentType("application/json").SetBody(login.ToJsonString()).SetRetryPolicy(3, 5000).PostAsStringAsync();
var token = JObject.Parse(rtn.Result).GetStringValue("data");
ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation"); var headers = new Dictionary<string, object>();
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: userauth.Id.ToString())); headers.Add("Authorization", $"Bearer {token}");
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: userauth.Account));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: userauth.Name));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: ((int)userauth.AdminType).ToString()));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: sysTenant.TenantType.ToString()));
identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: sysTenant.Id.ToString()));
identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: sysTenant.Name));
identity.AddClaim(new Claim(type: ClaimConst.DjyUserId, value: userauth.DjyUserId));
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
httpContext.User = claimsPrincipal;
//----- //-----
var body = ea.Body; var body = ea.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray()); var strBody = Encoding.UTF8.GetString(body.ToArray());
@ -204,7 +199,9 @@ namespace Myshipping.Core.MQ
PosIdList.Add(pos.Id); PosIdList.Add(pos.Id);
empOutput2.PosIdList = PosIdList; empOutput2.PosIdList = PosIdList;
adduser.SysEmpParam = empOutput2; adduser.SysEmpParam = empOutput2;
await _serviceUser.AddUser(adduser, true);
await "http://localhost:5000/sysUser/add".SetHeaders(headers).SetHttpMethod(HttpMethod.Post).SetBody(adduser).SetRetryPolicy(3, 5000).PostAsStringAsync();
// await _serviceUser.AddUser(adduser, true);
} }
//-----授权角色id普通用户 //-----授权角色id普通用户
@ -297,7 +294,10 @@ namespace Myshipping.Core.MQ
PosIdList.Add(pos.Id); PosIdList.Add(pos.Id);
empOutput2.PosIdList = PosIdList; empOutput2.PosIdList = PosIdList;
adduser.SysEmpParam = empOutput2; adduser.SysEmpParam = empOutput2;
await _serviceUser.AddUser(adduser, true); //await _serviceUser.AddUser(adduser, true);
await "http://localhost:5000/sysUser/add".SetHeaders(headers).SetHttpMethod(HttpMethod.Post).SetBody(adduser).SetRetryPolicy(3, 5000).PostAsStringAsync();
} }
//-----授权角色id普通用户 //-----授权角色id普通用户

Loading…
Cancel
Save