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.

128 lines
5.9 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 ICSPMIssueDoc : 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 A1.DocNo AS VouchCode,
  40. CAST(A2.LineNum AS NVARCHAR(50)) AS VouchRow,
  41. A4.Code AS SubInvCode,
  42. A2.IssueQty AS Quantity,
  43. A2.IssueQty AS DemandQuantity,
  44. CASE WHEN A1.IssueDirection=0 THEN '' ELSE '退' END AS MoveType,
  45. A6.Code AS WHCode,
  46. A8.Code AS ComUnitCode,
  47. CAST(A2.ID AS NVARCHAR(50)) AS Did,
  48. A1.BusinessDate AS VoucherDate,
  49. CAST(A1.DocState AS NVARCHAR(50)) AS Status,
  50. A1.BusinessDate AS MTIME,
  51. A12.DocNo AS POCode,
  52. A13.Code AS InvCode,
  53. A15.Code AS ORDERNO,
  54. A1.ID AS EATTRIBUTE,
  55. CAST(A10.DocLineNo AS NVARCHAR(50)) AS PORow,
  56. A16.Code AS WorkPoint,A18.Code,A2.LotNo AS cBatch
  57. into #TempPick
  58. FROM {0}.dbo.MaterialAppVouchs a
  59. INNER JOIN {0}.dbo.MaterialAppVouch b ON a.ID = b.ID
  60. INNER JOIN {0}.dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  61. LEFT JOIN {0}.dbo.OM_MOMain c ON b.MOID = c.MOID
  62. LEFT JOIN {0}.dbo.Inventory e ON a.cInvCode = e.cInvCode
  63. WHERE ISNULL(b.cHandler,'')<> ''
  64. AND ISNULL(b.dnverifytime,ISNULL(b.dnmodifytime, b.dnmaketime))>=@LastTime
  65. IF NOT EXISTS(SELECT * FROM #TempPick)
  66. RETURN";
  67. sql = ICSHelper.Time(Namespace, Class, ConstWorkPoint.WorkPoint, sql, "#TempPick");
  68. sql += @"--删除数据
  69. DELETE ICSOutSourePick WHERE Did NOT IN (SELECT ID FROM {0}.dbo.[PM_IssueDocLine]) AND LEN(Did)>0
  70. ";
  71. Dictionary<string, string> values = new Dictionary<string, string>();
  72. values.Add("VouchCode", "a.VouchCode");
  73. values.Add("VouchRow", "a.VouchRow");
  74. values.Add("POCode", "a.POCode");
  75. values.Add("InvCode", "a.InvCode");
  76. values.Add("SubInvCode", "a.SubInvCode");
  77. values.Add("Quantity", "a.Quantity");
  78. values.Add("DemandQuantity", "a.DemandQuantity");
  79. values.Add("WHCode", "a.WHCode");
  80. values.Add("ComUnitCode", "a.ComUnitCode");
  81. values.Add("Status", "a.Status");
  82. values.Add("VoucherDate", "a.VoucherDate");
  83. values.Add("MTIME", "a.MTIME");
  84. values.Add("EATTRIBUTE", "a.EATTRIBUTE");
  85. values.Add("PORow", "a.PORow");
  86. values.Add("WorkPoint", "a.WorkPoint");
  87. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  88. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  89. values.Add("cBatch", "a.cBatch");
  90. values.Add("MoveType", "a.MoveType");
  91. values.Add("ORDERNO", "a.ORDERNO");
  92. //values.Add("VoucherNO", "a.VoucherNO");
  93. //values.Add("Reservation", "a.Reservation");
  94. //values.Add("ReservationRow", "a.ReservationRow");
  95. //更新存在数据
  96. sql += ICSHelper.UpdateSQL("b", values)
  97. + @" #TempPick a
  98. INNER JOIN ICSOutSourePick b ON a.Did=b.Did
  99. ";
  100. values.Add("ID", "NEWID()");
  101. values.Add("HasQuantity", "'0'");
  102. values.Add("Sign", "'1'");
  103. values.Add("Did", "a.Did");
  104. //values.Add("WorkPoint", "'" + ConstWorkPoint.WorkPoint + "'");
  105. //插入新增数据
  106. sql += ICSHelper.InsertSQL("ICSOutSourePick", values)
  107. + @" #TempPick a
  108. LEFT JOIN ICSOutSourePick b ON a.Did=b.Did
  109. WHERE b.ID IS NULL
  110. ";
  111. sql += "DROP TABLE #TempPick";
  112. sql = string.Format(sql, ICSHelper.GetConfigString()["ERPDB"]);
  113. ICSHelper.ExecuteDate(conStr, sql);
  114. #endregion
  115. }
  116. catch (Exception ex)
  117. {
  118. log.Error(ex.ToString());
  119. }
  120. }
  121. }
  122. }