Search in sources :

Example 31 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ImportStorageLocationService method importPositionsFromFile.

@Transactional
public ImportStorageLocationsResult importPositionsFromFile(final Entity entity, final ViewDefinitionState view) {
    ImportStorageLocationsResult result = new ImportStorageLocationsResult();
    ImportedStorageLocationsPositionsContainer positionsContainer = importPositionsToContainer(entity, view);
    if (!positionsContainer.isImportedPositions()) {
        result.setImported(false);
        return result;
    }
    Entity warehouse = entity.getBelongsToField(LOCATION);
    warehouse.isValid();
    List<StorageLocationDto> storageLocations = findStorageLocationsForWarehouse(warehouse.getId());
    Map<String, StorageLocationDto> storageLocationsByNumber = storageLocations.stream().collect(Collectors.toMap(StorageLocationDto::getStorageLocationNumber, item -> item));
    List<ImportedStorageLocationPosition> storageLocationsToUpdate = Lists.newArrayList();
    String userLogin = securityService.getCurrentUserName();
    for (ImportedStorageLocationPosition position : positionsContainer.getPositions()) {
        if (storageLocationsByNumber.containsKey(position.getStorageLocation())) {
            storageLocationsToUpdate.add(position);
        } else {
            createStorageLocation(result, warehouse.getId(), position, userLogin);
        }
    }
    Iterable<List<ImportedStorageLocationPosition>> subSets = Iterables.partition(storageLocationsToUpdate, 100);
    subSets.forEach(list -> {
        List<String> productsNumber = storageLocationsToUpdate.stream().map(s -> s.getProduct()).collect(Collectors.toList());
        List<ProductDto> prods = findProductsByList(productsNumber);
        fillResultWithNotExistingProducts(result, productsNumber, prods);
        Map<String, Long> productsIdByNumber = prods.stream().collect(Collectors.toMap(ProductDto::getProductNumber, ProductDto::getProductId));
        for (ImportedStorageLocationPosition position : list) {
            updateStorageLocation(storageLocationsByNumber.get(position.getStorageLocation()), productsIdByNumber.get(position.getProduct()), userLogin);
        }
    });
    Set<String> storageLocationsToClearProduct = findStorageLocationsToClearProduct(storageLocationsByNumber.keySet(), positionsContainer.getPositions());
    storageLocationsToClearProduct.forEach(sl -> {
        updateStorageLocation(storageLocationsByNumber.get(sl), null, userLogin);
    });
    updateStorageLocationInResource(warehouse.getId());
    return result;
}
Also used : Iterables(com.google.common.collect.Iterables) Date(java.util.Date) ComponentState(com.qcadoo.view.api.ComponentState) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) FileService(com.qcadoo.model.api.file.FileService) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) SecurityService(com.qcadoo.security.api.SecurityService) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Iterator(java.util.Iterator) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class DivisionDetailsListenersPL method onRemoveSelectedProductionLines.

public void onRemoveSelectedProductionLines(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent productionLinesGrid = (GridComponent) view.getComponentByReference("productionLines");
    List<Entity> productionLinesToDelete = productionLinesGrid.getSelectedEntities();
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long divisionId = form.getEntityId();
    for (Entity productionLine : productionLinesToDelete) {
        List<Entity> workstations = productionLine.getHasManyField(ProductionLineFields.WORKSTATIONS);
        workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFields.DIVISION).getId().equals(divisionId)).forEach(workstation -> {
            workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
            workstation.setField(WorkstationFields.DIVISION, null);
            workstation.getDataDefinition().save(workstation);
        });
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) ProductionLineFields(com.qcadoo.mes.productionLines.constants.ProductionLineFields) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) LookupUtils(com.qcadoo.mes.basic.LookupUtils) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 33 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ProductionLineDetailsListeners method onRemoveSelectedDivisions.

public void onRemoveSelectedDivisions(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent divisionsGrid = (GridComponent) view.getComponentByReference("divisions");
    List<Entity> divisionsToDelete = divisionsGrid.getSelectedEntities();
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long productionLineId = form.getEntityId();
    for (Entity division : divisionsToDelete) {
        List<Entity> workstations = division.getHasManyField(DivisionFields.WORKSTATIONS);
        workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFieldsPL.PRODUCTION_LINE).getId().equals(productionLineId)).forEach(workstation -> {
            workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
            workstation.setField(WorkstationFields.DIVISION, null);
            workstation.getDataDefinition().save(workstation);
        });
    }
}
Also used : WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) FactoryStructureGenerationService(com.qcadoo.mes.productionLines.factoryStructure.FactoryStructureGenerationService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) DivisionFields(com.qcadoo.mes.basic.constants.DivisionFields) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) EntityTree(com.qcadoo.model.api.EntityTree) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) LookupUtils(com.qcadoo.mes.basic.LookupUtils) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 34 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ScheduleDetailsListenersPS method assignOperationsToWorkstations.

@Transactional
public void assignOperationsToWorkstations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    Entity schedule = ((FormComponent) state).getEntity();
    Map<Long, Date> workstationsFinishDates = Maps.newHashMap();
    Set<Long> ordersToAvoid = Sets.newHashSet();
    List<Long> positionsIds = sortPositionsForWorkstations(schedule.getId());
    Date scheduleStartTime = schedule.getDateField(ScheduleFields.START_TIME);
    for (Long positionId : positionsIds) {
        Entity position = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE_POSITION).get(positionId);
        if (ordersToAvoid.contains(position.getBelongsToField(SchedulePositionFields.ORDER).getId())) {
            continue;
        }
        List<Entity> workstations = getWorkstationsFromTOC(position);
        if (workstations.isEmpty()) {
            ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
            continue;
        }
        Map<Long, PositionNewData> operationWorkstationsPositionNewData = Maps.newHashMap();
        boolean allMachineWorkTimesEqualsZero = getWorkstationsNewFinishDate(workstationsFinishDates, scheduleStartTime, position, workstations, operationWorkstationsPositionNewData);
        if (allMachineWorkTimesEqualsZero) {
            ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
            continue;
        }
        if (ScheduleWorkstationAssignCriterion.SHORTEST_TIME.getStringValue().equals(schedule.getStringField(ScheduleFields.WORKSTATION_ASSIGN_CRITERION))) {
            operationWorkstationsPositionNewData.entrySet().stream().min(Comparator.comparing(e -> e.getValue().getFinishDate())).ifPresent(entry -> updatePositionWorkstationAndDates(entry, workstationsFinishDates, position));
        } else {
            Map.Entry<Long, PositionNewData> firstEntry;
            if (workstationsFinishDates.isEmpty()) {
                firstEntry = operationWorkstationsPositionNewData.entrySet().iterator().next();
            } else {
                firstEntry = operationWorkstationsPositionNewData.entrySet().stream().filter(entry -> workstationsFinishDates.containsKey(entry.getKey())).findFirst().orElse(operationWorkstationsPositionNewData.entrySet().iterator().next());
            }
            updatePositionWorkstationAndDates(firstEntry, workstationsFinishDates, position);
        }
    }
}
Also used : WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) Date(java.util.Date) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) BigDecimal(java.math.BigDecimal) PluginManager(com.qcadoo.plugin.api.PluginManager) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) REJECTED(com.qcadoo.mes.orders.states.constants.OperationalTaskStateStringValues.REJECTED) ScheduleDetailsListeners(com.qcadoo.mes.orders.listeners.ScheduleDetailsListeners) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Set(java.util.Set) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) TechnologyOperationComponentFieldsTNFO(com.qcadoo.mes.timeNormsForOperations.constants.TechnologyOperationComponentFieldsTNFO) SchedulePositionFields(com.qcadoo.mes.orders.constants.SchedulePositionFields) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Sets(com.google.common.collect.Sets) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) OperationProductOutComponentFields(com.qcadoo.mes.technologies.constants.OperationProductOutComponentFields) ScheduleSortOrder(com.qcadoo.mes.orders.constants.ScheduleSortOrder) OperationWorkTimeService(com.qcadoo.mes.operationTimeCalculations.OperationWorkTimeService) Optional(java.util.Optional) ScheduleWorkstationAssignCriterion(com.qcadoo.mes.orders.constants.ScheduleWorkstationAssignCriterion) TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ShiftsService(com.qcadoo.mes.basic.ShiftsService) WorkstationTypeFields(com.qcadoo.mes.basic.constants.WorkstationTypeFields) ComponentState(com.qcadoo.view.api.ComponentState) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) SearchProjections(com.qcadoo.model.api.search.SearchProjections) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) TechOperCompWorkstationTimeFields(com.qcadoo.mes.timeNormsForOperations.constants.TechOperCompWorkstationTimeFields) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) SearchOrders(com.qcadoo.model.api.search.SearchOrders) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) SearchProjections.list(com.qcadoo.model.api.search.SearchProjections.list) SchedulePositionValidators(com.qcadoo.mes.orders.validators.SchedulePositionValidators) AssignedToOperation(com.qcadoo.mes.technologies.constants.AssignedToOperation) DateTime(org.joda.time.DateTime) Maps(com.google.common.collect.Maps) GridComponent(com.qcadoo.view.api.components.GridComponent) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) ScheduleFields(com.qcadoo.mes.orders.constants.ScheduleFields) NumberService(com.qcadoo.model.api.NumberService) SearchProjections.rowCount(com.qcadoo.model.api.search.SearchProjections.rowCount) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) Comparator(java.util.Comparator) OperationalTaskFields(com.qcadoo.mes.orders.constants.OperationalTaskFields) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) Date(java.util.Date) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class StaffsListListeners method printStaffLabels.

public void printStaffLabels(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent staffsGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Set<Long> staffIds = staffsGrid.getSelectedEntitiesIds();
    if (staffIds.isEmpty()) {
        view.addMessage("basic.staffsList.error.notSelected", ComponentState.MessageType.INFO);
    } else {
        String redirectUrl = new StringBuilder("/basic/staffLabelsReport.pdf?").append(staffIds.stream().map(staffId -> "ids=" + staffId.toString()).collect(Collectors.joining("&"))).toString();
        view.redirectTo(redirectUrl, true, false);
    }
}
Also used : ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Service(org.springframework.stereotype.Service) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Set(java.util.Set) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11