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.

160 lines
5.9 KiB

3 months ago
3 months ago
2 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. and free1 <>'15' and Free2 not like '%e%' and free1<>'0'
  63. and LotNO <>''
  64. select
  65. a.*
  66. from
  67. (
  68. select a.*
  69. ,row_number() over(partition by a.EqCode order by a.CreateTime desc) RowSeq
  70. from #tempSyncCas_Jinyang a
  71. ) a
  72. where a.RowSeq=1
  73. order by a.EqCode ";
  74. // sql = string.Format(sql, ErpId, erpName);
  75. sql = ICSHelper.Time4Old(Namespace, Class, WorkPoint, sql, "#tempSyncCas_Jinyang");
  76. // sql += "DROP TABLE #tempSyncCas_Jinyang";
  77. // sql += @"";
  78. var resultDT = ICSHelper.ExecuteTable(conStr, sql);
  79. List<CapInputDto> list = new List<CapInputDto>();
  80. if (resultDT == null)
  81. {
  82. return;
  83. }
  84. var insertSql = "";
  85. foreach (DataRow item in resultDT.Rows)
  86. {
  87. var input = new CapInputDto();
  88. input.WorkshopID = "6";
  89. input.EquipmentID = item["EqCode"].ToStringExt();
  90. input.ProductNo = item["InvStd "].ToStringExt();
  91. input.LotNo = item["LotNO"].ToStringExt();
  92. input.CollectionTime = item["CreateTime"].ToString();
  93. input.ParamValue_Resistance = item["Free2"].ToDecimal();
  94. input.ParamValue_Height = item["Free1"].ToDecimal();
  95. input.Msg = "";
  96. list.Add(input);
  97. insertSql += @"
  98. INSERT INTO [dbo].[ICSDomeAmb_cus]
  99. ([CreateTime]
  100. ,IPAddress
  101. ,UserCode
  102. ,[LotNO]
  103. ,[InvStd ]
  104. ,[EqCode]
  105. ,[Free1]
  106. ,[Free2]
  107. )
  108. values ('" + item["CreateTime"].ToString() + "','"+ item["IPAddress"].ToString() + "','"+ item["UserCode"].ToStringExt() + "','" + input.LotNo + "','" + input.ProductNo + "','" + input.EquipmentID + "','" + item["Free1"].ToStringExt() + "','"+ item["Free2"].ToStringExt() + "')";
  109. }
  110. if (list.Count == 0)
  111. {
  112. log.Info("没有数据行");
  113. return;
  114. }
  115. var inputObj = JsonConvert.SerializeObject(list);
  116. //string url = ICSHelper.GetConfigString()["JinyangCapUrl"]+ @"?deipaaskeyauth=a5P1RTL4380zd9jpb57qXx63rdynUHN2";
  117. string url = ICSHelper.GetConfigString()["JinyangCapUrl"];
  118. var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj, new Dictionary<string, string>() { { "deipaaskeyauth", "a5P1RTL4380zd9jpb57qXx63rdynUHN2" } }).Result;
  119. // var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj).Result;
  120. if (result.Result == "OK")
  121. {
  122. ICSHelper.ExecuteDate(conStr, insertSql);
  123. }
  124. else
  125. {
  126. throw new Exception(result.Result);
  127. }
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. log.Error(ex.ToString());
  133. }
  134. }
  135. }
  136. }