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.

122 lines
4.7 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. public class IcsAutoMo2Lot4JWX : IJob
  11. {
  12. private static object key = new object();
  13. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  14. public void Execute(IJobExecutionContext context)
  15. {
  16. try
  17. {
  18. lock (key)
  19. {
  20. log.Info("开始……………………………………………………………………");
  21. Execute();
  22. log.Info("结束……………………………………………………………………");
  23. }
  24. }
  25. catch (Exception ex)
  26. {
  27. log.Error(ex.ToString());
  28. }
  29. }
  30. public void Execute()
  31. {
  32. try
  33. {
  34. //string conERPStr = ICSHelper.GetERPConnectString();
  35. string conStr = ICSHelper.GetConnectString();
  36. string Namespace = this.GetType().Namespace;
  37. //string Class = this.GetType().Name;
  38. // List<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
  39. DataTable dt = ICSHelper.GetERPDB(conStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  43. string TenantId = dr["TenantId"].ToString();
  44. string TenantCode = dr["TenantCode"].ToString();
  45. var sql0 = @"select RuleCode,a.Prefix,a.Suffix,a.DateCode,a.SerialLength,a.RuleSeq
  46. from SysLabelRule a with(nolock) where RuleCode='Mo2Lot' and TenantId='" + TenantId + "' ";
  47. var ruleDt = ICSHelper.ExecuteTable(conStr, sql0);
  48. if (ruleDt == null || ruleDt.Rows.Count == 0)
  49. {
  50. return;
  51. }
  52. string sql1 = @" select a.MoCode,a.MoSeq
  53. ,a.Id
  54. ,a.MoPlanQty
  55. from IcsMo a with(nolock) where
  56. exists (
  57. select ItemCode from IcsManufacturingHead t with(nolock) where (ContractNo like 'NK%' OR ContractNo like 'FW%')
  58. and t.ItemCode=a.ItemCode
  59. )
  60. and a.MoPlanQty>0
  61. and not exists (select MoCode from IcsMo2Lot with(nolock) where MoCode=a.MoCode)
  62. and TenantId='" + TenantId + "' ";
  63. var itemDt = ICSHelper.ExecuteTable(conStr, sql1);//生产工单
  64. if (itemDt != null && itemDt.Rows.Count > 0)
  65. {
  66. string sql2 = "";
  67. foreach (DataRow dr2 in itemDt.Rows)
  68. {
  69. var qty = dr2["MoPlanQty"].ToInt();
  70. var sql4 = "";
  71. //更新工单表
  72. sql2 += @"
  73. update icsmo
  74. set MoStatus='mostatus_release',LastModificationTime=GETDATE(),LastModifierUserId='c65321b94c804dc26eb93a0ba67c8a2a',LastModifierUserName='xusc'
  75. where Id=" + dr2["Id"].ToInt64() + " and MoStatus='mostatus_initial' and TenantId='" + TenantId + "' ";
  76. for (int i = 0; i < qty; i++)
  77. {
  78. //查询序列号
  79. var sql3 = @"
  80. 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() + "'";
  81. var lotno = ICSHelper.ExecuteScalar(conStr, sql3).ToStringExt();
  82. sql4 += @"
  83. insert into IcsMo2Lot (MoId,MoCode,MoSeq,Lotno,LotSeq,LotQty,LotStatus,PrintTimes,TenantId,CreationTime,CreatorUserId,CreatorUserName)
  84. select " + dr2["Id"].ToInt64() + ",'" + dr2["MoCode"].ToStringExt() + "'," + dr2["MoSeq"].ToInt64() + ",'" + lotno + "',1," + dr2["MoPlanQty"].ToDecimal() + ",'lotstatus_new',0,'" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc'";
  85. }
  86. ICSHelper.ExecuteDate(conStr, sql4);//批量更新批次(单个工单)
  87. }
  88. ICSHelper.ExecuteDate(conStr, sql2);//批量更新工单
  89. }
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. log.Error(ex.ToString());
  95. }
  96. }
  97. }
  98. }