同步erp用户
This commit is contained in:
@@ -41,9 +41,32 @@ namespace Tnb.BasicData
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
public async Task<string> Send(string id)
|
public async Task<string> Send(string id)
|
||||||
{
|
{
|
||||||
ThirdWebapiRecord record = await _repository.GetSingleAsync(x=>x.id==id);
|
ThirdWebapiRecord record = await _repository.GetSingleAsync(x=>x.id==id);
|
||||||
|
if (record.name == "产成品入库")
|
||||||
|
{
|
||||||
|
Dictionary<string, object> requestData = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(record.request_data)[0];
|
||||||
|
string reportId = requestData["report_id"].ToString();
|
||||||
|
PrdReport report = await _repository.AsSugarClient().Queryable<PrdReport>().Where(x=>x.id==reportId).SingleAsync();
|
||||||
|
if (report != null && !string.IsNullOrEmpty(report.erp_pk_wr) && !string.IsNullOrEmpty(report.erp_pk_wr_product))
|
||||||
|
{
|
||||||
|
requestData["csourcebillhid"] = report.erp_pk_wr;
|
||||||
|
JArray dtls = (JArray)requestData["dtls"];
|
||||||
|
foreach (var item in dtls)
|
||||||
|
{
|
||||||
|
item["csourcebillhid"] = report.erp_pk_wr;
|
||||||
|
item["csourcebillbid"] = report.erp_pk_wr_product;
|
||||||
|
}
|
||||||
|
|
||||||
|
record.request_data = JsonConvert.SerializeObject(requestData);
|
||||||
|
await _repository.AsSugarClient().Updateable<ThirdWebapiRecord>()
|
||||||
|
.SetColumns(x => x.request_data == record.request_data)
|
||||||
|
.Where(x => x.id == record.id)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
ThirdResult thirdResult = await Send(Arrays.AsList(record), "手动",null,false);
|
ThirdResult thirdResult = await Send(Arrays.AsList(record), "手动",null,false);
|
||||||
return thirdResult.msgResult;
|
return thirdResult.msgResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ using SqlSugar;
|
|||||||
|
|
||||||
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// erp人员
|
||||||
|
/// </summary>
|
||||||
[SugarTable("ERP_BD_PSNDOC")]
|
[SugarTable("ERP_BD_PSNDOC")]
|
||||||
public class ErpBdPsndoc
|
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>
|
/// </summary>
|
||||||
public string user_id { get; set; }
|
public string user_id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 人员id
|
||||||
|
/// </summary>
|
||||||
|
public string person_id { get; set; }
|
||||||
|
|
||||||
public DateTime create_time { get; set; }
|
public DateTime create_time { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1481,7 +1481,28 @@ namespace Tnb.ProductionMgr
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var erpdb = _db.AsTenant().GetConnection("erpdb");
|
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<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x=>x.table_name=="base_user").ToListAsync();
|
||||||
List<UserEntity> insertUsers = new List<UserEntity>();
|
List<UserEntity> insertUsers = new List<UserEntity>();
|
||||||
List<UserRelationEntity> insertUserRelations = new List<UserRelationEntity>();
|
List<UserRelationEntity> insertUserRelations = new List<UserRelationEntity>();
|
||||||
@@ -1489,48 +1510,57 @@ namespace Tnb.ProductionMgr
|
|||||||
|
|
||||||
await _db.Ado.BeginTranAsync();
|
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();
|
if (person.TYPE == "2" && insertErpExtendFields.FindIndex(x=>x.person_id==person.PERSON_ID)!=-1)
|
||||||
userEntity.Id = SnowflakeIdHelper.NextId();
|
{
|
||||||
userEntity.Account = user.CODE;
|
ErpExtendField eef = insertErpExtendFields.Find(x => x.person_id == person.PERSON_ID);
|
||||||
userEntity.RealName = user.NAME;
|
eef.user_id = person.USER_ID;
|
||||||
userEntity.Gender = 1;
|
}
|
||||||
userEntity.OrganizeId = WmsWareHouseConst.AdministratorOrgId;
|
else
|
||||||
userEntity.RoleId = "30327535942933";
|
{
|
||||||
userEntity.Secretkey = Guid.NewGuid().ToString();
|
UserEntity userEntity = new UserEntity();
|
||||||
userEntity.Password = MD5Encryption.Encrypt(MD5Encryption.Encrypt(CommonConst.DEFAULTPASSWORD) + userEntity.Secretkey);
|
userEntity.Id = SnowflakeIdHelper.NextId();
|
||||||
userEntity.EntryDate = DateTime.Now;
|
userEntity.Account = person.CODE;
|
||||||
userEntity.EnabledMark = 1;
|
userEntity.RealName = person.NAME;
|
||||||
userEntity.CreatorTime = DateTime.Now;
|
userEntity.Gender = 1;
|
||||||
insertUsers.Add(userEntity);
|
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 userRelationEntity = new UserRelationEntity();
|
||||||
userRelationEntity.Id = SnowflakeIdHelper.NextId();
|
userRelationEntity.Id = SnowflakeIdHelper.NextId();
|
||||||
userRelationEntity.UserId = userEntity.Id;
|
userRelationEntity.UserId = userEntity.Id;
|
||||||
userRelationEntity.ObjectType = "Role";
|
userRelationEntity.ObjectType = "Role";
|
||||||
userRelationEntity.ObjectId = "30327535942933";
|
userRelationEntity.ObjectId = "30327535942933";
|
||||||
userRelationEntity.CreatorTime = DateTime.Now;
|
userRelationEntity.CreatorTime = DateTime.Now;
|
||||||
insertUserRelations.Add(userRelationEntity);
|
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();
|
await _db.Insertable(insertUsers).ExecuteCommandAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user