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.

140 lines
7.0 KiB

4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
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 ICSMoBom : 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 TenantId = dr["TenantId"].ToString();//mes 组织
  44. string TenantCode = dr["TenantCode"].ToString();
  45. string ErpId = dr["ErpID"].ToString(); //erpID
  46. string Class = this.GetType().Name + TenantCode;
  47. erpName = string.Format(erpName, TenantId);
  48. #region SQL
  49. string sql = @"SELECT top 2000 A1.DocNo AS MOCODE ,
  50. A5.Code AS ITEMCODE,
  51. 1 AS SEQ,
  52. A4.Code AS MOBITEMCODE,
  53. CAST(A3.ID AS NVARCHAR(50)) AS MOBITEMECN,
  54. A4.Name AS MOBITEMNAME,
  55. A4.SPECS AS MOBITEMDESC,
  56. A1.DocState AS MOBITEMSTATUS,
  57. GETDATE() AS MOBITEMEFFTIME,
  58. GETDATE() AS MOBITEMINVTIME,
  59. A3.ActualReqQty AS MOBITEMQTY,
  60. A3.IssueStyle AS MOBITEMLOCATION,
  61. c.code AS MOFAC,
  62. A6.Code AS MOBOMITEMUOM,
  63. CAST(A3.DocLineNO AS NVARCHAR(50)) AS MOBOMLINE,
  64. A12.Code as WorkPoint,
  65. ISNULL(A3.ModifiedOn,A3.CreatedOn) AS MTIME
  66. into #TempPick
  67. FROM {0}.dbo.MO_MO A1
  68. INNER JOIN {0}.dbo.MO_MOPickList A3 ON A3.MO=A1.ID
  69. LEFT JOIN {0}.dbo.CBO_ItemMaster A4 ON A3.ItemMaster=A4.ID
  70. LEFT JOIN {0}.dbo.CBO_ItemMaster A5 ON A1.ItemMaster=A5.ID
  71. LEFT JOIN {0}.dbo.Base_UOM A6 ON A3.IssueUOM=A6.ID
  72. LEFT JOIN {0}.dbo.[Base_Organization] as A12 on (A1.[Org] = A12.[ID])
  73. LEFT JOIN {0}.dbo.CBO_Wh c on A3.SupplyWh=c.id and A1.org=c.org
  74. WHERE A3.IsPhantomPart!=1
  75. and ISNULL(A3.ModifiedOn,A3.CreatedOn)>=@LastTime
  76. and a12.id='{1}' order by ISNULL(A3.ModifiedOn,A3.CreatedOn)
  77. IF NOT EXISTS(SELECT * FROM #TempPick)
  78. RETURN";
  79. sql = string.Format(sql, erpName, ErpId);
  80. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempPick");
  81. Dictionary<string, string> value = new Dictionary<string, string>();
  82. sql += "\r\n";
  83. sql += @"--删除数据
  84. DELETE ICSMOBOM WHERE Default1 NOT IN (SELECT ID FROM {0}.dbo.MO_MOPickList) AND ICSMOBOM.TenantId='{1}'";
  85. Dictionary<string, string> values = new Dictionary<string, string>();
  86. values.Add("MOCODE", "a.MOCODE");
  87. values.Add("ITEMCODE", "a.ITEMCODE");
  88. values.Add("MOBITEMCODE", "a.MOBITEMCODE");
  89. values.Add("MOBITEMNAME", "a.MOBITEMNAME");
  90. values.Add("MoBItemSpec", "a.MOBITEMDESC");
  91. values.Add("MOBITEMSTATUS", "a.MOBITEMSTATUS");
  92. values.Add("MOBITEMEFFTIME", "a.MOBITEMEFFTIME");
  93. values.Add("MOBITEMINVTIME", "a.MOBITEMEFFTIME");
  94. values.Add("MOBITEMQTY", "a.MOBITEMQTY");
  95. values.Add("MOBOMITEMUOM", "a.MOBOMITEMUOM");
  96. values.Add("MOBOMLINE", "a.MOBOMLINE");
  97. values.Add("MOBITEMLOCATION", "a.MOBITEMLOCATION");
  98. values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");
  99. values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");
  100. values.Add("LastModificationTime", "a.Mtime");//操作时间
  101. values.Add("MOFAC", "a.MOFAC");
  102. //更新存在数据
  103. sql += ICSHelper.UpdateSQL("b", values)
  104. + @" #TempPick a
  105. INNER JOIN ICSMOBOM b ON a.MOBITEMECN=b.Default1 AND B.TenantId='{1}'
  106. ";
  107. values.Add("Default1", "a.MOBITEMECN");
  108. values.Add("CreationTime", "a.MTime");//操作人
  109. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  110. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  111. values.Add("TenantId", "'" + TenantId + "'");//站点
  112. sql += "\r\n";
  113. //插入新增数据
  114. sql += ICSHelper.InsertSQL("ICSMOBOM", values)
  115. + @" #TempPick a
  116. LEFT JOIN ICSMOBOM b ON a.MOBITEMECN=b.Default1 AND B.TenantId='{1}'
  117. WHERE b.Default1 IS NULL
  118. ";
  119. sql += "DROP TABLE #TempPick";
  120. sql = string.Format(sql, erpName, TenantId);
  121. //return;
  122. ICSHelper.ExecuteDate(conStr, sql);
  123. #endregion
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. log.Error(ex.ToString());
  129. }
  130. }
  131. }
  132. }