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;
}
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);
});
}
}
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);
});
}
}
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);
}
}
}
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);
}
}
Aggregations