diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs index 75971bc9..fea0441e 100644 --- a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs @@ -279,8 +279,4 @@ public partial class BasMaterial : BaseEntity /// public string? material_standard { get; set; } - /// - /// erp修改时间 - /// - public string erp_modify_time { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs index 09154f69..e59b6e7d 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdCustomer.cs @@ -8,5 +8,9 @@ namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity public string ID { get; set; } public string CODE { get; set; } public string NAME { get; set; } + /// + /// 修改时间 + /// + public string MODIFIEDTIME { get; set; } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs new file mode 100644 index 00000000..31698dac --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdPsndoc.cs @@ -0,0 +1,12 @@ +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity +{ + [SugarTable("ERP_BD_PSNDOC")] + public class ErpBdPsndoc + { + public string ID { 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/ErpBdSupplier.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdSupplier.cs new file mode 100644 index 00000000..9c7f9d58 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpEntity/ErpBdSupplier.cs @@ -0,0 +1,16 @@ +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities.Entity.ErpEntity +{ + [SugarTable("ERP_BD_SUPPLIER")] + public class ErpBdSupplier + { + public string ID { get; set; } + public string CODE { get; set; } + public string NAME { get; set; } + /// + /// 修改时间 + /// + public string MODIFIEDTIME { 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 941a75d3..5509bc61 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/ErpExtendField.cs @@ -90,5 +90,15 @@ namespace Tnb.ProductionMgr.Entities.Entity /// 客户id /// public string customer_id { get; set; } + + /// + /// 供应商id + /// + public string supplier_id { get; set; } + + /// + /// 修改时间 + /// + public string erp_modify_time { get; set; } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMo.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMo.cs index 58366665..b5384f77 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMo.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMo.cs @@ -256,5 +256,11 @@ public partial class PrdMo : BaseEntity /// public string erp_mo_pk { get; set; } + /// + /// 工单类别 + /// + /// + public string mo_category { get; set; } + } diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index ceee511b..5c6b873b 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -1,16 +1,19 @@ using System.Diagnostics; using Aop.Api.Domain; using JNPF; +using JNPF.Common.Const; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.DataEncryption; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Extras.CollectiveOAuth.Models; using JNPF.Extras.CollectiveOAuth.Utils; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.Permission; using JNPF.Systems.Interfaces.System; @@ -785,6 +788,19 @@ namespace Tnb.ProductionMgr string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material"); AuthResponse authResponse2 = JsonConvert.DeserializeObject(response2); result += ","+authResponse2.data.ToString(); + + string response3 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-customer"); + AuthResponse authResponse3 = JsonConvert.DeserializeObject(response3); + result += ","+authResponse3.data.ToString(); + + string response4 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-supplier"); + AuthResponse authResponse4 = JsonConvert.DeserializeObject(response4); + result += ","+authResponse4.data.ToString(); + + string response5 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-user"); + AuthResponse authResponse5 = JsonConvert.DeserializeObject(response5); + result += ","+authResponse5.data.ToString(); + return result; } @@ -883,7 +899,7 @@ namespace Tnb.ProductionMgr ErpExtendField extendField = erpExtendFields.Find(x => x.cmaterialoid == erpBdMaterial.ID); string materialId = extendField?.table_id ?? ""; BasMaterial basMaterial = await _db.Queryable().SingleAsync(x => x.id == materialId); - if (erpBdMaterial.MODIFIEDTIME != basMaterial.erp_modify_time) + if (erpBdMaterial.MODIFIEDTIME != extendField.erp_modify_time) { int updateRow = await _db.Updateable() .SetColumns(x => x.name == erpBdMaterial.NAME) @@ -892,9 +908,14 @@ namespace Tnb.ProductionMgr .SetColumns(x => x.material_standard == erpBdMaterial.MATERIALTYPE) .SetColumns(x => x.unit_id == unitId) .SetColumns(x => x.name == erpBdMaterial.NAME) - .SetColumns(x => x.erp_modify_time == erpBdMaterial.MODIFIEDTIME) .Where(x => x.id == materialId) .ExecuteCommandAsync(); + + await _db.Updateable() + .SetColumns(x => x.erp_modify_time == erpBdMaterial.MODIFIEDTIME) + .Where(x => x.table_id == extendField.table_id) + .ExecuteCommandAsync(); + editCount += updateRow; if (updateRow <= 0) { @@ -1127,8 +1148,8 @@ namespace Tnb.ProductionMgr try { int editCount = 0; - var mysqlDb = _db.AsTenant().GetConnection("erpdb"); - List list = await mysqlDb.Queryable().ToListAsync(); + var erpdb = _db.AsTenant().GetConnection("erpdb"); + List list = await erpdb.Queryable().ToListAsync(); List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="bas_customer").ToListAsync(); List insertCustomers = new List(); List insertExtendFields = new List(); @@ -1143,7 +1164,8 @@ namespace Tnb.ProductionMgr { id = SnowflakeIdHelper.NextId(), customer_code = erpBdCustomer.CODE, - customer_name = erpBdCustomer.NAME + customer_name = erpBdCustomer.NAME, + create_time = DateTime.Now }; ErpExtendField erpExtendField = new ErpExtendField() { @@ -1159,15 +1181,21 @@ namespace Tnb.ProductionMgr else { ErpExtendField erpExtendField = erpExtendFields.Find(x => x.customer_id == erpBdCustomer.ID); - - int updateRow = await _db.Updateable() - .SetColumns(x => x.customer_code == erpBdCustomer.CODE) - .SetColumns(x => x.customer_name == erpBdCustomer.NAME) - .Where(x => x.id == erpExtendField.customer_id) - .ExecuteCommandAsync(); - if (updateRow <= 0) + if (erpBdCustomer.MODIFIEDTIME != erpExtendField.erp_modify_time) { - Log.Error($"未找到客户{erpExtendField.customer_id},跳过此条数据"); + int updateRow = await _db.Updateable() + .SetColumns(x => x.customer_code == erpBdCustomer.CODE) + .SetColumns(x => x.customer_name == erpBdCustomer.NAME) + .Where(x => x.id == erpExtendField.table_id) + .ExecuteCommandAsync(); + + await _db.Updateable() + .SetColumns(x => x.erp_modify_time == erpBdCustomer.MODIFIEDTIME) + .Where(x => x.table_id == erpExtendField.table_id) + .ExecuteCommandAsync(); + + editCount += updateRow; + } } } @@ -1189,6 +1217,172 @@ namespace Tnb.ProductionMgr return msg; } + + /// + /// 同步供应商 + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task SyncSupplier() + { + string msg = ""; + try + { + int editCount = 0; + var erpdb = _db.AsTenant().GetConnection("erpdb"); + List list = await erpdb.Queryable().ToListAsync(); + List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="bas_supplier").ToListAsync(); + List insertSuppliers = new List(); + List insertExtendFields = new List(); + + await _db.Ado.BeginTranAsync(); + + foreach (ErpBdSupplier erpBdSupplier in list) + { + if (erpExtendFields.All(x => x.supplier_id != erpBdSupplier.ID)) + { + BasSupplier basSupplier = new BasSupplier() + { + id = SnowflakeIdHelper.NextId(), + supplier_code = erpBdSupplier.CODE, + supplier_name = erpBdSupplier.NAME, + create_time = DateTime.Now + }; + ErpExtendField erpExtendField = new ErpExtendField() + { + table_id = basSupplier.id, + table_name = "bas_supplier", + cunitid = erpBdSupplier.ID, + create_time = DateTime.Now + }; + + insertSuppliers.Add(basSupplier); + insertExtendFields.Add(erpExtendField); + } + else + { + ErpExtendField erpExtendField = erpExtendFields.Find(x => x.supplier_id == erpBdSupplier.ID); + if (erpBdSupplier.MODIFIEDTIME != erpExtendField.erp_modify_time) + { + int updateRow = await _db.Updateable() + .SetColumns(x => x.supplier_code == erpBdSupplier.CODE) + .SetColumns(x => x.supplier_name == erpBdSupplier.NAME) + .Where(x => x.id == erpExtendField.table_id) + .ExecuteCommandAsync(); + + await _db.Updateable() + .SetColumns(x => x.erp_modify_time == erpBdSupplier.MODIFIEDTIME) + .Where(x => x.table_id == erpExtendField.table_id) + .ExecuteCommandAsync(); + + editCount += updateRow; + + } + } + } + + await _db.Insertable(insertSuppliers).ExecuteCommandAsync(); + await _db.Insertable(insertExtendFields).ExecuteCommandAsync(); + + await _db.Ado.CommitTranAsync(); + + msg = $"新增供应商${insertSuppliers.Count}条,修改供应商{editCount}条"; + } + catch (Exception e) + { + Log.Error(e.Message, e); + msg = e.Message; + await _db.Ado.RollbackTranAsync(); + throw Oops.Bah(e.Message); + } + + return msg; + } + + + /// + /// 同步用户 + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task SyncUser() + { + string msg = ""; + try + { + var erpdb = _db.AsTenant().GetConnection("erpdb"); + List users = await erpdb.Queryable().ToListAsync(); + List erpExtendFields = await _db.Queryable().Where(x=>x.table_name=="base_user").ToListAsync(); + List insertUsers = new List(); + List insertUserRelations = new List(); + List insertErpExtendFields = new List(); + + await _db.Ado.BeginTranAsync(); + + foreach (var user in users) + { + if (erpExtendFields.All(x => x.user_id != 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); + + 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.user_id = user.ID; + insertErpExtendFields.Add(extendField); + } + + } + + await _db.Insertable(insertUsers).ExecuteCommandAsync(); + await _db.Insertable(insertUserRelations).ExecuteCommandAsync(); + await _db.Insertable(insertErpExtendFields).ExecuteCommandAsync(); + + await _db.Ado.CommitTranAsync(); + + msg = $"新增用户${insertUsers.Count}条"; + } + catch (Exception e) + { + Log.Error(e.Message, e); + msg = e.Message; + await _db.Ado.RollbackTranAsync(); + throw Oops.Bah(e.Message); + } + + return msg; + } } } \ No newline at end of file diff --git a/system/Tnb.Systems/Common/TestService.cs b/system/Tnb.Systems/Common/TestService.cs index e037d7e2..d0900970 100644 --- a/system/Tnb.Systems/Common/TestService.cs +++ b/system/Tnb.Systems/Common/TestService.cs @@ -8,14 +8,20 @@ using JNPF.DynamicApiController; using JNPF.JsonSerialization; using JNPF.Logging.Attributes; using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Entitys.System; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Npgsql.TypeHandlers; using SqlSugar; +using Tnb.BasicData.Entities; using Tnb.ProductionMgr.Entities.Entity; using Tnb.ProductionMgr.Entities.Entity.ErpEntity; +using Tnb.WarehouseMgr.Entities.Entity; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.BasicData; +using Tnb.WarehouseMgr.Entities; namespace JNPF.Systems.Common; @@ -96,10 +102,99 @@ public class TestService : IDynamicApiController, ITransient public string test1() { var mysqlDb = _sugar.GetConnection("erpdb"); - List list = mysqlDb.Queryable().ToList(); + List list = mysqlDb.Queryable().ToList(); + List list2 = _sugar.Queryable().ToList(); return JsonConvert.SerializeObject(list); } + [HttpGet] + [AllowAnonymous] + public async Task test2() + { + WmsMaterialTransferD wmsMaterialTransferd = await _sugar.Queryable().Where(r => r.id == "35610026468885").SingleAsync(); + WmsMaterialTransfer wmsMaterialTransfer = await _sugar.Queryable().SingleAsync(x => x.id == wmsMaterialTransferd.bill_id); + List dList = await _sugar.Queryable().Where(x => x.bill_id == wmsMaterialTransferd.bill_id).OrderBy(x=>x.id).ToListAsync(); + DictionaryDataEntity unitData = await _sugar.Queryable() + .LeftJoin((x, y) => x.Id == y.DictionaryTypeId) + .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == wmsMaterialTransferd.unit_id) + .Select((x,y)=>y) + .FirstAsync(); + List ids = new List(); + ids.Add(wmsMaterialTransfer.create_id); + ids.Add(WmsWareHouseConst.AdministratorOrgId); + ids.Add(wmsMaterialTransfer.warehouse_outstock); + ids.Add(wmsMaterialTransfer.warehouse_instock); + ids.Add(wmsMaterialTransferd.material_id); + if (unitData != null) + { + ids.Add(unitData.Id); + } + List erpExtendFields = await _sugar.Queryable().Where(x=>ids.Contains(x.table_id)).ToListAsync(); + + ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (wmsMaterialTransfer.org_id ?? WmsWareHouseConst.AdministratorOrgId)); + string erpCreateId = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.create_id)?.user_id ?? ""; + + List> requestData = new List>(); + Dictionary erpRequestData = new Dictionary(); + string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + erpRequestData.Add("billmaker",erpCreateId); + erpRequestData.Add("cdptid","1001A1100000000JRLI1");// 先写死 + erpRequestData.Add("cdptvid","0001A11000000007GGO8");// 先写死 + erpRequestData.Add("corpoid",erpOrg.corpoid); + erpRequestData.Add("corpvid",erpOrg.corpoid); + erpRequestData.Add("cothercalbodyoid",erpOrg.pk_org); + erpRequestData.Add("cotherwhid",erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_instock)?.cotherwhid ?? ""); + erpRequestData.Add("creationtime",nowStr); + erpRequestData.Add("creator",erpCreateId); + erpRequestData.Add("ctrantypeid","0001H11000000000D31W"); + erpRequestData.Add("cwarehouseid",erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_outstock)?.cotherwhid ?? ""); + erpRequestData.Add("dbilldate",nowStr); + erpRequestData.Add("dmakedate",nowStr); + erpRequestData.Add("ntotalnum",20); + erpRequestData.Add("pk_group",erpOrg.pk_group); + erpRequestData.Add("pk_org",erpOrg.pk_org); + erpRequestData.Add("pk_org_v",erpOrg.pk_org_v); + erpRequestData.Add("vbillcode",wmsMaterialTransfer.bill_code); + erpRequestData.Add("vtrantypecode","4I-01");//其他出库 先写死 + List> erpRequestDataDetails = new List>(); + erpRequestDataDetails.Add(new Dictionary() + { + ["cbodytranstypecode"] = "4I-01", + ["cbodywarehouseid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransfer.warehouse_outstock)?.cotherwhid ?? "", + ["cmaterialoid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransferd.material_id)?.cmaterialoid ?? "", + ["cmaterialvid"] = erpExtendFields.Find(x=>x.table_id==wmsMaterialTransferd.material_id)?.cmaterialvid ?? "", + ["corpoid"] = erpOrg.corpoid, + ["corpvid"] = erpOrg.corpvid, + ["crowno"] = wmsMaterialTransferd.lineno, + ["csourcebillbid"] = wmsMaterialTransferd.erp_line_pk, + ["csourcebillhid"] = wmsMaterialTransfer.erp_pk, + ["cunitid"] = erpExtendFields.Find(x=>x.table_id==unitData.Id)?.cunitid ?? "", + ["cvendorid"] = "", + ["cvendorvid"] = "", + ["dbizdate"] = nowStr, + ["nnum"] = 20, + ["nshouldnum"] = wmsMaterialTransferd.qty, + ["pk_group"] = erpOrg.pk_group, + ["pk_org"] = erpOrg.pk_org, + ["pk_org_v"] = erpOrg.pk_org_v, + ["vbatchcode"] = wmsMaterialTransferd.code_batch, + }); + erpRequestData.Add("dtls",erpRequestDataDetails); + requestData.Add(erpRequestData); + + ThirdWebapiRecord thirdWebapiRecord = new ThirdWebapiRecord(); + thirdWebapiRecord.id = SnowflakeIdHelper.NextId(); + thirdWebapiRecord.third_name = WmsWareHouseConst.BIP; + thirdWebapiRecord.name = "其它出库"; + thirdWebapiRecord.method = "POST"; + thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN+"uapws/rest/generalout/save"; + thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData); + thirdWebapiRecord.create_time = DateTime.Now; + + await _sugar.Insertable(thirdWebapiRecord).ExecuteCommandAsync(); + return "123"; + } + [HttpGet] [AllowAnonymous] public async Task insertUser() @@ -131,6 +226,14 @@ public class TestService : IDynamicApiController, ITransient 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 = "25193668006933"; + userRelationEntity2.CreatorTime = DateTime.Now; + insertUserRelations.Add(userRelationEntity2); ErpExtendField extendField = new ErpExtendField(); extendField.org_id = "25193668006933";