Search in sources :

Example 1 with TechnologyOperationDto

use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto in project mes by qcadoo.

the class OrderCreationService method createTechnologyForEachOperation.

private Either<String, Entity> createTechnologyForEachOperation(OrderCreationRequest orderCreationRequest) {
    Entity product = getProduct(orderCreationRequest.getProductId());
    Entity parameter = parameterService.getParameter();
    Entity dashboardComponentsLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_COMPONENTS_LOCATION);
    Entity dashboardProductsInputLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_PRODUCTS_INPUT_LOCATION);
    orderCreationRequest.getTechnologyOperations().sort(Comparator.comparing(TechnologyOperationDto::getNode));
    String range = parameter.getStringField(L_RANGE);
    Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).create();
    technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
    technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
    technology.setField(TechnologyFields.PRODUCT, product);
    technology.setField(TechnologyFields.EXTERNAL_SYNCHRONIZED, true);
    technology.setField(L_RANGE, range);
    technology.setField("componentsLocation", dashboardComponentsLocation);
    technology.setField("productsInputLocation", dashboardProductsInputLocation);
    technology.setField("typeOfProductionRecording", orderCreationRequest.getTypeOfProductionRecording());
    technology = technology.getDataDefinition().save(technology);
    if (!technology.isValid()) {
        return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
    }
    Entity parent = null;
    for (TechnologyOperationDto technologyOperation : orderCreationRequest.getTechnologyOperations()) {
        Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get(technologyOperation.getOperationId());
        Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).create();
        toc.setField(TechnologyOperationComponentFields.OPERATION, operation);
        toc.setField(TechnologyOperationComponentFields.ENTITY_TYPE, L_OPERATION);
        for (String fieldName : FIELDS_OPERATION) {
            toc.setField(fieldName, operation.getField(fieldName));
        }
        if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_TYPE) == null) {
            toc.setField(NEXT_OPERATION_AFTER_PRODUCED_TYPE, L_ALL);
        }
        if (operation.getField(PRODUCTION_IN_ONE_CYCLE) == null) {
            toc.setField(PRODUCTION_IN_ONE_CYCLE, "1");
        }
        if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY) == null) {
            toc.setField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY, "0");
        }
        if (Objects.isNull(parent)) {
            Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
            topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
            topoc.setField(OperationProductOutComponentFields.PRODUCT, product);
            toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Lists.newArrayList(topoc));
        }
        List<Entity> topics = Lists.newArrayList();
        for (MaterialDto material : technologyOperation.getMaterials()) {
            Entity inProduct = getProduct(material.getProductId());
            Entity topic = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).create();
            topic.setField(OperationProductInComponentFields.PRODUCT, inProduct);
            topic.setField(OperationProductInComponentFields.QUANTITY, material.getQuantityPerUnit());
            topics.add(topic);
        }
        toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS, topics);
        if (Objects.nonNull(parent)) {
            toc.setField(TechnologyOperationComponentFields.PARENT, parent.getId());
        }
        toc.setField(TechnologyOperationComponentFields.TECHNOLOGY, technology.getId());
        toc = toc.getDataDefinition().save(toc);
        if (Objects.nonNull(technologyOperation.getWorkstationId())) {
            List<Entity> workstations = Lists.newArrayList(toc.getHasManyField(TechnologyOperationComponentFields.WORKSTATIONS));
            Entity workstation = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(technologyOperation.getWorkstationId());
            workstations.add(workstation);
            toc.setField(TechnologyOperationComponentFields.WORKSTATIONS, workstations);
        }
        toc = toc.getDataDefinition().save(toc);
        technologyOperation.setId(toc.getId());
        if (toc.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).isEmpty()) {
            Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
            topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
            topoc.setField(OperationProductOutComponentFields.PRODUCT, getOrCreateProduct(operation));
            topoc.setField(OperationProductOutComponentFields.OPERATION_COMPONENT, toc);
            topoc.getDataDefinition().save(topoc);
        }
        parent = toc;
    }
    if (technology.isValid()) {
        final StateChangeContext technologyStateChangeContext = stateChangeContextBuilder.build(technologyStateChangeAspect.getChangeEntityDescriber(), technology, TechnologyState.ACCEPTED.getStringValue());
        technologyStateChangeAspect.changeState(technologyStateChangeContext);
        technology = technology.getDataDefinition().get(technology.getId());
        if (!technology.getStringField(TechnologyFields.STATE).equals(TechnologyStateStringValues.ACCEPTED)) {
            return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.acceptError", LocaleContextHolder.getLocale()));
        }
        technology.setField(TechnologyFields.MASTER, Boolean.TRUE);
        technology.getDataDefinition().save(technology);
    } else {
        return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
    }
    return Either.right(technology);
}
Also used : Entity(com.qcadoo.model.api.Entity) MaterialDto(com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) TechnologyOperationDto(com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto)

Example 2 with TechnologyOperationDto

use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto 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)

Example 3 with TechnologyOperationDto

use of com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto in project mes by qcadoo.

the class OrderCreationService method modifyProductionCountingQuantityForEach.

private void modifyProductionCountingQuantityForEach(Entity order, List<TechnologyOperationDto> technologyOperations) {
    for (TechnologyOperationDto technologyOperation : technologyOperations) {
        Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).get(technologyOperation.getId());
        List<Entity> materialsFromOrderPCQ = getMaterialsFromOrder(order, toc);
        List<MaterialDto> materials = technologyOperation.getMaterials();
        List<MaterialDto> addedMaterials = materials.stream().filter(m -> Objects.isNull(m.getProductInId())).collect(Collectors.toList());
        List<Long> technologyMaterials = materials.stream().filter(m -> Objects.nonNull(m.getProductInId())).map(MaterialDto::getProductId).collect(Collectors.toList());
        Map<Long, Entity> pacqByProductId = materialsFromOrderPCQ.stream().collect(Collectors.toMap(pcq -> pcq.getBelongsToField(L_PRODUCT).getId(), pcq -> pcq));
        for (Map.Entry<Long, Entity> entry : pacqByProductId.entrySet()) {
            if (!technologyMaterials.contains(entry.getKey())) {
                Entity pcq = entry.getValue();
                pcq.getDataDefinition().delete(pcq.getId());
            }
        }
        List<Entity> pcqs = Lists.newArrayList();
        for (MaterialDto material : addedMaterials) {
            Entity pcq = createProductionCoutingQuantity(order, material, toc);
            pcqs.add(pcq);
        }
        fillFlow(pcqs, order);
        pcqs.forEach(p -> p.getDataDefinition().save(p));
    }
}
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) MaterialDto(com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto) TechnologyOperationDto(com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto) Map(java.util.Map)

Aggregations

TechnologyOperationDto (com.qcadoo.mes.orders.controllers.dto.TechnologyOperationDto)3 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)3 MaterialDto (com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto)3 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