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.

179 lines
8.9 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
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. using System.Net.NetworkInformation;
  8. namespace ICSSoft.FromERP
  9. {
  10. /// <summary>
  11. /// 物料档案(来源U8)
  12. /// </summary>
  13. public class ICSInventoryFromU8 : 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 conERPStr = ICSHelper.GetERPConnectString();
  38. string conStr = ICSHelper.GetConnectString();
  39. string Namespace = this.GetType().Namespace;
  40. //string Class = this.GetType().Name;
  41. string erpNames = ICSHelper.GetConfigString()["Workpoint_ERPDB"];
  42. List<string> DBS = erpNames.Split(',').ToList();
  43. List<WorkpointERPDBLink> ListDB = new List<WorkpointERPDBLink>();
  44. foreach (string DB in DBS)
  45. {
  46. if (DB.Split('|') != null && DB.Split('|').Count() > 1)
  47. {
  48. WorkpointERPDBLink wd = new WorkpointERPDBLink();
  49. wd.Workpoint = DB.Split('|')[0];
  50. wd.ERPDB = DB.Split('|')[1];
  51. ListDB.Add(wd);
  52. }
  53. }
  54. DataTable dt = ICSHelper.GetERPDB(conStr);
  55. foreach (DataRow dr in dt.Rows)
  56. {
  57. string TenantId = dr["TenantId"].ToString();
  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 = @"
  70. select NEWID() AS ID,
  71. a.cInvCode AS ItemCode,
  72. CASE WHEN A.bSelf ='1' THEN '1' WHEN A.bPurchase='1' THEN '1' when a.bProxyForeign='1' THEN '2'
  73. else '' end ItemFormAttribute,
  74. dbo.GetReplaceStr(cInvName) AS ItemName,
  75. a.cEngineerFigNo ItemDrawingNo,
  76. '' ItemDesc,
  77. dbo.GetReplaceStr(isnull(cInvAddCode,'')+'|'+isnull(cInvStd,'')) AS ItemStd,
  78. a.cInvAddCode INVPARSETYPE,
  79. c.cComUnitName AS ItemUnit,
  80. a.cInvCCode ItemMainCategoryCode,
  81. b.cInvCName ClassName,
  82. ISNULL(c.iChangRate,0) as ItemRate,
  83. ISNULL(a.iMassDate,'') as EffectiveDays,
  84. ISNULL(CONVERT(NVARCHAR(50),a.dModifyDate,21),'') MTime,
  85. (case when isnull(a.fOutExcess,0)=0 then 0 else (case when isnull(a.fOutExcess,0)>5 then 3 else 2 end) end) ,
  86. isnull(a.fOutExcess,0)
  87. INTO #TempINV
  88. FROM {1}.dbo.Inventory a with(nolock)
  89. LEFT JOIN {1}.dbo.InventoryClass b with(nolock) ON a.cInvCCode = b.cInvCCode
  90. LEFT JOIN {1}.dbo.ComputationUnit c with(nolock) ON a.cComUnitCode = c.cComunitCode
  91. WHERE a.dEDate IS NULL AND a.dModifyDate>=@LastTime
  92. ORDER BY cInvCode
  93. IF NOT EXISTS(SELECT * FROM #TempINV)
  94. RETURN";
  95. sql = string.Format(sql, ErpId, erpName);
  96. sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempINV");
  97. sql += @"--删除数据
  98. SELECT a.ItemCode INTO #tableICSINVENTORY
  99. FROM ICSINVENTORY a With(NoLock)
  100. LEFT JOIN {1}.dbo.[Inventory] b With(NoLock) ON a.ItemCode=b.cInvCode
  101. WHERE b.cInvCode is null
  102. and a.TenantId='{0}'
  103. DELETE ICSINVENTORY
  104. WHERE TenantId='{0}' and ItemCode IN ( SELECT ItemCode from #tableICSINVENTORY) ";
  105. Dictionary<string, string> values = new Dictionary<string, string>();
  106. values.Add("ItemCode", "a.ItemCode");//物料编号
  107. values.Add("ItemName", "a.ItemName");//物料名称
  108. values.Add("ItemDesc", "a.ItemDesc");//物料描述
  109. values.Add("ItemStd", "a.ItemStd");//规格型号
  110. values.Add("ItemAttribute", "a.ItemFormAttribute");//产品属性(0:采购,1:自制,2:委外,3虚拟)
  111. values.Add("ItemAddCode", "a.INVPARSETYPE"); //产品代码(U8存货代码 )
  112. values.Add("ItemUnit", "a.ItemUnit");//主计量单位
  113. values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//大类编码
  114. values.Add("ItemRate", "a.ItemRate");
  115. values.Add("InvVersion", "''");
  116. values.Add("InvBrand", "''");
  117. values.Add("InvIQC", "0");//是否IQC检验
  118. values.Add("InvFQC", "0");//是否FQC检验
  119. values.Add("EffectiveEnable", "0");//
  120. values.Add("EffectiveDays", "a.EffectiveDays");//
  121. values.Add("BatchEnable", "1");//
  122. values.Add("LotEnable", "0");//
  123. values.Add("PrintEnable", "0");//
  124. values.Add("OverType", "a.备料超额类型");//超领类型(1:比例,2:数量,3:不管控)
  125. values.Add("OverValue", "a.备料超额值");
  126. values.Add("LastModificationTime", "a.Mtime");//操作时间
  127. values.Add("ItemType", "d.ItemType");//操作时间
  128. values.Add("ItemContype", "d.ItemContype");//操作时间
  129. values.Add("ItemControlType", "d.ItemControlType");//操作时间
  130. values.Add("ItemDrawingNo", "b.ItemDrawingNo");//产品图号
  131. //更新存在数据
  132. sql += ICSHelper.UpdateSQL("b", values)
  133. + @" #TempINV a
  134. INNER JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode
  135. left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId
  136. WHERE b.TenantId='" + TenantId + "' ";
  137. values.Add("CreationTime", "a.MTime");//操作人
  138. values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
  139. values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  140. values.Add("TenantId", "'" + TenantId + "'");//站点
  141. //插入新增数据
  142. sql += ICSHelper.InsertSQL("ICSINVENTORY", values)
  143. + @" #TempINV a
  144. LEFT JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode and b.TenantId='{0}'
  145. left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId
  146. WHERE 1=1 and b.ItemCode is null
  147. ";
  148. sql += " DROP TABLE #TempINV " +
  149. " DROP TABLE #tableICSINVENTORY ";
  150. sql = string.Format(sql, TenantId, erpName, ErpId);
  151. ICSHelper.ExecuteDate(conStr, sql);
  152. #endregion
  153. }
  154. }
  155. catch (Exception ex)
  156. {
  157. log.Error(ex.ToString());
  158. }
  159. }
  160. }
  161. }