IcsFromERPJob
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.8 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. using ICSSoft.FromERP.Model;
  2. using Newtonsoft.Json;
  3. using Quartz;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ICSSoft.FromERP
  11. {
  12. /// <summary>
  13. /// 数采上传(金杨)
  14. /// </summary>
  15. public class SyncCas_Jinyang : IJob
  16. {
  17. private static object key = new object();
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. public void Execute(IJobExecutionContext context)
  20. {
  21. try
  22. {
  23. lock (key)
  24. {
  25. log.Info("开始……………………………………………………………………");
  26. Execute();
  27. log.Info("结束……………………………………………………………………");
  28. }
  29. }
  30. catch (Exception ex)
  31. {
  32. log.Error(ex.ToString());
  33. }
  34. }
  35. public void Execute()
  36. {
  37. try
  38. {
  39. string conStr = ICSHelper.GetConnectString();
  40. string Namespace = this.GetType().Namespace;
  41. // string Class = this.GetType().Name;
  42. DataTable dt = ICSHelper.GetOldERPDB(conStr);
  43. foreach (DataRow dr in dt.Rows)
  44. {
  45. var dtNowBegin = new DateTime(2000, 1, 1, 0, 0, 0);//默认开始时间
  46. var dtNow = DateTime.Now;
  47. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  48. string WorkPoint = dr["WorkPointCode"].ToString();
  49. string Class = this.GetType().Name + WorkPoint;
  50. erpName = string.Format(erpName, WorkPoint);
  51. //string sql0 = " SELECT top 1 ModifyDate FROM ICSERPTime where ClassName='" + Class + "'";
  52. //var lastDate = ICSHelper.ExecuteScalar(conStr, sql0).ToDateOrNull();
  53. //if (!lastDate.HasValue)
  54. //{
  55. // lastDate = dtNowBegin;
  56. //}
  57. // string sql = @" select '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' as MTIME into #TempCas ";
  58. string sql = @"if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempSyncCas_Jinyang') and type='U')
  59. DROP TABLE #tempSyncCas_Jinyang
  60. select * ,a.CreateTime as MTime into #tempSyncCas_Jinyang from [ICSDomeAmb] a with( nolock)
  61. where a.CreateTime>@LastTime
  62. select
  63. a.*
  64. from
  65. (
  66. select a.*
  67. ,row_number() over(partition by a.EqCode order by a.CreateTime desc) RowSeq
  68. from #tempSyncCas_Jinyang a
  69. ) a
  70. where a.RowSeq=1
  71. order by a.EqCode ";
  72. // sql = string.Format(sql, ErpId, erpName);
  73. sql = ICSHelper.Time4Old(Namespace, Class, WorkPoint, sql, "#tempSyncCas_Jinyang");
  74. // sql += "DROP TABLE #tempSyncCas_Jinyang";
  75. // sql += @"";
  76. var resultDT = ICSHelper.ExecuteTable(conStr, sql);
  77. List<CapInputDto> list = new List<CapInputDto>();
  78. if (resultDT == null)
  79. {
  80. return;
  81. }
  82. var insertSql = "";
  83. foreach (DataRow item in resultDT.Rows)
  84. {
  85. var input = new CapInputDto();
  86. input.WorkshopID = "6";
  87. input.EquipmentID = item["EqCode"].ToStringExt();
  88. input.ProductNo = item["InvStd "].ToStringExt();
  89. input.LotNo = item["LotNO"].ToStringExt();
  90. input.CollectionTime = item["CreateTime"].ToString();
  91. input.ParamValue_Resistance = item["Free2"].ToDecimal();
  92. input.ParamValue_Height = item["Free1"].ToDecimal();
  93. input.Msg = "";
  94. list.Add(input);
  95. insertSql += @"
  96. INSERT INTO [dbo].[ICSDomeAmb_cus]
  97. ([CreateTime]
  98. ,IPAddress
  99. ,UserCode
  100. ,[LotNO]
  101. ,[InvStd ]
  102. ,[EqCode]
  103. ,[Free1]
  104. ,[Free2]
  105. )
  106. values ('" + item["CreateTime"].ToString() + "','"+ item["IPAddress"].ToString() + "','"+ item["UserCode"].ToStringExt() + "','" + input.LotNo + "','" + input.ProductNo + "','" + input.EquipmentID + "','" + item["Free1"].ToStringExt() + "','"+ item["Free2"].ToStringExt() + "')";
  107. }
  108. if (list.Count == 0)
  109. {
  110. log.Info("没有数据行");
  111. return;
  112. }
  113. var inputObj = JsonConvert.SerializeObject(list);
  114. //string url = ICSHelper.GetConfigString()["JinyangCapUrl"]+ @"?deipaaskeyauth=a5P1RTL4380zd9jpb57qXx63rdynUHN2";
  115. string url = ICSHelper.GetConfigString()["JinyangCapUrl"];
  116. var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj, new Dictionary<string, string>() { { "deipaaskeyauth", "a5P1RTL4380zd9jpb57qXx63rdynUHN2" } }).Result;
  117. // var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj).Result;
  118. if (result.Result == "OK")
  119. {
  120. ICSHelper.ExecuteDate(conStr, insertSql);
  121. }
  122. else
  123. {
  124. throw new Exception(result.Result);
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. log.Error(ex.ToString());
  131. }
  132. }
  133. }
  134. }