| | |
| | | package com.sinata.appointment.service; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | String approvalStatus, |
| | | String visitorKeyword, |
| | | String visitReasonCode) { |
| | | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| | | ExcelWriter writer = EasyExcel.write(bos, AppointmentAdminExportRow.class).build(); |
| | | WriteSheet sheet = EasyExcel.writerSheet("预约记录").build(); |
| | | long pageNo = 1L; |
| | | long pageSize = 200L; |
| | | List<AppointmentAdminExportRow> rows = new ArrayList<>(); |
| | | while (true) { |
| | | Page<AppointmentOrder> orderPage = new Page<>(pageNo, pageSize); |
| | | IPage<AppointmentOrder> pagedOrders = |
| | |
| | | break; |
| | | } |
| | | AdminPageData pageData = loadAdminPageData(orders); |
| | | List<AppointmentAdminExportRow> rows = |
| | | rows.addAll( |
| | | buildExportRows( |
| | | orders, |
| | | pageData.visitorRowsMap(), |
| | | pageData.approvalInstanceMap(), |
| | | pageData.reasonNameMap()); |
| | | writer.write(rows, sheet); |
| | | pageData.reasonNameMap())); |
| | | if (pageNo * pageSize >= pagedOrders.getTotal()) { |
| | | break; |
| | | } |
| | | pageNo++; |
| | | } |
| | | writer.finish(); |
| | | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| | | EasyExcel.write(bos, AppointmentAdminExportRow.class).sheet("预约记录").doWrite(rows); |
| | | return bos.toByteArray(); |
| | | } catch (Exception e) { |
| | | return new byte[0]; |
| | |
| | | vo.setVisitedDeptName(defaultText(trimToNull(deptName))); |
| | | vo.setAccessAreaText(defaultText(buildJsonNameText(order.getPassAccessAreaNames()))); |
| | | vo.setLocalUnitText(defaultText(buildJsonNameText(order.getPassLocalUnitNames()))); |
| | | vo.setPlateNoText(defaultText(joinUniqueTexts(visitorRows, AppointmentVisitor::getPlateNo))); |
| | | vo.setPlateNoText(defaultText(loadOrderPlateText(id))); |
| | | vo.setVisitReasonText(defaultText(buildVisitReasonText(order, reasonNameMap))); |
| | | vo.setVisitStartText(defaultText(resolveVisitStartText(order))); |
| | | vo.setVisitEndText(defaultText(resolveVisitEndText(order))); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private String loadOrderPlateText(Long orderId) { |
| | | if (orderId == null) { |
| | | return null; |
| | | } |
| | | List<AppointmentVehicle> rows = |
| | | appointmentVehicleMapper.selectList( |
| | | new LambdaQueryWrapper<AppointmentVehicle>() |
| | | .eq(AppointmentVehicle::getDelFlag, 0) |
| | | .eq(AppointmentVehicle::getOrderId, orderId) |
| | | .orderByAsc(AppointmentVehicle::getId)); |
| | | if (rows == null || rows.isEmpty()) { |
| | | return null; |
| | | } |
| | | return rows.stream() |
| | | .map(AppointmentVehicle::getPlateNo) |
| | | .filter(StringUtils::hasText) |
| | | .map(String::trim) |
| | | .distinct() |
| | | .collect(Collectors.joining("、")); |
| | | } |
| | | |
| | | private Map<Long, List<AppointmentVisitor>> loadVisitorRows(List<Long> orderIds) { |
| | | if (orderIds == null || orderIds.isEmpty()) { |
| | | return Map.of(); |