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.

121 lines
6.2 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. /// 备料表(工单BOM)
  10. /// </summary>
  11. public class ICSMOBOM : 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 a.MoCode AS MOCODE ,
  40. b.InvCode AS ITEMCODE,
  41. b.SortSeq AS SEQ,
  42. c.InvCode AS MOBITEMCODE,
  43. CAST(c.AllocateId AS NVARCHAR(50)) AS MOBITEMECN,
  44. d.cInvName AS MOBITEMNAME,
  45. d.cInvStd AS MOBITEMDESC,
  46. '1' AS MOBITEMSTATUS,
  47. GETDATE() AS MOBITEMEFFTIME,
  48. GETDATE() AS MOBITEMINVTIME,
  49. CASE WHEN d.bCutMantissa='1' AND d.bKCCutMantissa='1' THEN CEILING(c.Qty) ELSE c.Qty END AS MOBITEMQTY,
  50. c.WhCode AS MOBITEMLOCATION,
  51. CASE WHEN c.WIPType='1' THEN '1' ELSE '0' END AS MOBOMITEMUOM,
  52. '' AS MOFAC,
  53. c.SortSeq AS MOBOMLINE,
  54. CASE WHEN ISNULL(a.ModifyTime, a.CreateTime)>ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) THEN ISNULL(a.ModifyTime, a.CreateTime) ELSE ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) END as MTIME
  55. into #TempBOM
  56. FROM {0}.dbo.mom_order a
  57. INNER JOIN {0}.dbo.mom_orderdetail b ON a.MoId = b.MoId
  58. INNER JOIN {0}.dbo.mom_moallocate c ON b.MoDId = c.MoDId
  59. INNER JOIN {0}.dbo.Inventory d ON c.InvCode = d.cInvCode
  60. LEFT JOIN {0}.dbo.bom_parent e ON b.BomId = e.BomId
  61. LEFT JOIN {0}.dbo.bom_bom f ON e.BomId = f.BomId
  62. LEFT JOIN {0}.dbo.ComputationUnit unit ON d.cComUnitCode = unit.cComunitCode
  63. WHERE ISNULL (b.RelsUser,'') <> ''
  64. and CASE WHEN ISNULL(a.ModifyTime, a.CreateTime)>ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) THEN ISNULL(a.ModifyTime, a.CreateTime) ELSE ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) END>=@LastTime
  65. IF NOT EXISTS(SELECT * FROM #TempBOM)
  66. RETURN";
  67. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
  68. sql += "\r\n";
  69. sql += @"--删除数据
  70. DELETE ICSMOBOM WHERE MOBITEMECN NOT IN (SELECT AllocateId FROM {0}.dbo.mom_moallocate) ";
  71. Dictionary<string, string> values = new Dictionary<string, string>();
  72. values.Add("MOCODE", "a.MOCODE");
  73. values.Add("ITEMCODE", "a.ITEMCODE");
  74. values.Add("SEQ", "a.SEQ");
  75. values.Add("MOBITEMCODE", "a.MOBITEMCODE");
  76. values.Add("MOBITEMNAME", "a.MOBITEMNAME");
  77. values.Add("MOBITEMDESC", "a.MOBITEMDESC");
  78. values.Add("MOBITEMSTATUS", "a.MOBITEMSTATUS");
  79. values.Add("MOBITEMEFFTIME", "a.MOBITEMEFFTIME");
  80. values.Add("MOBITEMINVTIME", "a.MOBITEMEFFTIME");
  81. values.Add("MOBITEMQTY", "a.MOBITEMQTY");
  82. values.Add("MOBOMITEMUOM", "a.MOBOMITEMUOM");//供应类型:1:入库到冲
  83. values.Add("MOBOMLINE", "a.MOBOMLINE");
  84. values.Add("MOBITEMLOCATION", "a.MOBITEMLOCATION");
  85. values.Add("MTIME", "a.MTIME");
  86. values.Add("MOFAC", "a.MOFAC");
  87. //values.Add("WorkPoint", "a.WorkPoint");
  88. //更新存在数据
  89. sql += ICSHelper.UpdateSQL("b", values)
  90. + @" #TempBOM a
  91. INNER JOIN ICSMOBOM b ON a.MOBITEMECN=b.MOBITEMECN
  92. ";
  93. values.Add("MOBITEMECN", "a.MOBITEMECN");
  94. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  95. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  96. values.Add("WorkPoint", "'" + WorkPoint + "'");
  97. sql += "\r\n";
  98. //插入新增数据
  99. sql += ICSHelper.InsertSQL("ICSMOBOM", values)
  100. + @" #TempBOM a
  101. LEFT JOIN ICSMOBOM b ON a.MOBITEMECN=b.MOBITEMECN
  102. WHERE b.MOBITEMECN IS NULL
  103. ";
  104. sql += "DROP TABLE #TempBOM";
  105. sql = string.Format(sql, WorkPoint);
  106. ICSHelper.ExecuteDate(conStr, sql);
  107. #endregion
  108. }
  109. catch (Exception ex)
  110. {
  111. log.Error(ex.ToString());
  112. }
  113. }
  114. }
  115. }