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.

117 lines
5.6 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 ICSOMBOM : 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 c.cCode AS OMCODE ,
  40. b.cInvCode AS ITEMCODE,
  41. b.iVouchRowNo AS OMSEQ,
  42. a.cInvCode AS BOMITEMCODE,
  43. CAST(a.MOMaterialsID AS NVARCHAR(50)) AS BOMITEMECN,
  44. d.cInvName AS BOMITEMNAME,
  45. d.cInvStd AS BOMITEMDESC,
  46. '1' AS BOMITEMSTATUS,
  47. GETDATE() AS BOMITEMEFFTIME,
  48. GETDATE() AS BOMITEMINVTIME,
  49. CASE WHEN d.bCutMantissa='1' AND d.bKCCutMantissa='1' THEN CEILING(a.iQuantity) ELSE a.iQuantity END AS BOMITEMQTY,
  50. a.cWhCode AS BOMITEMLOCATION,
  51. '' AS BOMITEMUOM,
  52. ISNULL(a.irowno,0) AS BOMLINE,
  53. ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime)) AS MTIME
  54. INTO #TempBOM
  55. FROM {0}.dbo.OM_MOMaterials a
  56. INNER JOIN {0}.dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  57. LEFT JOIN {0}.dbo.OM_MOMain c ON b.MOID = c.MOID
  58. LEFT JOIN {0}.dbo.Inventory d ON a.cInvCode = d.cInvCode
  59. LEFT JOIN {0}.dbo.ComputationUnit g ON d.cComUnitCode = g.cComunitCode
  60. WHERE ISNULL(c.cverifier, '')<>'' AND ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime))>=@LastTime
  61. IF NOT EXISTS(SELECT * FROM #TempBOM)
  62. RETURN";
  63. sql = ICSHelper.Time(Namespace, Class, ConstWorkPoint.WorkPoint, sql, "#TempBOM");
  64. sql += "\r\n";
  65. sql += @"--删除数据
  66. DELETE ICSOMBOM WHERE BOMITEMECN NOT IN (SELECT MOMaterialsID FROM {0}.dbo.OM_MOMaterials) ";
  67. Dictionary<string, string> values = new Dictionary<string, string>();
  68. values.Add("OMCODE", "a.OMCODE");
  69. values.Add("ITEMCODE", "a.ITEMCODE");
  70. values.Add("OMSEQ", "a.OMSEQ");
  71. values.Add("BOMITEMCODE", "a.BOMITEMCODE");
  72. values.Add("BOMITEMNAME", "a.BOMITEMNAME");
  73. values.Add("BOMITEMDESC", "a.BOMITEMDESC");
  74. values.Add("BOMITEMSTATUS", "a.BOMITEMSTATUS");
  75. values.Add("BOMITEMEFFTIME", "a.BOMITEMEFFTIME");
  76. values.Add("BOMITEMINVTIME", "a.BOMITEMEFFTIME");
  77. values.Add("BOMITEMQTY", "a.BOMITEMQTY");
  78. values.Add("BOMITEMUOM", "a.BOMITEMUOM");
  79. values.Add("BOMLINE", "a.BOMLINE");
  80. values.Add("BOMITEMLOCATION", "a.BOMITEMLOCATION");
  81. values.Add("MTIME", "a.MTIME");
  82. //values.Add("WorkPoint", "a.WorkPoint");
  83. //更新存在数据
  84. sql += ICSHelper.UpdateSQL("b", values)
  85. + @" #TempBOM a
  86. INNER JOIN ICSOMBOM b ON a.BOMITEMECN=b.BOMITEMECN
  87. ";
  88. values.Add("HasQTY", "'0'");
  89. values.Add("BOMITEMECN", "a.BOMITEMECN");
  90. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  91. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  92. values.Add("WorkPoint", "'" + ConstWorkPoint.WorkPoint + "'");
  93. sql += "\r\n";
  94. //插入新增数据
  95. sql += ICSHelper.InsertSQL("ICSOMBOM", values)
  96. + @" #TempBOM a
  97. LEFT JOIN ICSOMBOM b ON a.BOMITEMECN=b.BOMITEMECN
  98. WHERE b.BOMITEMECN IS NULL
  99. ";
  100. sql += "DROP TABLE #TempBOM";
  101. sql = string.Format(sql, ICSHelper.GetConfigString()["ERPDB"]);
  102. ICSHelper.ExecuteDate(conStr, sql);
  103. #endregion
  104. }
  105. catch (Exception ex)
  106. {
  107. log.Error(ex.ToString());
  108. }
  109. }
  110. }
  111. }