Ver Fonte

导出排班表

xuzhancheng há 1 mês atrás
pai
commit
0fdf7604e5

+ 11 - 1
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/equippipescheduling/EquipPipeSchedulingController.java

@@ -156,7 +156,17 @@ public class EquipPipeSchedulingController {
         equipPipeSchedulingService.setShiftSchedule(pipeShiftScheduleRespVOS);
         return success(true);
     }
-
+    @GetMapping("/shiftSchedule/export-excel")
+    @Operation(summary = "导出管道排班表 Excel")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportSchedulingTbExcel(@Valid PipeShiftScheduleReqVO pageReqVO,
+                                        HttpServletResponse response) throws IOException {
+        List<PipeShiftScheduleRespVO> list = equipPipeSchedulingService.shiftSchedule(pageReqVO);
+        List<PipeShiftScheduleExportRespVO> res = equipPipeSchedulingService.convert(list);
+        // 导出 Excel
+        ExcelUtils.write(response, "排班表.xls", "数据", PipeShiftScheduleExportRespVO.class,
+                res);
+    }
 
     @PutMapping("/calendar/update")
     @Operation(summary = "更新计划排期日历")

+ 57 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/equippipescheduling/vo/PipeShiftScheduleExportRespVO.java

@@ -0,0 +1,57 @@
+package cn.start.tz.module.pressure2.controller.admin.equippipescheduling.vo;
+
+import cn.start.tz.module.system.api.user.AdminUserApi;
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDate;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Schema(description = "管理后台 - 导出排班表 Response VO")
+@Data
+public class PipeShiftScheduleExportRespVO {
+
+    @ExcelProperty("日期")
+    private LocalDate date;
+
+    @ExcelProperty("星期")
+    private String week;
+
+    @ExcelProperty("检验员")
+    private String checkers;
+
+    @ExcelProperty("检验类型")
+    private String checkType;
+
+    @ExcelProperty("使用单位")
+    private String unitName;
+
+    @ExcelProperty("管道使用地址")
+    private String pipeAddress;
+
+    @ExcelProperty("联系人")
+    private String contact;
+
+    @ExcelProperty("电话")
+    private String contactPhone;
+
+    @ExcelProperty("管道介质")
+    private String medium;
+
+    @ExcelProperty("管线长度(m)")
+    private Double pipeLengthTotal;
+
+    @ExcelProperty("区域街道")
+    private String street;
+
+    @ExcelProperty("上次报告编号")
+    private String lastReportNo;
+
+    @ExcelProperty("监督报告编号")
+    private String lastMaintenanceReportNo;
+
+    @ExcelProperty("状态")
+    private String status;
+}

+ 2 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/service/equippipescheduling/EquipPipeSchedulingService.java

@@ -82,5 +82,7 @@ public interface EquipPipeSchedulingService extends IService<EquipPipeScheduling
 
     List<PipeShiftScheduleRespVO> shiftSchedule(@Valid PipeShiftScheduleReqVO pageReqVO);
 
+    List<PipeShiftScheduleExportRespVO> convert(List<PipeShiftScheduleRespVO> list);
+
     void setShiftSchedule(@Valid List<PipeShiftScheduleRespVO> pipeShiftScheduleRespVOS);
 }

+ 119 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/service/equippipescheduling/EquipPipeSchedulingServiceImpl.java

@@ -1364,4 +1364,123 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
         return taskDetailsVO;
     }
 
