|
@@ -1,6 +1,10 @@
|
|
|
package com.ygtx.gxt.service.impl;
|
|
package com.ygtx.gxt.service.impl;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ygtx.gxt.mapper.GxtFanInspectionScoreMapper;
|
|
import com.ygtx.gxt.mapper.GxtFanInspectionScoreMapper;
|
|
@@ -9,6 +13,8 @@ import com.ygtx.gxt.service.IGxtFanInspectionScoreService;
|
|
|
import com.ygtx.common.exception.ServiceException;
|
|
import com.ygtx.common.exception.ServiceException;
|
|
|
import com.ygtx.common.utils.StringUtils;
|
|
import com.ygtx.common.utils.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 风机类型检查分值Service业务层处理
|
|
* 风机类型检查分值Service业务层处理
|
|
|
*
|
|
*
|
|
@@ -199,4 +205,87 @@ public class GxtFanInspectionScoreServiceImpl implements IGxtFanInspectionScoreS
|
|
|
}
|
|
}
|
|
|
return resultMsg.toString();
|
|
return resultMsg.toString();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void importTemplate(HttpServletResponse response) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
+ Sheet sheet = workbook.createSheet("风机类型检查分值数据");
|
|
|
|
|
+
|
|
|
|
|
+ // 表头行
|
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
|
+
|
|
|
|
|
+ // 表头和注释
|
|
|
|
|
+ String[] headers = { "机型", "维保类型", "分值" };
|
|
|
|
|
+ String[] comments = { "单位管理员:\n必填", "单位管理员:\n必填", "单位管理员:\n必填" };
|
|
|
|
|
+
|
|
|
|
|
+ // 创建字体(普通和加粗)
|
|
|
|
|
+ Font commentFont = workbook.createFont();
|
|
|
|
|
+ commentFont.setFontHeightInPoints((short) 9); // 默认字体大小
|
|
|
|
|
+
|
|
|
|
|
+ Font boldFont = workbook.createFont();
|
|
|
|
|
+ boldFont.setFontHeightInPoints((short) 9);
|
|
|
|
|
+ boldFont.setBold(true); // 加粗
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 创建表头样式(灰色背景 + 白色字体 + 居中)
|
|
|
|
|
+ CellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); // 浅灰色背景
|
|
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中
|
|
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 设置字体(白色 + 加粗)
|
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
|
+ font.setColor(IndexedColors.WHITE.getIndex()); // 白色字体
|
|
|
|
|
+ font.setBold(true); // 加粗
|
|
|
|
|
+ font.setFontHeightInPoints((short) 10); // 字体大小
|
|
|
|
|
+ headerStyle.setFont(font);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建注释绘图对象(只需一次)
|
|
|
|
|
+ Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
|
|
|
+ CreationHelper factory = workbook.getCreationHelper();
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
|
+ cell.setCellStyle(headerStyle); // 应用样式
|
|
|
|
|
+
|
|
|
|
|
+ // 固定列宽 200
|
|
|
|
|
+ sheet.setColumnWidth(i, 20 * 256);
|
|
|
|
|
+
|
|
|
|
|
+ // 添加注释
|
|
|
|
|
+ if (comments[i] != null) {
|
|
|
|
|
+ // 1. 创建 RichTextString 并设置文本
|
|
|
|
|
+ RichTextString richText = factory.createRichTextString(comments[i]);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 设置 "单位管理员:" 为加粗
|
|
|
|
|
+ richText.applyFont(0, 5, boldFont); // 索引 0-5("单位管理员:")
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 设置 "\n必填" 为默认字体(可选)
|
|
|
|
|
+ richText.applyFont(5, comments[i].length(), commentFont); // 索引 5 到末尾
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 创建注释并应用 RichTextString
|
|
|
|
|
+ ClientAnchor anchor = factory.createClientAnchor();
|
|
|
|
|
+ anchor.setCol1(i);
|
|
|
|
|
+ anchor.setCol2(i + 1);
|
|
|
|
|
+ anchor.setRow1(0);
|
|
|
|
|
+ anchor.setRow2(2);
|
|
|
|
|
+
|
|
|
|
|
+ Comment comment = drawing.createCellComment(anchor);
|
|
|
|
|
+ comment.setString(richText); // 使用 RichTextString 代替普通字符串
|
|
|
|
|
+ comment.setAuthor("系统提示");
|
|
|
|
|
+ cell.setCellComment(comment);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 输出到响应流
|
|
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=风机类型检查分值数据导入模版.xlsx");
|
|
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
|
|
+ workbook.close();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ } catch (Exception err) {
|
|
|
|
|
+ throw new ServiceException(err.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|