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.

166 lines
7.5 KiB

4 months ago
4 months ago
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ICSSoft.FromERP
  9. {
  10. /// <summary>
  11. /// 产品Bom(锐腾)
  12. /// </summary>
  13. public class IcsSBom_Rhtyon : IJob
  14. {
  15. private static object key = new object();
  16. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  17. public void Execute(IJobExecutionContext context)
  18. {
  19. try
  20. {
  21. lock (key)
  22. {
  23. log.Info("开始……………………………………………………………………");
  24. Execute();
  25. log.Info("结束……………………………………………………………………");
  26. }
  27. }
  28. catch (Exception ex)
  29. {
  30. log.Error(ex.ToString());
  31. }
  32. }
  33. public void Execute()
  34. {
  35. try
  36. {
  37. string conStr = ICSHelper.GetConnectString();
  38. string Namespace = this.GetType().Namespace;
  39. //string Class = this.GetType().Name;
  40. DataTable dt = ICSHelper.GetERPDB(conStr);
  41. foreach (DataRow dr in dt.Rows)
  42. {
  43. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  44. string TenantId = dr["TenantId"].ToString();
  45. string TenantCode = dr["TenantCode"].ToString();
  46. string ErpId = dr["ErpID"].ToString(); //erpID
  47. string Class = this.GetType().Name + TenantCode;
  48. erpName = string.Format(erpName, TenantId);
  49. #region SQL
  50. string sql = @" select distinct A2.[ID] as 料品ID,
  51. A2.[Code] as ,
  52. A2.Name as ,
  53. A4.Description as ,
  54. A3.ID as ID,
  55. A3.[Code] as ,
  56. A3.[Name] as ,
  57. A5.Description as ,
  58. A.FixedScrap as ,
  59. isnull( A6.[Code],'') as ,
  60. isnull( A.[ECNCode],'') as ,
  61. A.[UsageQty],
  62. a.ParentQty,
  63. cast(isnull( A.[UsageQty],0)/isnull( a.ParentQty,1) as decimal(18,6)) ,
  64. A.[ItemVersionCode] as ,
  65. A.[EffectiveDate] as ,
  66. isnull( A.IsSpecialUseItem,'') as ,
  67. A.[DisableDate] as ,
  68. A.[Sequence] as ,
  69. A.[IsEffective] as ,
  70. A1.[BOMVersionCode] as ,
  71. A.[OperationNum] as
  72. ,I.id as Org
  73. ,A.ModifiedOn as MTime
  74. ,A.ID as ErpDetailID
  75. INTO #TempBOM
  76. from {1}.dbo.CBO_BOMComponent as A
  77. left join {1}.dbo.[CBO_BOMMaster] as A1 on (A.[BOMMaster] = A1.[ID])
  78. left join {1}.dbo.[CBO_ItemMaster] as A2 on (A1.[ItemMaster] = A2.[ID])
  79. left join {1}.dbo.[CBO_ItemMaster_Trl] as A4 on (A4.SysMlFlag = 'zh-CN') and (A2.[ID] = A4.[ID])
  80. left join {1}.dbo.[CBO_ItemMaster] as A3 on (A.[ItemMaster] = A3.[ID])
  81. left join {1}.dbo.[CBO_ItemMaster_Trl] as A5 on (A5.SysMlFlag = 'zh-CN') and (A3.[ID] = A5.[ID])
  82. left join {1}.dbo.[CBO_Project] as A6 on (A.[CompProject] = A6.[ID])
  83. LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A1.[Org] = I.[ID] )
  84. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  85. where 1=1 and IsEffective=1 and A.ModifiedOn>=@LastTime AND I.id={0} and A.ComponentType=0 and A1.AlternateType=0
  86. and A1.bomtype=0
  87. IF NOT EXISTS(SELECT * FROM #TempBOM)
  88. RETURN";
  89. sql = string.Format(sql, ErpId, erpName);
  90. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempBOM");
  91. sql += "\r\n";
  92. sql += @"--删除数据
  93. -- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent)
  94. SELECT a.ErpId INTO #tableICSSBOM
  95. FROM ICSSBOM a With(NoLock)
  96. LEFT JOIN {1}.dbo.[CBO_BOMComponent] b With(NoLock) ON a.ErpId=b.Id
  97. LEFT JOIN {1}.dbo.CBO_BOMMaster c With(NoLock) ON b.BOMMaster=c.Id
  98. WHERE b.id is null
  99. and a.TenantId='{0}'
  100. AND c.Org={2}
  101. DELETE ICSSBOM
  102. WHERE TenantId='{0}' and ErpId IN ( SELECT ErpId from #tableICSSBOM)
  103. ";
  104. Dictionary<string, string> values = new Dictionary<string, string>();
  105. values.Add("SBOMVER", "a.母料版本号");
  106. values.Add("ITEMCODE", "a.料品编码");
  107. values.Add("SBITEMCODE", "a.子阶料编码");
  108. values.Add("SBItemName", "a.子阶料名称");
  109. //values.Add("SBItemDesc", "a.子阶料描述");
  110. values.Add("SBSITEMCODE", "a.子阶料编码");
  111. values.Add("SBITEMQTY", "a.子阶料计量数量");
  112. values.Add("SEQ", "1");
  113. values.Add("SBItemECN", "a.工程变更号");
  114. values.Add("SBItemStatus", "'Y'");
  115. values.Add("SBItemEfftime", "a.生效日期");
  116. values.Add("SBItemInvtime", "a.失效日期");
  117. values.Add("SBItemProject", "a.项目号");
  118. values.Add("SBItemSeq", "a.次序");
  119. values.Add("Location", "a.工序号");
  120. values.Add("LastModificationTime", "a.Mtime");//操作时间
  121. values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  122. values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  123. values.Add("SBItemContype", "c.ItemContype");
  124. //更新存在数据
  125. sql += ICSHelper.UpdateSQL("b", values)
  126. + @" #TempBOM a
  127. INNER JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId
  128. left join IcsInventory c on b.SBItemCode=c.ItemCode and b.TenantId=c.TenantId
  129. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and c.TenantId=d.TenantId
  130. WHERE b.TenantId='{0}' and a.Org={2} ";
  131. values.Add("ErpId", "convert(nvarchar(100), a.ErpDetailID)");
  132. values.Add("CreationTime", "a.MTime");//操作人
  133. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  134. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  135. values.Add("TenantId", "'" + TenantId + "'");//站点
  136. sql += "\r\n";
  137. //插入新增数据
  138. sql += ICSHelper.InsertSQL("ICSSBOM", values)
  139. + @" #TempBOM a
  140. LEFT JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId and b.TenantId='{0}'
  141. left join IcsInventory c on a.=c.ItemCode and c.TenantId='{0}'
  142. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and d.TenantId='{0}'
  143. WHERE 1=1 and b.id is null
  144. and a.Org={2} ";
  145. sql += " DROP TABLE #TempBOM " +
  146. "DROP TABLE #tableICSSBOM";
  147. sql = string.Format(sql, TenantId, erpName, ErpId);
  148. //return;
  149. ICSHelper.ExecuteDate(conStr, sql);
  150. #endregion
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. log.Error(ex.ToString());
  156. }
  157. }
  158. }
  159. }