+    @Override
+    public List<PipeShiftScheduleExportRespVO> convert(List<PipeShiftScheduleRespVO> list) {
+        if (list == null || list.isEmpty()) {
+            return List.of();
+        }
+        return list.stream().map(source -> {
+            PipeShiftScheduleExportRespVO target = new PipeShiftScheduleExportRespVO();
+
+            // 日期
+            target.setDate(source.getDate());
+
+            // 星期
+            target.setWeek(calculateWeek(source.getDate()));
+
+            // 检验员(将检验员ID列表转换为字符串)
+            if (source.getCheckers() != null && !source.getCheckers().isEmpty()) {
+                List<AdminUserRespDTO> checkedData = adminUserApi.getUserList(source.getCheckers()).getCheckedData();
+                target.setCheckers(String.join(",", checkedData.stream().map(AdminUserRespDTO::getNickname).toList()));
+            }
+
+            // 获取第一个任务项
+            PipeShiftScheduleRespVO.PipeShiftScheduleItemRespVO taskItem =
+                    source.getTaskItems() != null && !source.getTaskItems().isEmpty()
+                            ? source.getTaskItems().get(0)
+                            : null;
+
+            if (taskItem != null) {
+                // 检验类型
+                target.setCheckType("100".equals(taskItem.getCheckType()) ? "定期检验" : "年度检查");
+
+                // 使用单位
+                target.setUnitName(taskItem.getUnitName());
+
+                // 管道使用地址
+                target.setPipeAddress(taskItem.getPipeAddress());
+
+                // 联系人(去重后用/拼接)
+                List<String> contacts = source.getTaskItems().stream()
+                        .map(PipeShiftScheduleRespVO.PipeShiftScheduleItemRespVO::getContact)
+                        .filter(contact -> contact != null && !contact.isEmpty())
+                        .distinct()
+                        .collect(Collectors.toList());
+                target.setContact(String.join("/", contacts));
+
+                // 电话(去重后用/拼接)
+                List<String> contactPhones = source.getTaskItems().stream()
+                        .map(PipeShiftScheduleRespVO.PipeShiftScheduleItemRespVO::getContactPhone)
+                        .filter(phone -> phone != null && !phone.isEmpty())
+                        .distinct()
+                        .collect(Collectors.toList());
+                target.setContactPhone(String.join("/", contactPhones));
+
+                // 管线长度(累加)
+                double totalLength = source.getTaskItems().stream()
+                        .mapToDouble(item -> {
+                            try {
+                                return item.getPipeLengthTotal() != null
+                                        ? Double.parseDouble(item.getPipeLengthTotal())
+                                        : 0;
+                            } catch (NumberFormatException e) {
+                                return 0;
+                            }
+                        })
+                        .sum();
+                target.setPipeLengthTotal(totalLength);
+
+                // 上次报告编号(根据检验类型选择)
+                if ("100".equals(taskItem.getCheckType())) {
+                    target.setLastReportNo(taskItem.getLastLegalPeriodicalInspectionReportNo());
+                } else {
+                    target.setLastReportNo(taskItem.getLastYearReportNo());
+                }
+
+                // 监督报告编号
+                target.setLastMaintenanceReportNo(taskItem.getLastMaintenanceReportNo());
+
+                // 区域街道
+                String district = taskItem.getEquipDistrictName() != null ? taskItem.getEquipDistrictName() : "";
+                String street = taskItem.getEquipStreetName() != null ? taskItem.getEquipStreetName() : "";
+                target.setStreet(district + street);
+            }
+
+            // 管道介质(去重后用、拼接)
+            if (source.getPipeMedium() != null && !source.getPipeMedium().isEmpty()) {
+                List<String> distinctMediums = source.getPipeMedium().stream()
+                        .distinct()
+                        .collect(Collectors.toList());
+                target.setMedium(String.join("、", distinctMediums));
+            }
+
+            // 状态
+            target.setStatus(getStatusText(source.getStatus()));
+
+            return target;
+        }).collect(Collectors.toList());
+    }
+
+    private static String calculateWeek(LocalDate date) {
+        if (date == null) {
+            return "";
+        }
+        String[] weekDays = {"日", "一", "二", "三", "四", "五", "六"};
+        int week = date.getDayOfWeek().getValue() % 7;
+        return weekDays[week];
+    }
+
+    private static String getStatusText(Integer status) {
+        if (status == null) {
+            return "未知";
+        }
+        return switch (status) {
+            case 100 -> "已排期";
+            case 200 -> "待约检";
+            case 300 -> "已受理";
+            case 400 -> "检测中";
+            default -> "未知";
+        };
+    }
+
 }