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.

175 lines
9.7 KiB

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 ICSOOPick : 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 WorkPoint = dr["WorkPointCode"].ToString();
  44. string Class = this.GetType().Name + WorkPoint;
  45. erpName = string.Format(erpName, WorkPoint);
  46. #region SQL
  47. string sql = @"SELECT a.MoDetailsID as OODetailID,
  48. a.MOMaterialsID as PickID,
  49. Row_Number() OVER (partition by a.MoDetailsID ORDER BY a.MOMaterialsID desc) AS Sequence,
  50. a.cInvCode AS InvCode,isnull(a.inum,0)AS Amount,
  51. CASE WHEN d.bCutMantissa='1' AND d.bKCCutMantissa='1' THEN CEILING(a.iQuantity) ELSE a.iQuantity END AS Quantity,
  52. a.cWhCode AS WHCode,
  53. (case when bInvQuality=0 then '4' else a.iWIPtype end) as SupplyType,
  54. ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime)) AS MTIME,
  55. '' ProjectCode,isnull(a.cBatch,'') cBatch,'' version ,'' brand,
  56. (case WHEN d.bFree1=1 THEN isnull(a.cFree1,'') ELSE '' END) as cFree1,
  57. (case WHEN d.bFree2=1 THEN isnull(a.cFree2,'') ELSE '' END) as cFree2,
  58. (case WHEN d.bFree3=1 THEN isnull(a.cFree3,'') ELSE '' END) as cFree3,
  59. (case WHEN d.bFree4=1 THEN isnull(a.cFree4,'') ELSE '' END) as cFree4,
  60. (case WHEN d.bFree5=1 THEN isnull(a.cFree5,'') ELSE '' END) as cFree5,
  61. (case WHEN d.bFree6=1 THEN isnull(a.cFree6,'') ELSE '' END) as cFree6,
  62. (case WHEN d.bFree7=1 THEN isnull(a.cFree7,'') ELSE '' END) as cFree7,
  63. (case WHEN d.bFree8=1 THEN isnull(a.cFree8,'') ELSE '' END) as cFree8,
  64. (case WHEN d.bFree9=1 THEN isnull(a.cFree9,'') ELSE '' END) as cFree9,
  65. (case WHEN d.bFree10=1 THEN isnull(a.cFree10,'') ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  66. , '{0}' as WorkPoint
  67. INTO #TempBOM
  68. FROM {1}.dbo.OM_MOMaterials a
  69. INNER JOIN {1}.dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  70. LEFT JOIN {1}.dbo.OM_MOMain c ON b.MOID = c.MOID
  71. LEFT JOIN {1}.dbo.Inventory d ON a.cInvCode = d.cInvCode
  72. LEFT JOIN {1}.dbo.ComputationUnit g ON d.cComUnitCode = g.cComunitCode
  73. WHERE ISNULL(c.cverifier, '')<>'' AND ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime))>=@LastTime
  74. update #TempBOM set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
  75. select distinct
  76. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  77. INTO #TempExtension
  78. from #TempBOM
  79. IF NOT EXISTS(SELECT * FROM #TempBOM)
  80. RETURN";
  81. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
  82. Dictionary<string, string> value = new Dictionary<string, string>();
  83. value.Add("ID", "NEWID()");
  84. value.Add("BatchCode", "a.cBatch");
  85. value.Add("version", "a.version");
  86. value.Add("brand", "a.brand");
  87. value.Add("ProjectCode", "a.ProjectCode");
  88. value.Add("cFree1", "a.cFree1");
  89. value.Add("cFree2", "a.cFree2");
  90. value.Add("cFree3", "a.cFree3");
  91. value.Add("cFree4", "a.cFree4");
  92. value.Add("cFree5", "a.cFree5");
  93. value.Add("cFree6", "a.cFree6");
  94. value.Add("cFree7", "a.cFree7");
  95. value.Add("cFree8", "a.cFree8");
  96. value.Add("cFree9", "a.cFree9");
  97. value.Add("cFree10", "a.cFree10");
  98. value.Add("Colspan", "a.Colspan");
  99. value.Add("MTIME", "GETDATE()");
  100. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  101. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  102. value.Add("WorkPoint", "'" + WorkPoint + "'");
  103. //插入新增数据->ICSExtension表
  104. sql += ICSHelper.InsertSQL("ICSExtension", value)
  105. + @"#TempExtension a
  106. LEFT JOIN ICSExtension b ON a.ProjectCode+'~'+a.cBatch+'~'+a.Version+'~'+a.Brand+'~'+a.cFree1+'~'+a.cFree2+'~'+a.cFree3+'~'+a.cFree4+'~'+a.cFree5+'~'+a.cFree6+'~'+a.cFree7+'~'+a.cFree8+'~'+a.cFree9+'~'+a.cFree10=b.Colspan and a.WorkPoint=b.WorkPoint
  107. WHERE b.Colspan IS NULL";
  108. sql += "\r\n";
  109. sql += @"--删除数据
  110. --DELETE ICSOOPick WHERE PickID NOT IN (SELECT MOMaterialsID FROM {1}.dbo.OM_MOMaterials)
  111. SELECT a.PickID INTO #tableICSOOPick
  112. FROM ICSOOPick a With(NoLock)
  113. LEFT JOIN {1}.dbo.[OM_MOMaterials] b With(NoLock) ON a.PickID= b.MOMaterialsID
  114. WHERE a.WorkPoint='{0}' and b.MOMaterialsID IS NULL
  115. DELETE ICSOOPick
  116. WHERE WorkPoint='{0}' and PickID IN ( SELECT PickID from #tableICSOOPick)
  117. ";
  118. Dictionary<string, string> values = new Dictionary<string, string>();
  119. values.Add("OODetailID", "a.OODetailID");
  120. values.Add("PickID", "a.PickID");
  121. values.Add("Sequence", "a.Sequence");
  122. values.Add("InvCode", "a.InvCode");
  123. values.Add("Quantity", "a.Quantity");
  124. values.Add("Amount", "a.Amount");
  125. values.Add("WHCode", "a.WHCode");
  126. values.Add("SupplyType", "a.SupplyType");
  127. values.Add("ExtensionID", "c.ID");
  128. values.Add("MTIME", "a.MTIME");
  129. //values.Add("WorkPoint", "a.WorkPoint");
  130. //更新存在数据
  131. sql += ICSHelper.UpdateSQL("b", values)
  132. + @" #TempBOM a
  133. INNER JOIN ICSOOPick b ON a.PickID=b.PickID and a.WorkPoint=b.WorkPoint
  134. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  135. WHERE a.WorkPoint='" + WorkPoint + "' ";
  136. values.Add("ID", "NEWID()");
  137. values.Add("IssueQuantity", "0");
  138. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  139. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  140. values.Add("WorkPoint", "'" + WorkPoint + "'");
  141. sql += "\r\n";
  142. //插入新增数据
  143. sql += ICSHelper.InsertSQL("ICSOOPick", values)
  144. + @" #TempBOM a
  145. LEFT JOIN ICSOOPick b ON a.PickID=b.PickID and a.WorkPoint=b.WorkPoint
  146. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  147. WHERE b.PickID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  148. ";
  149. sql += "DROP TABLE #TempBOM";
  150. sql += " DROP TABLE #TempExtension " +
  151. " DROP TABLE #tableICSOOPick";
  152. sql = string.Format(sql, WorkPoint, erpName);
  153. ICSHelper.ExecuteDate(conStr, sql);
  154. #endregion
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. log.Error(ex.ToString());
  160. }
  161. }
  162. }
  163. }