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.

167 lines
8.5 KiB

4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quartz;
  6. using System.Data;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 物料档案(凯尔克)
  11. /// </summary>
  12. public class ICSInventory : 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();
  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.ID AS ID,
  51. A.Code AS ItemCode
  52. ,a.ItemFormAttribute
  53. ,dbo.GetReplaceStr(A.Name) AS ItemName,
  54. a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
  55. ,b.Description ItemDesc,
  56. dbo.GetReplaceStr(A.SPECS) AS ItemStd,
  57. D.Name AS ItemUnit,
  58. G.Code as ItemMainCategoryCode,
  59. H.Name as ClassName,
  60. 1 as ItemRate,
  61. 1 as EffectiveDays,
  62. A.ModifiedOn as MTime
  63. ,I.id as Org
  64. ,Case When Q.IsSueOverType=0 THEN 1 WHEN Q.IsSueOverType=1 THEN 2 WHEN Q.IsSueOverType=2 THEN 3 ELSE 0 END AS
  65. ,Case When Q.IsSueOverType=0 Then Q.StandardMaterialScale When Q.IsSueOverType=1 Then Q.StandardMaterialQty
  66. ELSE 0 END AS
  67. INTO #TempINV
  68. from {1}.dbo.[CBO_ItemMaster] AS A
  69. LEFT JOIN {1}.dbo.[CBO_ItemMaster_Trl] AS B ON ( A.[ID] = B.[ID] AND B.SysMLFlag='zh-CN')
  70. LEFT JOIN {1}.dbo.[Base_UOM] AS C ON ( A.[CostUOM] = C.[ID] )
  71. LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS D ON ( C.[ID] = D.[ID] AND D.SysMLFlag='zh-CN')
  72. LEFT JOIN {1}.dbo.[Base_UOM] AS E ON ( A.[InventoryUOM] = E.[ID] )
  73. LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS F ON ( E.[ID] = F.[ID] AND F.SysMLFlag='zh-CN')
  74. LEFT JOIN {1}.dbo.[CBO_Category] AS G ON ( A.[MainItemCategory] = G.[ID] )
  75. LEFT JOIN {1}.dbo.[CBO_Category_Trl] AS H ON ( G.[ID] = H.[ID] AND H.SysMLFlag='zh-CN')
  76. LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A.[Org] = I.[ID] )
  77. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  78. LEFT JOIN {1}.dbo.CBO_InventoryInfo L on A.id=L.ItemMaster
  79. LEFT JOIN {1}.dbo.CBO_Wh M on L.warehouse=M.id and A.org=M.org
  80. LEFT JOIN {1}.dbo.CBO_Category_Trl P ON P.ID=A.MainItemCategory
  81. LEFT JOIN {1}.dbo.CBO_MfgInfo Q ON Q.ItemMaster=A.ID
  82. where A.ModifiedOn>=@LastTime AND I.id={0}
  83. ORDER BY A.Code
  84. IF NOT EXISTS(SELECT * FROM #TempINV)
  85. RETURN";
  86. sql = string.Format(sql, ErpId, erpName);
  87. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempINV");
  88. sql += @"--删除数据
  89. SELECT a.ItemCode INTO #tableICSINVENTORY
  90. FROM ICSINVENTORY a With(NoLock)
  91. LEFT JOIN {1}.dbo.[CBO_ItemMaster] b With(NoLock) ON a.ItemCode=b.code
  92. WHERE b.code is null
  93. and a.TenantId='{0}'
  94. AND b.Org={2}
  95. DELETE ICSINVENTORY
  96. WHERE TenantId='{0}' and ItemCode IN ( SELECT ItemCode from #tableICSINVENTORY) ";
  97. Dictionary<string, string> values = new Dictionary<string, string>();
  98. values.Add("ItemCode", "a.ItemCode");//物料编号
  99. values.Add("ItemName", "a.ItemName");//物料名称
  100. values.Add("ItemDesc", "a.ItemDesc");//物料描述
  101. values.Add("ItemStd", "a.ItemStd");//规格型号
  102. values.Add("ItemAttribute", "a.ItemFormAttribute");//规格型号
  103. values.Add("ItemUnit", "a.ItemUnit");//主计量单位
  104. values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//大类编码
  105. values.Add("ItemRate", "a.ItemRate");
  106. values.Add("InvVersion", "''");
  107. values.Add("InvBrand", "''");
  108. values.Add("InvIQC", "0");//大类编码
  109. values.Add("InvFQC", "0");//大类编码
  110. values.Add("EffectiveEnable", "0");//大类名称
  111. values.Add("EffectiveDays", "a.EffectiveDays");//大类名称
  112. values.Add("BatchEnable", "1");//大类名称
  113. values.Add("LotEnable", "0");//大类名称
  114. values.Add("PrintEnable", "0");//大类名称
  115. values.Add("OverType", "a.备料超额类型");
  116. values.Add("OverValue", "a.备料超额值");
  117. values.Add("LastModificationTime", "a.Mtime");//操作时间
  118. values.Add("ItemType", "d.ItemType");//操作时间
  119. values.Add("ItemContype", "d.ItemContype");//操作时间
  120. values.Add("ItemControlType", "d.ItemControlType");//操作时间
  121. values.Add("ItemDrawingNo", "a.ItemDrawingNo");//操作时间
  122. //更新存在数据
  123. sql += ICSHelper.UpdateSQL("b", values)
  124. + @" #TempINV a
  125. INNER JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode
  126. left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId
  127. WHERE b.TenantId='" + TenantId + "' and a.Org={2} ";
  128. values.Add("CreationTime", "a.MTime");//操作人
  129. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  130. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  131. values.Add("TenantId", "'" + TenantId + "'");//站点
  132. //插入新增数据
  133. sql += ICSHelper.InsertSQL("ICSINVENTORY", values)
  134. + @" #TempINV a
  135. LEFT JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode and b.TenantId='{0}'
  136. left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId
  137. WHERE 1=1 and b.ItemCode is null
  138. and a.Org={2} ";
  139. sql += " DROP TABLE #TempINV " +
  140. " DROP TABLE #tableICSINVENTORY ";
  141. sql = string.Format(sql, TenantId, erpName, ErpId);
  142. // return;
  143. log.Info(sql);
  144. // return;
  145. ICSHelper.ExecuteDate(conStr, sql);
  146. #endregion
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. log.Error(ex.ToString());
  152. }
  153. }
  154. }
  155. }