纽威
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.

280 lines
17 KiB

  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. public class ICSBOM : IJob
  10. {
  11. private static object key = new object();
  12. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  13. public void Execute(IJobExecutionContext context)
  14. {
  15. try
  16. {
  17. lock (key)
  18. {
  19. log.Info("开始……………………………………………………………………");
  20. Execute();
  21. log.Info("结束……………………………………………………………………");
  22. }
  23. }
  24. catch (Exception ex)
  25. {
  26. log.Error(ex.ToString());
  27. }
  28. }
  29. public void Execute()
  30. {
  31. try
  32. {
  33. string conStr = ICSHelper.GetConnectString();
  34. string Namespace = this.GetType().Namespace;
  35. //string Class = this.GetType().Name;
  36. DataTable dt = ICSHelper.GetERPDB(conStr);
  37. foreach (DataRow dr in dt.Rows)
  38. {
  39. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  40. string WorkPoint = dr["WorkPointCode"].ToString();
  41. string Class = this.GetType().Name + WorkPoint;
  42. erpName = string.Format(erpName, WorkPoint);
  43. #region SQL
  44. string sql = @" SELECT DISTINCT g.cInvDefine1,--存货自定义项1
  45. c.partID ITEMID,
  46. f.partID SBITEMID,
  47. K.partID SBSITEMID,
  48. c.InvCode as ITEMCODE,--
  49. f.InvCode as SBITEMCODE,--
  50. K.InvCode as SBSITEMCODE,--
  51. d.BaseQtyD SBITEMQTY, --BaseQtyD - --
  52. d.BaseQtyN, --AuxBaseQtyN
  53. a.VersionEffDate SBITEMEFFTIME,--VersionEffDate
  54. a.VersionEndDate SBITEMINVTIME,--VersionEndDate
  55. d.SortSeq SEQ, --SortSeq SEQ
  56. d.SortSeq SBITEMSEQ, --SortSeq SEQ
  57. e.WIPType SBITEMCONTYPE, --WIPType WIP属性(1/2/3/4) ,
  58. a.Version SBOMVER ,--Version
  59. a.AuditStatus,--Version BOM状态
  60. a.CreateDate,a.CreateUser,a.ModifyDate,a.ModifyUser,a.cCurrentAuditor,--
  61. d.CompScrap, --CompScrap
  62. d.ByproductFlag, --ByproductFlag
  63. d.ProductType, --ProductType (1:/2:/3:)
  64. i.Factor ReplaceFactor,--
  65. i.EffBegDate ReplaceEffBegDate,--
  66. i.EffEndDate ReplaceEffEndDate,--
  67. ISNULL(a.ModifyDate, a.CreateDate) AS MTIME ,
  68. a.RelsTime as cAuditDate, --
  69. i.ReplaceFlag,--
  70. i.OpComponentId,-- Id
  71. i.Sequence ReplaceSequence,--
  72. a.VersionDesc --VersionDesc
  73. ,moall.OpComponentId as moOpComponentId --使BOM子件
  74. , '{0}' as WorkPoint
  75. into #TempBOM
  76. FROM {1}.dbo.bom_bom a -- BOM资料
  77. INNER JOIN {1}.dbo.bom_parent b on a.BomId = b.BomId --BOM母件资料
  78. INNER JOIN {1}.dbo.bas_part c on b.ParentId = c.PartId --
  79. INNER JOIN {1}.dbo.bom_opcomponent d on a.BomId=d.BomId --BOM子件资料
  80. INNER JOIN {1}.dbo.bas_part f on d.ComponentId = f.PartId
  81. INNER JOIN {1}.dbo.bom_opcomponentopt e ON d.OptionsId=e.OptionsId --
  82. left JOIN {1}.dbo.bom_opcomponentsub i ON d.OpComponentId =i.OpComponentId --
  83. left join {1}.dbo.inventory g on c.InvCode=g.cInvCode --
  84. LEFT JOIN {1}.dbo.bas_part K ON K.PartId=i.PartId
  85. LEFT JOIN {1}.dbo.mom_moallocate moall ON moall.OpComponentId=d.OpComponentId
  86. WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime
  87. IF NOT EXISTS(SELECT * FROM #TempBOM)
  88. RETURN";
  89. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
  90. sql += "\r\n";
  91. sql += @"--删除数据
  92. -- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent)
  93. SELECT a.moOpComponentId INTO #tableICSSBOM
  94. FROM ICSSBOM a With(NoLock)
  95. LEFT JOIN {1}.dbo.[bom_opcomponent] b With(NoLock) ON a.moOpComponentId=b.OpComponentId
  96. WHERE a.WorkPoint='{0}' and b.OpComponentId IS NULL
  97. DELETE ICSSBOM
  98. WHERE WorkPoint='{0}' and moOpComponentId IN ( SELECT moOpComponentId from #tableICSSBOM)
  99. ";
  100. Dictionary<string, string> values = new Dictionary<string, string>();
  101. values.Add("SBOMVER", "a.SBOMVER");
  102. values.Add("ITEMID", "a.ITEMID");
  103. values.Add("SBITEMID", "a.SBITEMID");
  104. values.Add("SBSITEMID", "a.SBSITEMID");
  105. values.Add("ITEMCODE", "a.ITEMCODE");
  106. values.Add("SBITEMCODE", "a.SBITEMCODE");
  107. values.Add("SBSITEMCODE", "a.SBSITEMCODE");
  108. values.Add("SBITEMQTY", "a.SBITEMQTY");
  109. values.Add("BaseQtyN", "a.BaseQtyN");
  110. values.Add("SBITEMEFFTIME", "a.SBITEMEFFTIME");
  111. values.Add("SBITEMINVTIME", "a.SBITEMINVTIME");
  112. values.Add("SEQ", "a.SEQ");
  113. values.Add("SBITEMCONTYPE", "a.SBITEMCONTYPE");
  114. values.Add("CreateDate", "a.CreateDate");
  115. values.Add("CreateUser", "a.CreateUser");
  116. values.Add("ModifyDate", "a.ModifyDate");
  117. values.Add("ModifyUser", "a.ModifyUser");
  118. values.Add("cCurrentAuditor", "a.cCurrentAuditor");
  119. values.Add("CompScrap", "a.CompScrap");
  120. values.Add("ByproductFlag", "a.ByproductFlag");
  121. values.Add("ProductType", "a.ProductType");
  122. values.Add("ReplaceFactor", "a.ReplaceFactor");
  123. values.Add("ReplaceEffBegDate", "a.ReplaceEffBegDate");
  124. values.Add("ReplaceEffEndDate", "a.ReplaceEffEndDate");
  125. values.Add("VersionDesc", "a.VersionDesc");
  126. values.Add("SBITEMSEQ", "a.SBITEMSEQ");
  127. values.Add("MTIME", "a.MTIME");
  128. values.Add("moOpComponentId", "a.moOpComponentId");
  129. values.Add("AuditStatus", "a.AuditStatus");
  130. //更新存在数据
  131. sql += ICSHelper.UpdateSQL("b", values)
  132. + @" #TempBOM a
  133. INNER JOIN ICSSBOM b ON a.ITEMID=b.ITEMID AND a.SBITEMID=b.SBITEMID and a.WorkPoint=b.WorkPoint
  134. WHERE a.WorkPoint='" + WorkPoint + "' ";
  135. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  136. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  137. values.Add("WorkPoint", "'" + WorkPoint + "'");
  138. sql += "\r\n";
  139. //插入新增数据
  140. sql += ICSHelper.InsertSQL("ICSSBOM", values)
  141. + @" #TempBOM a
  142. LEFT JOIN ICSSBOM b ON a.ITEMID=b.ITEMID AND a.SBITEMID=b.SBITEMID and a.WorkPoint=b.WorkPoint
  143. WHERE b.ITEMCODE IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  144. sql += " DROP TABLE #TempBOM " +
  145. "DROP TABLE #tableICSSBOM";
  146. sql = string.Format(sql, WorkPoint, erpName);
  147. ICSHelper.ExecuteDate(conStr, sql);
  148. #endregion
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. log.Error(ex.ToString());
  154. }
  155. }
  156. // public void Execute_bak20201201()
  157. // {
  158. // try
  159. // {
  160. // string conStr = ICSHelper.GetConnectString();
  161. // string Namespace = this.GetType().Namespace;
  162. // string Class = this.GetType().Name;
  163. // #region SQL
  164. // string sql = @" SELECT g.cInvDefine1,--存货自定义项1
  165. // a.Version,--Version 版本号
  166. // a.VersionDesc,--VersionDesc 版本说明
  167. // a.VersionEffDate,--VersionEffDate 版本生效日
  168. // a.VersionEndDate,--VersionEndDate 版本失效日
  169. // c.InvCode as cInvCode ,--存货编码
  170. // f.InvCode as SubcInvCode ,--存货编码
  171. // e.WIPType, --WIPType WIP属性(1入库/2工序/3领料/4虚拟)
  172. // d.SortSeq, --SortSeq 序号
  173. // d.BaseQtyN, --AuxBaseQtyN 辅助基本用量
  174. // d.BaseQtyD, --BaseQtyD 基本用量-分母
  175. // d.ByproductFlag, --ByproductFlag 是否联副产品
  176. // d.ProductType, --ProductType 产出类型(1:空/2:联产品/3:副产品)
  177. // d.CompScrap, --CompScrap 子件损耗率
  178. // a.CreateDate,a.CreateUser,a.ModifyDate,a.ModifyUser,a.cCurrentAuditor,--当前审批人
  179. // a.RelsTime as cAuditDate, --审核时间
  180. // i.ReplaceFlag,--是否替换料
  181. // i.OpComponentId,-- 子件Id
  182. // i.Sequence ReplaceSequence,--替代序号
  183. // K.InvCode as ReplaceInvCode ,--替代料编码
  184. // i.Factor ReplaceFactor,--替代比例
  185. // i.EffBegDate ReplaceEffBegDate,--生效日期
  186. // i.EffEndDate ReplaceEffEndDate,--失效日期
  187. // ISNULL(a.ModifyDate, a.CreateDate) AS MTIME
  188. // into #TempBOM
  189. // FROM {1}.dbo.bom_bom a -- BOM资料
  190. // INNER JOIN {1}.dbo.bom_parent b on a.BomId = b.BomId --BOM母件资料
  191. // INNER JOIN {1}.dbo.bas_part c on b.ParentId = c.PartId --物料表
  192. // INNER JOIN {1}.dbo.bom_opcomponent d on a.BomId=d.BomId --BOM子件资料
  193. // INNER JOIN {1}.dbo.bas_part f on d.ComponentId = f.PartId
  194. // INNER JOIN {1}.dbo.bom_opcomponentopt e ON d.OptionsId=e.OptionsId -- 子件选项资料
  195. // left JOIN {1}.dbo.bom_opcomponentsub i ON d.OpComponentId =i.OpComponentId --子件替代料
  196. // left join {1}.dbo.inventory g on c.InvCode=g.cInvCode --存货档案
  197. // LEFT JOIN {1}.dbo.bas_part K ON K.PartId=i.PartId
  198. //
  199. // WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime
  200. // IF NOT EXISTS(SELECT * FROM #TempBOM)
  201. // RETURN";
  202. // sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
  203. // sql += "\r\n";
  204. // sql += @"--删除数据
  205. // DELETE ICSBOM WHERE cInvCode NOT IN (SELECT InvCode FROM {1}.dbo.bas_part) ";
  206. // Dictionary<string, string> values = new Dictionary<string, string>();
  207. // values.Add("Version", "a.Version");
  208. // values.Add("VersionDesc", "a.VersionDesc");
  209. // values.Add("VersionEffDate", "a.VersionEffDate");
  210. // values.Add("VersionEndDate", "a.VersionEndDate");
  211. // values.Add("cInvCode", "a.cInvCode");
  212. // values.Add("SubcInvCode", "a.SubcInvCode");
  213. // values.Add("WIPType", "a.WIPType");
  214. // values.Add("SortSeq", "a.SortSeq");
  215. // values.Add("BaseQtyN", "a.BaseQtyN");
  216. // values.Add("BaseQtyD", "a.BaseQtyD");
  217. // values.Add("ByproductFlag", "a.ByproductFlag");
  218. // values.Add("ProductType", "a.ProductType");
  219. // values.Add("CompScrap", "a.CompScrap");
  220. // values.Add("CreateDate", "a.CreateDate");
  221. // values.Add("CreateUser", "a.CreateUser");
  222. // values.Add("ModifyDate", "a.ModifyDate");
  223. // values.Add("ModifyUser", "a.ModifyUser");
  224. // values.Add("cCurrentAuditor", "a.cCurrentAuditor");
  225. // values.Add("cAuditDate", "a.cAuditDate");
  226. // values.Add("ReplaceFlag", "a.ReplaceFlag");
  227. // values.Add("OpComponentId", "a.OpComponentId");
  228. // values.Add("ReplaceSequence", "a.ReplaceSequence");
  229. // values.Add("ReplaceInvCode", "a.ReplaceInvCode");
  230. // values.Add("ReplaceFactor", "a.ReplaceFactor");
  231. // values.Add("ReplaceEffBegDate", "a.ReplaceEffBegDate");
  232. // values.Add("ReplaceEffEndDate", "a.ReplaceEffEndDate");
  233. // values.Add("MTIME", "a.MTIME");
  234. // //更新存在数据
  235. // sql += ICSHelper.UpdateSQL("b", values)
  236. // + @" #TempBOM a
  237. // INNER JOIN ICSBOM b ON a.cInvCode=b.cInvCode ";
  238. // values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  239. // values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  240. // values.Add("WorkPoint", "'" + WorkPoint + "'");
  241. // sql += "\r\n";
  242. // //插入新增数据
  243. // sql += ICSHelper.InsertSQL("ICSBOM", values)
  244. // + @" #TempBOM a
  245. // LEFT JOIN ICSBOM b ON a.cInvCode=b.cInvCode
  246. // WHERE b.cInvCode IS NULL
  247. // ";
  248. // sql += "DROP TABLE #TempBOM";
  249. // sql = string.Format(sql, ICSHelper.GetConfigString()["ERPDB"]);
  250. // ICSHelper.ExecuteDate(conStr, sql);
  251. // #endregion
  252. // }
  253. // catch (Exception ex)
  254. // {
  255. // log.Error(ex.ToString());
  256. // }
  257. // }
  258. }
  259. }