Search in sources :

Example 1 with OrderCreationRequest

use of com.qcadoo.mes.orders.controllers.requests.OrderCreationRequest in project mes by qcadoo.

the class OrderCreationService method createOrder.

public OrderCreationResponse createOrder(OrderCreationRequest orderCreationRequest) {
    Entity parameter = parameterService.getParameter();
    boolean createOperationalTasks = !orderCreationRequest.getTechnologyOperations().isEmpty();
    if (Objects.isNull(orderCreationRequest.getTechnologyId())) {
        if (!isParameterSet(parameter, createOperationalTasks)) {
            return new OrderCreationResponse(translationService.translate("basic.dashboard.orderDefinitionWizard.createOrder.parameterNotSet", LocaleContextHolder.getLocale()));
        }
    }
    Entity product = getProduct(orderCreationRequest.getProductId());
    Either<String, Entity> isTechnology = getOrCreateTechnology(orderCreationRequest);
    if (isTechnology.isLeft()) {
        return new OrderCreationResponse(isTechnology.getLeft());
    }
    Entity technology = isTechnology.getRight();
    Entity productionLine = getProductionLine(orderCreationRequest.getProductionLineId(), technology);
    OrderCreationResponse response = new OrderCreationResponse(OrderCreationResponse.StatusCode.OK);
    Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).create();
    order.setField(OrderFields.NUMBER, numberGeneratorService.generateNumber(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, 6));
    order.setField(OrderFields.NAME, orderService.makeDefaultName(product, technology, LocaleContextHolder.getLocale()));
    order.setField(OrderFields.PRODUCT, product);
    order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, technology);
    order.setField(OrderFields.PRODUCTION_LINE, productionLine);
    order.setField(OrderFields.DIVISION, orderService.getDivision(technology));
    order.setField(OrderFields.DATE_FROM, orderCreationRequest.getStartDate());
    order.setField(OrderFields.DATE_TO, orderCreationRequest.getFinishDate());
    order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true);
    order.setField(IS_SUBCONTRACTED, false);
    order.setField(OrderFields.STATE, OrderStateStringValues.PENDING);
    order.setField(OrderFields.PLANNED_QUANTITY, orderCreationRequest.getQuantity());
    order.setField(OrderFields.DESCRIPTION, buildDescription(parameter, orderCreationRequest.getDescription(), technology, product));
    order.setField(IGNORE_MISSING_COMPONENTS, parameter.getBooleanField(IGNORE_MISSING_COMPONENTS));
    order.setField("typeOfProductionRecording", orderCreationRequest.getTypeOfProductionRecording());
    order = order.getDataDefinition().save(order);
    if (order.isValid()) {
        if (!order.getGlobalMessages().isEmpty()) {
            Optional<GlobalMessage> message = order.getGlobalMessages().stream().filter(gm -> gm.getMessage().equals("orders.order.message.plannedQuantityChanged")).findFirst();
            message.ifPresent(m -> {
                response.setAdditionalInformation(translationService.translate(m.getMessage(), LocaleContextHolder.getLocale(), m.getVars()[0], m.getVars()[1]));
            });
        }
        final StateChangeContext orderStateChangeContext = stateChangeContextBuilder.build(orderStateChangeAspect.getChangeEntityDescriber(), order, OrderState.ACCEPTED.getStringValue());
        orderStateChangeAspect.changeState(orderStateChangeContext);
        order = order.getDataDefinition().get(order.getId());
        if (!order.getStringField(OrderFields.STATE).equals(OrderStateStringValues.ACCEPTED)) {
            return new OrderCreationResponse(translationService.translate("basic.dashboard.orderDefinitionWizard.createOrder.acceptError", LocaleContextHolder.getLocale(), order.getStringField(OrderFields.NUMBER)));
        }
    } else {
        return new OrderCreationResponse(translationService.translate("basic.dashboard.orderDefinitionWizard.createOrder.validationError", LocaleContextHolder.getLocale()));
    }
    if (createOperationalTasks) {
        createOperationalTasks(order, orderCreationRequest);
        modifyProductionCountingQuantityForEach(order, orderCreationRequest.getTechnologyOperations());
    } else {
        modifyProductionCountingQuantity(order, orderCreationRequest.getMaterials());
    }
    response.setMessage(translationService.translate("orders.orderCreationService.created", LocaleContextHolder.getLocale(), order.getStringField(OrderFields.NUMBER)));
    if (createOperationalTasks) {
        response.setOperationalTasks(dashboardKanbanDataProvider.getOperationalTasksPendingForOrder(order.getId()));
    } else {
        response.setOrder(dashboardKanbanDataProvider.getOrder(order.getId()));
    }
    return response;
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) OrderDetailsListeners(com.qcadoo.mes.orders.listeners.OrderDetailsListeners) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductionLinesConstants(com.qcadoo.mes.productionLines.constants.ProductionLinesConstants) StringUtils(org.apache.commons.lang3.StringUtils) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) ParameterFields(com.qcadoo.mes.basic.constants.ParameterFields) TechnologyStateChangeAspect(com.qcadoo.mes.technologies.states.aop.TechnologyStateChangeAspect) BigDecimal(java.math.BigDecimal) TechnologyNameAndNumberGenerator(com.qcadoo.mes.technologies.TechnologyNameAndNumberGenerator) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Map(java.util.Map) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) OperationProductInComponentFields(com.qcadoo.mes.technologies.constants.OperationProductInComponentFields) TechnologyState(com.qcadoo.mes.technologies.states.constants.TechnologyState) Set(java.util.Set) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) TechnologyOperationComponentFieldsTNFO(com.qcadoo.mes.timeNormsForOperations.constants.TechnologyOperationComponentFieldsTNFO) TechnologyOperationDto(com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto) Collectors(java.util.stream.Collectors) OrderCreationResponse(com.qcadoo.mes.orders.controllers.responses.OrderCreationResponse) Sets(com.google.common.collect.Sets) OperationFields(com.qcadoo.mes.technologies.constants.OperationFields) Objects(java.util.Objects) List(java.util.List) OrderStateChangeAspect(com.qcadoo.mes.orders.states.aop.OrderStateChangeAspect) Entity(com.qcadoo.model.api.Entity) ParameterService(com.qcadoo.mes.basic.ParameterService) ParameterFieldsO(com.qcadoo.mes.orders.constants.ParameterFieldsO) OrderStateStringValues(com.qcadoo.mes.orders.states.constants.OrderStateStringValues) OperationProductOutComponentFields(com.qcadoo.mes.technologies.constants.OperationProductOutComponentFields) Optional(java.util.Optional) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DashboardKanbanDataProvider(com.qcadoo.mes.orders.controllers.dataProvider.DashboardKanbanDataProvider) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) ParameterFieldsPL(com.qcadoo.mes.productionLines.constants.ParameterFieldsPL) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) OrderCreationRequest(com.qcadoo.mes.orders.controllers.requests.OrderCreationRequest) Lists(com.google.common.collect.Lists) GlobalTypeOfMaterial(com.qcadoo.mes.basic.constants.GlobalTypeOfMaterial) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) Service(org.springframework.stereotype.Service) MaterialDto(com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) TranslationService(com.qcadoo.localization.api.TranslationService) StateChangeContextBuilder(com.qcadoo.mes.states.service.StateChangeContextBuilder) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) TechnologyStateStringValues(com.qcadoo.mes.technologies.states.constants.TechnologyStateStringValues) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ParameterFieldsT(com.qcadoo.mes.technologies.constants.ParameterFieldsT) OrderService(com.qcadoo.mes.orders.OrderService) Comparator(java.util.Comparator) OperationalTaskFields(com.qcadoo.mes.orders.constants.OperationalTaskFields) Entity(com.qcadoo.model.api.Entity) OrderCreationResponse(com.qcadoo.mes.orders.controllers.responses.OrderCreationResponse) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 2 with OrderCreationRequest

use of com.qcadoo.mes.orders.controllers.requests.OrderCreationRequest in project mes by qcadoo.

the class OrderCreationService method createOperationalTasks.

private void createOperationalTasks(Entity order, OrderCreationRequest orderCreationRequest) {
    orderDetailsListeners.createOperationalTasksForOrder(order, false);
    Map<Long, TechnologyOperationDto> operationsById = orderCreationRequest.getTechnologyOperations().stream().collect(Collectors.toMap(TechnologyOperationDto::getId, x -> x));
    order = order.getDataDefinition().get(order.getId());
    List<Entity> operationalTasks = order.getHasManyField(OrderFields.OPERATIONAL_TASKS);
    for (Entity operationalTask : operationalTasks) {
        Entity technologyOperationComponent = operationalTask.getBelongsToField(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT);
        Long workstation = operationsById.get(technologyOperationComponent.getId()).getWorkstationId();
        if (Objects.nonNull(workstation)) {
            operationalTask.setField(OperationalTaskFields.WORKSTATION, workstation);
            Entity workstationEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(workstation);
            if (Objects.nonNull(workstationEntity.getBelongsToField(WorkstationFields.STAFF)) && technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.OPTIMAL_STAFF) == 1) {
                operationalTask.setField(OperationalTaskFields.STAFF, workstationEntity.getBelongsToField(WorkstationFields.STAFF));
            }
            operationalTask.getDataDefinition().save(operationalTask);
        }
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) OrderDetailsListeners(com.qcadoo.mes.orders.listeners.OrderDetailsListeners) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductionLinesConstants(com.qcadoo.mes.productionLines.constants.ProductionLinesConstants) StringUtils(org.apache.commons.lang3.StringUtils) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) ParameterFields(com.qcadoo.mes.basic.constants.ParameterFields) TechnologyStateChangeAspect(com.qcadoo.mes.technologies.states.aop.TechnologyStateChangeAspect) BigDecimal(java.math.BigDecimal) TechnologyNameAndNumberGenerator(com.qcadoo.mes.technologies.TechnologyNameAndNumberGenerator) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Map(java.util.Map) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) OperationProductInComponentFields(com.qcadoo.mes.technologies.constants.OperationProductInComponentFields) TechnologyState(com.qcadoo.mes.technologies.states.constants.TechnologyState) Set(java.util.Set) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) TechnologyOperationComponentFieldsTNFO(com.qcadoo.mes.timeNormsForOperations.constants.TechnologyOperationComponentFieldsTNFO) TechnologyOperationDto(com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto) Collectors(java.util.stream.Collectors) OrderCreationResponse(com.qcadoo.mes.orders.controllers.responses.OrderCreationResponse) Sets(com.google.common.collect.Sets) OperationFields(com.qcadoo.mes.technologies.constants.OperationFields) Objects(java.util.Objects) List(java.util.List) OrderStateChangeAspect(com.qcadoo.mes.orders.states.aop.OrderStateChangeAspect) Entity(com.qcadoo.model.api.Entity) ParameterService(com.qcadoo.mes.basic.ParameterService) ParameterFieldsO(com.qcadoo.mes.orders.constants.ParameterFieldsO) OrderStateStringValues(com.qcadoo.mes.orders.states.constants.OrderStateStringValues) OperationProductOutComponentFields(com.qcadoo.mes.technologies.constants.OperationProductOutComponentFields) Optional(java.util.Optional) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DashboardKanbanDataProvider(com.qcadoo.mes.orders.controllers.dataProvider.DashboardKanbanDataProvider) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) ParameterFieldsPL(com.qcadoo.mes.productionLines.constants.ParameterFieldsPL) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) OrderCreationRequest(com.qcadoo.mes.orders.controllers.requests.OrderCreationRequest) Lists(com.google.common.collect.Lists) GlobalTypeOfMaterial(com.qcadoo.mes.basic.constants.GlobalTypeOfMaterial) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) Service(org.springframework.stereotype.Service) MaterialDto(com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) TranslationService(com.qcadoo.localization.api.TranslationService) StateChangeContextBuilder(com.qcadoo.mes.states.service.StateChangeContextBuilder) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) TechnologyStateStringValues(com.qcadoo.mes.technologies.states.constants.TechnologyStateStringValues) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ParameterFieldsT(com.qcadoo.mes.technologies.constants.ParameterFieldsT) OrderService(com.qcadoo.mes.orders.OrderService) Comparator(java.util.Comparator) OperationalTaskFields(com.qcadoo.mes.orders.constants.OperationalTaskFields) Entity(com.qcadoo.model.api.Entity) TechnologyOperationDto(com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto)

Aggregations

Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 Either (com.qcadoo.commons.functional.Either)2 TranslationService (com.qcadoo.localization.api.TranslationService)2 ParameterService (com.qcadoo.mes.basic.ParameterService)2 BasicConstants (com.qcadoo.mes.basic.constants.BasicConstants)2 GlobalTypeOfMaterial (com.qcadoo.mes.basic.constants.GlobalTypeOfMaterial)2 ParameterFields (com.qcadoo.mes.basic.constants.ParameterFields)2 ProductFamilyElementType (com.qcadoo.mes.basic.constants.ProductFamilyElementType)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 WorkstationFields (com.qcadoo.mes.basic.constants.WorkstationFields)2 OrderService (com.qcadoo.mes.orders.OrderService)2 OperationalTaskFields (com.qcadoo.mes.orders.constants.OperationalTaskFields)2 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)2 OrdersConstants (com.qcadoo.mes.orders.constants.OrdersConstants)2 ParameterFieldsO (com.qcadoo.mes.orders.constants.ParameterFieldsO)2 DashboardKanbanDataProvider (com.qcadoo.mes.orders.controllers.dataProvider.DashboardKanbanDataProvider)2 TechnologyOperationDto (com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto)2 OrderCreationRequest (com.qcadoo.mes.orders.controllers.requests.OrderCreationRequest)2 OrderCreationResponse (com.qcadoo.mes.orders.controllers.responses.OrderCreationResponse)2