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.

119 lines
4.8 KiB

4 months ago
  1. using NFine.Data.Extensions;
  2. using Quartz;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. namespace ICSSoft.FromERP
  9. {
  10. /// <summary>
  11. /// 装配工单(自动分批)
  12. /// </summary>
  13. public class IcsAutoMo2Lot : 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. // List<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
  42. DataTable dt = ICSHelper.GetERPDB(conStr);
  43. Dictionary<string, string> dis = new Dictionary<string, string>() {
  44. { "A2001", "ZP01_Route" },
  45. { "A2002", "ZP02_Route" },
  46. { "KA10", "ZP03_Route" },
  47. { "A2003", "ZP04_Route" },
  48. };
  49. foreach (DataRow dr in dt.Rows)
  50. {
  51. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  52. string TenantId = dr["TenantId"].ToString();
  53. string TenantCode = dr["TenantCode"].ToString();
  54. var sql0 = @"select RuleCode,a.Prefix,a.Suffix,a.DateCode,a.SerialLength,a.RuleSeq
  55. from SysLabelRule a with(nolock) where RuleCode='Mo2Lot' and TenantId='" + TenantId + "' ";
  56. var ruleDt = ICSHelper.ExecuteTable(conStr, sql0);
  57. if (ruleDt == null || ruleDt.Rows.Count == 0)
  58. {
  59. return;
  60. }
  61. foreach (var item in dis)
  62. {
  63. string sql1 = @" select a.MoCode,a.MoSeq, a.Id,a.MoPlanQty from IcsMo a with(nolock)
  64. where a.ItemCode like '" + item.Key+ "%' " +
  65. " and not exists (select MoCode from IcsMo2Lot with(nolock) where MoCode=a.MoCode)" +
  66. " and a.mocode like 'MOSCZP%' " +
  67. " and a.MoPlanQty=1 " +
  68. " and a.TenantId='" + TenantId+"' ";
  69. var itemDt = ICSHelper.ExecuteTable(conStr, sql1);
  70. if (itemDt != null && itemDt.Rows.Count > 0)
  71. {
  72. string sql2 = "";
  73. foreach (DataRow dr2 in itemDt.Rows)
  74. {
  75. //更新工单表
  76. sql2 += @"
  77. update icsmo
  78. set MoStatus='mostatus_release',LastModificationTime=GETDATE(),LastModifierUserId='c65321b94c804dc26eb93a0ba67c8a2a',LastModifierUserName='xusc'
  79. where Id="+ dr2["Id"].ToInt64() + " and MoStatus='mostatus_initial' and TenantId='" + TenantId + "' ";
  80. //查询序列号
  81. var sql3 = @"
  82. EXEC Addins_GetSerialCode '"+TenantId+ "','IcsMo2Lot','Lotno','" + ruleDt.Rows[0]["Prefix"].ToString() + "','" + ruleDt.Rows[0]["Suffix"].ToString() + "','"+ DateTime.Now.ToString(ruleDt.Rows[0]["DateCode"].ToString()) + "'," + ruleDt.Rows[0]["SerialLength"].ToInt() + ",'" + ruleDt.Rows[0]["RuleSeq"].ToStringExt() + "'";
  83. var lotno= ICSHelper.ExecuteScalar(conStr, sql3).ToStringExt();
  84. sql2 += @"
  85. insert into IcsMo2Lot (MoId,MoCode,MoSeq,Lotno,LotSeq,LotQty,LotStatus,PrintTimes,TenantId,CreationTime,CreatorUserId,CreatorUserName)
  86. select " + dr2["Id"].ToInt64() + ",'"+ dr2["MoCode"].ToStringExt() + "'," + dr2["MoSeq"].ToInt64() + ",'" + lotno + "',1," + dr2["MoPlanQty"].ToDecimal() + ",'lotstatus_new',0,'" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc'";
  87. }
  88. ICSHelper.ExecuteDate(conStr, sql2);
  89. }
  90. }
  91. }
  92. }
  93. catch (Exception ex)
  94. {
  95. log.Error(ex.ToString());
  96. }
  97. }
  98. }
  99. }