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.

201 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 ICSODeliveryNotice : 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 = @"
  48. select a.cCode as ODNCode,
  49. b.ivouchrowno as Sequence,
  50. a.cVenCode as VenCode ,
  51. cDepCode as DepCode ,
  52. CASE WHEN b.iQuantity>=0 THEN '1' ELSE '2' END AS ODNType,
  53. b.cInvCode as InvCode,
  54. b.iQuantity as Quantity ,
  55. isnull(b.iNum,0) as Amount,
  56. a.cexch_name as Currency,
  57. b.iCost as UnitPrice,
  58. a.cMaker as CreatePerson,
  59. a.cMakeTime as CreateDateTime,
  60. a.iverifystateex as Status,
  61. a.cMakeTime as MTIME,
  62. a.ID as ODNID,
  63. isnull(c.MOID,'') as OOID,
  64. isnull(b.iPOsID,'') as OODetailID,
  65. cast( b.AutoID AS VARCHAR) as ODNDetailID,
  66. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  67. (case WHEN inv.bFree1=1 THEN b.cFree1 ELSE '' END) as cFree1,
  68. (case WHEN inv.bFree2=1 THEN b.cFree2 ELSE '' END) as cFree2,
  69. (case WHEN inv.bFree3=1 THEN b.cFree3 ELSE '' END) as cFree3,
  70. (case WHEN inv.bFree4=1 THEN b.cFree4 ELSE '' END) as cFree4,
  71. (case WHEN inv.bFree5=1 THEN b.cFree5 ELSE '' END) as cFree5,
  72. (case WHEN inv.bFree6=1 THEN b.cFree6 ELSE '' END) as cFree6,
  73. (case WHEN inv.bFree7=1 THEN b.cFree7 ELSE '' END) as cFree7,
  74. (case WHEN inv.bFree8=1 THEN b.cFree8 ELSE '' END) as cFree8,
  75. (case WHEN inv.bFree9=1 THEN b.cFree9 ELSE '' END) as cFree9,
  76. (case WHEN inv.bFree10=1 THEN b.cFree10 ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan,
  77. '{0}' as WorkPoint,
  78. b.cWhCode as WHCode
  79. INTO #ICSSODelive
  80. from {1}.DBO.PU_ArrivalVouch a
  81. inner join {1}.DBO.PU_ArrivalVouchs b on a.ID =b.ID
  82. left join {1}.DBO.OM_MODetails c on b.iPOsID=c.MODetailsID
  83. LEFT JOIN {1}.dbo.Inventory inv ON b.cInvCode = inv.cInvCode
  84. where a.cBusType in('') and a.iBillType <>2 and
  85. ISNULL (a.cverifier ,'') <> ''and ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime))>=@LastTime
  86. update #ICSSODelive 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 #ICSSODelive
  91. IF NOT EXISTS(SELECT * FROM #ICSSODelive)
  92. RETURN";
  93. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#ICSSODelive");
  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 ICSODeliveryNotice WHERE ODNDetailID NOT IN ( SELECT AutoID FROM {1}.dbo.PU_ArrivalVouchs) and OASNCode IS NULL
  122. SELECT a.ODNDetailID INTO #tableICSODeliveryNotice
  123. FROM ICSODeliveryNotice a With(NoLock)
  124. LEFT JOIN {1}.dbo.[PU_ArrivalVouchs] b With(NoLock) ON a.ODNDetailID=b.AutoID
  125. WHERE a.WorkPoint='{0}' and b.AutoID IS NULL and a.OASNCode IS NULL
  126. DELETE ICSODeliveryNotice
  127. WHERE WorkPoint='{0}' and ODNDetailID IN ( SELECT ODNDetailID from #tableICSODeliveryNotice)
  128. ";
  129. Dictionary<string, string> values = new Dictionary<string, string>();
  130. values.Add("ODNCode", "a.ODNCode");
  131. values.Add("Sequence", "a.Sequence");
  132. values.Add("VenCode", "a.VenCode");
  133. values.Add("DepCode", "a.DepCode");
  134. values.Add("ODNType", "a.ODNType");
  135. values.Add("InvCode", "a.InvCode");
  136. values.Add("Quantity", "abs(a.Quantity)");
  137. values.Add("WHCode", "a.WHCode");
  138. values.Add("UnitPrice", "a.UnitPrice ");
  139. values.Add("Currency", "a.Currency");
  140. values.Add("Status", "a.Status");
  141. values.Add("CreatePerson", "a.CreatePerson");
  142. values.Add("CreateDateTime", "a.CreateDateTime");
  143. values.Add("OOID", "a.OOID");
  144. values.Add("OODetailID", "a.OODetailID");
  145. values.Add("ODNDetailID", "a.ODNDetailID");
  146. values.Add("ODNID", "a.ODNID");
  147. values.Add("ExtensionID", "c.ID");
  148. values.Add("EATTRIBUTE1", "''");
  149. //更新存在数据
  150. sql += ICSHelper.UpdateSQL("ICSODeliveryNotice", values)
  151. + @" #ICSSODelive a
  152. INNER JOIN ICSODeliveryNotice b ON a.ODNDetailID=b.ODNDetailID and a.WorkPoint=b.WorkPoint
  153. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  154. WHERE a.WorkPoint='" + WorkPoint + "' ";
  155. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  156. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  157. values.Add("WorkPoint", "'" + WorkPoint + "'");
  158. values.Add("MTIME", "a.MTIME");
  159. values.Add("ID", "NEWID()");
  160. values.Add("RCVQuantity", "0");
  161. //values.Add("ErpAutoID", "a.ErpAutoID");
  162. //values.Add("ErpID", "a.ErpID");
  163. //values.Add("iFQuantity", "a.iFQuantity");
  164. //插入新增数据
  165. sql += ICSHelper.InsertSQL("ICSODeliveryNotice", values)
  166. + @" #ICSSODelive a
  167. LEFT JOIN ICSODeliveryNotice b ON a.ODNDetailID=b.ODNDetailID and a.WorkPoint=b.WorkPoint
  168. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  169. WHERE b.ODNDetailID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  170. ";
  171. sql += "DROP TABLE #ICSSODelive";
  172. sql += " DROP TABLE #TempExtension " +
  173. " DROP TABLE #tableICSODeliveryNotice";
  174. sql = string.Format(sql, WorkPoint, erpName);
  175. ICSHelper.ExecuteDate(conStr, sql);
  176. #endregion
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. log.Error(ex.ToString());
  182. }
  183. }
  184. }
  185. }