Search in sources :

Example 1 with TimeUsageDTO

use of com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO in project mes by qcadoo.

the class TimeUsageRowMapper method mapRow.

@Override
public TimeUsageDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
    TimeUsageDTO timeUsage = new TimeUsageDTO();
    timeUsage.setWorker(rs.getString("worker"));
    timeUsage.setStartDate(rs.getDate("startDate"));
    timeUsage.setNumber(rs.getString("number"));
    timeUsage.setEventType(rs.getString("event_type"));
    timeUsage.setType(rs.getString("type"));
    timeUsage.setState(rs.getString("state"));
    timeUsage.setObject(rs.getString("object"));
    timeUsage.setParts(rs.getString("parts"));
    timeUsage.setDescription(rs.getString("description"));
    Seconds durationSeconds = Seconds.seconds(rs.getInt("duration")).plus(30);
    Period duration = new Period(durationSeconds);
    timeUsage.setDuration(duration.toStandardMinutes().getMinutes());
    DateTime startDateTime = new DateTime(rs.getTimestamp("registeredStart"));
    Date endDate = rs.getTimestamp("registeredEnd");
    if (endDate != null) {
        DateTime endDateTime = new DateTime(endDate);
        timeUsage.setRegisteredTime(Minutes.minutesBetween(startDateTime, endDateTime.plusSeconds(30)).getMinutes());
    } else {
        timeUsage.setRegisteredTime(0);
    }
    return timeUsage;
}
Also used : TimeUsageDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO) Period(org.joda.time.Period) Seconds(org.joda.time.Seconds) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 2 with TimeUsageDTO

use of com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO in project mes by qcadoo.

the class TimeUsageXlsService method group.

private List<TimeUsageGroupDTO> group(List<TimeUsageDTO> usages) {
    List<TimeUsageGroupDTO> groups = Lists.newLinkedList();
    Map<String, List<TimeUsageDTO>> workerMap = usages.stream().collect(Collectors.groupingBy(TimeUsageDTO::getWorker));
    for (Entry<String, List<TimeUsageDTO>> entry : workerMap.entrySet()) {
        Map<Date, List<TimeUsageDTO>> dateMap = entry.getValue().stream().collect(Collectors.groupingBy(TimeUsageDTO::getStartDate));
        for (Date date : dateMap.keySet()) {
            TimeUsageGroupDTO timeUsageGroup = new TimeUsageGroupDTO(date, entry.getKey(), dateMap.get(date));
            groups.add(timeUsageGroup);
        }
    }
    return groups.stream().sorted((g1, g2) -> {
        if (g1.getWorker().equals(g2.getWorker())) {
            return g1.getDate().compareTo(g2.getDate());
        } else {
            return g1.getWorker().compareTo(g2.getWorker());
        }
    }).collect(Collectors.toList());
}
Also used : EventFieldsForTypeFactory(com.qcadoo.mes.cmmsMachineParts.plannedEvents.factory.EventFieldsForTypeFactory) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) org.apache.poi.hssf.usermodel(org.apache.poi.hssf.usermodel) Date(java.util.Date) QcadooSecurityConstants(com.qcadoo.security.constants.QcadooSecurityConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) TranslationService(com.qcadoo.localization.api.TranslationService) DateUtils(com.qcadoo.localization.api.utils.DateUtils) Collectors(java.util.stream.Collectors) PlannedEventType(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventType) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) org.apache.poi.ss.usermodel(org.apache.poi.ss.usermodel) FieldsForType(com.qcadoo.mes.cmmsMachineParts.plannedEvents.fieldsForType.FieldsForType) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Lists(com.google.common.collect.Lists) TimeUsageDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) Map(java.util.Map) Entry(java.util.Map.Entry) SecurityService(com.qcadoo.security.api.SecurityService) TimeUsageGroupDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageGroupDTO) List(java.util.List) TimeUsageGroupDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageGroupDTO) Date(java.util.Date)

Example 3 with TimeUsageDTO

use of com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO in project mes by qcadoo.

the class TimeUsageXlsService method updatePartsAndDescription.

