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.

184 lines
8.5 KiB

4 weeks ago
2 months ago
4 days ago
2 months ago
4 weeks ago
4 days ago
2 months ago
3 days ago
3 months ago
4 days ago
3 days ago
4 weeks ago
2 months ago
4 weeks 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. A.Scrap as ,
  60. case when A.ScrapType=0 then '' when A.ScrapType=1 then '' else '' end as ,
  61. isnull( A6.[Code],'') as ,
  62. isnull( A.[ECNCode],'') as ,
  63. A.[UsageQty],
  64. a.ParentQty,
  65. cast(isnull( A.[UsageQty],0)/isnull( a.ParentQty,1) as decimal(18,6)) ,
  66. A.[ItemVersionCode] as ,
  67. A.[EffectiveDate] as ,
  68. isnull( A.IsSpecialUseItem,'') as ,
  69. A.[DisableDate] as ,
  70. A.[Sequence] as ,
  71. A.[IsEffective] as ,
  72. A1.[BOMVersionCode] as ,
  73. A.[OperationNum] as
  74. ,I.id as Org
  75. ,A.ModifiedOn as MTime
  76. ,A.ID as ErpDetailID
  77. ,e3.Name AlternateTypeName
  78. ,u1.Name as SBItemUom
  79. INTO #TempBOM
  80. from {1}.dbo.CBO_BOMComponent as A
  81. left join {1}.dbo.[CBO_BOMMaster] as A1 on (A.[BOMMaster] = A1.[ID])
  82. left join {1}.dbo.[CBO_ItemMaster] as A2 on (A1.[ItemMaster] = A2.[ID])
  83. left join {1}.dbo.[CBO_ItemMaster_Trl] as A4 on (A4.SysMlFlag = 'zh-CN') and (A2.[ID] = A4.[ID])
  84. left join {1}.dbo.[CBO_ItemMaster] as A3 on (A.[ItemMaster] = A3.[ID])
  85. left join {1}.dbo.[CBO_ItemMaster_Trl] as A5 on (A5.SysMlFlag = 'zh-CN') and (A3.[ID] = A5.[ID])
  86. left join {1}.dbo.[CBO_Project] as A6 on (A.[CompProject] = A6.[ID])
  87. LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A1.[Org] = I.[ID] )
  88. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  89. left join {1}.dbo.UBF_Sys_ExtEnumType e1 on e1.Code = 'UFIDA.U9.CBO.MFG.Enums.AlternateTypesEnum'
  90. left join {1}.dbo.UBF_Sys_ExtEnumValue e2 on e1.ID=e2.ExtEnumType and e2.evalue=A1.AlternateType
  91. left join {1}.dbo.UBF_Sys_ExtEnumValue_Trl e3 on e2.id=e3.ID and e3.SysMLFlag='zh-CN'
  92. left join {1}.dbo.Base_UOM_Trl u1 on a.IssueUOM=u1.id and u1.SysMLFlag='zh-CN'
  93. where 1=1 and IsEffective=1 and A.ModifiedOn>=@LastTime AND I.id={0} and A.ComponentType=0
  94. and A1.AlternateType=0
  95. and A1.bomtype=0
  96. IF NOT EXISTS(SELECT * FROM #TempBOM)
  97. RETURN";
  98. sql = string.Format(sql, ErpId, erpName);
  99. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempBOM");
  100. sql += "\r\n";
  101. sql += @"--删除数据
  102. -- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent)
  103. SELECT a.ErpId INTO #tableICSSBOM
  104. FROM ICSSBOM a With(NoLock)
  105. LEFT JOIN {1}.dbo.[CBO_BOMComponent] b With(NoLock) ON a.ErpId=b.Id
  106. LEFT JOIN {1}.dbo.CBO_BOMMaster c With(NoLock) ON b.BOMMaster=c.Id
  107. WHERE b.id is null
  108. and a.TenantId='{0}'
  109. --AND c.Org={2}
  110. DELETE FROM ICSSBOM
  111. WHERE TenantId='{0}' and ErpId IN ( SELECT ErpId from #tableICSSBOM)
  112. ";
  113. Dictionary<string, string> values = new Dictionary<string, string>();
  114. values.Add("SBOMVER", "a.母料版本号");
  115. values.Add("ITEMCODE", "a.料品编码");
  116. values.Add("SBITEMCODE", "a.子阶料编码");
  117. values.Add("SBItemName", "a.子阶料名称");
  118. //values.Add("SBItemDesc", "a.子阶料描述");
  119. values.Add("SBSITEMCODE", "a.子阶料编码");
  120. values.Add("SBITEMQTY", "a.子阶料计量数量");
  121. values.Add("SBUsageQty", "a.UsageQty");
  122. values.Add("ParentQty", "a.ParentQty");
  123. values.Add("SBItemUom", "a.SBItemUom");
  124. values.Add("SEQ", "1");
  125. values.Add("SBItemECN", "a.工程变更号");
  126. values.Add("SBItemStatus", "'Y'");
  127. values.Add("SBItemEfftime", "a.生效日期");
  128. values.Add("SBItemInvtime", "a.失效日期");
  129. values.Add("SBItemProject", "a.项目号");
  130. values.Add("SBItemSeq", "a.次序");
  131. values.Add("Location", "a.工序号");
  132. values.Add("LastModificationTime", "a.Mtime");//操作时间
  133. values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  134. values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  135. values.Add("SBItemContype", "c.ItemContype");
  136. values.Add("Alternate", "a.AlternateTypeName");
  137. values.Add("FixedScrap", "a.固定损耗");
  138. values.Add("Scrap", "a.变动损耗");
  139. values.Add("ScrapType", "a.损耗类型");
  140. //更新存在数据
  141. sql += ICSHelper.UpdateSQL("b", values)
  142. + @" #TempBOM a
  143. INNER JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId
  144. left join IcsInventory c on b.SBItemCode=c.ItemCode and b.TenantId=c.TenantId
  145. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and c.TenantId=d.TenantId
  146. WHERE b.TenantId='{0}' and a.Org={2} ";
  147. values.Add("ErpId", "convert(nvarchar(100), a.ErpDetailID)");
  148. values.Add("CreationTime", "a.MTime");//操作人
  149. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  150. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  151. values.Add("TenantId", "'" + TenantId + "'");//站点
  152. sql += "\r\n";
  153. //插入新增数据
  154. sql += ICSHelper.InsertSQL("ICSSBOM", values)
  155. + @" #TempBOM a
  156. LEFT JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId and b.TenantId='{0}'
  157. left join IcsInventory c on a.=c.ItemCode and c.TenantId='{0}'
  158. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and d.TenantId='{0}'
  159. WHERE 1=1 and b.id is null
  160. and a.Org={2} ";
  161. sql += " DROP TABLE #TempBOM " +
  162. "DROP TABLE #tableICSSBOM";
  163. sql = string.Format(sql, TenantId, erpName, ErpId);
  164. //return;
  165. //log.Info(sql);
  166. ICSHelper.ExecuteDate(conStr, sql);
  167. #endregion
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. log.Error(ex.ToString());
  173. }
  174. }
  175. }
  176. }