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.

104 lines
4.3 KiB

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. /// 工单工艺自动生成(锐腾)
  11. /// </summary>
  12. public class IcsAutoSyncMoRoute_Rhtyon : 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. // List<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
  41. DataTable dt = ICSHelper.GetERPDB(conStr);
  42. //循环组织
  43. foreach (DataRow dr in dt.Rows)
  44. {
  45. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  46. string TenantId = dr["TenantId"].ToString();
  47. string TenantCode = dr["TenantCode"].ToString();
  48. string sql1 = @"
  49. select a.MoCode,a.MoSeq, a.Id,a.ItemCode ,b.RouteCode
  50. from IcsMo a with(nolock)
  51. left join IcsItem2Route b with(nolock) on a.ItemCode=b.ItemCode and b.IsRef='Y' and a.TenantId=b.TenantId
  52. where a.MoStatus='mostatus_initial'
  53. and not exists (select MoCode from IcsMo2Route with(nolock) where MoCode=a.MoCode) and a.TenantId='" + TenantId + "' " +
  54. " and b.RouteCode is not null ";
  55. var itemDt = ICSHelper.ExecuteTable(conStr, sql1);
  56. if (itemDt != null && itemDt.Rows.Count > 0)
  57. {
  58. //循环工单
  59. string sql2 = "";
  60. for (int i = 0; i < itemDt.Rows.Count; i++)
  61. {
  62. var item = itemDt.Rows[i];
  63. //工艺路线表头
  64. sql2 += @"
  65. insert into IcsMo2Route (MoId,RouteId,MoCode,MoSeq, RouteCode,IsMRoute, TenantId,CreationTime,CreatorUserId,CreatorUserName)
  66. select top 1 " + item["Id"].ToInt64() + ",Id,'" + item["MoCode"].ToString() + "'," + item["MoSeq"].ToInt64() + ",RouteCode,'Y','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsItem2Route a " +
  67. " where ItemCode='" + item["ItemCode"].ToString() + "' " +
  68. "and a.IsRef='Y' and TenantId='" + TenantId + "' ";
  69. //工艺路线明细
  70. sql2 += @"
  71. insert into IcsMoRoute2Op (MoId,RouteId,OpId,MoCode,MoSeq, RouteCode,OpCode,OpSeq,OpControl ,OpLevel ,OpControlSeq,ParallelOp
  72. ,TenantId,CreationTime,CreatorUserId,CreatorUserName)
  73. select " + item["Id"].ToInt64() + ",RouteId,OpId,'" + item["MoCode"].ToString() + "'," + item["MoSeq"].ToInt64() + ",RouteCode,OpCode,OpSeq,OPControl,'A',OpControlSeq,'N','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsItemRoute2Op a " +
  74. "where ItemCode='" + item["ItemCode"].ToString() +
  75. "' and a.RouteCode='"+ item["RouteCode"].ToString() + "' and TenantId='" + TenantId + "' ";
  76. sql2 += @" update icsmo set MoRoute='" + item["RouteCode"].ToString() + "' where Id=" + item["Id"].ToInt64() + " and TenantId='" + TenantId + "' ";
  77. }
  78. ICSHelper.ExecuteDate(conStr, sql2);
  79. }
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. log.Error(ex.ToString());
  85. }
  86. }
  87. }
  88. }