同步erp用户
This commit is contained in:
@@ -2,6 +2,9 @@ using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// erp人员
|
||||
/// </summary>
|
||||
[SugarTable("ERP_BD_PSNDOC")]
|
||||
public class ErpBdPsndoc
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// erp用户
|
||||
/// </summary>
|
||||
[SugarTable("ERP_SM_USER")]
|
||||
public class ErpSmUser
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string PK_PSNDOC { get; set; }
|
||||
public string CODE { get; set; }
|
||||
public string NAME { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
||||
{
|
||||
public class ErpUserDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 员工id
|
||||
/// </summary>
|
||||
public string PERSON_ID { get; set; }
|
||||
public string USER_ID { get; set; }
|
||||
public string CODE { get; set; }
|
||||
public string NAME { get; set; }
|
||||
/// <summary>
|
||||
/// 1 erp人员 2 erp用户
|
||||
/// </summary>
|
||||
public string TYPE { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,11 @@ namespace Tnb.ProductionMgr.Entities.Entity
|
||||
/// </summary>
|
||||
public string user_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员id
|
||||
/// </summary>
|
||||
public string person_id { get; set; }
|
||||
|
||||
public DateTime create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1481,7 +1481,28 @@ namespace Tnb.ProductionMgr
|
||||
try
|
||||
{
|
||||
var erpdb = _db.AsTenant().GetConnection("erpdb");
|
||||
List<ErpBdPsndoc> users = await erpdb.Queryable<ErpBdPsndoc>().ToListAsync();
|
||||
List<ErpUserDto> persons = await erpdb.Queryable<ErpBdPsndoc>()
|
||||
.Select(x=>new ErpUserDto
|
||||
{
|
||||
PERSON_ID = x.ID,
|
||||
CODE = x.CODE,
|
||||
NAME = x.NAME,
|
||||
TYPE = "1",
|
||||
})
|
||||
.ToListAsync();
|
||||
List<ErpUserDto> users = await erpdb.Queryable<ErpSmUser>()
|
||||
.Select(x=>new ErpUserDto
|
||||
{
|
||||
PERSON_ID = x.PK_PSNDOC,
|
||||
USER_ID = x.ID,
|
||||
CODE = x.CODE,
|
||||
NAME = x.NAME,
|
||||
TYPE = "2",
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
persons.AddRange(users);
|
||||
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="base_user").ToListAsync();
|
||||
List<UserEntity> insertUsers = new List<UserEntity>();
|
||||
List<UserRelationEntity> insertUserRelations = new List<UserRelationEntity>();
|
||||
@@ -1489,48 +1510,57 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
foreach (var user in users)
|
||||
foreach (var person in persons)
|
||||
{
|
||||
if (erpExtendFields.All(x => x.user_id != user.ID))
|
||||
if ((person.TYPE=="1" && erpExtendFields.All(x => x.person_id != person.PERSON_ID)) || (person.TYPE=="2" && erpExtendFields.All(x => x.user_id != person.USER_ID)))
|
||||
{
|
||||
UserEntity userEntity = new UserEntity();
|
||||
userEntity.Id = SnowflakeIdHelper.NextId();
|
||||
userEntity.Account = user.CODE;
|
||||
userEntity.RealName = user.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);
|
||||
if (person.TYPE == "2" && insertErpExtendFields.FindIndex(x=>x.person_id==person.PERSON_ID)!=-1)
|
||||
{
|
||||
ErpExtendField eef = insertErpExtendFields.Find(x => x.person_id == person.PERSON_ID);
|
||||
eef.user_id = person.USER_ID;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
|
||||
ErpExtendField extendField = new ErpExtendField();
|
||||
extendField.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
extendField.table_name = "base_user";
|
||||
extendField.table_id = userEntity.Id;
|
||||
extendField.person_id = person.PERSON_ID;
|
||||
extendField.user_id = person.USER_ID;
|
||||
insertErpExtendFields.Add(extendField);
|
||||
}
|
||||
|
||||
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;
|
||||
extendField.table_name = "base_user";
|
||||
extendField.table_id = userEntity.Id;
|
||||
extendField.user_id = user.ID;
|
||||
insertErpExtendFields.Add(extendField);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await _db.Insertable(insertUsers).ExecuteCommandAsync();
|
||||
|
||||
Reference in New Issue
Block a user