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.

159 lines
7.1 KiB

  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 物料分类(锐腾)
  11. /// </summary>
  12. public class IcsMainCategoryCode_Rhtyon : 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 conERPStr = ICSHelper.GetERPConnectString();
  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();//mes 组织
  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 a.code as ItemMainCategoryCode
  51. ,b.Name as ItemMainCategoryName
  52. ,b.Description as ItemMainCategoryDesc
  53. ,a.ModifiedOn MTime
  54. ,I.id as Org
  55. ,p.parentCode
  56. ,a.DescFlexField_PrivateDescSeg1
  57. ,a.DescFlexField_PrivateDescSeg2
  58. ,a.DescFlexField_PrivateDescSeg3
  59. ,a.DescFlexField_PrivateDescSeg4
  60. INTO #TempItemCategory
  61. from {1}.dbo.[CBO_Category] a
  62. left join {1}.dbo.CBO_CategoryType catt on catt.id=a.CategorySystem
  63. left join {1}.dbo.[CBO_Category_Trl] b on a.id=b.id AND b.SysMLFlag='zh-CN'
  64. left join {1}.dbo.[Base_Organization] AS I ON ( A.[Org] = I.[ID] )
  65. left join {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  66. left join
  67. (
  68. SELECT
  69. a2.code parentCode
  70. ,a3.name parentName
  71. , A .code
  72. , A1.[Name]
  73. , a.level+1
  74. FROM {1}.dbo.Base_DefineValue AS A
  75. LEFT JOIN {1}.dbo.[Base_DefineValue_Trl] AS A1 ON(A1.SysMlFlag = 'zh-CN') AND(A.[ID] = A1.[ID])
  76. left join {1}.dbo.Base_DefineValue a2 on a2.id=a.ParentNode
  77. and a2.Effective_IsEffective=1
  78. and a2.Effective_DisableDate>= CAST ( CAST ( GETDATE( ) AS DATE ) AS VARCHAR ( 10 ) ) + ' 00:00:00'
  79. AND a2.Effective_EffectiveDate< CAST ( CAST ( dateadd( DAY, 1, GETDATE( ) ) AS DATE ) AS VARCHAR ( 10 ) ) + ' 00:00:00'
  80. LEFT JOIN {1}.dbo.[Base_DefineValue_Trl] AS A3 ON(A3.SysMlFlag = 'zh-CN') AND(A2.[ID] = A3.[ID])
  81. WHERE 1=1
  82. and A.[ValueSetDef] = (SELECT ID FROM {1}.dbo.Base_ValueSetDef_trl DD WHERE name = '' )
  83. and a.Effective_IsEffective=1
  84. and a.Effective_DisableDate>= CAST ( CAST ( GETDATE( ) AS DATE ) AS VARCHAR ( 10 ) ) + ' 00:00:00'
  85. AND a.Effective_EffectiveDate< CAST ( CAST ( dateadd( DAY, 1, GETDATE( ) ) AS DATE ) AS VARCHAR ( 10 ) ) + ' 00:00:00'
  86. --order by a.level+1, a2.code,A .code
  87. ) p ON a.code=p.code
  88. where 1=1
  89. and A.ModifiedOn>=@LastTime AND I.id={0}
  90. and catt.IsStock='1'
  91. ORDER BY A.Code
  92. IF NOT EXISTS(SELECT * FROM #TempItemCategory)
  93. RETURN";
  94. sql = string.Format(sql, ErpId, erpName);
  95. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempItemCategory");
  96. sql += @"--删除数据
  97. -- DELETE ICSINVENTORY WHERE ItemCode NOT IN (SELECT cInvCode FROM {1}.dbo.[CBO_ItemMaster])
  98. SELECT a.ItemMainCategoryCode INTO #tableItemCategory
  99. FROM IcsMainCategoryCode a With(NoLock)
  100. LEFT JOIN {1}.dbo.[CBO_Category] b With(NoLock) ON a.ItemMainCategoryCode=b.Code
  101. WHERE b.code is null
  102. and a.TenantId='{0}'
  103. AND b.Org={2}
  104. DELETE IcsMainCategoryCode
  105. WHERE TenantId='{0}' and ItemMainCategoryCode IN ( SELECT ItemMainCategoryCode from #tableItemCategory) ";
  106. Dictionary<string, string> values = new Dictionary<string, string>();
  107. values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//物料编号
  108. values.Add("ItemMainCategoryName", "a.ItemMainCategoryNAME");//物料名称
  109. values.Add("ItemMainCategoryDesc", "a.ItemMainCategoryDesc");//物料描述
  110. values.Add("LastModificationTime", "a.MTime");//操作时间
  111. values.Add("PCode", "a.parentCode");//操作人
  112. values.Add("Default1", "a.DescFlexField_PrivateDescSeg1");//操作人
  113. values.Add("Default2", "a.DescFlexField_PrivateDescSeg2");//操作人
  114. values.Add("Default3", "a.DescFlexField_PrivateDescSeg3");//操作人
  115. values.Add("Default4", "a.DescFlexField_PrivateDescSeg4");//操作人
  116. //更新存在数据
  117. sql += ICSHelper.UpdateSQL("b", values)
  118. + @" #TempItemCategory a
  119. INNER JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode
  120. WHERE b.TenantId='" + TenantId + "' and a.Org={2}";
  121. values.Add("CreationTime", "a.MTime");//操作人
  122. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  123. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  124. values.Add("TenantId", "'" + TenantId + "'");//站点
  125. //插入新增数据
  126. sql += ICSHelper.InsertSQL("IcsMainCategoryCode", values)
  127. + @" #TempItemCategory a
  128. LEFT JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode and b.TenantId='{0}'
  129. WHERE 1=1 and b.ItemMainCategoryCode is null
  130. and a.Org={2}
  131. ";
  132. sql += " DROP TABLE #TempItemCategory " +
  133. " DROP TABLE #tableItemCategory ";
  134. sql = string.Format(sql, TenantId, erpName, ErpId);
  135. // return;
  136. ICSHelper.ExecuteDate(conStr, sql);
  137. #endregion
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. log.Error(ex.ToString());
  143. }
  144. }
  145. }
  146. }