Search in sources :

Example 31 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class ProductQuantitiesWithComponentsServiceImpl method getProductComponentWithQuantitiesForTechnology.

@Override
public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) {
    OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
    EntityTree operationComponents = productStructureTreeService.getOperationComponentsFromTechnology(technology);
    technology.setField(TechnologyFields.OPERATION_COMPONENTS, EntityTreeUtilsService.getDetachedEntityTree(operationComponents));
    Entity root = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot();
    Map<Long, Entity> entitiesById = new LinkedHashMap<>();
    for (Entity entity : operationComponents) {
        entitiesById.put(entity.getId(), entity);
    }
    if (root != null) {
        productQuantitiesService.preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns);
        productQuantitiesService.traverseProductQuantitiesAndOperationRuns(technology, entitiesById, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
    }
    return operationProductComponentWithQuantityContainer;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityTree(com.qcadoo.model.api.EntityTree) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class OperationsCostCalculationServiceImpl method calculateOperationsCost.

@Override
public BigDecimal calculateOperationsCost(final Entity costCalculation, final Entity technology) {
    DataDefinition costCalculationDataDefinition = costCalculation.getDataDefinition();
    BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
    ProductQuantitiesHolder productQuantitiesAndOperationRuns = getProductQuantitiesAndOperationRuns(technology, quantity, costCalculation);
    Entity copyCostCalculation = operationCostCalculationTreeBuilder.copyTechnologyTree(costCalculation, technology);
    Entity yetAnotherCostCalculation = costCalculationDataDefinition.save(copyCostCalculation);
    Entity newCostCalculation = costCalculationDataDefinition.get(yetAnotherCostCalculation.getId());
    EntityTree calculationOperationComponents = newCostCalculation.getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);
    checkArgument(calculationOperationComponents != null, "given operation components is null");
    List<Entity> tocs = calculationOperationComponents.stream().map(e -> e.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT)).collect(Collectors.toList());
    OperationTimesContainer operationTimes = operationWorkTimeService.estimateOperationsWorkTimes(tocs, productQuantitiesAndOperationRuns.getOperationRuns(), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_TPZ), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME), true);
    boolean hourlyCostFromOperation = !SourceOfOperationCosts.PARAMETERS.getStringValue().equals(costCalculation.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS));
    Map<String, BigDecimal> resultsMap = estimateCostCalculationForHourly(calculationOperationComponents.getRoot(), operationTimes, hourlyCostFromOperation, costCalculation);
    costCalculation.setField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS, calculationOperationComponents);
    return BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.MACHINE_HOURLY_COST))).add(BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.LABOR_HOURLY_COST))), numberService.getMathContext());
}
Also used : OperationTimesContainer(com.qcadoo.mes.operationTimeCalculations.dto.OperationTimesContainer) TechnologyOperationComponentFieldsCNFO(com.qcadoo.mes.costNormsForOperation.constants.TechnologyOperationComponentFieldsCNFO) ProductQuantitiesHolder(com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) ProductQuantitiesWithComponentsService(com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService) BigDecimal(java.math.BigDecimal) CostCalculationFields(com.qcadoo.mes.costCalculation.constants.CostCalculationFields) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PluginManager(com.qcadoo.plugin.api.PluginManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) MathContext(java.math.MathContext) Set(java.util.Set) CalculationOperationComponentFields(com.qcadoo.mes.costNormsForOperation.constants.CalculationOperationComponentFields) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) SourceOfOperationCosts(com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Sets(com.google.common.collect.Sets) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) List(java.util.List) Entity(com.qcadoo.model.api.Entity) OperationTimes(com.qcadoo.mes.operationTimeCalculations.dto.OperationTimes) NumberService(com.qcadoo.model.api.NumberService) OperationWorkTimeService(com.qcadoo.mes.operationTimeCalculations.OperationWorkTimeService) OperationCostCalculationTreeBuilder(com.qcadoo.mes.operationCostCalculations.OperationCostCalculationTreeBuilder) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Entity(com.qcadoo.model.api.Entity) ProductQuantitiesHolder(com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder) OperationTimesContainer(com.qcadoo.mes.operationTimeCalculations.dto.OperationTimesContainer) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) BigDecimal(java.math.BigDecimal)

Example 33 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class EventListeners method addEvent.

public void addEvent(final ViewDefinitionState viewDefinitionState, final ComponentState triggerState, final String[] args) {
    String eventType = args[0];
    factoryStructureId = Long.parseLong(args[1]);
    EntityTree tree = factoryStructureForEventHooks.getGeneratedTree();
    Optional<Entity> maybeElement = tree.stream().filter(element -> element.getId() == factoryStructureId).findFirst();
    if (!maybeElement.isPresent()) {
        viewDefinitionState.addMessage("cmmsMachineParts.error.elementNotSelected", ComponentState.MessageType.FAILURE);
        return;
    }
    Entity selectedElement = maybeElement.get();
    FactoryStructureElementType elementType = FactoryStructureElementType.of(selectedElement);
    if (elementType.compareTo(FactoryStructureElementType.COMPANY) == 0) {
        viewDefinitionState.addMessage("cmmsMachineParts.error.companySelected", ComponentState.MessageType.INFO);
        return;
    }
    if (elementType.compareTo(FactoryStructureElementType.FACTORY) == 0) {
        viewDefinitionState.addMessage("cmmsMachineParts.error.factorySelected", ComponentState.MessageType.INFO);
        return;
    }
    DataDefinition dataDefinition = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT);
    Entity maintenanceEvent = dataDefinition.create();
    if (elementType.compareTo(FactoryStructureElementType.DIVISION) == 0 || elementType.compareTo(FactoryStructureElementType.PRODUCTION_LINE) == 0 || MaintenanceEventType.parseString(eventType).compareTo(MaintenanceEventType.PROPOSAL) == 0) {
        maintenanceEvent.setField(MaintenanceEventFields.FAULT_TYPE, faultTypesService.getDefaultFaultType());
    }
    fillEventFieldsFromSelectedElement(maintenanceEvent, selectedElement);
    maintenanceEvent.setField(MaintenanceEventFields.TYPE, eventType);
    maintenanceEvent = dataDefinition.save(maintenanceEvent);
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put("form.id", maintenanceEvent.getId());
    viewDefinitionState.redirectTo("../page/" + CmmsMachinePartsConstants.PLUGIN_IDENTIFIER + "/maintenanceEventDetails.html", false, true, parameters);
}
Also used : FaultTypesService(com.qcadoo.mes.basic.FaultTypesService) FactoryStructureElementsService(com.qcadoo.mes.productionLines.factoryStructure.FactoryStructureElementsService) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) EventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.EventHooks) MaintenanceEventFields(com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventFields) FactoryStructureElementType(com.qcadoo.mes.productionLines.constants.FactoryStructureElementType) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) MaintenanceEventType(com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventType) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) MaintenanceEventState(com.qcadoo.mes.cmmsMachineParts.states.constants.MaintenanceEventState) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) MaintenanceEventService(com.qcadoo.mes.cmmsMachineParts.MaintenanceEventService) CmmsMachinePartsConstants(com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Collectors(java.util.stream.Collectors) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) List(java.util.List) FieldComponent(com.qcadoo.view.api.components.FieldComponent) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FactoryStructureForEventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.FactoryStructureForEventHooks) Optional(java.util.Optional) FactoryStructureElementFields(com.qcadoo.mes.productionLines.constants.FactoryStructureElementFields) Entity(com.qcadoo.model.api.Entity) FactoryStructureElementType(com.qcadoo.mes.productionLines.constants.FactoryStructureElementType) EntityTree(com.qcadoo.model.api.EntityTree) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 34 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class ProductionLineDetailsListeners method generateFactoryStructure.

public void generateFactoryStructure(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity productionLine = form.getEntity();
    EntityTree structure = factoryStructureGenerationService.generateFactoryStructureForProductionLine(productionLine);
    productionLine.setField(WorkstationFieldsPL.FACTORY_STRUCTURE, structure);
    form.setEntity(productionLine);
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    window.setActiveTab("factoryStructureTab");
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) WindowComponent(com.qcadoo.view.api.components.WindowComponent) EntityTree(com.qcadoo.model.api.EntityTree)

Example 35 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class TechnologyStateChangeListenerServiceTNFO method checkIfAllOperationComponenthHaveTJSet.

public boolean checkIfAllOperationComponenthHaveTJSet(final StateChangeContext stateChangeContext) {
    Entity technology = stateChangeContext.getOwner();
    DataDefinition dataDefinition = technology.getDataDefinition();
    StringBuilder errors = new StringBuilder();
    Entity savedTechnology = dataDefinition.get(technology.getId());
    EntityTree operationComponents = savedTechnology.getTreeField("operationComponents");
    boolean isValid = true;
    for (Entity operationComponent : operationComponents) {
        if (!checkIfTJSet(operationComponent)) {
            isValid = false;
            errors.append(" ");
            StringBuilder fieldName = new StringBuilder();
            fieldName.append(operationComponent.getStringField("nodeNumber")).append(" ");
            fieldName.append(operationComponent.getBelongsToField("operation").getStringField("number")).append(" ");
            fieldName.append(operationComponent.getBelongsToField("operation").getStringField("name"));
            errors.append(fieldName);
            errors.append(", ");
        }
    }
    if (!isValid) {
        stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid");
        stateChangeContext.addMessage("technologies.technology.validate.global.error.noTJSpecified", StateMessageType.FAILURE, false, errors.toString());
    }
    return isValid;
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2