zhangxiaofeng 1 year ago
commit 94328cfe24

@ -0,0 +1,444 @@
using Furion;
using Furion.DataEncryption;
using Furion.EventBus;
using Furion.RemoteRequest.Extensions;
using Microsoft.Extensions.Logging;
using Myshipping.Core.Entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;
namespace Myshipping.Core
{
/// <summary>
/// 公司、用户同步订阅器
/// </summary>
public class CompanyUserSyncSubscriber : IEventSubscriber
{
private readonly ILogger<CompanyUserSyncSubscriber> _logger;
public CompanyUserSyncSubscriber(IServiceProvider services, ILogger<CompanyUserSyncSubscriber> logger)
{
Services = services;
_logger = logger;
}
public IServiceProvider Services { get; }
//公司及用户信息的同步
[EventSubscribe("CompanyUserSync:CompanyUser")]
public async Task CompanyUserSyncCompanyUser(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到公司及用户信息的同步订阅消息:{context.Source.Payload}");
var dto = JsonConvert.DeserializeObject<MyshippingCompanyUserSyncDto>(context.Source.Payload.ToString());
var repoMenu = App.GetService<SqlSugarRepository<SysMenu>>();
var repoTenant = App.GetService<SqlSugarRepository<SysTenant>>();
var repoOrg = App.GetService<SqlSugarRepository<SysOrg>>();
var repoPos = App.GetService<SqlSugarRepository<SysPos>>();
var repoRole = App.GetService<SqlSugarRepository<SysRole>>();
var repoRoleMenu = App.GetService<SqlSugarRepository<SysRoleMenu>>();
var repoUser = App.GetService<SqlSugarRepository<SysUser>>();
var repoEmp = App.GetService<SqlSugarRepository<SysEmp>>();
var repoEmpPos = App.GetService<SqlSugarRepository<SysEmpPos>>();
var repoUserRole = App.GetService<SqlSugarRepository<SysUserRole>>();
//租户信息
var tenant = await repoTenant.AsQueryable().Filter(null, true).FirstAsync(x => x.CompId == dto.Company.CompId && x.IsDeleted == false);
if (tenant == null)
{
tenant = new SysTenant();
tenant.Id = YitIdHelper.NextId();
tenant.Name = dto.Company.CompName;
tenant.AdminName = dto.Company.AdminShowName;
tenant.Email = dto.Company.AdminUserEmail;
tenant.Phone = dto.Company.AdminUserMobile;
tenant.CompId = dto.Company.CompId;
tenant.CreatedUserId = 142307070910551L;
tenant.CreatedUserName = "超级管理员";
await repoTenant.InsertAsync(tenant);
}
else
{
tenant.Name = dto.Company.CompName;
tenant.AdminName = dto.Company.AdminShowName;
tenant.Email = dto.Company.AdminUserEmail;
tenant.Phone = dto.Company.AdminUserMobile;
tenant.UpdatedUserId = 142307070910551L;
tenant.UpdatedUserName = "超级管理员";
await repoTenant.UpdateAsync(tenant);
}
//组织机构
var org = await repoOrg.AsQueryable().Filter(null, true).FirstAsync(x => x.Pid == 0 && x.TenantId == tenant.Id && x.IsDeleted == false);
if (org == null)
{
org = new SysOrg();
org.Id = YitIdHelper.NextId();
org.Name = tenant.Name;
org.Pid = 0;
org.Pids = string.Empty;
org.Code = string.Empty;
org.Contacts = dto.Company.AdminShowName;
org.Tel = dto.Company.AdminUserMobile;
org.Sort = 0;
org.TenantId = tenant.Id;
org.CreatedUserId = 142307070910551L;
org.CreatedUserName = "超级管理员";
await repoOrg.InsertAsync(org);
}
//职位
var pos = await repoPos.AsQueryable().Filter(null, true).FirstAsync(x => x.Code == "SystemPos" && x.TenantId == tenant.Id && x.IsDeleted == false);
if (pos == null)
{
pos = new SysPos();
pos.Id = YitIdHelper.NextId();
pos.Code = "SystemPos";
pos.Name = "系统职位";
pos.Sort = 0;
pos.TenantId = tenant.Id;
pos.CreatedUserId = 142307070910551L;
pos.CreatedUserName = "超级管理员";
await repoPos.InsertAsync(pos);
}
//系统角色
var roleSystem = await repoRole.AsQueryable().Filter(null, true).FirstAsync(x => x.Code == "SystemRole" && x.TenantId == tenant.Id && x.IsDeleted == false);
if (roleSystem == null)
{
roleSystem = new SysRole();
roleSystem.Id = YitIdHelper.NextId();
roleSystem.Code = "SystemRole";
roleSystem.Name = "系统角色";
roleSystem.RoleType = RoleType.NormalRole;
roleSystem.DataScopeType = DataScopeType.SELF;
roleSystem.Sort = 1;
roleSystem.TenantId = tenant.Id;
roleSystem.CreatedUserId = 142307070910551L;
roleSystem.CreatedUserName = "超级管理员";
await repoRole.InsertAsync(roleSystem);
//角色菜单
var initMenu = new long[] {
347225881825349,
351064299098181,
351175233155141,
353548710699077,
410157538861125,
430004145692741
};
foreach (var menuId in initMenu)
{
var roleMenu = new SysRoleMenu();
roleMenu.SysRoleId = roleSystem.Id;
roleMenu.SysMenuId = menuId;
await repoRoleMenu.InsertAsync(roleMenu);
}
}
//管理员角色
var roleAdmin = await repoRole.AsQueryable().Filter(null, true).FirstAsync(x => x.Code == "AdminRole" && x.TenantId == tenant.Id && x.IsDeleted == false);
if (roleAdmin == null)
{
roleAdmin = new SysRole();
roleAdmin.Id = YitIdHelper.NextId();
roleAdmin.Code = "AdminRole";
roleAdmin.Name = "管理员角色";
roleAdmin.RoleType = RoleType.AdminRole;
roleAdmin.DataScopeType = DataScopeType.ALL;
roleAdmin.Sort = 0;
roleAdmin.TenantId = tenant.Id;
roleAdmin.CreatedUserId = 142307070910551L;
roleAdmin.CreatedUserName = "超级管理员";
await repoRole.InsertAsync(roleAdmin);
//角色菜单
var initMenu = new long[] {
347225881825349,
351064299098181,
351175233155141,
353548710699077,
410157538861125,
430004145692741,
142307070910564,
142307070910581,
142307070910589,
142307070914651,
360699813744709,
374126362341445,
142307070910563,
142307000914633,
};
foreach (var menuId in initMenu)
{
var roleMenu = new SysRoleMenu();
roleMenu.SysRoleId = roleAdmin.Id;
roleMenu.SysMenuId = menuId;
await repoRoleMenu.InsertAsync(roleMenu);
}
//管理员的部分菜单有子项,需要加入权限
var parentMenuList = new long[] {
142307070910563,
142307070910564,
142307000914633,
142307070910581,
142307070910589,
142307070914651
};
var subMenuList = repoMenu.AsQueryable().Filter(null, true).Where(x => parentMenuList.Contains(x.Pid)).Select(x => x.Id).ToList();
foreach (var menuId in subMenuList)
{
if (repoRoleMenu.AsQueryable().Filter(null, true).Count(x => x.SysRoleId == roleAdmin.Id && x.SysMenuId == menuId) == 0)
{
var roleMenu = new SysRoleMenu();
roleMenu.SysRoleId = roleAdmin.Id;
roleMenu.SysMenuId = menuId;
await repoRoleMenu.InsertAsync(roleMenu);
}
}
}
//用户信息
var dbUsers = await repoUser.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenant.Id && x.IsDeleted == false).ToListAsync();
var keyDES = App.GetOptions<EncryptKeyOptions>().DES;
foreach (var usr in dto.Users)
{
var user = dbUsers.FirstOrDefault(u => u.DjyUserId == usr.GID);
if (user == null)
{
user = new SysUser();
user.Id = YitIdHelper.NextId();
user.Name = usr.SHOWNAME;
user.NickName = usr.SHOWNAME;
user.Account = usr.CODENAME;
user.Password = DESCEncryption.Encrypt(usr.PASSWORD, keyDES);
user.Email = usr.EMAIL1;
user.Phone = usr.MOBILE;
user.AdminType = AdminType.None;
user.DjyUserId = usr.GID;
user.TenantId = tenant.Id;
await repoUser.InsertAsync(user);
//SysEmp
var emp = new SysEmp();
emp.Id = user.Id;
emp.OrgId = org.Id;
emp.OrgName = org.Name;
await repoEmp.InsertAsync(emp);
//SysEmpPos
var empPos = new SysEmpPos();
empPos.SysEmpId = emp.Id;
empPos.SysPosId = pos.Id;
await repoEmpPos.InsertAsync(empPos);
//SysUserRole
var userRole = new SysUserRole();
userRole.SysUserId = user.Id;
userRole.SysRoleId = roleSystem.Id;
await repoUserRole.InsertAsync(userRole);
}
//管理员账号
if (usr.GID == dto.Company.AdminUser && dbUsers.Count(u => u.AdminType == AdminType.Admin) == 0)
{
var adminUser = new SysUser();
adminUser.Id = YitIdHelper.NextId();
adminUser.Name = "系统管理员";
adminUser.NickName = adminUser.Name;
adminUser.Account = usr.EMAIL1;
adminUser.Password = DESCEncryption.Encrypt(usr.PASSWORD, keyDES);
adminUser.Email = string.Empty;
adminUser.Phone = string.Empty;
adminUser.AdminType = AdminType.Admin;
adminUser.TenantId = tenant.Id;
await repoUser.InsertAsync(adminUser);
//SysEmp
var emp = new SysEmp();
emp.Id = adminUser.Id;
emp.OrgId = org.Id;
emp.OrgName = org.Name;
await repoEmp.InsertAsync(emp);
//SysEmpPos
var empPos = new SysEmpPos();
empPos.SysEmpId = emp.Id;
empPos.SysPosId = pos.Id;
await repoEmpPos.InsertAsync(empPos);
//SysUserRole
var userRole = new SysUserRole();
userRole.SysUserId = adminUser.Id;
userRole.SysRoleId = roleAdmin.Id;
await repoUserRole.InsertAsync(userRole);
}
}
}
//用户离职信息的同步
[EventSubscribe("CompanyUserSync:UserLeave")]
public async Task CompanyUserSyncUserLeave(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到用户离职信息的同步订阅消息:{context.Source.Payload}");
var dto = JsonConvert.DeserializeObject<MyshippingUserLeaveSyncDto>(context.Source.Payload.ToString());
var repoTenant = App.GetService<SqlSugarRepository<SysTenant>>();
var repoUser = App.GetService<SqlSugarRepository<SysUser>>();
//租户信息
var tenant = await repoTenant.AsQueryable().Filter(null, true).FirstAsync(x => x.CompId == dto.CompId && x.IsDeleted == false);
if (tenant != null)
{
var user = await repoUser.AsQueryable().Filter(null, true).FirstAsync(u => u.DjyUserId == dto.UserId && u.TenantId == tenant.Id);
if (user != null)
{
_logger.LogInformation($"处理 {tenant.Name} 的 {user.Name} 离职");
var keyDES = App.GetOptions<EncryptKeyOptions>().DES;
user.Account = YitIdHelper.NextId().ToString();
user.Phone = string.Empty;
user.Email = string.Empty;
user.Name += "(离职)";
user.Password = DESCEncryption.Encrypt("123456", keyDES);
await repoUser.UpdateAsync(user);
}
}
}
}
/// <summary>
/// 公司及用户信息的同步dto
/// </summary>
public class MyshippingCompanyUserSyncDto
{
/// <summary>
/// 类型
/// </summary>
public string Type { get; set; }
/// <summary>
/// 公司
/// </summary>
public MyshippingCompanySyncDto Company { get; set; }
/// <summary>
/// 员工信息
/// </summary>
public List<MyshippingUserSyncDto> Users { get; set; }
}
/// <summary>
/// 用户离职信息的同步dto
/// </summary>
public class MyshippingUserLeaveSyncDto
{
/// <summary>
/// 类型
/// </summary>
public string Type { get; set; }
/// <summary>
/// 公司ID
/// </summary>
public string CompId { get; set; }
/// <summary>
/// 用户ID
/// </summary>
public string UserId { get; set; }
}
/// <summary>
/// 公司信息的同步dto
/// </summary>
public class MyshippingCompanySyncDto
{
/// <summary>
/// 公司ID
/// </summary>
public string CompId { get; set; }
/// <summary>
/// 公司名称
/// </summary>
public string CompName { get; set; }
/// <summary>
/// 地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 税号
/// </summary>
public string TaxCode { get; set; }
/// <summary>
/// 海关登记号
/// </summary>
public string CustomsCode { get; set; }
/// <summary>
/// 开户行
/// </summary>
public string BankName { get; set; }
/// <summary>
/// 开户行账号
/// </summary>
public string BankAccount { get; set; }
/// <summary>
/// 管理员ID
/// </summary>
public string AdminUser { get; set; }
/// <summary>
/// 管理员姓名
/// </summary>
public string AdminShowName { get; set; }
/// <summary>
/// 管理员邮箱
/// </summary>
public string AdminUserEmail { get; set; }
/// <summary>
/// 管理员手机
/// </summary>
public string AdminUserMobile { get; set; }
}
/// <summary>
/// 员工信息的同步dto
/// </summary>
public class MyshippingUserSyncDto
{
/// <summary>
/// 员工ID
/// </summary>
public string GID { get; set; }
/// <summary>
/// 登录名
/// </summary>
public string CODENAME { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string SHOWNAME { get; set; }
/// <summary>
/// 密码
/// </summary>
public string PASSWORD { get; set; }
/// <summary>
/// 手机
/// </summary>
public string MOBILE { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string EMAIL1 { get; set; }
}
}

@ -5282,6 +5282,146 @@
</summary>
</member>
<member name="T:Myshipping.Core.CompanyUserSyncSubscriber">
<summary>
公司、用户同步订阅器
</summary>
</member>
<member name="T:Myshipping.Core.MyshippingCompanyUserSyncDto">
<summary>
公司及用户信息的同步dto
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanyUserSyncDto.Type">
<summary>
类型
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanyUserSyncDto.Company">
<summary>
公司
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanyUserSyncDto.Users">
<summary>
员工信息
</summary>
</member>
<member name="T:Myshipping.Core.MyshippingUserLeaveSyncDto">
<summary>
用户离职信息的同步dto
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserLeaveSyncDto.Type">
<summary>
类型
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserLeaveSyncDto.CompId">
<summary>
公司ID
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserLeaveSyncDto.UserId">
<summary>
用户ID
</summary>
</member>
<member name="T:Myshipping.Core.MyshippingCompanySyncDto">
<summary>
公司信息的同步dto
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.CompId">
<summary>
公司ID
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.CompName">
<summary>
公司名称
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.Address">
<summary>
地址
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.TaxCode">
<summary>
税号
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.CustomsCode">
<summary>
海关登记号
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.BankName">
<summary>
开户行
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.BankAccount">
<summary>
开户行账号
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.AdminUser">
<summary>
管理员ID
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.AdminShowName">
<summary>
管理员姓名
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.AdminUserEmail">
<summary>
管理员邮箱
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingCompanySyncDto.AdminUserMobile">
<summary>
管理员手机
</summary>
</member>
<member name="T:Myshipping.Core.MyshippingUserSyncDto">
<summary>
员工信息的同步dto
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.GID">
<summary>
员工ID
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.CODENAME">
<summary>
登录名
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.SHOWNAME">
<summary>
姓名
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.PASSWORD">
<summary>
密码
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.MOBILE">
<summary>
手机
</summary>
</member>
<member name="P:Myshipping.Core.MyshippingUserSyncDto.EMAIL1">
<summary>
邮箱
</summary>
</member>
<member name="T:Myshipping.Core.BStyleServiceExtension">
<summary>
B格
@ -16081,6 +16221,18 @@
<param name="pos">职位代码 PCDD-调度</param>
<returns>返回用户详情</returns>
</member>
<member name="M:Myshipping.Core.Service.SysUserService.CompanyUserSync(Myshipping.Core.MyshippingCompanyUserSyncDto)">
<summary>
公司用户信息同步
</summary>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.SysUserService.UserLeave(Myshipping.Core.MyshippingUserLeaveSyncDto)">
<summary>
用户离职信息同步
</summary>
<returns></returns>
</member>
<member name="T:Myshipping.Core.DjyEdiSettingDto">
<summary>
EDI参数设置输出参数

@ -20,8 +20,8 @@ using NPOI.HSSF.UserModel;
using Myshipping.Core.Helper;
using System.Web;
using System.Text;
using Furion.EventBus;
using Microsoft.AspNetCore.Authorization;
namespace Myshipping.Core.Service;
@ -38,6 +38,7 @@ public class SysUserService : ISysUserService, IDynamicApiController, ITransient
private readonly ISysUserDataScopeService _sysUserDataScopeService;
private readonly ISysUserRoleService _sysUserRoleService;
private readonly ISysEmpPosService _sysEmpPosService;
private readonly IEventPublisher _publisher;
public SysUserService(SqlSugarRepository<SysUser> sysUserRep,
ISysCacheService sysCacheService,
@ -45,7 +46,8 @@ public class SysUserService : ISysUserService, IDynamicApiController, ITransient
ISysUserDataScopeService sysUserDataScopeService,
ISysUserRoleService sysUserRoleService,
ISysConfigService sysConfigService,
ISysEmpPosService sysEmpPosService)
ISysEmpPosService sysEmpPosService,
IEventPublisher publisher)
{
_sysUserRep = sysUserRep;
_sysCacheService = sysCacheService;
@ -54,6 +56,7 @@ public class SysUserService : ISysUserService, IDynamicApiController, ITransient
_sysUserRoleService = sysUserRoleService;
_sysConfigService = sysConfigService;
_sysEmpPosService = sysEmpPosService;
_publisher = publisher;
}
/// <summary>
@ -620,4 +623,63 @@ public class SysUserService : ISysUserService, IDynamicApiController, ITransient
return allList;
}
/// <summary>
/// 公司用户信息同步
/// </summary>
/// <returns></returns>
[HttpPost("/sysUser/CompanyUserSync"), AllowAnonymous, ApiUser(ApiCode = "CompanyUserSync")]
public async Task CompanyUserSync(MyshippingCompanyUserSyncDto dto)
{
if (dto.Type != "CompanyUserSync")
{
throw Oops.Bah($"类型有误:{dto.Type}");
}
if (string.IsNullOrEmpty(dto.Company.CompId)
|| string.IsNullOrEmpty(dto.Company.CompName)
|| string.IsNullOrEmpty(dto.Company.AdminUser)
|| string.IsNullOrEmpty(dto.Company.AdminShowName)
|| string.IsNullOrEmpty(dto.Company.AdminUserEmail)
|| string.IsNullOrEmpty(dto.Company.AdminUserMobile)
|| string.IsNullOrEmpty(dto.Company.CompId))
{
throw Oops.Bah($"公司信息不全。公司ID、名称、管理员ID、名称、手机、邮箱都不能为空");
}
var cc = dto.Users.Where(x => string.IsNullOrEmpty(x.GID)
|| string.IsNullOrEmpty(x.CODENAME)
|| string.IsNullOrEmpty(x.SHOWNAME)
|| string.IsNullOrEmpty(x.EMAIL1)
|| string.IsNullOrEmpty(x.MOBILE))
.Count();
if (cc > 0)
{
throw Oops.Bah($"用户信息不全。用户ID、姓名、登录名、密码、手机、邮箱都不能为空");
}
await _publisher.PublishAsync(new ChannelEventSource("CompanyUserSync:CompanyUser", dto.ToJsonString()));
}
/// <summary>
/// 用户离职信息同步
/// </summary>
/// <returns></returns>
[HttpPost("/sysUser/UserLeave"), AllowAnonymous, ApiUser(ApiCode = "CompanyUserSync")]
public async Task UserLeave(MyshippingUserLeaveSyncDto dto)
{
if (dto.Type != "UserLeave")
{
throw Oops.Bah($"类型有误:{dto.Type}");
}
if (string.IsNullOrEmpty(dto.CompId)
|| string.IsNullOrEmpty(dto.UserId))
{
throw Oops.Bah($"信息不全。公司ID、用户ID都不能为空");
}
await _publisher.PublishAsync(new ChannelEventSource("CompanyUserSync:UserLeave", dto.ToJsonString()));
}
}

@ -117,6 +117,8 @@ public class Startup : AppStartup
builder.AddSubscriber<BookingSyncSubscriber>();
//日志压缩清理
builder.AddSubscriber<LogZipClearSubscriber>();
//公司及用户信息的同步
builder.AddSubscriber<CompanyUserSyncSubscriber>();
});
}

@ -17,7 +17,7 @@
{
"DbNumber": "pingtai",
"DbType": "SqlServer",
"DbString": "Server=60.209.125.238,28000;Database=DevDsPingTai;User=dev;Password=dev123;MultipleActiveResultSets=True;"
"DbString": "Server=60.209.125.238,32009;Database=DevDsPingTai;User=dev;Password=dev123;MultipleActiveResultSets=True;"
},
{
"DbNumber": "taskmanage",

Loading…
Cancel
Save