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.

192 lines
10 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 ICSOtherOut : 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
  48. CAST(A2.ID AS NVARCHAR(50)) AS OutDetailID,
  49. CAST(A1.ID AS NVARCHAR(50)) AS OutID,
  50. '' as TransferID,
  51. '' as TransferDetailID,
  52. A1.DocNo AS OutCode,
  53. A1.BusinessDate AS VoucherDate,
  54. A3.Code AS cWhCode,
  55. CAST(A2.DocLineNo AS NVARCHAR(50)) AS Sequence,
  56. A2.ItemInfo_ItemCode AS InvCode,
  57. A2.StoreUOMQty AS iQuantity,
  58. 0 as Amount,
  59. '1' AS Status,
  60. A1.CreatedBy as CreatePerson,
  61. A1.CreatedOn as CreateDateTime,
  62. ISNULL(A2.LotInfo_LotCode,'') AS cBatch,
  63. '出' AS TransType,
  64. ISNULL(A2.ModifiedOn ,A2.CreatedOn) AS MTIME,
  65. isnull(A5.Code,'') ProjectCode, '' version ,'' brand,
  66. '' as cFree1,
  67. '' as cFree2,
  68. '' as cFree3,
  69. '' as cFree4,
  70. '' as cFree5,
  71. '' as cFree6,
  72. '' as cFree7,
  73. '' as cFree8,
  74. '' as cFree9,
  75. '' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  76. ,A4.Code as WorkPoint
  77. INTO #TempPick
  78. FROM {1}.dbo.InvDoc_MiscShip A1
  79. LEFT JOIN {1}.dbo.InvDoc_MiscShipL A2 ON A2.MiscShip=A1.ID
  80. LEFT JOIN {1}.dbo.CBO_Wh A3 ON A2.Wh=A3.ID
  81. LEFT JOIN {1}.dbo.Base_Organization A4 ON A1.Org=a4.ID
  82. LEFT JOIN {1}.dbo.CBO_Project A5 ON A2.Project=A5.ID
  83. WHERE A1.Status<2 AND A4.Code='{0}' AND ISNULL(A2.ModifiedOn ,A2.CreatedOn)>=@LastTime
  84. update #TempPick 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,'')
  85. select distinct
  86. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  87. INTO #TempExtension
  88. from #TempPick
  89. IF NOT EXISTS(SELECT * FROM #TempPick)
  90. RETURN";
  91. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPick");
  92. Dictionary<string, string> value = new Dictionary<string, string>();
  93. value.Add("ID", "NEWID()");
  94. value.Add("BatchCode", "a.cBatch");
  95. value.Add("version", "a.version");
  96. value.Add("brand", "a.brand");
  97. value.Add("ProjectCode", "a.ProjectCode");
  98. value.Add("cFree1", "a.cFree1");
  99. value.Add("cFree2", "a.cFree2");
  100. value.Add("cFree3", "a.cFree3");
  101. value.Add("cFree4", "a.cFree4");
  102. value.Add("cFree5", "a.cFree5");
  103. value.Add("cFree6", "a.cFree6");
  104. value.Add("cFree7", "a.cFree7");
  105. value.Add("cFree8", "a.cFree8");
  106. value.Add("cFree9", "a.cFree9");
  107. value.Add("cFree10", "a.cFree10");
  108. value.Add("Colspan", "a.Colspan");
  109. value.Add("MTIME", "GETDATE()");
  110. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  111. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  112. value.Add("WorkPoint", "'" + WorkPoint + "'");
  113. //插入新增数据->ICSExtension表
  114. sql += ICSHelper.InsertSQL("ICSExtension", value)
  115. + @"#TempExtension a
  116. 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
  117. WHERE b.Colspan IS NULL";
  118. sql += @"--删除数据
  119. -- DELETE ICSOtherOut WHERE OutDetailID NOT IN ( SELECT AutoID FROM {1}.dbo.rdrecords09)
  120. SELECT a.OutDetailID INTO #tableICSOtherOut
  121. FROM ICSOtherOut a With(NoLock)
  122. LEFT JOIN {1}.dbo.[InvDoc_MiscShipL] b With(NoLock) ON a.OutDetailID= b.ID
  123. WHERE a.WorkPoint='{0}' and b.ID IS NULL
  124. DELETE ICSOtherOut
  125. WHERE WorkPoint='{0}' and OutDetailID IN ( SELECT OutDetailID from #tableICSOtherOut)
  126. ";
  127. Dictionary<string, string> values = new Dictionary<string, string>();
  128. values.Add("OutCode", "a.OutCode");
  129. values.Add("WHCode", "a.cWhCode");
  130. values.Add("Sequence", "a.Sequence");
  131. values.Add("InvCode", "a.InvCode");
  132. values.Add("Quantity", "a.iQuantity");
  133. values.Add("Amount", "a.Amount");
  134. values.Add("Status", "a.Status");
  135. values.Add("CreatePerson", "a.CreatePerson ");
  136. values.Add("CreateDateTime", "a.CreateDateTime");
  137. values.Add("OutID", "a.OutID");
  138. values.Add("OutDetailID", "a.OutDetailID");
  139. values.Add("TransferID", "a.TransferID");
  140. values.Add("TransferDetailID", "a.TransferDetailID");
  141. values.Add("ExtensionID", "c.ID");
  142. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  143. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  144. values.Add("WorkPoint", "'" + WorkPoint + "'");
  145. values.Add("MTIME", "a.MTIME");
  146. //更新存在数据
  147. sql += ICSHelper.UpdateSQL("ICSOtherOut", values)
  148. + @" #TempPick a
  149. INNER JOIN ICSOtherOut b ON a.OutDetailID=b.OutDetailID and a.WorkPoint=b.WorkPoint
  150. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  151. WHERE a.WorkPoint='" + WorkPoint + "' ";
  152. values.Add("ID", "NEWID()");
  153. values.Add("OutQuantity", "0");
  154. //values.Add("ErpAutoID", "a.ErpAutoID");
  155. //values.Add("ErpID", "a.ErpID");
  156. //values.Add("iFQuantity", "a.iFQuantity");
  157. //插入新增数据
  158. sql += ICSHelper.InsertSQL("ICSOtherOut", values)
  159. + @" #TempPick a
  160. LEFT JOIN ICSOtherOut b ON a.OutDetailID=b.OutDetailID and a.WorkPoint=b.WorkPoint
  161. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  162. WHERE b.OutID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  163. ";
  164. sql += "DROP TABLE #TempPick";
  165. sql += " DROP TABLE #TempExtension " +
  166. " DROP TABLE #tableICSOtherOut";
  167. sql = string.Format(sql, WorkPoint, erpName);
  168. ICSHelper.ExecuteDate(conStr, sql);
  169. #endregion
  170. }
  171. }
  172. catch (Exception ex)
  173. {
  174. log.Error(ex.ToString());
  175. }
  176. }
  177. }
  178. }