diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs
index 81c3cc2..cfe09da 100644
--- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs
+++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs
@@ -8858,7 +8858,27 @@ HLCUTA12307DPXJ3 以这票为例 6个柜
}
}
+ ///
+ /// 公司用户同步临时测试
+ ///
+ ///
+ [HttpGet("/BookingOrder/CompanyUserSync"), AllowAnonymous]
+ public async Task CompanyUserSync()
+ {
+ var json = "{\"type\":\"CompanyUserSync\",\"company\":{\"CompId\":\"6bb062a3-f1dc-40a0-912b-e51e63cb7930\",\"CompName\":\"山东捷丰国际储运有限公司\",\"Address\":\"青岛市市南区南京路8号府都大厦12/13楼\",\"TaxCode\":\"91370212MA3P5JHB27\",\"CustomsCode\":null,\"BankName\":null,\"BankAccount\":null,\"AdminUser\":\"4fb53bc0-8901-4f0d-a34f-c8a7aeb6692e\",\"AdminShowName\":\"田\",\"AdminUserEmail\":\"tlh@sdsmartlogistics.com\",\"AdminUserMobile\":\"15336429710\"},\"users\":[{\"GID\":\"03dcd969-bdb6-42c1-991b-ee35eeb77261\",\"CODENAME\":\"Smart_mcc\",\"SHOWNAME\":\"侯啸天\",\"PASSWORD\":\"Smart111\",\"MOBILE\":\"18253272359\",\"EMAIL1\":\"xt.hou@sdsmartlogistics.com\"},{\"GID\":\"06e40c0e-f21e-416d-adf3-996ede73baad\",\"CODENAME\":\"cuihanzhi\",\"SHOWNAME\":\"崔瀚之\",\"PASSWORD\":\"53640002\",\"MOBILE\":\"15969826021\",\"EMAIL1\":\"jun.wang@sdsmartlogistics.com\"},{\"GID\":\"1468e0e0-d264-48ed-98b5-dc8f3182a8c2\",\"CODENAME\":\"MEGU\",\"SHOWNAME\":\"夏梦\",\"PASSWORD\":\"megu3259\",\"MOBILE\":\"13505321564\",\"EMAIL1\":\"meng.xia@sdsmartlogistics.com\"},{\"GID\":\"179f5fe5-912d-4fc6-b040-c223c4038990\",\"CODENAME\":\"cjk930715\",\"SHOWNAME\":\"陈吉凯\",\"PASSWORD\":\"shenhua123\",\"MOBILE\":\"15864236957\",\"EMAIL1\":\"jk.chen@sdsmartlogistics.com\"},{\"GID\":\"1f5f6407-7f18-4716-85f2-efa07a54ade9\",\"CODENAME\":\"liqun\",\"SHOWNAME\":\"李群\",\"PASSWORD\":\"liqun930722.\",\"MOBILE\":\"16678507727\",\"EMAIL1\":\"qun.li@sdsmartlogistics.com\"},{\"GID\":\"21370af3-76f0-42b5-81e0-74711e375b89\",\"CODENAME\":\"wangxucui\",\"SHOWNAME\":\"王绪翠\",\"PASSWORD\":\"02170217\",\"MOBILE\":\"13730959185\",\"EMAIL1\":\"wangxc@sdsmartlogistics.com\"},{\"GID\":\"2685494d-0632-425c-9408-97047ccc3ce2\",\"CODENAME\":\"CXL01\",\"SHOWNAME\":\"陈宣霖\",\"PASSWORD\":\"19970907\",\"MOBILE\":\"13589331387\",\"EMAIL1\":\"xl.chen@sdsmartlogistics.com\"},{\"GID\":\"2f4b2fcb-d3c3-464f-a9b4-fb818ac5ab9f\",\"CODENAME\":\"smarthk\",\"SHOWNAME\":\"韩岿\",\"PASSWORD\":\"87073579\",\"MOBILE\":\"18678922466\",\"EMAIL1\":\"hankui@sdsmartlogistics.com\"},{\"GID\":\"37871a1b-a252-4132-a002-7ec674ed7926\",\"CODENAME\":\"smart1\",\"SHOWNAME\":\"赵炳祺\",\"PASSWORD\":\"smart.111\",\"MOBILE\":\"18763393637\",\"EMAIL1\":\"bq.zhao@sdsmartlogistics.com\"},{\"GID\":\"3a783b72-7d21-435a-8357-15cb86e7ed2a\",\"CODENAME\":\"Dongyanan\",\"SHOWNAME\":\"董亚男\",\"PASSWORD\":\"Cma_yanan12\",\"MOBILE\":\"13969795773\",\"EMAIL1\":\"yanan.dong@sdsmartlogistics.com\"},{\"GID\":\"3cae388c-2119-4e1c-8103-3b7aa252c2e4\",\"CODENAME\":\"zq0911\",\"SHOWNAME\":\"张骞\",\"PASSWORD\":\"z000000.\",\"MOBILE\":\"15863004952\",\"EMAIL1\":\"zhq@sdsmartlogistics.com\"},{\"GID\":\"4a1829c5-113d-4faa-8a0c-3eea0b792856\",\"CODENAME\":\"liusitong\",\"SHOWNAME\":\"刘思彤\",\"PASSWORD\":\"1177\",\"MOBILE\":\"13573831886\",\"EMAIL1\":\"liusitong@sdsmartlogistics.com\"},{\"GID\":\"4cebb4f7-d661-4644-9e55-f92f018b7f24\",\"CODENAME\":\"jianghe\",\"SHOWNAME\":\"江河\",\"PASSWORD\":\"jianghe54973175\",\"MOBILE\":\"13405326993\",\"EMAIL1\":\"he.jiang@sdsmartlogistics.com\"},{\"GID\":\"4fb53bc0-8901-4f0d-a34f-c8a7aeb6692e\",\"CODENAME\":\"Lily8256\",\"SHOWNAME\":\"田\",\"PASSWORD\":\"123456\",\"MOBILE\":\"15336429710\",\"EMAIL1\":\"tlh@sdsmartlogistics.com\"},{\"GID\":\"5cb61bd6-6733-48a8-a130-1d21457f2fce\",\"CODENAME\":\"smart01\",\"SHOWNAME\":\"庄娜\",\"PASSWORD\":\"luo12345\",\"MOBILE\":\"18354202065\",\"EMAIL1\":\"na.zhuang@sdsmartlogistics.com\"},{\"GID\":\"5d2dfd4f-3d46-45a0-add1-cd6ec5495d93\",\"CODENAME\":\"sjw789868\",\"SHOWNAME\":\"孙经文\",\"PASSWORD\":\"Smart_2021\",\"MOBILE\":\"13969728305\",\"EMAIL1\":\"sjw@SDSMARTLOGISTICS.COM\"},{\"GID\":\"6099c7d6-43b1-4f67-b8d5-e7913dfa082f\",\"CODENAME\":\"Camilla\",\"SHOWNAME\":\"宋盼\",\"PASSWORD\":\"18561337552\",\"MOBILE\":\"18561337552\",\"EMAIL1\":\"songpan@sdsmartlogistics.com\"},{\"GID\":\"63484585-0b5f-4382-ab76-66b96eba44ef\",\"CODENAME\":\"xuwenxia\",\"SHOWNAME\":\"徐文侠\",\"PASSWORD\":\"xia_Smart\",\"MOBILE\":\"15192581165\",\"EMAIL1\":\"WX.XU@SDSMARTLOGISTICS.COM\"},{\"GID\":\"6bad453d-eb14-44c7-8975-e29b49ddbee4\",\"CODENAME\":\"wangyajing\",\"SHOWNAME\":\"王雅静\",\"PASSWORD\":\"123456789wyj\",\"MOBILE\":\"13605322649\",\"EMAIL1\":\"tdprint@sdsmartlogistics.com\"},{\"GID\":\"6db65ddf-fc18-47be-bdca-4d97867b0f27\",\"CODENAME\":\"soina\",\"SHOWNAME\":\"战娜\",\"PASSWORD\":\"12120209\",\"MOBILE\":\"15053275526\",\"EMAIL1\":\"na.zhan@sdsmartlogistics.com\"},{\"GID\":\"7560af17-05f8-4611-b4f7-a5f5743741fe\",\"CODENAME\":\"YOKIYU\",\"SHOWNAME\":\"余雪\",\"PASSWORD\":\"asd333309\",\"MOBILE\":\"15954866831\",\"EMAIL1\":\"xue.yu@sdsmartlogistics.com\"},{\"GID\":\"80c45f91-910c-4cc9-81b9-d45e46f6547a\",\"CODENAME\":\"JFLSL\",\"SHOWNAME\":\"刘帅玲\",\"PASSWORD\":\"huamao198961_\",\"MOBILE\":\"15275292206\",\"EMAIL1\":\"liushuailing@sdsmartlogistics.com\"},{\"GID\":\"90438b14-2def-4a55-8827-a4a270a91c74\",\"CODENAME\":\"yhr2021\",\"SHOWNAME\":\"杨惠茹\",\"PASSWORD\":\"yhr199766\",\"MOBILE\":\"18364283231\",\"EMAIL1\":\"hr.yang@sdsmartlogistics.com\"},{\"GID\":\"9660682a-0314-4b4b-8631-acd0c371c7dd\",\"CODENAME\":\"XT.XU\",\"SHOWNAME\":\"徐晓彤\",\"PASSWORD\":\"XXT_8866\",\"MOBILE\":\"15054288208\",\"EMAIL1\":\"xt.xu@sdsmartlogistics.com\"},{\"GID\":\"a059af5e-0234-4f01-8e9a-a0da36727538\",\"CODENAME\":\"sunqian\",\"SHOWNAME\":\"孙倩\",\"PASSWORD\":\"52Ss1314\",\"MOBILE\":\"15964259026\",\"EMAIL1\":\"sunqian@sdsmartlogistics.com\"},{\"GID\":\"a2ae47c8-34f1-4bd4-9e94-501cd3e14fdd\",\"CODENAME\":\"LILI\",\"SHOWNAME\":\"李丽\",\"PASSWORD\":\"Ll730826_.\",\"MOBILE\":\"15066878476\",\"EMAIL1\":\"li.li@sdsmartlogistics.com\"},{\"GID\":\"b2902b42-c60e-4257-b7f9-5001aff2abae\",\"CODENAME\":\"tuxin\",\"SHOWNAME\":\"屠鑫\",\"PASSWORD\":\"87073258\",\"MOBILE\":\"13589225429\",\"EMAIL1\":\"xin.tu@sdsmartlogistics.com\"},{\"GID\":\"b7cb767b-e48b-431a-9ff7-0f6b8600a545\",\"CODENAME\":\"yangdi\",\"SHOWNAME\":\"杨棣\",\"PASSWORD\":\"563876\",\"MOBILE\":\"18364965672\",\"EMAIL1\":\"di.yang@sdsmartlogistics.com\"},{\"GID\":\"baa5ebfe-e6d7-45ca-a42f-aa814ed45bea\",\"CODENAME\":\"smart123\",\"SHOWNAME\":\"王彧\",\"PASSWORD\":\"Qwerty123\",\"MOBILE\":\"13905320875\",\"EMAIL1\":\"yu.wang@sdsmartlogistics.com\"},{\"GID\":\"d201e1f3-8db8-49c4-9d83-b2896fc25744\",\"CODENAME\":\"qibin\",\"SHOWNAME\":\"綦斌\",\"PASSWORD\":\"XiaoHai7980\",\"MOBILE\":\"13515323231\",\"EMAIL1\":\"qibin@sdsmartlogistics.com\"},{\"GID\":\"dfc662d4-818c-4026-b5f8-dfb5cf71be69\",\"CODENAME\":\"LIUSHA\",\"SHOWNAME\":\"刘莎\",\"PASSWORD\":\"liusha0215\",\"MOBILE\":\"15969887160\",\"EMAIL1\":\"sha.liu@sdsmartlogistics.com\"},{\"GID\":\"e2d456e7-0bd2-486a-a5c6-6d20a3fb17ed\",\"CODENAME\":\"Blanche\",\"SHOWNAME\":\"丁娟娟\",\"PASSWORD\":\"Dj992412\",\"MOBILE\":\"15253218125\",\"EMAIL1\":\"JJ.DING@SDSMARTLOGISTICS.COM\"},{\"GID\":\"f22995ad-1548-44e2-a885-9ad9761f7610\",\"CODENAME\":\"ZHAOYUNXUE\",\"SHOWNAME\":\"赵云雪\",\"PASSWORD\":\"ZHAOyunxue0925\",\"MOBILE\":\"15725248205\",\"EMAIL1\":\"yx.zhao@sdsmartlogistics.com\"},{\"GID\":\"fb3320fc-a125-41f6-aaa7-6866e4978d48\",\"CODENAME\":\"LINSHISEN\",\"SHOWNAME\":\"林诗森\",\"PASSWORD\":\"Lss123456\",\"MOBILE\":\"18340091787\",\"EMAIL1\":\"ss.lin@sdsmartlogistics.com\"}]}";
+ await _publisher.PublishAsync(new ChannelEventSource($"CompanyUserSync:CompanyUser", json));
+ }
+ ///
+ /// 用户离职临时测试
+ ///
+ ///
+ [HttpGet("/BookingOrder/UserLeaveSync"), AllowAnonymous]
+ public async Task UserLeaveSync()
+ {
+ var json = "{\"type\": \"UserLeave\",\"compId\": \"6bb062a3-f1dc-40a0-912b-e51e63cb7930\",\"userId\": \"fb3320fc-a125-41f6-aaa7-6866e4978d48\"}";
+ await _publisher.PublishAsync(new ChannelEventSource($"CompanyUserSync:UserLeave", json));
+ }
#endregion
#region 打印船公司ONE的订舱附件
diff --git a/Myshipping.Core/EventSubscriber/CompanyUserSyncSubscriber.cs b/Myshipping.Core/EventSubscriber/CompanyUserSyncSubscriber.cs
new file mode 100644
index 0000000..1e94b40
--- /dev/null
+++ b/Myshipping.Core/EventSubscriber/CompanyUserSyncSubscriber.cs
@@ -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
+{
+ ///
+ /// 公司、用户同步订阅器
+ ///
+ public class CompanyUserSyncSubscriber : IEventSubscriber
+ {
+ private readonly ILogger _logger;
+ public CompanyUserSyncSubscriber(IServiceProvider services, ILogger 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(context.Source.Payload.ToString());
+
+ var repoMenu = App.GetService>();
+ var repoTenant = App.GetService>();
+ var repoOrg = App.GetService>();
+ var repoPos = App.GetService>();
+ var repoRole = App.GetService>();
+ var repoRoleMenu = App.GetService>();
+ var repoUser = App.GetService>();
+ var repoEmp = App.GetService>();
+ var repoEmpPos = App.GetService>();
+ var repoUserRole = App.GetService>();
+
+ //租户信息
+ 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().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(context.Source.Payload.ToString());
+
+ var repoTenant = App.GetService>();
+ var repoUser = App.GetService>();
+
+ //租户信息
+ 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().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);
+ }
+ }
+ }
+ }
+
+ ///
+ /// 公司及用户信息的同步dto
+ ///
+ public class MyshippingCompanyUserSyncDto
+ {
+ ///
+ /// 类型
+ ///
+ public string Type { get; set; }
+
+ ///
+ /// 公司
+ ///
+ public MyshippingCompanySyncDto Company { get; set; }
+
+ ///
+ /// 员工信息
+ ///
+ public List Users { get; set; }
+ }
+
+ ///
+ /// 用户离职信息的同步dto
+ ///
+ public class MyshippingUserLeaveSyncDto
+ {
+ ///
+ /// 类型
+ ///
+ public string Type { get; set; }
+
+ ///
+ /// 公司ID
+ ///
+ public string CompId { get; set; }
+
+ ///
+ /// 用户ID
+ ///
+ public string UserId { get; set; }
+ }
+
+ ///
+ /// 公司信息的同步dto
+ ///
+ public class MyshippingCompanySyncDto
+ {
+ ///
+ /// 公司ID
+ ///
+ public string CompId { get; set; }
+ ///
+ /// 公司名称
+ ///
+ public string CompName { get; set; }
+ ///
+ /// 地址
+ ///
+ public string Address { get; set; }
+ ///
+ /// 税号
+ ///
+ public string TaxCode { get; set; }
+ ///
+ /// 海关登记号
+ ///
+ public string CustomsCode { get; set; }
+ ///
+ /// 开户行
+ ///
+ public string BankName { get; set; }
+ ///
+ /// 开户行账号
+ ///
+ public string BankAccount { get; set; }
+ ///
+ /// 管理员ID
+ ///
+ public string AdminUser { get; set; }
+ ///
+ /// 管理员姓名
+ ///
+ public string AdminShowName { get; set; }
+ ///
+ /// 管理员邮箱
+ ///
+ public string AdminUserEmail { get; set; }
+ ///
+ /// 管理员手机
+ ///
+ public string AdminUserMobile { get; set; }
+ }
+
+ ///
+ /// 员工信息的同步dto
+ ///
+ public class MyshippingUserSyncDto
+ {
+ ///
+ /// 员工ID
+ ///
+ public string GID { get; set; }
+ ///
+ /// 登录名
+ ///
+ public string CODENAME { get; set; }
+ ///
+ /// 姓名
+ ///
+ public string SHOWNAME { get; set; }
+ ///
+ /// 密码
+ ///
+ public string PASSWORD { get; set; }
+ ///
+ /// 手机
+ ///
+ public string MOBILE { get; set; }
+ ///
+ /// 邮箱
+ ///
+ public string EMAIL1 { get; set; }
+ }
+}
diff --git a/Myshipping.Core/MQ/RecCompanyUserChangeService.cs b/Myshipping.Core/MQ/RecCompanyUserChangeService.cs
index 6c43e48..8c00fa3 100644
--- a/Myshipping.Core/MQ/RecCompanyUserChangeService.cs
+++ b/Myshipping.Core/MQ/RecCompanyUserChangeService.cs
@@ -1,5 +1,6 @@
using Furion;
using Furion.DataEncryption;
+using Furion.EventBus;
using Furion.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
@@ -29,39 +30,18 @@ namespace Myshipping.Core.MQ
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly IServiceScope _serviceScope;
- private readonly ISysUserService _serviceUser;
private readonly ILogger _logger;
- private readonly ISysTenantService _tenantService;
- private readonly ISysUserService _userService;
- private readonly SqlSugarRepository _sysUserRep;
- private readonly SqlSugarRepository _sysTenantRep;
- private readonly SqlSugarRepository _sysOrgRep;
- private readonly SqlSugarRepository _sysPosRep;
- private readonly SqlSugarRepository _sysRoleRep;
- private readonly SqlSugarRepository _sysMenuRep;
- private readonly ISysRoleMenuService _sysRoleMenuService;
- private readonly IAuthService _IAuthService;
-
+ private readonly IEventPublisher _publisher;
private IConnection mqConn;
private IModel model;
- public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory, ISysUserService serviceUser, ISysRoleMenuService sysRoleMenuService,IAuthService IAuthService)
+ public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
//通过这个注入DBContext
_serviceScope = _scopeFactory.CreateScope();
- _serviceUser = serviceUser;
- _IAuthService = IAuthService;
- _sysRoleMenuService = sysRoleMenuService;
_logger = _serviceScope.ServiceProvider.GetService>();
- _tenantService = _serviceScope.ServiceProvider.GetService();
- _userService = _serviceScope.ServiceProvider.GetService();
- _sysUserRep = _serviceScope.ServiceProvider.GetService>();
- _sysTenantRep = _serviceScope.ServiceProvider.GetService>();
- _sysOrgRep = _serviceScope.ServiceProvider.GetService>();
- _sysPosRep = _serviceScope.ServiceProvider.GetService>();
- _sysRoleRep = _serviceScope.ServiceProvider.GetService>();
- _sysMenuRep = _serviceScope.ServiceProvider.GetService>();
+ _publisher = _serviceScope.ServiceProvider.GetService();
}
public override void Dispose()
@@ -85,11 +65,13 @@ namespace Myshipping.Core.MQ
string ExchangeName = "djy.comp&user.change";
string QueueName = $"djy.comp&user.change.{DateTime.Now.Ticks}";
+
ConnectionFactory factory = new ConnectionFactory();
var repoSysCfg = _serviceScope.ServiceProvider.GetService>();
var mqUrl = repoSysCfg.FirstOrDefault(x => x.Code == "CompanyUserChangeMqUrl").Value;
+ _logger.LogInformation($"准备连接公司用户同步消息队列:{mqUrl}");
factory.Uri = new Uri(mqUrl);
- mqConn = factory.CreateConnection("客户订舱平台");
+ mqConn = factory.CreateConnection("客户订舱平台客户端");
model = mqConn.CreateModel();
model.ExchangeDeclare(ExchangeName, ExchangeType.Fanout);
@@ -107,207 +89,18 @@ namespace Myshipping.Core.MQ
private async void Consumer_Received(object ch, BasicDeliverEventArgs ea)
{
-
- //获取授权---------- (用超级管理员的权限)
- LoginInput login = new LoginInput();
- login.Account = "superAdmin";
- login.Password = "123456";
- 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");
- var headers = new Dictionary();
- headers.Add("Authorization", $"Bearer {token}");
-
- //-----
var body = ea.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray());
var jobj = JObject.Parse(strBody);
var type = jobj.GetStringValue("type");
- if (type == "CompanyAudit") //新公司审核通过
- {
- var comp = jobj.GetJObjectValue("company");
- var compid = comp.GetStringValue("CompId");
- var compname = comp.GetStringValue("CompName");
- var adminShowName = comp.GetStringValue("AdminShowName");
-
- var findTenant = _sysTenantRep.FirstOrDefault(x => x.CompId == compid); //先根据关联ID查找
- if (findTenant == null)
- {
- findTenant = _sysTenantRep.FirstOrDefault(x => x.Name == compname); //再根据公司全称查找
- }
-
- if (findTenant == null) //找不到,新建
- {
- var tenant = new SysTenant();
- tenant.Id = YitIdHelper.NextId();
- tenant.Name = compname;
- tenant.AdminName = adminShowName;
- tenant.Email = $"{tenant.Id}";
- tenant.TenantType = TenantTypeEnum.COMMON;
- tenant.CompId = compid;
- findTenant = _sysTenantRep.InsertReturnEntity(tenant);
- await _tenantService.InitNewTenant(findTenant);
- //新增的系统租户新增权限
- GrantRoleMenuInput tenantmenuInput = new GrantRoleMenuInput();
- tenantmenuInput.Id = findTenant.Id;
- List tenantGrantMenuIdList = new List();
- tenantGrantMenuIdList = _sysMenuRep.AsQueryable().Where(x => x.Pids.Contains("142307070910563")).Select(x => x.Id).ToList();//暂时写死默认新增权限管理
- tenantmenuInput.GrantMenuIdList = tenantGrantMenuIdList;
- await _sysRoleMenuService.GrantMenu(tenantmenuInput);
- }
-
-
-
-
-
- }
- else if (type == "UserJoin") //用户加入公司
- {
- var compid = jobj.GetStringValue("compId");
- var findTenant = _sysTenantRep.FirstOrDefault(x => x.CompId == compid); //先根据关联ID查找
-
- //同步用户
- var user = jobj.GetJArrayValue("users");
- //租户id
- var tenantid = findTenant.Id;
- var keyDES = App.GetOptions().DES;
- foreach (JObject item in user)
- {
- var GID = item.GetStringValue("GID");
- var Accont = item.GetStringValue("CODENAME");
- var Name = item.GetStringValue("SHOWNAME");
- var Pass = DESCEncryption.Encrypt(item.GetStringValue("PASSWORD"), keyDES);
- var Email = item.GetStringValue("EMAIL1");
- var Phone = item.GetStringValue("MOBILE");
- var PassWord = item.GetStringValue("PASSWORD");
- var Org = await _sysOrgRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.IsDeleted == false && x.Pid == 0).FirstAsync();
-
- //------ 拼接对象调用新增用户接口
-
- AddUserInput adduser = new AddUserInput();
- adduser.Account = Accont;
- adduser.Password = PassWord;
- adduser.Confirm = PassWord;
- adduser.Sex = 1;
- adduser.Phone = Phone;
- adduser.TenantId = tenantid;
- EmpOutput2 empOutput2 = new EmpOutput2();
- empOutput2.OrgId = Org.Id.ToString();
- empOutput2.OrgName = Org.Name;
- List PosIdList = new List();
- var pos = _sysPosRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.IsDeleted == false).FirstAsync();
- PosIdList.Add(pos.Id);
- empOutput2.PosIdList = PosIdList;
- adduser.SysEmpParam = empOutput2;
-
- await "http://localhost:5000/sysUser/add".SetHeaders(headers).SetHttpMethod(HttpMethod.Post).SetBody(adduser).SetRetryPolicy(3, 5000).PostAsStringAsync();
- // await _serviceUser.AddUser(adduser, true);
- }
-
- //-----授权角色id普通用户
- var role = _sysRoleRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.Name == "普通用户").FirstAsync();
- GrantRoleMenuInput menuInput = new GrantRoleMenuInput();
- menuInput.Id = Convert.ToInt64(role.Id);
- List GrantMenuIdList = new List();
- GrantMenuIdList.Add(351064299098181);//暂时写死 ,后续从字典获取 新增订舱台账
- menuInput.GrantMenuIdList = GrantMenuIdList;
- await _sysRoleMenuService.GrantMenu(menuInput);
-
-
-
-
- }
- else if (type == "UserLeave") //用户离职
+ if (type == "UserLeave") //用户离职
{
- var userId = jobj.GetJObjectValue("userId");
- var compId = jobj.GetStringValue("compId");
- //删除用户
- _sysUserRep.Delete(x => x.DjyUserId == userId.ToString());
-
-
+ await _publisher.PublishAsync(new ChannelEventSource($"CompanyUserSync:UserLeave", strBody));
}
else if (type == "CompanyUserSync") //公司及员工数据同步
{
- //----------同步租户
- var comp = jobj.GetJObjectValue("company");
- var compid = comp.GetStringValue("CompId");
- var compname = comp.GetStringValue("CompName");
- var adminShowName = comp.GetStringValue("AdminShowName");
-
- var findTenant = _sysTenantRep.FirstOrDefault(x => x.CompId == compid); //先根据关联ID查找
-
- if (findTenant == null)
- {
- findTenant = _sysTenantRep.FirstOrDefault(x => x.Name == compname); //再根据公司全称查找
- }
-
- if (findTenant == null) //找不到,新建
- {
- var tenant = new SysTenant();
- tenant.Id = YitIdHelper.NextId();
- tenant.Name = compname;
- tenant.AdminName = adminShowName;
- tenant.Email = $"{tenant.Id}";
- tenant.TenantType = TenantTypeEnum.COMMON;
- tenant.CompId = compid;
- findTenant = _sysTenantRep.InsertReturnEntity(tenant);
- await _tenantService.InitNewTenant(findTenant);
- //新增的系统租户新增权限
- GrantRoleMenuInput tenantmenuInput = new GrantRoleMenuInput();
- tenantmenuInput.Id = findTenant.Id;
- List tenantGrantMenuIdList = new List();
- tenantGrantMenuIdList = _sysMenuRep.AsQueryable().Where(x => x.Pids.Contains("142307070910563")).Select(x => x.Id).ToList();//暂时写死默认新增权限管理
- tenantmenuInput.GrantMenuIdList = tenantGrantMenuIdList;
- await _sysRoleMenuService.GrantMenu(tenantmenuInput);
- }
- //----------
- //同步用户
- var user = jobj.GetJArrayValue("users");
- //租户id
- var tenantid = findTenant.Id;
- var keyDES = App.GetOptions().DES;
- foreach (JObject item in user)
- {
- var GID = item.GetStringValue("GID");
- var Accont = item.GetStringValue("CODENAME");
- var Name = item.GetStringValue("SHOWNAME");
- var Pass = DESCEncryption.Encrypt(item.GetStringValue("PASSWORD"), keyDES);
- var Email = item.GetStringValue("EMAIL1");
- var Phone = item.GetStringValue("MOBILE");
- var PassWord = item.GetStringValue("PASSWORD");
- var Org = await _sysOrgRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.IsDeleted == false && x.Pid == 0).FirstAsync();
-
- //------ 拼接对象调用新增用户接口
-
- AddUserInput adduser = new AddUserInput();
- adduser.Account = Accont;
- adduser.Password = PassWord;
- adduser.Confirm = PassWord;
- adduser.Sex = 1;
- adduser.Phone = Phone;
- adduser.TenantId = tenantid;
- EmpOutput2 empOutput2 = new EmpOutput2();
- empOutput2.OrgId = Org.Id.ToString();
- empOutput2.OrgName = Org.Name;
- List PosIdList = new List();
- var pos = _sysPosRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.IsDeleted == false).FirstAsync();
- PosIdList.Add(pos.Id);
- empOutput2.PosIdList = PosIdList;
- 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();
-
- }
-
- //-----授权角色id普通用户
- var role = _sysRoleRep.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantid && x.Name == "普通用户").FirstAsync();
- GrantRoleMenuInput menuInput = new GrantRoleMenuInput();
- menuInput.Id = Convert.ToInt64(role.Id);
- List GrantMenuIdList = new List();
- GrantMenuIdList.Add(351064299098181);//暂时写死 ,后续从字典获取 新增订舱台账
- menuInput.GrantMenuIdList = GrantMenuIdList;
- await _sysRoleMenuService.GrantMenu(menuInput);
+ await _publisher.PublishAsync(new ChannelEventSource($"CompanyUserSync:CompanyUser", strBody));
}
_logger.LogInformation($"收到消息:{strBody}");
diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml
index ad37dd5..46a30f5 100644
--- a/Myshipping.Core/Myshipping.Core.xml
+++ b/Myshipping.Core/Myshipping.Core.xml
@@ -5447,6 +5447,146 @@
否
+
+
+ 公司、用户同步订阅器
+
+
+
+
+ 公司及用户信息的同步dto
+
+
+
+
+ 类型
+
+
+
+
+ 公司
+
+
+
+
+ 员工信息
+
+
+
+
+ 用户离职信息的同步dto
+
+
+
+
+ 类型
+
+
+
+
+ 公司ID
+
+
+
+
+ 用户ID
+
+
+
+
+ 公司信息的同步dto
+
+
+
+
+ 公司ID
+
+
+
+
+ 公司名称
+
+
+
+
+ 地址
+
+
+
+
+ 税号
+
+
+
+
+ 海关登记号
+
+
+
+
+ 开户行
+
+
+
+
+ 开户行账号
+
+
+
+
+ 管理员ID
+
+
+
+
+ 管理员姓名
+
+
+
+
+ 管理员邮箱
+
+
+
+
+ 管理员手机
+
+
+
+
+ 员工信息的同步dto
+
+
+
+
+ 员工ID
+
+
+
+
+ 登录名
+
+
+
+
+ 姓名
+
+
+
+
+ 密码
+
+
+
+
+ 手机
+
+
+
+
+ 邮箱
+
+
B格
diff --git a/Myshipping.Report/Properties/PublishProfiles/FolderProfile1.pubxml b/Myshipping.Report/Properties/PublishProfiles/FolderProfile1.pubxml
new file mode 100644
index 0000000..cc55443
--- /dev/null
+++ b/Myshipping.Report/Properties/PublishProfiles/FolderProfile1.pubxml
@@ -0,0 +1,16 @@
+
+
+
+
+ False
+ False
+ True
+ Release
+ Any CPU
+ FileSystem
+ bin\app.publish\
+ FileSystem
+
+
\ No newline at end of file
diff --git a/Myshipping.Web.Core/Startup.cs b/Myshipping.Web.Core/Startup.cs
index ca2c837..baf5ddf 100644
--- a/Myshipping.Web.Core/Startup.cs
+++ b/Myshipping.Web.Core/Startup.cs
@@ -23,6 +23,7 @@ using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using Myshipping.Application.ConfigOption;
using Myshipping.Application.Event;
+using Myshipping.Core.MQ;
namespace Myshipping.Web.Core;
@@ -119,8 +120,13 @@ public class Startup : AppStartup
builder.AddSubscriber();
//消息推送
builder.AddSubscriber();
-
+ //公司及用户信息的同步
+ builder.AddSubscriber();
+
});
+
+ //公司员工变动消息队列服务
+ services.AddHostedService();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
diff --git a/Myshipping.Web.Core/dbsettings.json b/Myshipping.Web.Core/dbsettings.json
index 802249b..3edbb30 100644
--- a/Myshipping.Web.Core/dbsettings.json
+++ b/Myshipping.Web.Core/dbsettings.json
@@ -4,8 +4,8 @@
"DefaultDbType": "MySql",
//"DefaultDbString": "Data Source=60.209.125.238;Database=booking_customer_test;User ID=root;Password=Djy@Mysql.test;pooling=true;port=32006;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
//"DefaultDbString": "Data Source=60.209.125.238;Database=booking_djy_test;User ID=root;Password=Djy@Mysql.test;pooling=true;port=32006;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
- //"DefaultDbString": "Data Source=47.104.222.4;Database=booking_customer;User ID=root;Password=d0pC?Vhxq!Aj5g29H-TZ=M74rX38~]Jw;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
- "DefaultDbString": "Data Source=47.104.222.4;Database=booking_djy;User ID=root;Password=d0pC?Vhxq!Aj5g29H-TZ=M74rX38~]Jw;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
+ "DefaultDbString": "Data Source=47.104.222.4;Database=booking_customer;User ID=root;Password=d0pC?Vhxq!Aj5g29H-TZ=M74rX38~]Jw;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
+ //"DefaultDbString": "Data Source=47.104.222.4;Database=booking_djy;User ID=root;Password=d0pC?Vhxq!Aj5g29H-TZ=M74rX38~]Jw;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
"DbConfigs": [
{