Commit 459a6ae7 authored by wujipeng's avatar wujipeng
Browse files

运维工单导出-优化

parent a66e3917
......@@ -133,7 +133,7 @@ public class CertificateController {
//查询运维项目
return Result.data(CertificateVO.builder().build());
return Result.data(null);
}
}
\ No newline at end of file
......@@ -10,9 +10,6 @@ import lombok.*;
* @Desc : 描述信息
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class CertificateVO extends CertificateEntity {
}
package com.ruzhoukj.sms.service.impl;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruzhoukj.sms.dao.KzWorkDao;
import com.ruzhoukj.sms.entity.KzWorkEntity;
import com.ruzhoukj.sms.model.dto.KzWorkDTO;
import com.ruzhoukj.sms.model.vo.KzWorkVO;
import com.ruzhoukj.sms.service.KzWorkService;
import com.ruzhoukj.sms.util.DateUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
......@@ -38,7 +39,7 @@ public class KzWorkServiceImpl extends ServiceImpl<KzWorkDao, KzWorkEntity> impl
// 创建表头
Row headerRow = sheet.createRow(0);
String[] headers = {"运维人员", "运维时间", "运维项目", "运维状态"};
String[] headers = {"运维人员", "运维时间", "运维项目", "操作时间", "运维状态"};
// 设置表头样式
CellStyle headerStyle = workbook.createCellStyle();
......@@ -60,17 +61,19 @@ public class KzWorkServiceImpl extends ServiceImpl<KzWorkDao, KzWorkEntity> impl
dataRow.createCell(0).setCellValue(work.getUser());
dataRow.createCell(1).setCellValue(work.getReservationTime());
dataRow.createCell(2).setCellValue(work.getProject());
dataRow.createCell(3).setCellValue(work.getOperationTime());
dataRow.createCell(3).setCellValue(DateUtils.formatToDateTimeString(work.getOperationTime()));
dataRow.createCell(4).setCellValue(work.getStatus());
}
// 自动调整列宽
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
sheet.setColumnWidth(i, 20 * 256);
}
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=work_export.xlsx");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("运维工单", "utf-8") + ".xlsx");
// 写入响应流
workbook.write(response.getOutputStream());
......
......@@ -111,4 +111,19 @@ public class DateUtils {
throw new IllegalArgumentException("日期转换失败", e);
}
}
/**
* 将Date类型数据转换为"yyyy-MM-dd HH:mm:ss"格式的字符串
*
* @param date 需要转换的Date对象
* @return 格式化后的日期时间字符串。如果传入的date为null,则返回空字符串""
*/
public static String formatToDateTimeString(Date date) {
if (date == null) {
return ""; // 处理空值情况,避免NullPointerException[3](@ref)
}
// 创建指定格式的格式化对象[1,6](@ref)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment