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
4 months ago
4 months ago
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. /// 产品Bom(凯尔克)
  11. /// </summary>
  12. public class IcsSBom : 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 TenantId = dr["TenantId"].ToString();
  44. string TenantCode = dr["TenantCode"].ToString();
  45. string ErpId = dr["ErpID"].ToString(); //erpID
  46. string Class = this.GetType().Name + TenantCode;
  47. erpName = string.Format(erpName, TenantId);
  48. #region SQL
  49. string sql = @" select distinct A2.[ID] as 料品ID,
  50. A2.[Code] as ,
  51. A2.Name as ,
  52. A4.Description as ,
  53. A3.ID as ID,
  54. A3.[Code] as ,
  55. A3.[Name] as ,
  56. A5.Description as ,
  57. A.FixedScrap as ,
  58. isnull( A6.[Code],'') as ,
  59. isnull( A.[ECNCode],'') as ,
  60. A.[UsageQty],
  61. a.ParentQty,
  62. cast(isnull( A.[UsageQty],0)/isnull( a.ParentQty,1) as decimal(18,6)) ,
  63. A.[ItemVersionCode] as ,
  64. A.[EffectiveDate] as ,
  65. isnull( A.IsSpecialUseItem,'') as ,
  66. A.[DisableDate] as ,
  67. A.[Sequence] as ,
  68. A.[IsEffective] as ,
  69. A1.[BOMVersionCode] as ,
  70. A.[OperationNum] as
  71. ,I.id as Org
  72. ,A.ModifiedOn as MTime
  73. ,A.ID as ErpDetailID
  74. INTO #TempBOM
  75. from {1}.dbo.CBO_BOMComponent as A
  76. left join {1}.dbo.[CBO_BOMMaster] as A1 on (A.[BOMMaster] = A1.[ID])
  77. left join {1}.dbo.[CBO_ItemMaster] as A2 on (A1.[ItemMaster] = A2.[ID])
  78. left join {1}.dbo.[CBO_ItemMaster_Trl] as A4 on (A4.SysMlFlag = 'zh-CN') and (A2.[ID] = A4.[ID])
  79. left join {1}.dbo.[CBO_ItemMaster] as A3 on (A.[ItemMaster] = A3.[ID])
  80. left join {1}.dbo.[CBO_ItemMaster_Trl] as A5 on (A5.SysMlFlag = 'zh-CN') and (A3.[ID] = A5.[ID])
  81. left join {1}.dbo.[CBO_Project] as A6 on (A.[CompProject] = A6.[ID])
  82. LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A1.[Org] = I.[ID] )
  83. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  84. where 1=1 and A1.AlternateType=0 and IsEffective=1 and A.ModifiedOn>=@LastTime AND I.id={0} and A.ComponentType=0
  85. IF NOT EXISTS(SELECT * FROM #TempBOM)
  86. RETURN";
  87. sql = string.Format(sql, ErpId, erpName);
  88. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempBOM");
  89. sql += "\r\n";
  90. sql += @"--删除数据
  91. -- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent)
  92. SELECT a.ErpId INTO #tableICSSBOM
  93. FROM ICSSBOM a With(NoLock)
  94. LEFT JOIN {1}.dbo.[CBO_BOMComponent] b With(NoLock) ON a.ErpId=b.Id
  95. LEFT JOIN {1}.dbo.CBO_BOMMaster c With(NoLock) ON b.BOMMaster=c.Id
  96. WHERE b.id is null
  97. and a.TenantId='{0}'
  98. AND c.Org={2}
  99. DELETE ICSSBOM
  100. WHERE TenantId='{0}' and ErpId IN ( SELECT ErpId from #tableICSSBOM)
  101. ";
  102. Dictionary<string, string> values = new Dictionary<string, string>();
  103. values.Add("SBOMVER", "a.母料版本号");
  104. values.Add("ITEMCODE", "a.料品编码");
  105. values.Add("SBITEMCODE", "a.子阶料编码");
  106. values.Add("SBItemName", "a.子阶料名称");
  107. //values.Add("SBItemDesc", "a.子阶料描述");
  108. values.Add("SBSITEMCODE", "a.子阶料编码");
  109. values.Add("SBITEMQTY", "a.子阶料计量数量");
  110. values.Add("SEQ", "1");
  111. values.Add("SBItemECN", "a.工程变更号");
  112. values.Add("SBItemStatus", "'Y'");
  113. values.Add("SBItemEfftime", "a.生效日期");
  114. values.Add("SBItemInvtime", "a.失效日期");
  115. values.Add("SBItemProject", "a.项目号");
  116. values.Add("SBItemSeq", "a.次序");
  117. values.Add("Location", "a.工序号");
  118. values.Add("LastModificationTime", "a.Mtime");//操作时间
  119. values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  120. values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  121. values.Add("SBItemContype", "c.ItemContype");
  122. //更新存在数据
  123. sql += ICSHelper.UpdateSQL("b", values)
  124. + @" #TempBOM a
  125. INNER JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId
  126. left join IcsInventory c on b.SBItemCode=c.ItemCode and b.TenantId=c.TenantId
  127. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and c.TenantId=d.TenantId
  128. WHERE b.TenantId='{0}' and a.Org={2} ";
  129. values.Add("ErpId", "convert(nvarchar(100), a.ErpDetailID)");
  130. values.Add("CreationTime", "a.MTime");//操作人
  131. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  132. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  133. values.Add("TenantId", "'" + TenantId + "'");//站点
  134. sql += "\r\n";
  135. //插入新增数据
  136. sql += ICSHelper.InsertSQL("ICSSBOM", values)
  137. + @" #TempBOM a
  138. LEFT JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId and b.TenantId='{0}'
  139. left join IcsInventory c on a.=c.ItemCode and c.TenantId='{0}'
  140. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and d.TenantId='{0}'
  141. WHERE 1=1 and b.id is null
  142. and a.Org={2} ";
  143. sql += " DROP TABLE #TempBOM " +
  144. "DROP TABLE #tableICSSBOM";
  145. sql = string.Format(sql, TenantId, erpName, ErpId);
  146. // return;
  147. ICSHelper.ExecuteDate(conStr, sql);
  148. #endregion
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. log.Error(ex.ToString());
  154. }
  155. }
  156. }
  157. }