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.

147 lines
6.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 物料主分类(来源U8)
  11. /// </summary>
  12. public class IcsMainCategoryCodeFromU8 : 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. string erpNames = ICSHelper.GetConfigString()["Workpoint_ERPDB"];
  41. List<string> DBS = erpNames.Split(',').ToList();
  42. List<WorkpointERPDBLink> ListDB = new List<WorkpointERPDBLink>();
  43. foreach (string DB in DBS)
  44. {
  45. if (DB.Split('|') != null && DB.Split('|').Count() > 1)
  46. {
  47. WorkpointERPDBLink wd = new WorkpointERPDBLink();
  48. wd.Workpoint = DB.Split('|')[0];
  49. wd.ERPDB = DB.Split('|')[1];
  50. ListDB.Add(wd);
  51. }
  52. }
  53. DataTable dt = ICSHelper.GetERPDB(conStr);
  54. foreach (DataRow dr in dt.Rows)
  55. {
  56. // string erpName = ICSHelper.GetConfigString()["ERPDB"];
  57. string TenantId = dr["TenantId"].ToString();//mes 组织
  58. string TenantCode = dr["TenantCode"].ToString();
  59. string ErpId = dr["ErpID"].ToString(); //erpID
  60. string Class = this.GetType().Name + TenantCode;
  61. WorkpointERPDBLink dblink = ListDB.FindLast(a => a.Workpoint == TenantCode);
  62. if (dblink == null)
  63. {
  64. return;
  65. }
  66. string erpName = dblink.ERPDB;
  67. // erpName = string.Format(erpName, TenantId);
  68. #region SQL
  69. string sql = @" select a.cInvCCode as ItemMainCategoryCode
  70. ,a.cInvCName as ItemMainCategoryName
  71. ,'' as ItemMainCategoryDesc
  72. ,getdate() MTime
  73. ,p.parentCode
  74. INTO #TempItemCategory
  75. from {1}.dbo.[InventoryClass] a with(nolock)
  76. left join
  77. (
  78. select cc.cInvCCode,cc_p.cInvCCode parentCode
  79. from {1}.dbo.InventoryClass cc with(nolock)
  80. left join {1}.dbo.InventoryClass cc_p with(nolock) on cc.cInvCCode like cc_p.cInvCCode+'%'
  81. and cc.iInvCGrade=cc_p.iInvCGrade+1
  82. ) p ON a.cInvCCode=p.cInvCCode
  83. where 1=1
  84. -- and A.ModifiedOn>=@LastTime
  85. ORDER BY A.cInvCCode
  86. IF NOT EXISTS(SELECT * FROM #TempItemCategory)
  87. RETURN";
  88. sql = string.Format(sql, ErpId, erpName);
  89. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempItemCategory");
  90. sql += @"--删除数据
  91. SELECT a.ItemMainCategoryCode INTO #tableItemCategory
  92. FROM IcsMainCategoryCode a With(NoLock)
  93. LEFT JOIN {1}.dbo.[InventoryClass] b With(NoLock) ON a.ItemMainCategoryCode=b.cInvCCode
  94. WHERE b.cInvCCode is null
  95. and a.TenantId='{0}'
  96. DELETE IcsMainCategoryCode
  97. WHERE TenantId='{0}' and ItemMainCategoryCode IN ( SELECT ItemMainCategoryCode from #tableItemCategory) ";
  98. Dictionary<string, string> values = new Dictionary<string, string>();
  99. values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//物料编号
  100. values.Add("ItemMainCategoryName", "a.ItemMainCategoryNAME");//物料名称
  101. values.Add("ItemMainCategoryDesc", "a.ItemMainCategoryDesc");//物料描述
  102. values.Add("LastModificationTime", "a.MTime");//操作时间
  103. values.Add("PCode", "a.parentCode");//操作人
  104. //更新存在数据
  105. sql += ICSHelper.UpdateSQL("b", values)
  106. + @" #TempItemCategory a
  107. INNER JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode
  108. WHERE b.TenantId='" + TenantId + "' ";
  109. values.Add("CreationTime", "a.MTime");//操作人
  110. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  111. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  112. values.Add("TenantId", "'" + TenantId + "'");//站点
  113. //插入新增数据
  114. sql += ICSHelper.InsertSQL("IcsMainCategoryCode", values)
  115. + @" #TempItemCategory a
  116. LEFT JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode and b.TenantId='{0}'
  117. WHERE 1=1 and b.ItemMainCategoryCode is null
  118. ";
  119. sql += " DROP TABLE #TempItemCategory " +
  120. " DROP TABLE #tableItemCategory ";
  121. sql = string.Format(sql, TenantId, erpName,ErpId);
  122. // return;
  123. ICSHelper.ExecuteDate(conStr, sql);
  124. #endregion
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. log.Error(ex.ToString());
  130. }
  131. }
  132. }
  133. }