PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/BlueGardensEESystem/src/main/java/com/netbuilder/BlueGardensEESystem/WarehouseOperation.java

https://gitlab.com/GAndrews13/BlueGardens
Java | 213 lines | 183 code | 20 blank | 10 comment | 15 complexity | 0ce00f524e172491319afe8f3e3471f1 MD5 | raw file
  1. package com.netbuilder.BlueGardensEESystem;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import javax.inject.Inject;
  5. import com.netbuilder.entities.CustomerOrder;
  6. import com.netbuilder.entities.CustomerOrderLine;
  7. import com.netbuilder.entities.Product;
  8. import com.netbuilder.entities.WarehouseLocation;
  9. import com.netbuilder.entities.WarehouseWorker;
  10. import com.netbuilder.entitymanagers.CustomerOrderLineManager;
  11. import com.netbuilder.entitymanagers.CustomerOrderManager;
  12. import com.netbuilder.entitymanagers.ProductManager;
  13. import com.netbuilder.entitymanagers.WarehouseLocationManager;
  14. import com.netbuilder.entitymanagers.WarehouseWorkerManager;
  15. import com.netbuilder.entitymanagers.Dummy.CustomerOrderManagerDummy;
  16. import com.netbuilder.entitymanagers.Dummy.ProductManagerDummy;
  17. import com.netbuilder.entitymanagers.Dummy.WarehouseLocationManagerDummy;
  18. public class WarehouseOperation implements Serializable
  19. {
  20. /**
  21. *
  22. */
  23. private static final long serialVersionUID = -2116270683372912345L;
  24. @Inject
  25. private WarehouseWorkerManager warehouseWorkerManager;
  26. @Inject
  27. private CustomerOrderManager customerOrderManager;
  28. @Inject
  29. private CustomerOrderLineManager customerOrderLineManager;
  30. @Inject
  31. private WarehouseLocationManager warehouseLocationManager;
  32. WarehouseLocationManager wlm = new WarehouseLocationManagerDummy();
  33. ArrayList<CustomerOrder> openOrders;
  34. ArrayList<CustomerOrder> assignedOrders;
  35. boolean pickingSequenced;
  36. public WarehouseOperation()
  37. {
  38. customerOrderManager = new CustomerOrderManagerDummy();
  39. openOrders = customerOrderManager.findByDeliveryStatus(DeliveryStatus.ORDER_PLACED);
  40. assignedOrders = customerOrderManager.findByDeliveryStatus(DeliveryStatus.PROCESSING);
  41. }
  42. /*
  43. * @author David Ogbonnah
  44. * @param id the workers id number
  45. * @return the id number of the customer order assigned to the worker
  46. *
  47. * Assigns a worker to a new order. Returns an id allowing the picking order can be calculated
  48. */
  49. public String loginWorker(int id, String password)
  50. {
  51. WarehouseWorker worker = warehouseWorkerManager.findById(id);
  52. if (worker.equals(null))
  53. {
  54. return "Worker does not exist";
  55. }
  56. else if(!worker.getPassword().equals(password))
  57. {
  58. return "Password for worker incorrect";
  59. }
  60. else if(worker.getPassword().equals(password))
  61. {
  62. worker.setLoggedIn(true);
  63. warehouseWorkerManager.updateWarehouseWorker(worker);
  64. return "Worker " + worker.getName() + " is logged in";
  65. }
  66. return null;
  67. }
  68. public String logoutWorker(int id)
  69. {
  70. WarehouseWorker worker = warehouseWorkerManager.findById(id);
  71. if(worker.isLoggedIn())
  72. {
  73. worker.setLoggedIn(false);
  74. warehouseWorkerManager.updateWarehouseWorker(worker);
  75. return "Worker " + worker.getName() + " is logged out";
  76. }
  77. return null;
  78. }
  79. public int assignWorkerToOrder(int id)
  80. {
  81. WarehouseWorker worker = warehouseWorkerManager.findById(id);
  82. CustomerOrder order = openOrders.get(1);
  83. worker.setAssigned(true);
  84. order.setIsAssigned(true);
  85. order.setWorker(worker);
  86. order.setStatus(DeliveryStatus.PROCESSING);
  87. return order.getCustomerOrderID();
  88. }
  89. public void setPickingSequence(int coid)
  90. {
  91. ArrayList<CustomerOrderLine> currentOrderLines = customerOrderLineManager.findByCustomerOrderID(coid);
  92. ArrayList<CustomerOrderLine> pickingSequence = new ArrayList<CustomerOrderLine>();
  93. ArrayList<String> ssectionA = new ArrayList<String>();
  94. ArrayList<CustomerOrderLine> sectionA = new ArrayList<CustomerOrderLine>();
  95. ArrayList<String> ssectionB = new ArrayList<String>();
  96. ArrayList<CustomerOrderLine> sectionB = new ArrayList<CustomerOrderLine>();
  97. ArrayList<String> ssectionC = new ArrayList<String>();
  98. ArrayList<CustomerOrderLine> sectionC = new ArrayList<CustomerOrderLine>();
  99. ArrayList<String> ssectionD = new ArrayList<String>();
  100. ArrayList<CustomerOrderLine> sectionD = new ArrayList<CustomerOrderLine>();
  101. ArrayList<String> ssectionE = new ArrayList<String>();
  102. ArrayList<CustomerOrderLine> sectionE = new ArrayList<CustomerOrderLine>();
  103. ArrayList<String> ssectionF = new ArrayList<String>();
  104. ArrayList<CustomerOrderLine> sectionF = new ArrayList<CustomerOrderLine>();
  105. ArrayList<String> ssectionG = new ArrayList<String>();
  106. ArrayList<CustomerOrderLine> sectionG = new ArrayList<CustomerOrderLine>();
  107. ArrayList<String> ssectionH = new ArrayList<String>();
  108. ArrayList<CustomerOrderLine> sectionH = new ArrayList<CustomerOrderLine>();
  109. ArrayList<String> ssectionI = new ArrayList<String>();
  110. ArrayList<CustomerOrderLine> sectionI = new ArrayList<CustomerOrderLine>();
  111. for (CustomerOrderLine col : currentOrderLines) {
  112. int productID = col.getProductId();
  113. ArrayList<WarehouseLocation> thisIDLocations = wlm
  114. .findByProductID(productID);
  115. WarehouseLocation selected = thisIDLocations.get(1);
  116. String locID = selected.getLocationId();
  117. findRowInSection("A", ssectionA, sectionA, locID, col);
  118. findRowInSection("B", ssectionB, sectionB, locID, col);
  119. findRowInSection("C", ssectionC, sectionC, locID, col);
  120. findRowInSection("D", ssectionD, sectionD, locID, col);
  121. findRowInSection("E", ssectionE, sectionE, locID, col);
  122. findRowInSection("F", ssectionF, sectionF, locID, col);
  123. findRowInSection("G", ssectionG, sectionG, locID, col);
  124. findRowInSection("H", ssectionH, sectionH, locID, col);
  125. findRowInSection("I", ssectionI, sectionI, locID, col);
  126. }
  127. orderCols(sectionA, pickingSequence);
  128. orderCols(sectionB, pickingSequence);
  129. orderCols(sectionC, pickingSequence);
  130. orderCols(sectionD, pickingSequence);
  131. orderCols(sectionE, pickingSequence);
  132. orderCols(sectionF, pickingSequence);
  133. orderCols(sectionG, pickingSequence);
  134. orderCols(sectionH, pickingSequence);
  135. orderCols(sectionI, pickingSequence);
  136. pickingSequenced = true;
  137. }
  138. public String showNextProduct(int coid)
  139. {
  140. ArrayList<CustomerOrderLine> currentOrderLines = customerOrderLineManager.findByCustomerOrderID(coid);
  141. int i = 0;
  142. while(i<currentOrderLines.size())
  143. {
  144. CustomerOrderLine col = currentOrderLines.get(i);
  145. if(!col.getIsPicked())
  146. {
  147. int id = col.getProductId();
  148. ProductManager pm = new ProductManagerDummy();
  149. Product product = pm.findById(id);
  150. return product.getProductName();
  151. }
  152. i++;
  153. }
  154. return null;
  155. }
  156. public void findRowInSection(String sec, ArrayList<String> locIDs,
  157. ArrayList<CustomerOrderLine> cols, String tempLocID,
  158. CustomerOrderLine col) {
  159. if (tempLocID.startsWith(sec)) {
  160. String[] s = tempLocID.split(sec);
  161. int row = Integer.parseInt(s[1]);
  162. if (locIDs.size() == 0) {
  163. locIDs.add(tempLocID);
  164. cols.add(col);
  165. } else {
  166. for (int i = 0; i < locIDs.size(); i++) {
  167. String[] tempS = locIDs.get(i).split(sec);
  168. int tempRow = Integer.parseInt(tempS[1]);
  169. if (row > tempRow) {
  170. locIDs.add(i, tempLocID);
  171. cols.add(i, col);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. public void orderCols(ArrayList<CustomerOrderLine> colsBySection,
  178. ArrayList<CustomerOrderLine> allCols) {
  179. for (CustomerOrderLine col : colsBySection) {
  180. allCols.add(col);
  181. }
  182. }
  183. public void completeOrder(int id)
  184. {
  185. WarehouseWorker worker = warehouseWorkerManager.findById(id);
  186. CustomerOrder order = openOrders.get(1);
  187. worker.setAssigned(false);
  188. order.setIsAssigned(false);
  189. order.setWorker(worker);
  190. order.setStatus(DeliveryStatus.READY);
  191. pickingSequenced = false;
  192. }
  193. }