TaskBookBehavior_63007.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using DbCommon.BusinessCore.BaseCore;
  2. using DbCommon.Enties.DbModels;
  3. using Pms.DataLibrary.Models;
  4. using Pms.DataLibrary.Order;
  5. using Pms.Models;
  6. using ProjectManagementSystem.Common.Core;
  7. using ProjectManagementSystem.Common.Logger;
  8. using ProjectManagementSystem.Common.WebApi;
  9. using ProjectManagementSystem.Common.Models;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using ProjectManagementSystem.Common.Extenions;
  16. using ProjectManagementSystem.Common.Config;
  17. namespace ProjectManagementSystem.TaskBookEvent
  18. {
  19. public class TaskBookBehavior_63007 : BaseTaskBookBehaviorV2
  20. {
  21. LocationPropertyManager locationManager = new LocationPropertyManager();
  22. public TaskBookBehavior_63007() : base(63007, "更改步骤库位")
  23. {
  24. }
  25. public override bool TaskBookOperator(TaskData taskDetailInfo, StepData stepInfo)
  26. {
  27. try
  28. {
  29. string allNextLocation = stepInfo.WareHouseID.GetLocationMember("下个工位");
  30. string[] nextLocations = allNextLocation.ToValueArray<string>();
  31. string[] nextAllowLocations = nextLocations.Where(d =>
  32. {
  33. string plcAllowEnter = d.GetLocationMember("PLC允许进入");
  34. if (string.IsNullOrEmpty(plcAllowEnter))
  35. {
  36. return false;
  37. }
  38. var config = ExcelConfig.Instance.GetRouteConfig(d);
  39. if (config == null
  40. || config.PlcReadWrite == null
  41. || config.PlcConnected == false)
  42. {
  43. return false;
  44. }
  45. var read = config.PlcReadWrite.ReadBool(plcAllowEnter);
  46. return read.IsSuccess && read.Content;
  47. }).ToArray();
  48. if(nextAllowLocations == null || nextAllowLocations.Length == 0)
  49. {
  50. Log(taskDetailInfo, stepInfo, $"{allNextLocation} 中未找到PLC允许进入的工位");
  51. return false;
  52. }
  53. string nextLocation = null;
  54. for (int i = 0; i < nextAllowLocations.Length; i++)
  55. {
  56. string tempLocation = nextAllowLocations[i];
  57. if (PackControl.Instance.StationDictionary.ContainsKey(tempLocation)
  58. && PackControl.Instance.StationDictionary[tempLocation].区域有Agv == false)
  59. {
  60. nextLocation = tempLocation;
  61. break;
  62. }
  63. }
  64. if (string.IsNullOrEmpty(nextLocation))
  65. {
  66. Log(taskDetailInfo, stepInfo, $"{allNextLocation} 中未找到空位");
  67. return false;
  68. }
  69. Log(taskDetailInfo, stepInfo, $"检测到可以分配的位置 {nextLocation}");
  70. //更改库位
  71. bool result = true;
  72. int startStepId = taskDetailInfo.CurrentStepID + 1;
  73. int endStepId = taskDetailInfo.StepList.Max(d => d.StepID);
  74. for (int i = startStepId; i <= endStepId; i++)
  75. {
  76. result &= PmsApi.UpdateStepWarehouse(taskDetailInfo.TaskID, i, nextLocation);
  77. if (!result)
  78. {
  79. Log(taskDetailInfo, stepInfo, $"更改库位失败");
  80. return false;
  81. }
  82. }
  83. locationManager.UpdateStatusAndStatusBackup(nextLocation, LocationStatus.Locked, LocationStatus.Empty);
  84. Log(taskDetailInfo, stepInfo, $"已更改库位 {nextLocation}");
  85. return true;
  86. }
  87. catch (Exception ex)
  88. {
  89. LogException(ex);
  90. }
  91. return false;
  92. }
  93. }
  94. }