📄 productionrunservices.java
字号:
/* * $Id: ProductionRunServices.java 7324 2006-04-18 06:28:52Z jacopo $ * * Copyright (c) 2001-2004, 2003 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.manufacturing.jobshopmgt;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.math.BigDecimal;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilNumber;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.manufacturing.bom.BOMTree;import org.ofbiz.manufacturing.techdata.TechDataServices;import org.ofbiz.product.config.ProductConfigWrapper;import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption;import org.ofbiz.security.Security;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;/** * Services for Production Run maintenance * * @author <a href="mailto:olivier.heintz@nereide.biz">Olivier Heintz</a> */public class ProductionRunServices { public static final String module = ProductionRunServices.class.getName(); public static final String resource = "ManufacturingUiLabels"; private static BigDecimal ZERO = new BigDecimal("0"); private static BigDecimal ONE = new BigDecimal("1"); private static int decimals = -1; private static int rounding = -1; static { decimals = UtilNumber.getBigDecimalScale("order.decimals"); rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding"); // set zero to the proper scale ZERO.setScale(decimals); ONE.setScale(decimals); } /** * Cancels a ProductionRun. * @param ctx The DispatchContext that this service is operating in. * @param context Map containing the input parameters. * @return Map with the result of the service, the output parameters. */ public static Map cancelProductionRun(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"); String productionRunId = (String) context.get("productionRunId"); ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher); if (!productionRun.exist()){ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotExists", locale)); } String currentStatusId = productionRun.getGenericValue().getString("currentStatusId"); // PRUN_CREATED, PRUN_DOC_PRINTED --> PRUN_CANCELLED if (currentStatusId.equals("PRUN_CREATED") || currentStatusId.equals("PRUN_DOC_PRINTED")) { try { // First of all, make sure that there aren't production runs that depend on this one. List mandatoryWorkEfforts = new ArrayList(); ProductionRunHelper.getLinkedProductionRuns(delegator, dispatcher, productionRunId, mandatoryWorkEfforts); for (int i = 1; i < mandatoryWorkEfforts.size(); i++) { GenericValue mandatoryWorkEffort = ((ProductionRun)mandatoryWorkEfforts.get(i)).getGenericValue(); if (!(mandatoryWorkEffort.getString("currentStatusId").equals("PRUN_CANCELLED"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChangedMandatoryProductionRunFound", locale)); } } Map serviceContext = new HashMap(); // change the production run (header) status to PRUN_CANCELLED serviceContext.put("workEffortId", productionRunId); serviceContext.put("currentStatusId", "PRUN_CANCELLED"); serviceContext.put("userLogin", userLogin); Map resultService = null; resultService = dispatcher.runSync("updateWorkEffort", serviceContext); // change the tasks status to PRUN_CANCELLED List tasks = productionRun.getProductionRunRoutingTasks(); GenericValue oneTask = null; String taskId = null; for (int i = 0; i < tasks.size(); i++) { oneTask = (GenericValue)tasks.get(i); taskId = oneTask.getString("workEffortId"); serviceContext.clear(); serviceContext.put("workEffortId", taskId); serviceContext.put("currentStatusId", "PRUN_CANCELLED"); serviceContext.put("userLogin", userLogin); resultService = dispatcher.runSync("updateWorkEffort", serviceContext); } } catch (Exception e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); } result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusChanged",UtilMisc.toMap("newStatusId", "PRUN_DOC_PRINTED"), locale)); return result; } return ServiceUtil.returnError("Cannot cancel productionRun, not in a valid status"); } /** * Creates a Production Run. * <li> check if routing - product link exist * <li> check if product have a Bill Of Material * <li> check if routing have routingTask * <li> create the workEffort for ProductionRun * <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, pRQuantity, startDate, workEffortName, description * @return Map with the result of the service, the output parameters. */ public static Map createProductionRun(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); Security security = ctx.getSecurity(); Timestamp now = UtilDateTime.nowTimestamp(); List msgResult = new LinkedList(); 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; } */ // Mandatory input fields String productId = (String) context.get("productId"); Timestamp startDate = (Timestamp) context.get("startDate"); Double pRQuantity = (Double) context.get("pRQuantity"); String facilityId = (String) context.get("facilityId"); // Optional input fields String workEffortId = (String) context.get("routingId"); String workEffortName = (String) context.get("workEffortName"); String description = (String) context.get("description"); GenericValue routing = null; GenericValue product = null; List workEffortProducts = null; List productBoms = null; List routingTaskAssocs = null; try { // Find the product 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()); } // ------------------- // Components // ------------------- // The components are retrieved using the getManufacturingComponents service // (that performs a bom breakdown and if needed runs the configurator). List components = null; Map serviceContext = new HashMap(); serviceContext.put("productId", productId); // the product that we want to manufacture serviceContext.put("quantity", pRQuantity); // the quantity that we want to manufacture serviceContext.put("userLogin", userLogin); Map resultService = null; try { resultService = dispatcher.runSync("getManufacturingComponents", serviceContext); components = (List)resultService.get("components"); // a list of objects representing the product's components if (workEffortId == null) { workEffortId = (String)resultService.get("workEffortId"); // the product routing id } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the getManufacturingComponents service", module);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -