feiyue 3 лет назад
Родитель
Сommit
54793eaa0c
2 измененных файлов с 336 добавлено и 64 удалено
  1. 334 62
      DK.Service/SAPDataService/SAPDataLogic.cs
  2. 2 2
      DK.Service/SAPTest/Form1.cs

+ 334 - 62
DK.Service/SAPDataService/SAPDataLogic.cs

@@ -3601,36 +3601,36 @@ namespace Dongke.IBOSS.PRD.Service.SAPHegiiDataService
 			funCode = "," + funCode + ",";
 			ServiceResultEntity sre = null;
 			// 10 模具
-			if (funCode == ",ALL," || funCode.Contains(",10,"))
-			{
-				try
-				{
-					sre = SetWorkData10_50("10", 0, ndate);
-					if (sre.Status != Constant.ServiceResultStatus.Success ||
-						"S" != sre.Result + "")
-					{
-						OutputLog.TraceLog(LogPriority.Warning,
-								"AutoWorkDataToSAP",
-								"10 模具 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-								JsonHelper.ToJson(sre),
-								LocalPath.LogExePath + "SAP_HEGII\\Warn_");
-					}
-				}
-				catch (Exception ex)
-				{
-					OutputLog.TraceLog(LogPriority.Error,
-							"AutoWorkDataToSAP",
-							"10 模具 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-							ex.ToString(),
-							LocalPath.LogExePath + "SAP_HEGII\\Error_");
-				}
-			}
+			//if (funCode == ",ALL," || funCode.Contains(",10,"))
+			//{
+			//	try
+			//	{
+			//		sre = SetWorkData10_50_test("10", 0, ndate);
+			//		if (sre.Status != Constant.ServiceResultStatus.Success ||
+			//			"S" != sre.Result + "")
+			//		{
+			//			OutputLog.TraceLog(LogPriority.Warning,
+			//					"AutoWorkDataToSAP",
+			//					"10 模具 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//					JsonHelper.ToJson(sre),
+			//					LocalPath.LogExePath + "SAP_HEGII\\Warn_");
+			//		}
+			//	}
+			//	catch (Exception ex)
+			//	{
+			//		OutputLog.TraceLog(LogPriority.Error,
+			//				"AutoWorkDataToSAP",
+			//				"10 模具 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//				ex.ToString(),
+			//				LocalPath.LogExePath + "SAP_HEGII\\Error_");
+			//	}
+			//}
 			// 20 湿坯
 			if (funCode == ",ALL," || funCode.Contains(",20,"))
 			{
 				try
 				{
-					sre = SetWorkData10_50("20", 0, ndate);
+					sre = SetWorkData10_50_test("20", 0, ndate);
 					if (sre.Status != Constant.ServiceResultStatus.Success ||
 						"S" != sre.Result + "")
 					{
@@ -3655,7 +3655,7 @@ namespace Dongke.IBOSS.PRD.Service.SAPHegiiDataService
 			{
 				try
 				{
-					sre = SetWorkData10_50("30", 0, ndate);
+					sre = SetWorkData10_50_test("30", 0, ndate);
 					if (sre.Status != Constant.ServiceResultStatus.Success ||
 						"S" != sre.Result + "")
 					{
@@ -3680,7 +3680,7 @@ namespace Dongke.IBOSS.PRD.Service.SAPHegiiDataService
 			{
 				try
 				{
-					sre = SetWorkData10_50("40", 0, ndate);
+					sre = SetWorkData10_50_test("40", 0, ndate);
 					if (sre.Status != Constant.ServiceResultStatus.Success ||
 						"S" != sre.Result + "")
 					{
@@ -3705,7 +3705,7 @@ namespace Dongke.IBOSS.PRD.Service.SAPHegiiDataService
 			{
 				try
 				{
-					sre = SetWorkData10_50("50", 0, ndate);
+					sre = SetWorkData10_50_test("50", 0, ndate);
 					if (sre.Status != Constant.ServiceResultStatus.Success ||
 						"S" != sre.Result + "")
 					{
@@ -3726,53 +3726,325 @@ namespace Dongke.IBOSS.PRD.Service.SAPHegiiDataService
 				}
 			}
 			// 6001 成品明细
-			if (funCode == ",ALL," || funCode.Contains(",6001,"))
+			//if (funCode == ",ALL," || funCode.Contains(",6001,"))
+			//{
+			//	try
+			//	{
+			//		sre = SetFP6001(ndate, 0);
+			//		if (sre.Status != Constant.ServiceResultStatus.Success ||
+			//			"S" != sre.Result + "")
+			//		{
+			//			OutputLog.TraceLog(LogPriority.Warning,
+			//					"AutoWorkDataToSAP",
+			//					"6001 成品明细 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//					JsonHelper.ToJson(sre),
+			//					LocalPath.LogExePath + "SAP_HEGII\\Warn_");
+			//		}
+			//	}
+			//	catch (Exception ex)
+			//	{
+			//		OutputLog.TraceLog(LogPriority.Error,
+			//				"AutoWorkDataToSAP",
+			//				"6001 成品明细 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//				ex.ToString(),
+			//				LocalPath.LogExePath + "SAP_HEGII\\Error_");
+			//	}
+			//}
+			// 6001 成品明细(小时)-20分钟
+			//if (funCode == ",6002,")
+			//{
+			//	try
+			//	{
+			//		sre = SetFP6002(ndate, 0);
+			//		if (sre.Status != Constant.ServiceResultStatus.Success ||
+			//			"S" != sre.Result + "")
+			//		{
+			//			OutputLog.TraceLog(LogPriority.Warning,
+			//					"AutoWorkDataToSAP",
+			//					"6002 成品明细(小时) " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//					JsonHelper.ToJson(sre),
+			//					LocalPath.LogExePath + "SAP_HEGII\\Warn_");
+			//		}
+			//	}
+			//	catch (Exception ex)
+			//	{
+			//		OutputLog.TraceLog(LogPriority.Error,
+			//				"AutoWorkDataToSAP",
+			//				"6002 成品明细(小时) " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
+			//				ex.ToString(),
+			//				LocalPath.LogExePath + "SAP_HEGII\\Error_");
+			//	}
+			//}
+		}
+
+		public static ServiceResultEntity SetWorkData10_50_test(string datacode, int userid, DateTime ndate)
+		{
+			ServiceResultEntity sre = new ServiceResultEntity();
+			IDBTransaction oracleConn = null;
+			try
 			{
-				try
+				#region 事务1,执行存储过程
+				OracleParameter[] paras = null;
+				int logid = 0;
+				string message = string.Empty;
+
+				// 10 模具
+				//if ("10".Equals(datacode))
+				//{
+				//	paras = new OracleParameter[]
+				//	{
+				//		new OracleParameter("in_dateend", OracleDbType.Date, ndate, ParameterDirection.Input),
+				//		new OracleParameter("out_logid", OracleDbType.Int32, null, ParameterDirection.Output),
+				//		new OracleParameter("out_msg", OracleDbType.NVarchar2, 500, null, ParameterDirection.Output)
+				//	};
+
+				//	oracleConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
+				//	DataSet ds = oracleConn.ExecStoredProcedure("pro_sap_hegii_workdata_10_1", paras);
+				//	int.TryParse(paras[1].Value + "", out logid);
+				//	message = paras[2].Value + "";
+				//	oracleConn.Commit();
+				//}
+				// 20 湿坯
+				if ("20".Equals(datacode))
 				{
-					sre = SetFP6001(ndate, 0);
-					if (sre.Status != Constant.ServiceResultStatus.Success ||
-						"S" != sre.Result + "")
+					paras = new OracleParameter[]
 					{
-						OutputLog.TraceLog(LogPriority.Warning,
-								"AutoWorkDataToSAP",
-								"6001 成品明细 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-								JsonHelper.ToJson(sre),
-								LocalPath.LogExePath + "SAP_HEGII\\Warn_");
-					}
+						new OracleParameter("in_dateend", OracleDbType.Date, ndate, ParameterDirection.Input),
+						new OracleParameter("out_logid", OracleDbType.Int32, null, ParameterDirection.Output),
+						new OracleParameter("out_msg", OracleDbType.NVarchar2, 500, null, ParameterDirection.Output)
+					};
+
+					oracleConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
+					DataSet ds = oracleConn.ExecStoredProcedure("pro_sap_hegii_workdata_20_1_test", paras);
+					int.TryParse(paras[1].Value + "", out logid);
+					message = paras[2].Value + "";
+					oracleConn.Commit();
 				}
-				catch (Exception ex)
+				// 30 精坯、40 釉坯、50 烧成
+				else if ("30".Equals(datacode) || "40".Equals(datacode) || "50".Equals(datacode))
 				{
-					OutputLog.TraceLog(LogPriority.Error,
-							"AutoWorkDataToSAP",
-							"6001 成品明细 " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-							ex.ToString(),
-							LocalPath.LogExePath + "SAP_HEGII\\Error_");
+					paras = new OracleParameter[]
+					{
+						new OracleParameter("in_dateend", OracleDbType.Date, ndate, ParameterDirection.Input),
+						new OracleParameter("in_datacode", OracleDbType.Varchar2, datacode, ParameterDirection.Input),
+						new OracleParameter("out_logid", OracleDbType.Int32, null, ParameterDirection.Output),
+						new OracleParameter("out_msg", OracleDbType.NVarchar2, 500, null, ParameterDirection.Output)
+					};
+
+					oracleConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
+					DataSet ds = oracleConn.ExecStoredProcedure("pro_sap_hegii_workdata_30_1_test", paras);
+					int.TryParse(paras[2].Value + "", out logid);
+					message = paras[3].Value + "";
+					oracleConn.Commit();
+				}
+
+				// 如果logid为0,则数据没有生成
+				if (logid == 0)
+				{
+					sre.Status = Constant.ServiceResultStatus.Other;
+					sre.Message = message;
+					return sre;
 				}
+				#endregion
+
+				// 事物2,同步SAP接口
+				sre = SyncSap_test(ndate, datacode, userid, logid);
+				return sre;
 			}
-			// 6001 成品明细(小时)-20分钟
-			if (funCode == ",6002,")
+			catch (Exception ex)
 			{
-				try
+				throw ex;
+			}
+			finally
+			{
+				if (oracleConn != null &&
+					oracleConn.ConnState == ConnectionState.Open)
 				{
-					sre = SetFP6002(ndate, 0);
-					if (sre.Status != Constant.ServiceResultStatus.Success ||
-						"S" != sre.Result + "")
+					oracleConn.Disconnect();
+				}
+			}
+		}
+
+		public static ServiceResultEntity SyncSap_test(DateTime date, string datacode, int userid, int logid)
+		{
+			ServiceResultEntity sre = new ServiceResultEntity();
+			IDBTransaction oracleConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
+
+			try
+			{
+				OracleParameter[] paras = null;
+				string sqlString = string.Empty;
+
+				sqlString = "select workcode from tp_mst_account where rownum = 1";
+				string workcode = oracleConn.GetSqlResultToStr(sqlString);
+				string yyyymmdd = date.ToString("yyyyMMdd");
+				int r = 0;
+
+				// 查询出当前日志外,最新的一次日志
+				sqlString = "SELECT t.executedateend\n" +
+							"  FROM (SELECT dl.executedateend\n" +
+							"          FROM tsap_hegii_datalog dl\n" +
+							"         WHERE dl.logtype = '3'\n" +
+							"           AND dl.datastuts = 'S'\n" +
+							"           AND dl.datacode = :datacode\n" +
+							"           AND dl.logid   <> :logid\n" +
+							"         ORDER BY dl.executedateend DESC) t\n" +
+							" WHERE rownum = 1";
+
+				paras = new OracleParameter[]
+				{
+					new OracleParameter(":datacode", datacode),
+					new OracleParameter(":logid", logid)
+				};
+
+				object executedateend = oracleConn.GetSqlResultToObj(sqlString, paras);
+
+				//if (executedateend == null || Convert.ToDateTime(executedateend) >= date)
+				//{
+				//	sre.Result = "W";
+				//	sre.Message = "当前日志的结束时间小于最新日志的结束时间,不能同步";
+				//	return sre;
+				//}
+
+
+				sqlString = "SELECT wd.yyyymmdd\n" +
+							"      ,wd.workcode\n" +
+							"      ,wd.datacode\n" +
+							"      ,wd.goodscode\n" +
+							"      ,wd.sapcode\n" +
+							"      ,wd.usercode\n" +
+							"      ,wd.ordercode\n" +
+							"      ,wd.orderitem\n" +
+							"      ,wd.outputnum\n" +
+							"      ,wd.scrapnum\n" +
+							"      ,wd.cleanupnum\n" +
+							"      ,wd.recoverynum\n" +
+							"      ,wd.repairnum\n" +
+							"      ,wd.testmouldflag\n" +
+							"      ,wd.zscs\n" +
+							"  FROM tsap_hegii_workdata wd\n" +
+							" WHERE wd.logid = :logid";
+
+				paras = new OracleParameter[]
+				{
+					new OracleParameter(":logid", OracleDbType.Int32, logid, ParameterDirection.Input),
+				};
+
+				DataTable workData = oracleConn.GetSqlResultToDt(sqlString, paras);
+
+				Zppfm008 sapParameter = new Zppfm008();
+				if (workData != null && workData.Rows.Count > 0)
+				{
+					sapParameter.ZSUM = workData.Rows.Count;
+					sapParameter.TABLE_IN = new ZSPP100[sapParameter.ZSUM];
+					int index = 0;
+					foreach (DataRow item in workData.Rows)
 					{
-						OutputLog.TraceLog(LogPriority.Warning,
-								"AutoWorkDataToSAP",
-								"6002 成品明细(小时) " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-								JsonHelper.ToJson(sre),
-								LocalPath.LogExePath + "SAP_HEGII\\Warn_");
+						ZSPP100 info100 = new ZSPP100();
+						// 工厂
+						info100.WERKS = workcode;
+						// 型号
+						info100.GROES = item["GoodsCode"].ToString();
+						// 物料编号
+						info100.MATNR = item["SAPCode"].ToString();
+						// 生产工号
+						info100.ZGHNU = item["UserCode"].ToString();
+						// 数据节点
+						info100.ZJDNU = item["DataCode"].ToString();
+						// 时间戳
+						info100.ZSCNU = yyyymmdd;
+						// 销售凭证
+						info100.VBELN = item["ORDERCODE"].ToString().Trim();
+						// 销售凭证项目
+						info100.POSNR = item["ORDERITEM"].ToString();
+						// 产量
+						info100.ZCLNG = item["OutputNum"].ToString();
+						// 损坯
+						info100.ZSPNG = item["SCRAPNUM"].ToString();
+						// 清除
+						info100.ZQCNG = item["CLEANUPNUM"].ToString();
+						// 回收
+						info100.ZHSNG = item["RECOVERYNUM"].ToString();
+						// 干补
+						info100.ZGBNG = item["REPAIRNUM"].ToString();
+						// 注浆类型 G高压 L普通
+						info100.ZSCS = item["ZSCS"].ToString();
+						//info100.ZKSSJ = Convert.ToDateTime(executedateend).ToString("HHmmss");
+						info100.ZKSSJ = Convert.ToDateTime("2022-06-24 12:00:00").ToString("HHmmss");
+						info100.ZJSRQ = Convert.ToDecimal(date.ToString("yyyyMMddHHmmss"));
+
+						sapParameter.TABLE_IN[index++] = info100;
 					}
 				}
-				catch (Exception ex)
+				else
 				{
-					OutputLog.TraceLog(LogPriority.Error,
-							"AutoWorkDataToSAP",
-							"6002 成品明细(小时) " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
-							ex.ToString(),
-							LocalPath.LogExePath + "SAP_HEGII\\Error_");
+					sapParameter.ZSUM = 0;
+					sapParameter.TABLE_IN = new ZSPP100[sapParameter.ZSUM];
+				}
+
+				// 调用SAP接口
+				ZPPFM008Response result = HGSAPDK_ZPPFM008(sapParameter, yyyymmdd, datacode);
+				if (result.TABLE_OUT != null && result.TABLE_OUT.Length > 0)
+				{
+					sqlString = "update TSAP_HEGII_WorkData t set t.ZTime =sysdate, ZTYPE = :ZTYPE, ZMSG = :ZMSG where logid = " + logid +
+						" \n and YYYYMMDD='" + yyyymmdd + "' and WorkCode='" + workcode +
+						"' and DataCode=:DataCode and GoodsCode=:GoodsCode and SAPCode=:SAPCode and UserCode=:UserCode \n" +
+						"and OrderCode=:OrderCode and OrderItem=:OrderItem";
+
+					foreach (ZSPP100 item in result.TABLE_OUT)
+					{
+						string posnr = item.POSNR.TrimStart('0');
+						paras = new OracleParameter[]
+						{
+								new OracleParameter(":ZTYPE",OracleDbType.Varchar2, item.ZTYPE, ParameterDirection.Input),
+								new OracleParameter(":ZMSG",OracleDbType.Varchar2, item.ZMSG, ParameterDirection.Input),
+								new OracleParameter(":DataCode",OracleDbType.Varchar2, datacode, ParameterDirection.Input),
+								new OracleParameter(":GoodsCode",OracleDbType.Varchar2, item.GROES, ParameterDirection.Input),
+								new OracleParameter(":SAPCode",OracleDbType.Varchar2, item.MATNR, ParameterDirection.Input),
+								new OracleParameter(":UserCode",OracleDbType.Varchar2, item.ZGHNU, ParameterDirection.Input),
+								new OracleParameter(":OrderCode",OracleDbType.Varchar2, (string.IsNullOrEmpty(item.VBELN) ? " " : item.VBELN), ParameterDirection.Input),
+								new OracleParameter(":OrderItem",OracleDbType.Varchar2, ((string.IsNullOrEmpty(posnr)) ? "0" : posnr), ParameterDirection.Input),
+						};
+						r = oracleConn.ExecuteNonQuery(sqlString, paras);
+					}
+				}
+
+				result.ZMSG = $"{result.ZMSG}({sapParameter.ZSUM})";
+				sqlString = "update tsap_hegii_datalog t set t.EndTime = sysdate, DataStuts = :DataStuts, DataMSG =:msg where logid = :logid";
+				paras = new OracleParameter[]
+				{
+						new OracleParameter(":DataStuts",OracleDbType.Varchar2, result.ZTYPE, ParameterDirection.Input),
+						new OracleParameter(":msg",OracleDbType.Varchar2, result.ZMSG, ParameterDirection.Input),
+						new OracleParameter(":logid",OracleDbType.Int32, logid, ParameterDirection.Input),
+				};
+				r = oracleConn.ExecuteNonQuery(sqlString, paras);
+				if (result.ZTYPE == "S")
+				{
+					sqlString = "update tsap_hegii_datalog t set t.createuserid = :userid where logid = :logid";
+					paras = new OracleParameter[]
+					{
+							new OracleParameter(":logid",OracleDbType.Int32, logid, ParameterDirection.Input),
+							new OracleParameter(":userid",OracleDbType.Int32, userid, ParameterDirection.Input),
+					};
+					r = oracleConn.ExecuteNonQuery(sqlString, paras);
+				}
+
+				oracleConn.Commit();
+
+				sre.Message = result.ZMSG;
+				sre.Result = result.ZTYPE;
+				return sre;
+			}
+			catch (Exception ex)
+			{
+				throw ex;
+			}
+			finally
+			{
+				if (oracleConn != null &&
+					oracleConn.ConnState == ConnectionState.Open)
+				{
+					oracleConn.Disconnect();
 				}
 			}
 		}

+ 2 - 2
DK.Service/SAPTest/Form1.cs

@@ -29,11 +29,11 @@ namespace SAPTest
                 //SAPDataLogic.HGSAPDK_SyncSap(DateTime.Now, "50", 0, logid);
                 //SAPDataLogic.SetFP60_240(DateTime.Now, 1);
 
-                string dateString = "2022-09-23 00:00:00";
+                string dateString = "2022-09-27 14:00:00";
                 DateTime dt = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
                 //SAPDataLogic.BGYKToSAP(DateTime.Now, dt);
                 //SAPDataLogic.CrossWorkshopToSAP(DateTime.Now, dt);
-                SAPDataLogic.AutoWorkDataToSAP5000(dt, "ALL", dt);
+                //SAPDataLogic.AutoWorkDataToSAP_Test("ALL", dt);
                 MessageBox.Show("OK");
             }
             catch (Exception ex)