📄 productionrunservices.java
字号:
*/ String productionRunId = (String) context.get("productionRunId"); String routingTaskId = (String) context.get("routingTaskId"); if (! UtilValidate.isEmpty(productionRunId) && ! UtilValidate.isEmpty(routingTaskId)) { ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher); if (productionRun.exist()){ if (!productionRun.getGenericValue().getString("currentStatusId").equals("PRUN_CREATED")) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunPrinted", locale)); } Timestamp estimatedStartDate = (Timestamp) context.get("estimatedStartDate"); Timestamp pRestimatedStartDate = productionRun.getEstimatedStartDate(); if (pRestimatedStartDate.after(estimatedStartDate)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingTaskStartDateBeforePRun", locale)); } Long priority = (Long) context.get("priority"); List pRRoutingTasks = productionRun.getProductionRunRoutingTasks(); boolean first = true; for (Iterator iter=pRRoutingTasks.iterator();iter.hasNext();){ GenericValue routingTask = (GenericValue) iter.next(); if (priority.equals(routingTask.get("priority")) && ! routingTaskId.equals(routingTask.get("workEffortId"))) return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingTaskSeqIdAlreadyExist", locale)); if (routingTaskId.equals(routingTask.get("workEffortId"))){ routingTask.set("estimatedSetupMillis", context.get("estimatedSetupMillis")); routingTask.set("estimatedMilliSeconds", context.get("estimatedMilliSeconds")); if (first){ // for the first routingTask the estimatedStartDate update imply estimatedStartDate productonRun update if (! estimatedStartDate.equals(pRestimatedStartDate)){ productionRun.setEstimatedStartDate(estimatedStartDate); } } // the priority has been changed if (! priority.equals(routingTask.get("priority"))){ routingTask.set("priority", priority); // update the routingTask List and re-read it to be able to have it sorted with the new value if ( ! productionRun.store()) { Debug.logError("productionRun.store(), in routingTask.priority update, fail for productionRunId ="+productionRunId,module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotUpdated", locale)); } productionRun.clearRoutingTasksList(); } } if (first) first = false; } productionRun.setEstimatedCompletionDate(productionRun.recalculateEstimatedCompletionDate(priority, estimatedStartDate)); if (productionRun.store()) { return ServiceUtil.returnSuccess(); } else { Debug.logError("productionRun.store() fail for productionRunId ="+productionRunId,module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotUpdated", locale)); } } Debug.logError("no productionRun for productionRunId ="+productionRunId,module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotUpdated", locale)); } Debug.logError("service updateProductionRun call with productionRunId empty",module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotUpdated", locale)); } public static Map addProductionRunComponent(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Timestamp now = UtilDateTime.nowTimestamp(); List msgResult = new LinkedList(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); // Mandatory input fields String productionRunId = (String)context.get("productionRunId"); String productId = (String)context.get("productId"); Double quantity = (Double) context.get("estimatedQuantity"); // Optional input fields String workEffortId = (String)context.get("workEffortId"); ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher); List tasks = productionRun.getProductionRunRoutingTasks(); if (tasks == null || tasks.size() == 0){ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale)); } if (!productionRun.getGenericValue().getString("currentStatusId").equals("PRUN_CREATED")) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunPrinted", locale)); } if (workEffortId != null) { boolean found = false; for (int i = 0; i < tasks.size(); i++) { GenericValue oneTask = (GenericValue)tasks.get(i); if (oneTask.getString("workEffortId").equals(workEffortId)) { found = true; break; } } if (!found) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale)); } } else { workEffortId = EntityUtil.getFirst(tasks).getString("workEffortId"); } try { // Find the product GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); if (product == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductNotExists", locale)); } } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(e.getMessage()); } Map serviceContext = new HashMap(); serviceContext.clear(); serviceContext.put("workEffortId", workEffortId); serviceContext.put("productId", productId); serviceContext.put("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"); serviceContext.put("statusId", "WEGS_CREATED"); serviceContext.put("fromDate", now); serviceContext.put("estimatedQuantity", quantity); serviceContext.put("userLogin", userLogin); Map resultService = null; try { resultService = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentNotAdded", locale)); } result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentAdded",UtilMisc.toMap("productionRunId", productionRunId), locale)); return result; } public static Map updateProductionRunComponent(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Timestamp now = UtilDateTime.nowTimestamp(); List msgResult = new LinkedList(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); // Mandatory input fields String productionRunId = (String)context.get("productionRunId"); String productId = (String)context.get("productId"); // Optional input fields String workEffortId = (String)context.get("workEffortId"); // the production run task Double quantity = (Double) context.get("estimatedQuantity"); ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher); List components = productionRun.getProductionRunComponents(); if (components == null || components.size() == 0){ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentNotExists", locale)); } if (!productionRun.getGenericValue().getString("currentStatusId").equals("PRUN_CREATED")) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunPrinted", locale)); } boolean found = false; GenericValue theComponent = null; for (int i = 0; i < components.size(); i++) { theComponent = (GenericValue)components.get(i); if (theComponent.getString("productId").equals(productId)) { if (workEffortId != null) { if (theComponent.getString("workEffortId").equals(workEffortId)) { found = true; break; } } else { found = true; break; } } } if (!found) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale)); } try { // Find the product GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); if (product == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductNotExists", locale)); } } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(e.getMessage()); } Map serviceContext = new HashMap(); serviceContext.clear(); serviceContext.put("workEffortId", theComponent.getString("workEffortId")); serviceContext.put("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"); serviceContext.put("productId", productId); serviceContext.put("fromDate", theComponent.getTimestamp("fromDate")); if (quantity != null) { serviceContext.put("estimatedQuantity", quantity); } serviceContext.put("userLogin", userLogin); Map resultService = null; try { resultService = dispatcher.runSync("updateWorkEffortGoodStandard", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffortGoodStandard service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentNotAdded", locale)); } result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentUpdated",UtilMisc.toMap("productionRunId", productionRunId), locale)); return result; } public static Map addProductionRunRoutingTask(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Timestamp now = UtilDateTime.nowTimestamp(); List msgResult = new LinkedList(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); // Mandatory input fields String productionRunId = (String)context.get("productionRunId"); String routingTaskId = (String)context.get("routingTaskId"); Long priority = (Long)context.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -