From dc5cce35ee5c72c06d28c30f7e043224351672e4 Mon Sep 17 00:00:00 2001 From: zhou keda <1315948824@qq.com> Date: Wed, 9 Oct 2024 09:24:28 +0800 Subject: [PATCH] bug --- .../Tnb.ProductionMgr/TimeWorkService.cs | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index c632f04b..97a36109 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -1505,6 +1505,7 @@ namespace Tnb.ProductionMgr List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="base_user").ToListAsync(); List insertUsers = new List(); + List existsUsers = await _db.Queryable().ToListAsync(); List insertUserRelations = new List(); List insertErpExtendFields = new List(); @@ -1522,34 +1523,41 @@ namespace Tnb.ProductionMgr else { UserEntity userEntity = new UserEntity(); - userEntity.Id = SnowflakeIdHelper.NextId(); - userEntity.Account = person.CODE; - userEntity.RealName = person.NAME; - userEntity.Gender = 1; - userEntity.OrganizeId = WmsWareHouseConst.AdministratorOrgId; - userEntity.RoleId = "30327535942933"; - userEntity.Secretkey = Guid.NewGuid().ToString(); - userEntity.Password = MD5Encryption.Encrypt(MD5Encryption.Encrypt(CommonConst.DEFAULTPASSWORD) + userEntity.Secretkey); - userEntity.EntryDate = DateTime.Now; - userEntity.EnabledMark = 1; - userEntity.CreatorTime = DateTime.Now; - insertUsers.Add(userEntity); - - UserRelationEntity userRelationEntity = new UserRelationEntity(); - userRelationEntity.Id = SnowflakeIdHelper.NextId(); - userRelationEntity.UserId = userEntity.Id; - userRelationEntity.ObjectType = "Role"; - userRelationEntity.ObjectId = "30327535942933"; - userRelationEntity.CreatorTime = DateTime.Now; - insertUserRelations.Add(userRelationEntity); + if (existsUsers.Exists(x => x.Account == person.CODE)) + { + userEntity = existsUsers.Find(x => x.Account == person.CODE); + } + else + { + userEntity.Id = SnowflakeIdHelper.NextId(); + userEntity.Account = person.CODE; + userEntity.RealName = person.NAME; + userEntity.Gender = 1; + userEntity.OrganizeId = WmsWareHouseConst.AdministratorOrgId; + userEntity.RoleId = "30327535942933"; + userEntity.Secretkey = Guid.NewGuid().ToString(); + userEntity.Password = MD5Encryption.Encrypt(MD5Encryption.Encrypt(CommonConst.DEFAULTPASSWORD) + userEntity.Secretkey); + userEntity.EntryDate = DateTime.Now; + userEntity.EnabledMark = 1; + userEntity.CreatorTime = DateTime.Now; + insertUsers.Add(userEntity); + + UserRelationEntity userRelationEntity = new UserRelationEntity(); + userRelationEntity.Id = SnowflakeIdHelper.NextId(); + userRelationEntity.UserId = userEntity.Id; + userRelationEntity.ObjectType = "Role"; + userRelationEntity.ObjectId = "30327535942933"; + userRelationEntity.CreatorTime = DateTime.Now; + insertUserRelations.Add(userRelationEntity); - UserRelationEntity userRelationEntity2 = new UserRelationEntity(); - userRelationEntity2.Id = SnowflakeIdHelper.NextId(); - userRelationEntity2.UserId = userEntity.Id; - userRelationEntity2.ObjectType = "Organize"; - userRelationEntity2.ObjectId = WmsWareHouseConst.AdministratorOrgId; - userRelationEntity2.CreatorTime = DateTime.Now; - insertUserRelations.Add(userRelationEntity2); + UserRelationEntity userRelationEntity2 = new UserRelationEntity(); + userRelationEntity2.Id = SnowflakeIdHelper.NextId(); + userRelationEntity2.UserId = userEntity.Id; + userRelationEntity2.ObjectType = "Organize"; + userRelationEntity2.ObjectId = WmsWareHouseConst.AdministratorOrgId; + userRelationEntity2.CreatorTime = DateTime.Now; + insertUserRelations.Add(userRelationEntity2); + } ErpExtendField extendField = new ErpExtendField(); extendField.org_id = WmsWareHouseConst.AdministratorOrgId;