📄 productionrunservices.java
字号:
return ServiceUtil.returnError(e.getMessage()); } // ------------------- // Routing and routing tasks // ------------------- // Select the product's routing try { Map routingInMap = UtilMisc.toMap("productId", productId, "userLogin", userLogin); Map routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); routing = (GenericValue)routingOutMap.get("routing"); routingTaskAssocs = (List)routingOutMap.get("tasks"); } catch(GenericServiceException gse) { Debug.logWarning(gse.getMessage(), module); } // ================================= if (routing == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductRoutingNotExist", locale)); } if (routingTaskAssocs == null || routingTaskAssocs.size()==0) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingHasNoRoutingTask", locale)); } // ProductionRun header creation, if (workEffortName == null) { String prdName = UtilValidate.isNotEmpty(product.getString("productName"))? product.getString("productName"): product.getString("productId"); String wefName = UtilValidate.isNotEmpty(routing.getString("workEffortName"))? routing.getString("workEffortName"): routing.getString("workEffortId"); workEffortName = prdName + "-" + wefName; } serviceContext.clear(); serviceContext.put("workEffortTypeId", "PROD_ORDER_HEADER"); serviceContext.put("workEffortPurposeTypeId", "WEPT_PRODUCTION_RUN"); serviceContext.put("currentStatusId", "PRUN_CREATED"); serviceContext.put("workEffortName", workEffortName); serviceContext.put("description",description); serviceContext.put("facilityId", facilityId); serviceContext.put("estimatedStartDate",startDate); serviceContext.put("quantityToProduce", pRQuantity); serviceContext.put("userLogin", userLogin); try { resultService = dispatcher.runSync("createWorkEffort", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffort service", module); return ServiceUtil.returnError(e.getMessage()); } String productionRunId = (String) resultService.get("workEffortId"); if (Debug.infoOn()) { Debug.logInfo("ProductionRun created: " + productionRunId, module); } // ProductionRun, product will be produce creation = WorkEffortGoodStandard for the productId serviceContext.clear(); serviceContext.put("workEffortId", productionRunId); serviceContext.put("productId", productId); serviceContext.put("workEffortGoodStdTypeId", "PRUN_PROD_DELIV"); serviceContext.put("statusId", "WEGS_CREATED"); serviceContext.put("estimatedQuantity", pRQuantity); serviceContext.put("fromDate", startDate); serviceContext.put("userLogin", userLogin); try { resultService = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); return ServiceUtil.returnError(e.getMessage()); } // Multi creation (like clone) ProductionRunTask and GoodAssoc Iterator rt = routingTaskAssocs.iterator(); boolean first = true; while (rt.hasNext()) { GenericValue routingTaskAssoc = (GenericValue) rt.next(); if (TechDataServices.routingTaskAssocIsValid(routingTaskAssoc, startDate)) { GenericValue routingTask = null; try { routingTask = routingTaskAssoc.getRelatedOne("ToWorkEffort"); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } // Calculate the estimatedCompletionDate long totalTime = ProductionRun.getEstimatedTaskTime(routingTask, pRQuantity, dispatcher); Timestamp endDate = TechDataServices.addForward(TechDataServices.getTechDataCalendar(routingTask),startDate, totalTime); serviceContext.clear(); serviceContext.put("priority", routingTaskAssoc.get("sequenceNum")); serviceContext.put("workEffortPurposeTypeId", routingTask.get("workEffortPurposeTypeId")); serviceContext.put("workEffortName",routingTask.get("workEffortName")); serviceContext.put("description",routingTask.get("description")); serviceContext.put("fixedAssetId",routingTask.get("fixedAssetId")); serviceContext.put("workEffortTypeId", "PROD_ORDER_TASK"); serviceContext.put("currentStatusId","PRUN_CREATED"); serviceContext.put("workEffortParentId", productionRunId); serviceContext.put("facilityId", facilityId); serviceContext.put("estimatedStartDate",startDate); serviceContext.put("estimatedCompletionDate",endDate); serviceContext.put("estimatedSetupMillis", routingTask.get("estimatedSetupMillis")); serviceContext.put("estimatedMilliSeconds", routingTask.get("estimatedMilliSeconds")); serviceContext.put("quantityToProduce", pRQuantity); serviceContext.put("userLogin", userLogin); resultService = null; try { resultService = dispatcher.runSync("createWorkEffort", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffort service", module); } String productionRunTaskId = (String) resultService.get("workEffortId"); if (Debug.infoOn()) Debug.logInfo("ProductionRunTaskId created: " + productionRunTaskId, module); // The newly created production run task is associated to the routing task // to keep track of the template used to generate it. serviceContext.clear(); serviceContext.put("userLogin", userLogin); serviceContext.put("workEffortIdFrom", routingTask.getString("workEffortId")); serviceContext.put("workEffortIdTo", productionRunTaskId); serviceContext.put("workEffortAssocTypeId", "WORK_EFF_TEMPLATE"); try { resultService = dispatcher.runSync("createWorkEffortAssoc", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortAssoc service", module); } // copy date valid WorkEffortPartyAssignments from the routing task to the run task List workEffortPartyAssignments = null; try { workEffortPartyAssignments = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", routingTaskAssoc.getString("workEffortIdTo")))); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } if (workEffortPartyAssignments != null) { Iterator i = workEffortPartyAssignments.iterator(); while(i.hasNext()) { GenericValue workEffortPartyAssignment = (GenericValue) i.next(); Map partyToWorkEffort = UtilMisc.toMap( "workEffortId", productionRunTaskId, "partyId", workEffortPartyAssignment.getString("partyId"), "roleTypeId", workEffortPartyAssignment.getString("roleTypeId"), "fromDate", workEffortPartyAssignment.getTimestamp("fromDate"), "statusId", workEffortPartyAssignment.getString("statusId"), "userLogin", userLogin ); try { resultService = dispatcher.runSync("assignPartyToWorkEffort", partyToWorkEffort); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the assignPartyToWorkEffort service", module); } if (Debug.infoOn()) Debug.logInfo("ProductionRunPartyassigment for party: " + workEffortPartyAssignment.get("partyId") + " created", module); } } // Now we iterate thru the components returned by the getManufacturingComponents service // TODO: if in the BOM a routingWorkEffortId is specified, but the task is not in the routing // the component is not added to the production run. Iterator pb = components.iterator(); while (pb.hasNext()) { // The components variable contains a list of BOMNodes: // each node represents a product (component). org.ofbiz.manufacturing.bom.BOMNode node = (org.ofbiz.manufacturing.bom.BOMNode) pb.next(); GenericValue productBom = node.getProductAssoc(); if ((productBom.getString("routingWorkEffortId") == null && first) || (productBom.getString("routingWorkEffortId") != null && productBom.getString("routingWorkEffortId").equals(routingTask.getString("workEffortId")))) { serviceContext.clear(); serviceContext.put("workEffortId", productionRunTaskId); // Here we get the ProductAssoc record from the BOMNode // object to be sure to use the // right component (possibly configured). serviceContext.put("productId", node.getProduct().get("productId")); serviceContext.put("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"); serviceContext.put("statusId", "WEGS_CREATED"); serviceContext.put("fromDate", productBom.get("fromDate")); // Here we use the getQuantity method to get the quantity already // computed by the getManufacturingComponents service //double scrapFactor = (productBom.get("scrapFactor") != null)? productBom.getDouble("scrapFactor").doubleValue() : 0; //serviceContext.put("estimatedQuantity", new Double(Math.floor((productBom.getDouble("quantity").doubleValue() * pRQuantity.doubleValue() / (1-(scrapFactor / 100))) + 0.5))); serviceContext.put("estimatedQuantity", new Double(node.getQuantity())); serviceContext.put("userLogin", userLogin); resultService = null; try { resultService = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); } if (Debug.infoOn()) Debug.logInfo("ProductLink created for productId: " + productBom.getString("productIdTo"), module); } } first = false; startDate = endDate; } } // update the estimatedCompletionDate field for the productionRun serviceContext.clear(); serviceContext.put("workEffortId",productionRunId); serviceContext.put("estimatedCompletionDate",startDate); serviceContext.put("userLogin", userLogin); resultService = null; try { resultService = dispatcher.runSync("updateWorkEffort", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); } result.put("productionRunId", productionRunId); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated",UtilMisc.toMap("productionRunId", productionRunId), locale)); return result; } /** * Update a Production Run. * <li> update field and after recalculate the entire ProductionRun data (routingTask and productComponent) * <li> create the WorkEffortGoodStandard for link between ProductionRun and the product it will produce * <li> for each valid routingTask of the routing create a workeffort-task * <li> for the first routingTask, create for all the valid productIdTo with no associateRoutingTask a WorkEffortGoodStandard * <li> for each valid routingTask of the routing and valid productIdTo associate with this RoutingTask create a WorkEffortGoodStandard * @param ctx The DispatchContext that this service is operating in. * @param context Map containing the input parameters, productId, routingId, quantity, estimatedStartDate, workEffortName, description * @return Map with the result of the service, the output parameters. */ public static Map updateProductionRun(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Security security = ctx.getSecurity(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); /* TODO: security management and finishing cleaning (ex copy from PartyServices.java) if (!security.hasEntityPermission(secEntity, secOperation, userLogin)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -