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.

159 lines
7.6 KiB

4 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using Quartz;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 杂收杂发(其他出入)
  11. /// </summary>
  12. public class ICSOtherOutIn : IJob
  13. {
  14. private static object key = new object();
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. public void Execute(IJobExecutionContext context)
  17. {
  18. try
  19. {
  20. lock (key)
  21. {
  22. log.Info("开始……………………………………………………………………");
  23. Execute();
  24. log.Info("结束……………………………………………………………………");
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. log.Error(ex.ToString());
  30. }
  31. }
  32. public void Execute()
  33. {
  34. try
  35. {
  36. string conStr = ICSHelper.GetConnectString();
  37. string Namespace = this.GetType().Namespace;
  38. //string Class = this.GetType().Name;
  39. DataTable dt = ICSHelper.GetERPDB(conStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  43. string WorkPoint = dr["WorkPointCode"].ToString();
  44. string Class = this.GetType().Name + WorkPoint;
  45. erpName = string.Format(erpName, WorkPoint);
  46. #region SQL
  47. string sql = @"SELECT
  48. CAST(b.AutoID AS NVARCHAR(50)) AS ErpAutoID,
  49. CAST(a.ID AS NVARCHAR(50)) AS ErpID,
  50. a.cCode AS cCode,
  51. a.dDate AS VoucherDate,
  52. a.cWhCode AS cWhCode,
  53. b.cInvCode AS cInvCode,
  54. b.iQuantity AS iQuantity,
  55. ISNULL(b.iFQuantity,0) AS iFQuantity,
  56. ISNULL(b.cBatch,'') AS cBatch,
  57. '入' AS TransType,
  58. CAST(b.irowno AS NVARCHAR(50)) AS irowno,
  59. '' AS Status,
  60. ISNULL(a.dnverifytime, a.dnmaketime) AS MTIME
  61. ,'{0}' as WorkPoint
  62. INTO #TempPick
  63. FROM {1}.dbo.RdRecord08 a
  64. LEFT JOIN {1}.dbo.rdrecords08 b ON a.ID=b.ID
  65. WHERE ISNULL(a.cHandler, '')='' AND ISNULL(a.dnverifytime, a.dnmaketime)>=@LastTime
  66. UNION ALL
  67. SELECT
  68. CAST(b.AutoID AS NVARCHAR(50)) AS ErpAutoID,
  69. CAST(a.ID AS NVARCHAR(50)) AS ErpID,
  70. a.cCode AS cCode,
  71. a.dDate AS VoucherDate,
  72. a.cWhCode AS cWhCode,
  73. b.cInvCode AS cInvCode,
  74. b.iQuantity AS iQuantity,
  75. ISNULL(b.iFQuantity,0) AS iFQuantity,
  76. ISNULL(b.cBatch,'') AS cBatch,
  77. '出' AS TransType,
  78. CAST(b.irowno AS NVARCHAR(50)) AS irowno,
  79. '' AS Status,
  80. ISNULL(a.dnverifytime, a.dnmaketime) AS MTIME
  81. ,'{0}' as WorkPoint
  82. FROM {1}.dbo.RdRecord09 a
  83. LEFT JOIN {1}.dbo.rdrecords09 b ON b.ID=a.ID
  84. WHERE ISNULL(a.cHandler, '')='' AND ISNULL(a.dnverifytime, a.dnmaketime)>=@LastTime
  85. IF NOT EXISTS(SELECT * FROM #TempPick)
  86. RETURN";
  87. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPick");
  88. sql += @"--删除数据
  89. --DELETE ICSOtherOutIn WHERE ErpAutoID+TransType NOT IN (SELECT CAST(AutoID AS VARCHAR)+'入' FROM {1}.dbo.rdrecords08
  90. --UNION ALL
  91. --SELECT CAST(AutoID AS VARCHAR)+'出' FROM {1}.dbo.rdrecords09)
  92. SELECT a.ErpAutoID+a.TransType ID INTO #tableICSOtherOutIn
  93. FROM ICSOtherOutIn a With(NoLock)
  94. LEFT JOIN (SELECT CAST(AutoID AS VARCHAR)+'入' str1
  95. FROM {1}.dbo.[rdrecords08] With(NoLock)
  96. UNION ALL
  97. SELECT CAST(AutoID AS VARCHAR)+'出' str1
  98. FROM {1}.dbo.[rdrecords09] With(NoLock)
  99. ) b ON a.ErpAutoID+a.TransType=b.str1
  100. WHERE a.WorkPoint='{0}' and b.str1 IS NULL
  101. DELETE ICSOtherOutIn
  102. WHERE WorkPoint='{0}' and ErpAutoID+TransType IN ( SELECT ID from #tableICSOtherOutIn)
  103. ";
  104. Dictionary<string, string> values = new Dictionary<string, string>();
  105. values.Add("cCode", "a.cCode");
  106. values.Add("VoucherDate", "a.VoucherDate");
  107. values.Add("cWhCode", "a.cWhCode");
  108. values.Add("cInvCode", "a.cInvCode");
  109. values.Add("iQuantity", "a.iQuantity");
  110. values.Add("cBatch", "a.cBatch");
  111. values.Add("TransType", "a.TransType");
  112. values.Add("irowno", "a.irowno");
  113. values.Add("Status", "a.Status");
  114. values.Add("MTIME", "a.MTIME");
  115. //更新存在数据
  116. sql += ICSHelper.UpdateSQL("b", values)
  117. + @" #TempPick a
  118. INNER JOIN ICSOtherOutIn b ON a.ErpAutoID+a.TransType=b.ErpAutoID+a.TransType and a.WorkPoint=b.WorkPoint
  119. WHERE a.WorkPoint='" + WorkPoint + "' ";
  120. values.Add("ID", "NEWID()");
  121. values.Add("ErpAutoID", "a.ErpAutoID");
  122. values.Add("ErpID", "a.ErpID");
  123. values.Add("iFQuantity", "a.iFQuantity");
  124. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  125. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  126. values.Add("WorkPoint", "'" + WorkPoint + "'");
  127. //插入新增数据
  128. sql += ICSHelper.InsertSQL("ICSOtherOutIn", values)
  129. + @" #TempPick a
  130. LEFT JOIN ICSOtherOutIn b ON a.ErpAutoID+a.TransType=b.ErpAutoID+a.TransType and a.WorkPoint=b.WorkPoint
  131. WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  132. ";
  133. sql += "DROP TABLE #TempPick " +
  134. " DROP TABLE #tableICSOtherOutIn";
  135. sql = string.Format(sql, WorkPoint, erpName);
  136. ICSHelper.ExecuteDate(conStr, sql);
  137. #endregion
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. log.Error(ex.ToString());
  143. }
  144. }
  145. }
  146. }