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.

182 lines
8.4 KiB

4 months ago
4 months ago
4 months ago
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(来源U8)
  11. /// </summary>
  12. public class IcsSBomFromU8 : 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. 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. foreach (DataRow dr in dt.Rows)
  54. {
  55. // string erpName = ICSHelper.GetConfigString()["ERPDB"];
  56. string TenantId = dr["TenantId"].ToString();
  57. string TenantCode = dr["TenantCode"].ToString();
  58. string ErpId = dr["ErpID"].ToString(); //erpID
  59. string Class = this.GetType().Name + TenantCode;
  60. WorkpointERPDBLink dblink = ListDB.FindLast(a => a.Workpoint == TenantCode);
  61. if (dblink == null)
  62. {
  63. return;
  64. }
  65. string erpName = dblink.ERPDB;
  66. // erpName = string.Format(erpName, TenantId);
  67. #region SQL
  68. string sql = @"
  69. SELECT DISTINCT
  70. c.InvCode as ,
  71. f.InvCode as ,
  72. g2.cInvName as ,
  73. '' ,
  74. '' ,
  75. '' ,
  76. d.BaseQtyD ,
  77. '' ,
  78. d.EffBegDate ,
  79. d.EffEndDate ,
  80. d.SortSeq ,
  81. d.OpSeq ,
  82. a.Version ,
  83. ISNULL(a.ModifyDate, a.CreateDate) as MTime
  84. ,d.OpComponentId as ErpDetailID
  85. into #TempBOM
  86. FROM {1}.dbo.bom_bom a With(NoLock) -- BOM资料
  87. INNER JOIN {1}.dbo.bom_parent b With(NoLock) on a.BomId = b.BomId --BOM母件资料
  88. INNER JOIN {1}.dbo.bas_part c With(NoLock) on b.ParentId = c.PartId --
  89. INNER JOIN {1}.dbo.bom_opcomponent d With(NoLock) on a.BomId=d.BomId --BOM子件资料
  90. INNER JOIN {1}.dbo.bas_part f With(NoLock) on d.ComponentId = f.PartId
  91. left join {1}.dbo.inventory g With(NoLock) on c.InvCode=g.cInvCode --
  92. left join {1}.dbo.inventory g2 With(NoLock) on f.InvCode=g2.cInvCode --
  93. WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime
  94. IF NOT EXISTS(SELECT * FROM #TempBOM)
  95. RETURN";
  96. sql = string.Format(sql, ErpId, erpName);
  97. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempBOM");
  98. sql += "\r\n";
  99. sql += @"--删除数据
  100. SELECT a.ErpId INTO #tableICSSBOM
  101. FROM ICSSBOM a With(NoLock)
  102. left join {1}.dbo.bom_opcomponent d With(NoLock) on a.ErpId=d.OpComponentId
  103. WHERE d.OpComponentId is null
  104. and a.TenantId='{0}'
  105. DELETE ICSSBOM
  106. WHERE TenantId='{0}' and ErpId IN ( SELECT ErpId from #tableICSSBOM)
  107. ";
  108. Dictionary<string, string> values = new Dictionary<string, string>();
  109. values.Add("SBOMVER", "a.母料版本号");
  110. values.Add("ITEMCODE", "a.料品编码");
  111. values.Add("SBITEMCODE", "a.子阶料编码");
  112. values.Add("SBItemName", "a.子阶料名称");
  113. values.Add("SBSITEMCODE", "a.子阶料编码");
  114. values.Add("SBITEMQTY", "a.子阶料计量数量");
  115. values.Add("SEQ", "1");
  116. values.Add("SBItemECN", "a.工程变更号");
  117. values.Add("SBItemStatus", "'Y'");
  118. values.Add("SBItemEfftime", "a.生效日期");
  119. values.Add("SBItemInvtime", "a.失效日期");
  120. values.Add("SBItemProject", "a.项目号");
  121. values.Add("SBItemSeq", "a.次序");
  122. values.Add("Location", "a.工序号");
  123. values.Add("LastModificationTime", "a.Mtime");//操作时间
  124. values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  125. values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  126. values.Add("SBItemContype", "c.ItemContype");
  127. //更新存在数据
  128. sql += ICSHelper.UpdateSQL("b", values)
  129. + @" #TempBOM a
  130. INNER JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId
  131. left join IcsInventory c on b.SBItemCode=c.ItemCode and b.TenantId=c.TenantId
  132. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and c.TenantId=d.TenantId
  133. WHERE b.TenantId='{0}' ";
  134. values.Add("ErpId", "convert(nvarchar(100), a.ErpDetailID)");
  135. values.Add("CreationTime", "a.MTime");//操作人
  136. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  137. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  138. values.Add("TenantId", "'" + TenantId + "'");//站点
  139. sql += "\r\n";
  140. //插入新增数据
  141. sql += ICSHelper.InsertSQL("ICSSBOM", values)
  142. + @" #TempBOM a
  143. LEFT JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId and b.TenantId='{0}'
  144. left join IcsInventory c on a.=c.ItemCode and c.TenantId='{0}'
  145. left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and d.TenantId='{0}'
  146. WHERE 1=1 and b.id is null
  147. ";
  148. sql += " DROP TABLE #TempBOM " +
  149. "DROP TABLE #tableICSSBOM";
  150. sql = string.Format(sql, TenantId, erpName, ErpId);
  151. // return;
  152. ICSHelper.ExecuteDate(conStr, sql);
  153. #endregion
  154. }
  155. }
  156. catch (Exception ex)
  157. {
  158. log.Error(ex.ToString());
  159. }
  160. }
  161. }
  162. }