📄 productionrunservices.java
字号:
} } if (theTask == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale)); } String currentStatusId = theTask.getString("currentStatusId"); if (statusId != null && currentStatusId.equals(statusId)) { result.put("newStatusId", currentStatusId); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskStatusChanged",UtilMisc.toMap("newStatusId", currentStatusId), locale)); return result; } // PRUN_CREATED --> PRUN_RUNNING // this should be called only when the first task is started if (currentStatusId.equals("PRUN_CREATED") && (statusId == null || statusId.equals("PRUN_RUNNING"))) { // change the production run task status to PRUN_RUNNING // if necessary change the production run (header) status to PRUN_RUNNING if (!allPrecTaskCompleted) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskCannotStartPrevTasksNotCompleted", locale)); } if (productionRun.getGenericValue().getString("currentStatusId").equals("PRUN_CREATED")) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskCannotStartDocsNotPrinted", locale)); } Map serviceContext = new HashMap(); serviceContext.clear(); serviceContext.put("workEffortId", taskId); serviceContext.put("currentStatusId", "PRUN_RUNNING"); serviceContext.put("actualStartDate", UtilDateTime.nowTimestamp()); serviceContext.put("userLogin", userLogin); Map resultService = null; try { resultService = dispatcher.runSync("updateWorkEffort", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } if (!productionRun.getGenericValue().getString("currentStatusId").equals("PRUN_RUNNING")) { serviceContext.clear(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", "PRUN_RUNNING"); serviceContext.put("userLogin", userLogin); resultService = null; try { resultService = dispatcher.runSync("changeProductionRunStatus", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunStatus service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } } result.put("newStatusId", "PRUN_RUNNING"); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusChanged",UtilMisc.toMap("newStatusId", "PRUN_DOC_PRINTED"), locale)); return result; } // PRUN_RUNNING --> PRUN_COMPLETED // this should be called only when the last task is completed if (currentStatusId.equals("PRUN_RUNNING") && (statusId == null || statusId.equals("PRUN_COMPLETED"))) { Map serviceContext = new HashMap(); Map resultService = null; if (issueAllComponents.booleanValue()) { // Issue all the components, if this task needs components and they still need to be issued try { List inventoryAssigned = delegator.findByAnd("WorkEffortInventoryAssign", UtilMisc.toMap("workEffortId", taskId)); if (UtilValidate.isEmpty(inventoryAssigned)) { serviceContext.clear(); serviceContext.put("workEffortId", taskId); serviceContext.put("userLogin", userLogin); resultService = dispatcher.runSync("issueProductionRunTask", serviceContext); } } catch (Exception e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } } // change only the production run (header) status to PRUN_COMPLETED serviceContext.clear(); serviceContext.put("workEffortId", taskId); serviceContext.put("currentStatusId", "PRUN_COMPLETED"); serviceContext.put("actualCompletionDate", UtilDateTime.nowTimestamp()); Double quantityToProduce = theTask.getDouble("quantityToProduce"); if (quantityToProduce == null) { quantityToProduce = new Double(0); } Double quantityProduced = theTask.getDouble("quantityProduced"); if (quantityProduced == null) { quantityProduced = new Double(0); } Double quantityRejected = theTask.getDouble("quantityRejected"); if (quantityRejected == null) { quantityRejected = new Double(0); } double totalQuantity = quantityProduced.doubleValue() + quantityRejected.doubleValue(); double diffQuantity = quantityToProduce.doubleValue() - totalQuantity; if (diffQuantity > 0) { quantityProduced = new Double(quantityProduced.doubleValue() + diffQuantity); } serviceContext.put("quantityProduced", quantityProduced); if (theTask.get("actualSetupMillis") == null) { serviceContext.put("actualSetupMillis", theTask.get("estimatedSetupMillis")); } if (theTask.get("actualMilliSeconds") == null) { Double autoMillis = null; if (theTask.get("estimatedMilliSeconds") != null) { autoMillis = new Double(quantityProduced.doubleValue() * theTask.getDouble("estimatedMilliSeconds").doubleValue()); } serviceContext.put("actualMilliSeconds", autoMillis); } serviceContext.put("userLogin", userLogin); try { resultService = dispatcher.runSync("updateWorkEffort", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } // If this is the last task, then the production run is marked as 'completed' if (allTaskCompleted) { serviceContext.clear(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", "PRUN_COMPLETED"); serviceContext.put("userLogin", userLogin); resultService = null; try { resultService = dispatcher.runSync("changeProductionRunStatus", serviceContext); } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } } result.put("newStatusId", "PRUN_COMPLETED"); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusChanged",UtilMisc.toMap("newStatusId", "PRUN_DOC_PRINTED"), locale)); return result; } result.put("newStatusId", currentStatusId); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskStatusChanged",UtilMisc.toMap("newStatusId", currentStatusId), locale)); return result; } public static Map getWorkEffortCosts(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); String workEffortId = (String)context.get("workEffortId"); try { GenericValue workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); if (workEffort == null) { return ServiceUtil.returnError("Cannot find work effort [" + workEffortId + "]"); } // Get all the valid CostComponents entries List costComponents = EntityUtil.filterByDate(delegator.findByAnd("CostComponent", UtilMisc.toMap("workEffortId", workEffortId))); result.put("costComponents", costComponents); Iterator costComponentsIt = costComponents.iterator(); // TODO: before doing these totals we should convert the cost components' costs to the // base currency uom of the owner of the facility in which the task is running BigDecimal totalCost = ZERO; BigDecimal totalCostNoMaterials = ZERO; while (costComponentsIt.hasNext()) { GenericValue costComponent = (GenericValue)costComponentsIt.next(); BigDecimal cost = costComponent.getBigDecimal("cost"); totalCost = totalCost.add(cost); if (!"ACTUAL_MAT_COST".equals(costComponent.getString("costComponentTypeId"))) { totalCostNoMaterials = totalCostNoMaterials.add(cost); } } result.put("totalCost", totalCost); result.put("totalCostNoMaterials", totalCostNoMaterials); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Cannot retrieve costs for work effort [" + workEffortId + "]: " + gee.getMessage()); } return result; } public static Map getProductionRunCost(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); String workEffortId = (String)context.get("workEffortId"); try { List tasks = delegator.findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", workEffortId), UtilMisc.toList("workEffortId")); Iterator tasksIt = tasks.iterator(); BigDecimal totalCost = ZERO; while (tasksIt.hasNext()) { GenericValue task = (GenericValue)tasksIt.next(); Map outputMap = dispatcher.runSync("getWorkEffortCosts", UtilMisc.toMap("userLogin", userLogin, "workEffortId", task.getString("workEffortId"))); BigDecimal taskCost = (BigDecimal)outputMap.get("totalCost"); totalCost = totalCost.add(taskCost); } result.put("totalCost", totalCost); } catch(Exception exc) { return ServiceUtil.returnError("Cannot retrieve costs for production run [" + workEffortId + "]: " + exc.getMessage()); } return result; } /** * check if field for routingTask update are correct and if need recalculated data in Production Run. * Check<ul> * <li> if estimatedStartDate is not before Production Run estimatedStartDate.</ul> * <li> if there is not a another routingTask with the same priority * If priority or estimatedStartDate has changed recalculated data for routingTask after that one. * <br/> update the productionRun * @param ctx The DispatchContext that this service is operating in. * @param context Map containing the input parameters, productId, routingId, priority, estimatedStartDate, estimatedSetupMillis, estimatedMilliSeconds * @return Map with the result of the service, the output parameters, estimatedCompletionDate. */ public static Map checkUpdatePrunRoutingTask(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)) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, "You do not have permission to perform this operation for this party"); return partyId; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -