1 25 package org.ofbiz.manufacturing.jobshopmgt; 26 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.ofbiz.base.util.Debug; 32 import org.ofbiz.base.util.UtilMisc; 33 import org.ofbiz.entity.GenericDelegator; 34 import org.ofbiz.entity.GenericEntityException; 35 import org.ofbiz.entity.GenericValue; 36 import org.ofbiz.entity.util.EntityUtil; 37 import org.ofbiz.service.LocalDispatcher; 38 39 40 45 public class ProductionRunHelper { 46 47 public static final String module = ProductionRunHelper.class.getName(); 48 public static final String resource = "ManufacturingUiLabels"; 49 50 51 60 public static Map getProductionRun(GenericDelegator delegator, String productionRunId) { 61 Map result = new HashMap (); 62 64 try { 65 if (productionRunId != null ) { 66 GenericValue productionRun = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", productionRunId)); 67 if (productionRun != null) { 68 List productionRunProducts = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV"),null); 69 GenericValue productionRunProduct = EntityUtil.getFirst(productionRunProducts); 70 GenericValue productProduced = productionRunProduct.getRelatedOneCache("Product"); 71 List productionRunComponents = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"),null); 72 List productionRunRoutingTasks = productionRun.getRelated("FromWorkEffortAssoc",UtilMisc.toMap("workEffortTypeId","PROD_ORDER_TASK"),null); 73 74 } 75 } 76 } catch (GenericEntityException e) { 77 Debug.logWarning(e.getMessage(), module); 78 } 79 return result; 80 } 81 82 public static boolean hasTask(GenericDelegator delegator, String taskName, String workEffortId) throws GenericEntityException { 83 List tasks = delegator.findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", workEffortId, 84 "workEffortTypeId", "PROD_ORDER_TASK", 85 "workEffortName", taskName)); 86 return (tasks != null && tasks.size() > 0); 87 } 88 89 public static void getLinkedProductionRuns(GenericDelegator delegator, LocalDispatcher dispatcher, String productionRunId, List productionRuns) throws GenericEntityException { 90 productionRuns.add(new ProductionRun(productionRunId, delegator, dispatcher)); 91 List linkedWorkEfforts = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdTo", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY"))); 92 for (int i = 0; i < linkedWorkEfforts.size(); i++) { 93 GenericValue link = (GenericValue)linkedWorkEfforts.get(i); 94 getLinkedProductionRuns(delegator, dispatcher, link.getString("workEffortIdFrom"), productionRuns); 95 } 96 } 97 98 public static String getRootProductionRun(GenericDelegator delegator, String productionRunId) throws GenericEntityException { 99 List linkedWorkEfforts = delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdFrom", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY")); 100 GenericValue linkedWorkEffort = EntityUtil.getFirst(linkedWorkEfforts); 101 if (linkedWorkEffort != null) { 102 productionRunId = getRootProductionRun(delegator, linkedWorkEffort.getString("workEffortIdTo")); 103 } 104 return productionRunId; 105 } 106 107 } 108 | Popular Tags |