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