From 92d5a5400f6a78c1e93890835772ce60555a58fb Mon Sep 17 00:00:00 2001 From: zhou keda <1315948824@qq.com> Date: Wed, 9 Oct 2024 08:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5erp=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.BasicData/ThirdApiRecordService.cs | 23 ++++ .../Entity/ErpEntity/ErpBdPsndoc.cs | 3 + .../Entity/ErpEntity/ErpSmUser.cs | 16 +++ .../Entity/ErpEntity/ErpUserDto.cs | 17 +++ .../Entity/ErpExtendField.cs | 5 + .../Tnb.ProductionMgr/TimeWorkService.cs | 106 +++++++++++------- 6 files changed, 132 insertions(+), 38 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs diff --git a/BasicData/Tnb.BasicData/ThirdApiRecordService.cs b/BasicData/Tnb.BasicData/ThirdApiRecordService.cs index ea304e86..4b9517d1 100644 --- a/BasicData/Tnb.BasicData/ThirdApiRecordService.cs +++ b/BasicData/Tnb.BasicData/ThirdApiRecordService.cs @@ -41,9 +41,32 @@ namespace Tnb.BasicData } [HttpGet] + [AllowAnonymous] public async Task Send(string id) { ThirdWebapiRecord record = await _repository.GetSingleAsync(x=>x.id==id); + if (record.name == "产成品入库") + { + Dictionary requestData = JsonConvert.DeserializeObject>>(record.request_data)[0]; + string reportId = requestData["report_id"].ToString(); + PrdReport report = await _repository.AsSugarClient().Queryable().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() + .SetColumns(x => x.request_data == record.request_data) + .Where(x => x.id == record.id) + .ExecuteCommandAsync(); + } + } ThirdResult thirdResult = await Send(Arrays.AsList(record), "手动",null,false); return thirdResult.msgResult; } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs index 31698dac..766bff23 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs @@ -2,6 +2,9 @@ using SqlSugar; namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity { + /// + /// erp人员 + /// [SugarTable("ERP_BD_PSNDOC")] public class ErpBdPsndoc { diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs new file mode 100644 index 00000000..06d65f52 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpSmUser.cs @@ -0,0 +1,16 @@ +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity +{ + /// + /// erp用户 + /// + [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; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs new file mode 100644 index 00000000..ffd8091e --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpUserDto.cs @@ -0,0 +1,17 @@ +namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity +{ + public class ErpUserDto + { + /// + /// 员工id + /// + public string PERSON_ID { get; set; } + public string USER_ID { get; set; } + public string CODE { get; set; } + public string NAME { get; set; } + /// + /// 1 erp人员 2 erp用户 + /// + public string TYPE { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs index 4093dda0..cd7fcac7 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs @@ -29,6 +29,11 @@ namespace Tnb.ProductionMgr.Entities.Entity /// public string user_id { get; set; } + /// + /// 人员id + /// + public string person_id { get; set; } + public DateTime create_time { get; set; } /// diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index 7dd513dc..c632f04b 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -1481,7 +1481,28 @@ namespace Tnb.ProductionMgr try { var erpdb = _db.AsTenant().GetConnection("erpdb"); - List users = await erpdb.Queryable().ToListAsync(); + List persons = await erpdb.Queryable() + .Select(x=>new ErpUserDto + { + PERSON_ID = x.ID, + CODE = x.CODE, + NAME = x.NAME, + TYPE = "1", + }) + .ToListAsync(); + List users = await erpdb.Queryable() + .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 erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="base_user").ToListAsync(); List insertUsers = new List(); List insertUserRelations = new List(); @@ -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();