From a9faf144b54211b1c4bb151f17659e60478ebd86 Mon Sep 17 00:00:00 2001 From: "shiqian.wang" Date: Wed, 24 Jul 2024 18:34:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E6=97=B6=E7=BB=9F=E8=AE=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20.net=E7=89=88=E6=9C=AC=E5=8F=98=E6=9B=B4=E4=B8=BA4.?= =?UTF-8?q?5.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ICSSoft.FromERP/App.config | 3 +- ICSSoft.FromERP/ICSAddStdWorkHourFromMES.cs | 83 ++++++++++++++------- ICSSoft.FromERP/ICSSoft.FromERP.csproj | 2 +- ICSSoft.FromERP/packages.config | 14 ++-- ICSSoft.Test/ICSSoft.Test.csproj | 4 +- ICSSoft.Test/Program.cs | 2 +- ICSSoft.Test/app.config | 2 +- 7 files changed, 71 insertions(+), 39 deletions(-) diff --git a/ICSSoft.FromERP/App.config b/ICSSoft.FromERP/App.config index eeb2f00..d7ac3a6 100644 --- a/ICSSoft.FromERP/App.config +++ b/ICSSoft.FromERP/App.config @@ -5,6 +5,7 @@ + @@ -12,4 +13,4 @@ - + diff --git a/ICSSoft.FromERP/ICSAddStdWorkHourFromMES.cs b/ICSSoft.FromERP/ICSAddStdWorkHourFromMES.cs index 30ba13f..d524ed6 100644 --- a/ICSSoft.FromERP/ICSAddStdWorkHourFromMES.cs +++ b/ICSSoft.FromERP/ICSAddStdWorkHourFromMES.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using log4net.Core; +using Newtonsoft.Json; using Quartz; using System; using System.Collections.Generic; @@ -41,6 +42,7 @@ namespace ICSSoft.FromERP { Configuration config = GetConfig(); string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString(); + // 若变更环境 除了修改接口外,还需要替换ERP.U9DB u9数据库 log.Info("获取创建定额工时接口 " + url); if (string.IsNullOrEmpty(url)) { @@ -48,7 +50,9 @@ namespace ICSSoft.FromERP } string conStr = ICSHelper.GetConnectString(); string Namespace = this.GetType().Namespace; - List ErrorCode = new List(); + List AErrorCode = new List(); + List BErrorCode = new List(); + List CErrorCode = new List(); // 业务逻辑 从u9那边料品关联工时表 找到没有工时数据的料品 再向mes这边根据料号找到数据 去匹配条件 计算出工时 给u9 // 二 分别抓取整机、本体部、驱动部未统计的料号 本体部、驱动部逆向去找型号 @@ -69,18 +73,20 @@ namespace ICSSoft.FromERP if (dt != null) { log.Info("查询到整机待统计数量:" + dt.Rows.Count + "。"); - //准备整机条件 - string argsqls = @"select ItemModel,Type,NominalDiameter,Coefficient,ManHour,AdditiveManHour,ISNULL(SpecialRequirement,'') as SpecialRequirement + //准备整机条件 口径+A拼接 + string argsqls = @"select ItemModel,Type,NominalDiameter+'A' as NominalDiameter,Coefficient,ManHour,AdditiveManHour,ISNULL(SpecialRequirement,'') as SpecialRequirement from IcsProductionDurationStatistics where Type = 0 --and TenantId = ''"; DataTable argdt = ICSHelper.ExecuteTable(conStr, argsqls); if (argdt != null) { + //log.Info("整机循环开始!"); foreach (DataRow dr in dt.Rows) { // 整机条件过滤 阀门型号、口径、特殊要求 - DataRow[] infoArgRow = argdt?.Select("ItemModel='" + dr["ValueModel"].ToString() - + "' and SpecialRequirement = '" + dr["SpecialRequirement"].ToString() //特殊条件都为空 或者有特殊条件 + var ValueModel = dr["ValueModel"].ToString().Length > 5 ? dr["ValueModel"].ToString().Substring(0, 5) : dr["ValueModel"].ToString(); // 截取前五位数字符 + DataRow[] infoArgRow = argdt?.Select("ItemModel='" + ValueModel + // + "' and SpecialRequirement = '" + dr["SpecialRequirement"].ToString() //特殊条件都为空 或者有特殊条件 + "' and NominalDiameter = '" + dr["NominalDiameter"].ToString() + "'"); if (infoArgRow.Length > 0) @@ -100,9 +106,10 @@ namespace ICSSoft.FromERP else { //记录未匹配到条件 统计失败的料号 - ErrorCode.Add(dr["code"].ToString()); + AErrorCode.Add(dr["code"].ToString()+ "(阀门型号:" + dr["ValueModel"].ToString() + ",特殊规格:" + dr["SpecialRequirement"].ToString()+ ",口径:" + dr["NominalDiameter"].ToString() + ");"); } } + //log.Info("整机循环结束!"); } else { @@ -127,18 +134,21 @@ namespace ICSSoft.FromERP if (vbsdt != null) { log.Info("查询到本体部待统计数量:" + vbsdt.Rows.Count + "。"); - //准备本体部条件 ItemModel型号 驱动部类型时此字段为驱动型号 - string vbsargsqls = @"select ItemModel,Type,NominalDiameter,Coefficient,ManHour,AdditiveManHour,ISNULL(SpecialRequirement,'') as SpecialRequirement + //准备本体部条件 ItemModel型号 驱动部类型时此字段为驱动型号 口径+A拼接 + string vbsargsqls = @"select ItemModel,Type,NominalDiameter+'A' as NominalDiameter,Coefficient,ManHour,AdditiveManHour,ISNULL(SpecialRequirement,'') as SpecialRequirement from IcsProductionDurationStatistics where Type = 1 --and TenantId = ''"; DataTable vbsargdt = ICSHelper.ExecuteTable(conStr, vbsargsqls); if (vbsargdt != null) { + //log.Info("本体部循环开始!"); foreach (DataRow dr in vbsdt.Rows) { // 本体部条件过滤 阀门型号、口径、特殊条件 - DataRow[] infoVbsRow = vbsargdt?.Select("ItemModel='" + dr["ValueModel"].ToString() - + "' and SpecialRequirement = '" + dr["SpecialRequirement"].ToString() //特殊条件都为空 或者有特殊条件 + var ValueModel = dr["ValueModel"].ToString().Length > 5 ? dr["ValueModel"].ToString().Substring(0, 5) : dr["ValueModel"].ToString(); // 截取前五位数字符 + //log.Info(ValueModel); + DataRow[] infoVbsRow = vbsargdt?.Select("ItemModel='" + ValueModel + // + "' and SpecialRequirement = '" + dr["SpecialRequirement"].ToString() //特殊条件都为空 或者有特殊条件 + "' and NominalDiameter = '" + dr["NominalDiameter"].ToString() + "'"); if (infoVbsRow.Length > 0) @@ -158,9 +168,10 @@ namespace ICSSoft.FromERP else { //记录未匹配到条件 统计失败的料号 - ErrorCode.Add(dr["code"].ToString()); + BErrorCode.Add(dr["code"].ToString() + "(阀门型号:" + dr["ValueModel"].ToString() + ",特殊规格:" + dr["SpecialRequirement"].ToString() + ",口径:" + dr["NominalDiameter"].ToString() + ");"); } } + //log.Info("本体部循环结束!"); } else { @@ -176,11 +187,11 @@ namespace ICSSoft.FromERP string dssqls = @"select d.DriveModel,case when ISNULL(d.HandwheelMechanism,'NON') = 'NON' then 1 else 0 end as HandwheelMechanism,b.MFId,a.code from ERP.U9DB.dbo.CBO_ItemMaster a join (select ROW_NUMBER() over(partition by PartItemCode order by MFId desc) as Flag,PartItemCode,MFId from ICSPartItem where PartItemName = '驱动部') b - on a.code = b.PartItemCode + on a.code = b.PartItemCode and b.Flag = 1 join IcsMfDriverSpec d on b.MFId = d.MFId left join ERP.U9DB.dbo.CA_StdWorkingHours c on a.Id = c.ItemMaster LEFT OUTER JOIN ERP.U9DB.dbo.Base_Organization AS oo ON oo.ID = a.Org - where oo.Code = '01' and c.id is null and a.code like 'A2002%''"; + where oo.Code = '01' and c.id is null and a.code like 'A2002%'"; DataTable dsdt = ICSHelper.ExecuteTable(conStr, dssqls); if (dsdt != null) { @@ -192,10 +203,13 @@ namespace ICSSoft.FromERP DataTable dsArgdt = ICSHelper.ExecuteTable(conStr, dsArgsqls); if (dsArgdt != null) { - foreach (DataRow dr in vbsdt.Rows) + //log.Info("驱动部循环开始!"); + foreach (DataRow dr in dsdt.Rows) { // 驱动部条件过滤 驱动型号、是否有手轮机构 - DataRow[] infoDsArgRow = dsArgdt?.Select("ItemModel='" + dr["DriveModel"].ToString() + var DriveModel = dr["DriveModel"].ToString().Length > 5 ? dr["DriveModel"].ToString().Substring(0, 5) : dr["DriveModel"].ToString(); // 截取前五位数字符 + //log.Info(DriveModel); + DataRow[] infoDsArgRow = dsArgdt?.Select("ItemModel='" + DriveModel + "' and HandwheelMechanism = '" + dr["HandwheelMechanism"].ToString() + "'"); if (infoDsArgRow.Length > 0) @@ -215,9 +229,10 @@ namespace ICSSoft.FromERP else { //记录未匹配到条件 统计失败的料号 - ErrorCode.Add(dr["code"].ToString()); + CErrorCode.Add(dr["code"].ToString() + "(驱动型号:" + dr["DriveModel"].ToString() + ",是否有手轮机构:" + dr["HandwheelMechanism"].ToString() + ");"); } } + //log.Info("驱动部循环结束!"); } else { @@ -230,27 +245,43 @@ namespace ICSSoft.FromERP } #endregion - if (ErrorCode.Any()) + if (AErrorCode.Any()) + { + log.Info("未匹配到统计条件的整机料号:" + string.Join(",", AErrorCode) + "。"); + } + if (BErrorCode.Any()) + { + log.Info("未匹配到统计条件的本体部料号:" + string.Join(",", BErrorCode) + "。"); + } + if (CErrorCode.Any()) { - log.Info("未匹配到统计条件的料号:" + string.Join(",", ErrorCode) + "。"); + log.Info("未匹配到统计条件的驱动部料号:" + string.Join(",", CErrorCode) + "。"); } log.Info("创建定额工时Req:" + JsonConvert.SerializeObject(AddList)); - var response = await HttpHelper.HttpClientPost(url, JsonConvert.SerializeObject(AddList)); - //返回成功后 用流水号填写 表头产品名称、产品编码、u9料号 - if (response != null) + if (AddList.Any()) { - if (response.IsOK) + + var response = await HttpHelper.HttpClientPost(url, JsonConvert.SerializeObject(AddList)); + //返回成功后 用流水号填写 表头产品名称、产品编码、u9料号 + if (response != null) { - log.Info("请求成功。" + response.Message); + if (response.IsOK) + { + log.Info("请求成功。" + response.Message); + } + else + { + log.Info("请求失败。" + response.Message); + } } else { - log.Info("请求失败。" + response.Message); + log.Info("未拿到响应,请求失败。"); } } else { - log.Info("未拿到响应,请求失败。"); + log.Info("无需请求。"); } } diff --git a/ICSSoft.FromERP/ICSSoft.FromERP.csproj b/ICSSoft.FromERP/ICSSoft.FromERP.csproj index 24123d7..d3752b6 100644 --- a/ICSSoft.FromERP/ICSSoft.FromERP.csproj +++ b/ICSSoft.FromERP/ICSSoft.FromERP.csproj @@ -10,7 +10,7 @@ Properties ICSSoft.FromERP ICSSoft.FromERP - v4.8 + v4.5.2 512 diff --git a/ICSSoft.FromERP/packages.config b/ICSSoft.FromERP/packages.config index 5452f68..2dff2c9 100644 --- a/ICSSoft.FromERP/packages.config +++ b/ICSSoft.FromERP/packages.config @@ -1,11 +1,11 @@  - - - - - - - + + + + + + + \ No newline at end of file diff --git a/ICSSoft.Test/ICSSoft.Test.csproj b/ICSSoft.Test/ICSSoft.Test.csproj index a1801e6..6b67a8a 100644 --- a/ICSSoft.Test/ICSSoft.Test.csproj +++ b/ICSSoft.Test/ICSSoft.Test.csproj @@ -10,7 +10,7 @@ Properties ICSSoft.Test ICSSoft.Test - v4.8 + v4.5.2 512 @@ -22,6 +22,7 @@ + false publish\ true Disk @@ -34,7 +35,6 @@ true 0 1.0.0.%2a - false false true diff --git a/ICSSoft.Test/Program.cs b/ICSSoft.Test/Program.cs index aeadcc2..a49413a 100644 --- a/ICSSoft.Test/Program.cs +++ b/ICSSoft.Test/Program.cs @@ -13,7 +13,7 @@ namespace ICSSoft.Test //ICSVendor test = new ICSVendor(); //test.Execute(); - IcsAutoMo2Lot4JWX test = new IcsAutoMo2Lot4JWX(); + ICSAddStdWorkHourFromMES test = new ICSAddStdWorkHourFromMES(); test.Execute(); } diff --git a/ICSSoft.Test/app.config b/ICSSoft.Test/app.config index 20bb449..ad3d876 100644 --- a/ICSSoft.Test/app.config +++ b/ICSSoft.Test/app.config @@ -1,6 +1,6 @@ - +