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.

191 lines
11 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 ICSDisassemblyDoc : 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 CAST(b.ID as VARCHAR(50)) AS EATTRIBUTE ,
  48. b.cAVCode AS DABDOCCode,
  49. b.cDepCode AS DepCode,
  50. ISNULL(a.cWhCode,'') AS WHCode ,
  51. CAST(a.irowno as VARCHAR(50)) AS Sequence ,
  52. a.cInvCode AS InvCode ,
  53. a.iAVQuantity AS Quantity ,
  54. isnull(a.iAVNum,0) as Amount,
  55. CASE WHEN a.bAVType=''THEN '1' ELSE '2' END AS DABDOCType,
  56. CASE WHEN ISNULL(b.cVerifyPerson , '')='' THEN '1' ELSE '2' END AS Status,
  57. isnull(b.cMaker,'') as CreatePerson,
  58. b.dnmaketime as CreateDateTime,
  59. CAST(a.ID as VARCHAR(50)) AS DABDOCID ,
  60. CAST(a.autoID as VARCHAR(50)) AS DABDOCDetailID ,
  61. ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME,
  62. isnull(a.cItemCode,'') ProjectCode,isnull(a.cAVBatch,'') cBatch,'' version ,'' brand,
  63. (case WHEN e.bFree1=1 THEN a.cFree1 ELSE '' END) as cFree1,
  64. (case WHEN e.bFree2=1 THEN a.cFree2 ELSE '' END) as cFree2,
  65. (case WHEN e.bFree3=1 THEN a.cFree3 ELSE '' END) as cFree3,
  66. (case WHEN e.bFree4=1 THEN a.cFree4 ELSE '' END) as cFree4,
  67. (case WHEN e.bFree5=1 THEN a.cFree5 ELSE '' END) as cFree5,
  68. (case WHEN e.bFree6=1 THEN a.cFree6 ELSE '' END) as cFree6,
  69. (case WHEN e.bFree7=1 THEN a.cFree7 ELSE '' END) as cFree7,
  70. (case WHEN e.bFree8=1 THEN a.cFree8 ELSE '' END) as cFree8,
  71. (case WHEN e.bFree9=1 THEN a.cFree9 ELSE '' END) as cFree9,
  72. (case WHEN e.bFree10=1 THEN a.cFree10 ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  73. , '{0}' as WorkPoint
  74. INTO #TempPickAssem
  75. FROM {1}.dbo.AssemVouchs a
  76. INNER JOIN {1}.dbo.AssemVouch b ON a.ID = b.ID
  77. LEFT JOIN {1}.dbo.Inventory e ON a.cInvCode = e.cInvCode
  78. WHERE ISNULL(b.cVerifyPerson,'')='' AND b.cVouchType='14'
  79. AND ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime
  80. update #TempPickAssem 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,'')
  81. select distinct
  82. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  83. INTO #TempExtension
  84. from #TempPickAssem
  85. IF NOT EXISTS(SELECT * FROM #TempPickAssem)
  86. RETURN";
  87. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPickAssem");
  88. Dictionary<string, string> value = new Dictionary<string, string>();
  89. value.Add("ID", "NEWID()");
  90. value.Add("BatchCode", "a.cBatch");
  91. value.Add("version", "a.version");
  92. value.Add("brand", "a.brand");
  93. value.Add("ProjectCode", "a.ProjectCode");
  94. value.Add("cFree1", "a.cFree1");
  95. value.Add("cFree2", "a.cFree2");
  96. value.Add("cFree3", "a.cFree3");
  97. value.Add("cFree4", "a.cFree4");
  98. value.Add("cFree5", "a.cFree5");
  99. value.Add("cFree6", "a.cFree6");
  100. value.Add("cFree7", "a.cFree7");
  101. value.Add("cFree8", "a.cFree8");
  102. value.Add("cFree9", "a.cFree9");
  103. value.Add("cFree10", "a.cFree10");
  104. value.Add("Colspan", "a.Colspan");
  105. value.Add("MTIME", "GETDATE()");
  106. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  107. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  108. value.Add("WorkPoint", "'" + WorkPoint + "'");
  109. //插入新增数据->ICSExtension表
  110. sql += ICSHelper.InsertSQL("ICSExtension", value)
  111. + @"#TempExtension a
  112. 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
  113. WHERE b.Colspan IS NULL";
  114. sql += "\r\n";
  115. sql += @"--删除数据
  116. --DELETE ICSDisassemblyDoc WHERE DABDOCDetailID NOT IN (SELECT autoID FROM {1}.dbo.AssemVouchs ) AND LEN(DABDOCDetailID)>0
  117. SELECT a.DABDOCDetailID INTO #tableICSDisassemblyDoc
  118. FROM ICSDisassemblyDoc a With(NoLock)
  119. LEFT JOIN {1}.dbo.[AssemVouchs] b With(NoLock) ON a.DABDOCDetailID=b.autoID
  120. WHERE a.WorkPoint='{0}' and b.autoID IS NULL AND LEN(a.DABDOCDetailID)>0
  121. DELETE ICSDisassemblyDoc
  122. WHERE WorkPoint='{0}' and DABDOCDetailID IN ( SELECT DABDOCDetailID from #tableICSDisassemblyDoc)
  123. ";
  124. Dictionary<string, string> values = new Dictionary<string, string>();
  125. values.Add("DABDOCCode", "a.DABDOCCode");
  126. values.Add("DepCode", "a.DepCode");
  127. values.Add("WHCode", "a.WHCode");
  128. values.Add("Sequence", "a.Sequence");
  129. values.Add("InvCode", "a.InvCode");
  130. values.Add("Quantity", "a.Quantity");
  131. values.Add("Amount", "a.Amount");
  132. values.Add("DABDOCType", "a.DABDOCType");
  133. values.Add("Status", "a.Status");
  134. values.Add("CreatePerson", "a.CreatePerson");
  135. values.Add("CreateDateTime", "a.CreateDateTime");
  136. values.Add("DABDOCID", "a.DABDOCID");
  137. values.Add("DABDOCDetailID", "a.DABDOCDetailID");
  138. values.Add("ExtensionID", "c.ID");
  139. //values.Add("ORDERNO", "a.ORDERNO");
  140. //values.Add("WorkPoint", "a.WorkPoint");
  141. //values.Add("cBatch", "a.cBatch");
  142. //values.Add("DepCode", "a.DepCode");
  143. //更新存在数据
  144. sql += ICSHelper.UpdateSQL("b", values)
  145. + @" #TempPickAssem a
  146. INNER JOIN ICSDisassemblyDoc b ON a.DABDOCDetailID=b.DABDOCDetailID and a.WorkPoint=b.WorkPoint
  147. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  148. WHERE a.WorkPoint='" + WorkPoint + "' ";
  149. values.Add("ID", "NEWID()");
  150. values.Add("DABDOCQuantity", "0");
  151. //values.Add("HasQuantity", "'0'");
  152. //values.Add("Did", "a.Did");
  153. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  154. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  155. values.Add("MTIME", "a.MTIME");
  156. values.Add("WorkPoint", "'" + WorkPoint + "'");
  157. //插入新增数据
  158. sql += ICSHelper.InsertSQL("ICSDisassemblyDoc", values)
  159. + @" #TempPickAssem a
  160. LEFT JOIN ICSDisassemblyDoc b ON a.DABDOCDetailID=b.DABDOCDetailID and a.WorkPoint=b.WorkPoint
  161. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  162. WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  163. sql += " DROP TABLE #TempPickAssem ";
  164. sql += " DROP TABLE #TempExtension " +
  165. " DROP TABLE #tableICSDisassemblyDoc";
  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. }