COrderLogic.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using DbCommon.BusinessCore.BaseCore;
  2. using DbCommon.Enties.DbModels;
  3. using DbCommon.Extenions;
  4. using DbCommon.Function;
  5. using Newtonsoft.Json;
  6. using PmsSecondaryPackaging.Interface.Model.Carrier;
  7. using PmsSecondaryPackaging.Interface.Model.TaskBook;
  8. using PmsSecondaryPackaging.Interface.Service;
  9. using ProjectManagementSystem.Common.Log;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace ProjectManagementSystem.OrderLogic
  17. {
  18. public class COrderLogic
  19. {
  20. private static COrderLogic m_instance;
  21. private LocationPropertyManager m_locationManager = new LocationPropertyManager();
  22. public InterfaceService interfaceService { get; set; } = new InterfaceService();
  23. public static COrderLogic Instance
  24. {
  25. get
  26. {
  27. if (m_instance == null)
  28. {
  29. m_instance = new COrderLogic();
  30. }
  31. return m_instance;
  32. }
  33. }
  34. public List<IOrderLogic> Logics { get; private set; } = new List<IOrderLogic>();
  35. private COrderLogic()
  36. {
  37. Logics.Add(new Logic_3F还原车间());
  38. Logics.Add(new Logic_3F空车缓存区());
  39. Task.Factory.StartNew(TaskThread);
  40. }
  41. private void TaskAdd(TaskAddInfoModel data)
  42. {
  43. bool result = interfaceService.TaskAdd(data, out string Message);
  44. CLog.Instance.GetLog("Task").WriteInfo($"{data.TaskID} {data.ParentTaskId} {data.TemplateName} {data.Parameters} 任务添加{result.ToChineseString()}");
  45. if (result)
  46. {
  47. string[] posArray = data.ParametersDic.Values.ToArray().Distinct().ToArray();
  48. for (int i = 0; i < posArray.Length; i++)
  49. {
  50. string location = posArray[i];
  51. var locationData = m_locationManager.QueryData(location);
  52. if (locationData.Status != LocationStatus.Locked
  53. && locationData.Status != LocationStatus.LineCall)
  54. {
  55. //锁定库位状态并备份状态
  56. m_locationManager.UpdateStatusAndStatusBackup(location, LocationStatus.Locked, locationData.Status);
  57. }
  58. if (locationData.Status == LocationStatus.LineCall)
  59. {
  60. m_locationManager.UpdateStatusAndStatusBackup(location, LocationStatus.Locked, Tools.ParseStatus(locationData.StatusBackup));
  61. }
  62. }
  63. }
  64. }
  65. public void LogicsRunProc()
  66. {
  67. for (int i = 0; i < Logics.Count; i++)
  68. {
  69. var logic = Logics[i];
  70. //检查叫料状态
  71. if (logic.FirstCheck())
  72. {
  73. if (logic.SecondCheck())
  74. {
  75. //检查是否满足任务条件
  76. var data = logic.GetTask();
  77. if (data != null)
  78. {
  79. TaskAdd(data);
  80. }
  81. else
  82. {
  83. //成功叫料但不满足条件时的处理
  84. logic.CallTaskCheckFailProc();
  85. }
  86. }
  87. else
  88. {
  89. logic.SecondCheckFailProc();
  90. }
  91. }
  92. }
  93. }
  94. public void TaskThread()
  95. {
  96. byte couter = 0;
  97. while (true)
  98. {
  99. try
  100. {
  101. LogicsRunProc();
  102. }
  103. catch (Exception ex)
  104. {
  105. CLog.Instance.GetLog("Task").WriteException("Exception", ex);
  106. Thread.Sleep(5000);
  107. }
  108. couter++;
  109. Thread.Sleep(500);
  110. }
  111. }
  112. }
  113. }