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.

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