还是同步员工

This commit is contained in:
2024-11-01 17:31:28 +08:00
parent 8c1d98456c
commit 4f630ffaf0

View File

@@ -1501,17 +1501,17 @@ namespace Tnb.ProductionMgr
try
{
var erpdb = _db.AsTenant().GetConnection("erpdb");
// List<ErpUserDto> persons = await erpdb.Queryable<ErpBdPsndoc>()
// .Where(x=>x.ENABLESTATE!=1)
// .Select(x=>new ErpUserDto
// {
// PERSON_ID = x.ID,
// CODE = x.CODE,
// NAME = x.NAME,
// TYPE = "1",
// ENABLESTATE = x.ENABLESTATE
// })
// .ToListAsync();
List<ErpUserDto> persons = await erpdb.Queryable<ErpBdPsndoc>()
.Where(x=>x.ENABLESTATE!=1)
.Select(x=>new ErpUserDto
{
PERSON_ID = x.ID,
CODE = x.CODE,
NAME = x.NAME,
TYPE = "1",
ENABLESTATE = x.ENABLESTATE
})
.ToListAsync();
List<ErpUserDto> users = await erpdb.Queryable<ErpSmUser>()
.Where(x=>x.ENABLESTATE!=1)
.Select(x=>new ErpUserDto
@@ -1625,89 +1625,89 @@ namespace Tnb.ProductionMgr
await _db.Insertable(insertErpExtendFields).ExecuteCommandAsync();
}
// foreach (var person in persons)
// {
// List<ErpExtendField> userErpExtendFields = erpExtendFields.Where(x => x.person_id == person.PERSON_ID).ToList();
// if (userErpExtendFields == null || userErpExtendFields.IsEmpty() || userErpExtendFields.Count == 1)
// {
//
// UserEntity userEntity = new UserEntity();
// if (userErpExtendFields.Count == 1)
// {
// userEntity = existsUsers.Find(x => x.Id == erpExtendFields[0].table_id);
// int state = person.ENABLESTATE == 2 ? 1 : 0;
// if (userEntity != null)
// {
// if (userEntity.EnabledMark != state)
// {
// await _db.Updateable<UserEntity>()
// .SetColumns(x => x.EnabledMark == state)
// .Where(x => x.Id == userEntity.Id)
// .ExecuteCommandAsync();
// }
// continue;
// }
// }
//
//
// 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 = person.ENABLESTATE == 2 ? 1 : 0;
// userEntity.CreatorTime = DateTime.Now;
// insertUsers2.Add(userEntity);
//
// UserRelationEntity userRelationEntity = new UserRelationEntity();
// userRelationEntity.Id = SnowflakeIdHelper.NextId();
// userRelationEntity.UserId = userEntity.Id;
// userRelationEntity.ObjectType = "Role";
// userRelationEntity.ObjectId = "30327535942933";
// userRelationEntity.CreatorTime = DateTime.Now;
// insertUserRelations2.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;
// insertUserRelations2.Add(userRelationEntity2);
//
// ErpExtendField erpExtendField = new ErpExtendField();
// erpExtendField.org_id = WmsWareHouseConst.AdministratorOrgId;
// erpExtendField.table_name = "base_user";
// erpExtendField.table_id = userEntity.Id;
// erpExtendField.person_id = person.PERSON_ID;
// erpExtendField.user_id = person.USER_ID;
// insertErpExtendFields2.Add(erpExtendField);
// }
// else
// {
//
// }
// }
//
// if (!insertUsers2.IsEmpty())
// {
// await _db.Insertable(insertUsers2).ExecuteCommandAsync();
//
// }
// if (!insertUserRelations2.IsEmpty())
// {
// await _db.Insertable(insertUserRelations2).ExecuteCommandAsync();
// }
//
// if (!insertErpExtendFields2.IsEmpty())
// {
// await _db.Insertable(insertErpExtendFields2).ExecuteCommandAsync();
// }
foreach (var person in persons)
{
List<ErpExtendField> userErpExtendFields = erpExtendFields.Where(x => x.person_id == person.PERSON_ID).ToList();
if (userErpExtendFields == null || userErpExtendFields.IsEmpty() || userErpExtendFields.Count == 1)
{
UserEntity userEntity = new UserEntity();
if (userErpExtendFields.Count == 1)
{
userEntity = existsUsers.Find(x => x.Id == erpExtendFields[0].table_id);
int state = person.ENABLESTATE == 2 ? 1 : 0;
if (userEntity != null)
{
if (userEntity.EnabledMark != state)
{
await _db.Updateable<UserEntity>()
.SetColumns(x => x.EnabledMark == state)
.Where(x => x.Id == userEntity.Id)
.ExecuteCommandAsync();
}
continue;
}
}
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 = person.ENABLESTATE == 2 ? 1 : 0;
userEntity.CreatorTime = DateTime.Now;
insertUsers2.Add(userEntity);
UserRelationEntity userRelationEntity = new UserRelationEntity();
userRelationEntity.Id = SnowflakeIdHelper.NextId();
userRelationEntity.UserId = userEntity.Id;
userRelationEntity.ObjectType = "Role";
userRelationEntity.ObjectId = "30327535942933";
userRelationEntity.CreatorTime = DateTime.Now;
insertUserRelations2.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;
insertUserRelations2.Add(userRelationEntity2);
ErpExtendField erpExtendField = new ErpExtendField();
erpExtendField.org_id = WmsWareHouseConst.AdministratorOrgId;
erpExtendField.table_name = "base_user";
erpExtendField.table_id = userEntity.Id;
erpExtendField.person_id = person.PERSON_ID;
erpExtendField.user_id = person.USER_ID;
insertErpExtendFields2.Add(erpExtendField);
}
else
{
}
}
if (!insertUsers2.IsEmpty())
{
await _db.Insertable(insertUsers2).ExecuteCommandAsync();
}
if (!insertUserRelations2.IsEmpty())
{
await _db.Insertable(insertUserRelations2).ExecuteCommandAsync();
}
if (!insertErpExtendFields2.IsEmpty())
{
await _db.Insertable(insertErpExtendFields2).ExecuteCommandAsync();
}
await _db.Ado.CommitTranAsync();