private void updatePartsAndDescription(List<TimeUsageDTO> usages, Locale locale) {
    for (TimeUsageDTO usage : usages) {
        if ("planned".equals(usage.getEventType())) {
            PlannedEventType type = PlannedEventType.parseString(usage.getType());
            FieldsForType fields = fieldsForTypeFactory.createFieldsForType(type);
            if (fields.getHiddenTabs().contains(PlannedEventFields.MACHINE_PARTS_TAB)) {
                String notApplicable = translationService.translate("cmmsMachineParts.timeUsageReport.na", locale);
                usage.setParts(notApplicable);
            }
            if (fields.getHiddenTabs().contains(PlannedEventFields.SOLUTION_DESCRIPTION_TAB)) {
                String notApplicable = translationService.translate("cmmsMachineParts.timeUsageReport.na", locale);
                usage.setDescription(notApplicable);
            }
        }
    }
}
Also used : TimeUsageDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO) PlannedEventType(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventType) FieldsForType(com.qcadoo.mes.cmmsMachineParts.plannedEvents.fieldsForType.FieldsForType)

Example 4 with TimeUsageDTO

use of com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO in project mes by qcadoo.

the class TimeUsageXlsService method fillTimeUsageRows.

private int fillTimeUsageRows(final HSSFWorkbook workbook, final HSSFSheet sheet, final TimeUsageGroupDTO timeUsage, int rowCounter, final Locale locale) {
    Font font = workbook.createFont();
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setFontHeightInPoints((short) 10);
    font.setBold(false);
    int usagesCounter = 0;
    for (TimeUsageDTO usage : timeUsage.getTimeUsages()) {
        HSSFRow usageRow = sheet.createRow(rowCounter + usagesCounter);
        boolean isFirst = usagesCounter == 0;
        HSSFCellStyle style = getLeftAlignedStyle(workbook, isFirst, usage);
        HSSFCellStyle styleRight = getRightAlignedStyle(workbook, isFirst, usage);
        addNewRow(usageRow, usage, locale, style, styleRight);
        if (isFirst) {
            addNewCell(usageRow, timeUsage.getDurationSum().toString(), 10, styleRight, true);
            addNewCell(usageRow, timeUsage.getRegisteredTimeSum().toString(), 11, styleRight, true);
        } else {
            addNewCell(usageRow, "", 10, styleRight, false);
            addNewCell(usageRow, "", 11, styleRight, false);
        }
        ++usagesCounter;
    }
    return rowCounter + usagesCounter;
}
Also used : TimeUsageDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO)

Example 5 with TimeUsageDTO

use of com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO in project mes by qcadoo.

the class TimeUsageXlsService method buildExcelContent.

public void buildExcelContent(final HSSFWorkbook workbook, final HSSFSheet sheet, Map<String, Object> filters, final Locale locale) {
    reportStyleFactory = new ReportStyleFactory(workbook);
    List<TimeUsageDTO> usages = timeUsageXLSDataProvider.getUsages((Map<String, Object>) filters.get("filtersMap"));
    updatePartsAndDescription(usages, locale);
    fillHeaderData(workbook, sheet, 0, locale, (Map<String, Object>) filters.get("filtersMap"));
    fillHeaderRow(workbook, sheet, 4, locale);
    List<TimeUsageGroupDTO> timeUsageGroups = group(usages);
    int rowCounter = 5;
    for (TimeUsageGroupDTO timeUsageGroupDTO : timeUsageGroups) {
        rowCounter = fillTimeUsageRows(workbook, sheet, timeUsageGroupDTO, rowCounter++, locale);
    }
    setColumnsWidths(sheet);
}
Also used : TimeUsageDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO) TimeUsageGroupDTO(com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageGroupDTO)

Aggregations

TimeUsageDTO (com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageDTO)5 PlannedEventType (com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventType)2 FieldsForType (com.qcadoo.mes.cmmsMachineParts.plannedEvents.fieldsForType.FieldsForType)2 TimeUsageGroupDTO (com.qcadoo.mes.cmmsMachineParts.reports.xls.timeUsage.dto.TimeUsageGroupDTO)2 Date (java.util.Date)2 Lists (com.google.common.collect.Lists)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 DateUtils (com.qcadoo.localization.api.utils.DateUtils)1 PlannedEventFields (com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields)1 EventFieldsForTypeFactory (com.qcadoo.mes.cmmsMachineParts.plannedEvents.factory.EventFieldsForTypeFactory)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 Entity (com.qcadoo.model.api.Entity)1 SecurityService (com.qcadoo.security.api.SecurityService)1 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1