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.

119 lines
5.5 KiB

4 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quartz;
  6. namespace ICSSoft.FromERP
  7. {
  8. /// <summary>
  9. /// 采购(委外)退货
  10. /// </summary>
  11. public class ICSPOArrive : IJob
  12. {
  13. private static object key = new object();
  14. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  15. public void Execute(IJobExecutionContext context)
  16. {
  17. try
  18. {
  19. lock (key)
  20. {
  21. log.Info("开始……………………………………………………………………");
  22. Execute();
  23. log.Info("结束……………………………………………………………………");
  24. }
  25. }
  26. catch (Exception ex)
  27. {
  28. log.Error(ex.ToString());
  29. }
  30. }
  31. public void Execute()
  32. {
  33. try
  34. {
  35. string conStr = ICSHelper.GetConnectString();
  36. string Namespace = this.GetType().Namespace;
  37. string Class = this.GetType().Name;
  38. #region SQL
  39. string sql = @"SELECT CAST(a.Autoid AS NVARCHAR(50)) AS ERPAutoid,
  40. b.cCode AS cCode,
  41. CAST(a.irowno AS NVARCHAR(50)) AS irowno,
  42. b.cVenCode AS cVenCode,
  43. d.cVenName AS cVenName,
  44. b.cDepCode AS cDepCode,
  45. c.cDepName AS cDepName,
  46. b.cWhCode AS cWhCode,
  47. a.cInvCode AS cInvCode,
  48. -a.iQuantity AS iQuantity,
  49. ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME,
  50. ISNULL(a.cBatch,'') AS Batch,
  51. CAST(b.ID AS NVARCHAR(50)) AS ErpID,
  52. b.cOrderCode AS POCode,
  53. CAST(e.ivouchrowno AS NVARCHAR(50)) AS iPOsID,
  54. b.cBusType AS Free1
  55. INTO #TempPOArrive
  56. FROM {0}.dbo.RdRecords01 a
  57. INNER JOIN {0}.dbo.RdRecord01 b ON a.ID = b.ID
  58. LEFT JOIN {0}.dbo.Department c ON b.cDepCode = c.cDepCode
  59. LEFT JOIN {0}.dbo.Vendor d ON b.cVenCode = d.cVenCode
  60. LEFT JOIN {0}.dbo.PO_Podetails e ON a.iPOsID = e.ID
  61. WHERE ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime AND b.cBusType IN ('','') AND a.iQuantity<0 AND ISNULL(b.cHandler, '')=''
  62. IF NOT EXISTS(SELECT * FROM #TempPOArrive)
  63. RETURN";
  64. sql = ICSHelper.Time(Namespace, Class, ConstWorkPoint.WorkPoint, sql, "#TempPOArrive");
  65. sql += "\r\n";
  66. sql += @"--删除数据
  67. DELETE ICSPOArrive WHERE ERPAutoid NOT IN
  68. (SELECT Autoid FROM {0}.dbo.RdRecords01) AND LEN(ERPAutoid)>0 and Free2='退'";
  69. Dictionary<string, string> values = new Dictionary<string, string>();
  70. values.Add("cCode", "a.cCode");
  71. values.Add("irowno", "a.irowno");
  72. values.Add("cVenCode", "a.cVenCode");
  73. values.Add("cVenName", "a.cVenName");
  74. values.Add("cDepCode", "a.cDepCode");
  75. values.Add("cDepName", "a.cDepName");
  76. values.Add("cWhCode", "a.cWhCode");
  77. values.Add("cInvCode", "a.cInvCode");
  78. values.Add("iQuantity", "a.iQuantity");
  79. values.Add("MTime", "a.MTime");
  80. values.Add("Batch", "a.Batch");
  81. values.Add("POCode", "a.POCode");
  82. values.Add("iPOsID", "a.iPOsID");
  83. values.Add("Free1", "a.Free1");
  84. values.Add("Free2", "'退'");
  85. //更新存在数据
  86. sql += ICSHelper.UpdateSQL("b", values)
  87. + @" #TempPOArrive a
  88. INNER JOIN ICSPOArrive b ON a.ERPAutoid=b.ERPAutoid
  89. ";
  90. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  91. //values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  92. values.Add("WorkPoint", "'" + ConstWorkPoint.WorkPoint + "'");
  93. values.Add("ID", "NewID()");
  94. values.Add("ERPAutoid", "a.ERPAutoid");
  95. sql += "\r\n";
  96. //插入新增数据
  97. sql += ICSHelper.InsertSQL("ICSPOArrive", values)
  98. + @" #TempPOArrive a
  99. LEFT JOIN ICSPOArrive b ON a.ERPAutoid=b.ERPAutoid
  100. WHERE b.ERPAutoid IS NULL
  101. ";
  102. sql += "DROP TABLE #TempPOArrive";
  103. sql = string.Format(sql, ICSHelper.GetConfigString()["ERPDB"]);
  104. ICSHelper.ExecuteDate(conStr, sql);
  105. #endregion
  106. }
  107. catch (Exception ex)
  108. {
  109. log.Error(ex.ToString());
  110. }
  111. }
  112. }
  113. }