Commit f272d2f1 authored by qinhu's avatar qinhu

质量管理报告--下标去掉null

parent cdd1a981
...@@ -33,56 +33,55 @@ import java.util.stream.Collectors; ...@@ -33,56 +33,55 @@ import java.util.stream.Collectors;
@RequestMapping("/business/quality") @RequestMapping("/business/quality")
public class QualityController { public class QualityController {
final final
IEntrustService iEntrustService; IEntrustService iEntrustService;
final final
IQualityApplyService iQualityApplyService; IQualityApplyService iQualityApplyService;
public QualityController(IEntrustService iEntrustService, IQualityApplyService iQualityApplyService) { public QualityController(IEntrustService iEntrustService, IQualityApplyService iQualityApplyService) {
this.iEntrustService = iEntrustService; this.iEntrustService = iEntrustService;
this.iQualityApplyService = iQualityApplyService; this.iQualityApplyService = iQualityApplyService;
} }
@ApiOperation(value = "质量检测分页列表") @ApiOperation(value = "质量检测分页列表")
@ApiImplicitParams(value = { @ApiImplicitParams(value = {
@ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "clientId", value = "委托单位id", paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "clientId", value = "委托单位id", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "projectCode", value = "项目编号", paramType = "query", dataType = "String") @ApiImplicitParam(name = "projectCode", value = "项目编号", paramType = "query", dataType = "String")
}) })
@GetMapping("/getPage") @GetMapping("/getPage")
public BaseResponse<IPage<EntrustVo>> page(PageQuery pageQuery, String startDate, String endDate, public BaseResponse<IPage<EntrustVo>> page(PageQuery pageQuery, String startDate, String endDate,
Integer clientId, String projectName, String projectCode) { Integer clientId, String projectName, String projectCode) {
BaseResponse<IPage<EntrustVo>> baseResponse = iEntrustService.getQualityPage( BaseResponse<IPage<EntrustVo>> baseResponse = iEntrustService.getQualityPage(
pageQuery, startDate, endDate, clientId, projectName, projectCode); pageQuery, startDate, endDate, clientId, projectName, projectCode);
//判断是否已经评审过 //判断是否已经评审过
if (baseResponse.getCode() == 200) { if (baseResponse.getCode() == 200) {
List<EntrustVo> records = baseResponse.getData().getRecords(); List<EntrustVo> records = baseResponse.getData().getRecords();
if (records.size() == 0) { if (records.size() == 0) {
return BaseResponse.okData(new Page<>()); return BaseResponse.okData(new Page<>());
} }
List<Integer> projectIds = records.stream().map(EntrustVo::getId).collect(Collectors.toList()); List<Integer> projectIds = records.stream().map(EntrustVo::getId).collect(Collectors.toList());
Set<Integer> qualityApplyIds = iQualityApplyService.selectQualityApplyStatusByProIds(projectIds); Set<Integer> qualityApplyIds = iQualityApplyService.selectQualityApplyStatusByProIds(projectIds);
records.forEach(arg -> { records.forEach(arg -> {
if (qualityApplyIds.contains(arg.getId())) { if (qualityApplyIds.contains(arg.getId())) {
arg.setStatusValue("审核完成"); arg.setStatusValue("审核完成");
arg.setStatus(10); arg.setStatus(10);
} else { } else {
arg.setStatusValue("待审核"); arg.setStatusValue("待审核");
arg.setStatus(9); arg.setStatus(9);
} }
}); });
} }
return baseResponse; return baseResponse;
} }
@GetMapping("/{entrustId}")
@ApiOperation("获取质量详情")
public BaseResponse<QualityDetailVo> getReportDetail(@PathVariable("entrustId") Integer entrustId) {
return BaseResponse.okData(iEntrustService.getQualityDetail(entrustId));
}
@GetMapping("/{entrustId}")
@ApiOperation("获取质量详情")
public BaseResponse<QualityDetailVo> getReportDetail(@PathVariable("entrustId") Integer entrustId) {
return BaseResponse.okData(iEntrustService.getQualityDetail(entrustId));
}
} }
...@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSON; ...@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -154,22 +155,22 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua ...@@ -154,22 +155,22 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua
List<String> inputValus = JSON.parseArray(arg.getInputResult(), String.class); List<String> inputValus = JSON.parseArray(arg.getInputResult(), String.class);
Object[] objs = new Object[inputValus.size() + 8]; Object[] objs = new Object[inputValus.size() + 8];
if (!"误差".equals(arg.getUserName())) { if (!"误差".equals(arg.getUserName())) {
objs[0] = arg.getProjectName(); objs[0] = arg.getProjectName() == null ? "" : arg.getProjectName();
objs[1] = arg.getProjectId(); objs[1] = arg.getProjectId() == null ? "" : arg.getProjectId();
objs[2] = arg.getSampleName(); objs[2] = arg.getSampleName() == null ? "" : arg.getSampleName();
objs[3] = arg.getSampleForm(); objs[3] = arg.getSampleForm() == null ? "" : arg.getSampleForm();
objs[4] = arg.getSampleCode(); objs[4] = arg.getSampleCode() == null ? "" : arg.getSampleCode();
objs[5] = arg.getCementCode(); objs[5] = arg.getCementCode() == null ? "" : arg.getCementCode();
objs[6] = userGroupMap.get(arg.getUserId()); objs[6] = userGroupMap.get(arg.getUserId());
} }
//添加名字 //添加名字
objs[7] = arg.getUserName(); objs[7] = arg.getUserName();
for (int i = 0; i < inputValus.size(); i++) { for (int i = 0; i < inputValus.size(); i++) {
String value = inputValus.get(i); String value = inputValus.get(i);
if (value == null){ if (value == null) {
value = "0"; value = "0";
} }
if ( value.contains("\"")) { if (value.contains("\"")) {
value = value.replace("\"", ""); value = value.replace("\"", "");
} }
objs[8 + i] = value; objs[8 + i] = value;
......
...@@ -28,300 +28,302 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; ...@@ -28,300 +28,302 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*/ */
public class ExcelUtil { public class ExcelUtil {
public static void excelLocal(String path, String fileName, String[] headers, List<Object[]> datas) { public static void excelLocal(String path, String fileName, String[] headers, List<Object[]> datas) {
Workbook workbook = getWorkbook(headers, datas); Workbook workbook = getWorkbook(headers, datas);
if (workbook != null) { if (workbook != null) {
ByteArrayOutputStream byteArrayOutputStream = null; ByteArrayOutputStream byteArrayOutputStream = null;
FileOutputStream fileOutputStream = null; FileOutputStream fileOutputStream = null;
try { try {
byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream = new ByteArrayOutputStream();
workbook.write(byteArrayOutputStream); workbook.write(byteArrayOutputStream);
String suffix = ".xls"; String suffix = ".xls";
File file = new File(path + File.separator + fileName + suffix); File file = new File(path + File.separator + fileName + suffix);
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
} }
fileOutputStream = new FileOutputStream(file); fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(byteArrayOutputStream.toByteArray()); fileOutputStream.write(byteArrayOutputStream.toByteArray());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
if (fileOutputStream != null) { if (fileOutputStream != null) {
fileOutputStream.close(); fileOutputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
try { try {
if (byteArrayOutputStream != null) { if (byteArrayOutputStream != null) {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
try { try {
workbook.close(); workbook.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
/** /**
* 导出excel * 导出excel
* *
* @param fileName * @param fileName
* @param headers * @param headers
* @param datas * @param datas
* @param response * @param response
*/ */
public static void excelExport(String fileName, String[] headers, List<Object[]> datas, public static void excelExport(String fileName, String[] headers, List<Object[]> datas,
HttpServletResponse response) { HttpServletResponse response) {
Workbook workbook = getWorkbook(headers, datas); Workbook workbook = getWorkbook(headers, datas);
if (workbook != null) { if (workbook != null) {
ByteArrayOutputStream byteArrayOutputStream = null; ByteArrayOutputStream byteArrayOutputStream = null;
try { try {
byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream = new ByteArrayOutputStream();
workbook.write(byteArrayOutputStream); workbook.write(byteArrayOutputStream);
String suffix = ".xls"; String suffix = ".xls";
response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
"attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1")); "attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1"));
OutputStream outputStream = response.getOutputStream(); OutputStream outputStream = response.getOutputStream();
outputStream.write(byteArrayOutputStream.toByteArray()); outputStream.write(byteArrayOutputStream.toByteArray());
outputStream.close(); outputStream.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
if (byteArrayOutputStream != null) { if (byteArrayOutputStream != null) {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
try { try {
workbook.close(); workbook.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
public static void excelExportNew(String fileName, String[] headers, List<Object[]> datas,
HttpServletResponse response) { public static void excelExportNew(String fileName, String[] headers, List<Object[]> datas,
Workbook workbook = getWorkbookNew(headers, datas); HttpServletResponse response) {
if (workbook != null) { Workbook workbook = getWorkbookNew(headers, datas);
ByteArrayOutputStream byteArrayOutputStream = null; if (workbook != null) {
try { ByteArrayOutputStream byteArrayOutputStream = null;
byteArrayOutputStream = new ByteArrayOutputStream(); try {
workbook.write(byteArrayOutputStream); byteArrayOutputStream = new ByteArrayOutputStream();
workbook.write(byteArrayOutputStream);
String suffix = ".xls";
response.setContentType("application/vnd.ms-excel;charset=utf-8"); String suffix = ".xls";
response.setHeader("Content-Disposition", response.setContentType("application/vnd.ms-excel;charset=utf-8");
"attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1")); response.setHeader("Content-Disposition",
"attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1"));
OutputStream outputStream = response.getOutputStream();
outputStream.write(byteArrayOutputStream.toByteArray()); OutputStream outputStream = response.getOutputStream();
outputStream.close(); outputStream.write(byteArrayOutputStream.toByteArray());
} catch (Exception e) { outputStream.close();
e.printStackTrace(); } catch (Exception e) {
} finally { e.printStackTrace();
try { } finally {
if (byteArrayOutputStream != null) { try {
byteArrayOutputStream.close(); if (byteArrayOutputStream != null) {
} byteArrayOutputStream.close();
} catch (IOException e) { }
e.printStackTrace(); } catch (IOException e) {
} e.printStackTrace();
}
try {
workbook.close(); try {
} catch (IOException e) { workbook.close();
e.printStackTrace(); } catch (IOException e) {
} e.printStackTrace();
} }
} }
} }
/** }
* @param headers 列头
* @param datas 数据 /**
* @return * @param headers 列头
*/ * @param datas 数据
public static Workbook getWorkbook(String[] headers, List<Object[]> datas) { * @return
XSSFWorkbook workbook = new XSSFWorkbook(); */
XSSFSheet sheet = workbook.createSheet(); public static Workbook getWorkbook(String[] headers, List<Object[]> datas) {
XSSFWorkbook workbook = new XSSFWorkbook();
Row row = null; XSSFSheet sheet = workbook.createSheet();
Cell cell = null;
XSSFFont font = workbook.createFont(); Row row = null;
int line = 0, maxColumn = 0; Cell cell = null;
if (headers != null && headers.length > 0) { // 设置列头 XSSFFont font = workbook.createFont();
CellStyle style = workbook.createCellStyle(); int line = 0, maxColumn = 0;
style.setAlignment(HorizontalAlignment.CENTER_SELECTION); if (headers != null && headers.length > 0) { // 设置列头
CellStyle style = workbook.createCellStyle();
row = sheet.createRow(line++); style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
row.setHeightInPoints(23);
font.setBold(true); row = sheet.createRow(line++);
font.setFontHeightInPoints((short) 13); row.setHeightInPoints(23);
style.setFont(font); font.setBold(true);
font.setFontHeightInPoints((short) 13);
maxColumn = headers.length; style.setFont(font);
for (int i = 0; i < maxColumn; i++) {
cell = row.createCell(i); maxColumn = headers.length;
cell.setCellValue(headers[i]); for (int i = 0; i < maxColumn; i++) {
cell.setCellStyle(style); cell = row.createCell(i);
} cell.setCellValue(headers[i]);
} cell.setCellStyle(style);
}
if (datas != null && datas.size() > 0) {// 渲染数据 }
CellStyle style = workbook.createCellStyle();
XSSFFont xxsfFont = workbook.createFont(); if (datas != null && datas.size() > 0) {// 渲染数据
CellStyle style = workbook.createCellStyle();
for (int index = 0, size = datas.size(); index < size; index++) { XSSFFont xxsfFont = workbook.createFont();
Object[] data = datas.get(index);
if (data != null && data.length > 0) { for (int index = 0, size = datas.size(); index < size; index++) {
row = sheet.createRow(line++); Object[] data = datas.get(index);
row.setHeightInPoints(20); if (data != null && data.length > 0) {
row = sheet.createRow(line++);
int length = data.length; row.setHeightInPoints(20);
if (length > maxColumn) {
maxColumn = length; int length = data.length;
} if (length > maxColumn) {
maxColumn = length;
for (int i = 0; i < length; i++) { }
String value = data[i] == null ? null : data[i].toString();
cell = row.createCell(i); for (int i = 0; i < length; i++) {
//处理下标 String value = data[i] == null ? null : data[i].toString();
if(value.contains("<sub>") || value.contains("</sub>") ){ cell = row.createCell(i);
xxsfFont.setTypeOffset(FontFormatting.SS_SUB); if (value != null) {
cell.setCellStyle(style); //处理下标
XSSFRichTextString richString = new XSSFRichTextString(value.replaceAll("</sub>","<sub>").replaceAll("<sub>","")); if (value.contains("<sub>") || value.contains("</sub>")) {
//提取下标位置 xxsfFont.setTypeOffset(FontFormatting.SS_SUB);
applyRichStringFontsub(value, richString, xxsfFont); cell.setCellStyle(style);
cell.setCellValue(richString); XSSFRichTextString richString = new XSSFRichTextString(value.replaceAll("</sub>", "<sub>").replaceAll("<sub>", ""));
}else if(value.contains("<sup>") || value.contains("</sup>")){ //提取下标位置
xxsfFont.setTypeOffset(FontFormatting.SS_SUPER); applyRichStringFontsub(value, richString, xxsfFont);
cell.setCellStyle(style); cell.setCellValue(richString);
XSSFRichTextString richString = new XSSFRichTextString(value.replaceAll("</sup>","<sup>").replaceAll("<sup>","")); } else if (value.contains("<sup>") || value.contains("</sup>")) {
//提取下标位置 xxsfFont.setTypeOffset(FontFormatting.SS_SUPER);
applyRichStringFontsup(value, richString, xxsfFont); cell.setCellStyle(style);
cell.setCellValue(richString); XSSFRichTextString richString = new XSSFRichTextString(value.replaceAll("</sup>", "<sup>").replaceAll("<sup>", ""));
}else{ //提取下标位置
cell.setCellValue(value); applyRichStringFontsup(value, richString, xxsfFont);
cell.setCellValue(richString);
cell.setCellStyle(style); } else {
} cell.setCellValue(value);
} cell.setCellStyle(style);
} }
} }
} }
}
for (int i = 0; i < maxColumn; i++) { }
sheet.autoSizeColumn(i); }
}
for (int i = 0; i < maxColumn; i++) {
return workbook; sheet.autoSizeColumn(i);
} }
private static void applyRichStringFontsub(String sub, XSSFRichTextString richString,XSSFFont xxsfFont) { return workbook;
String[] split = sub.replaceAll("</sub>", "<sub>").split("<sub>"); }
String it_str = "";
for (int i = 1; i < split.length + 1; i++) { private static void applyRichStringFontsub(String sub, XSSFRichTextString richString, XSSFFont xxsfFont) {
if (i % 2 != 0) { String[] split = sub.replaceAll("</sub>", "<sub>").split("<sub>");
it_str = it_str + split[i - 1]; String it_str = "";
} else { for (int i = 1; i < split.length + 1; i++) {
richString.applyFont(it_str.length(),(it_str+split[i-1]).length(),xxsfFont); if (i % 2 != 0) {
it_str = it_str + split[i - 1]; it_str = it_str + split[i - 1];
} } else {
richString.applyFont(it_str.length(), (it_str + split[i - 1]).length(), xxsfFont);
} it_str = it_str + split[i - 1];
} }
private static void applyRichStringFontsup(String sup, XSSFRichTextString richString,XSSFFont xxsfFont) { }
String[] split = sup.replaceAll("</sup>", "<sup>").split("<sup>"); }
String it_str = "";
for (int i = 1; i < split.length + 1; i++) { private static void applyRichStringFontsup(String sup, XSSFRichTextString richString, XSSFFont xxsfFont) {
if (i % 2 != 0) { String[] split = sup.replaceAll("</sup>", "<sup>").split("<sup>");
it_str = it_str + split[i - 1]; String it_str = "";
} else { for (int i = 1; i < split.length + 1; i++) {
richString.applyFont(it_str.length(),(it_str+split[i-1]).length(),xxsfFont); if (i % 2 != 0) {
it_str = it_str + split[i - 1]; it_str = it_str + split[i - 1];
} } else {
richString.applyFont(it_str.length(), (it_str + split[i - 1]).length(), xxsfFont);
} it_str = it_str + split[i - 1];
} }
}
}
public static Workbook getWorkbookNew(String[] headers, List<Object[]> datas) {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(); public static Workbook getWorkbookNew(String[] headers, List<Object[]> datas) {
workbook.setSheetName(0,"样品处置记录"); Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row = null; workbook.setSheetName(0, "样品处置记录");
Cell cell = null;
Row row = null;
Font font = workbook.createFont(); Cell cell = null;
int line = 0, maxColumn = 0; Font font = workbook.createFont();
if (headers != null && headers.length > 0) { // 设置列头
CellStyle style = workbook.createCellStyle(); int line = 0, maxColumn = 0;
style.setAlignment(HorizontalAlignment.CENTER_SELECTION); if (headers != null && headers.length > 0) { // 设置列头
style.setVerticalAlignment(VerticalAlignment.CENTER); CellStyle style = workbook.createCellStyle();
row = sheet.createRow(line++); style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
row.setHeightInPoints(23); style.setVerticalAlignment(VerticalAlignment.CENTER);
font.setFontHeightInPoints((short) 12); row = sheet.createRow(line++);
font.setFontName("宋体"); row.setHeightInPoints(23);
style.setFont(font); font.setFontHeightInPoints((short) 12);
font.setFontName("宋体");
maxColumn = headers.length; style.setFont(font);
for (int i = 0; i < maxColumn; i++) {
cell = row.createCell(i); maxColumn = headers.length;
cell.setCellValue(headers[i]); for (int i = 0; i < maxColumn; i++) {
cell.setCellStyle(style); cell = row.createCell(i);
} cell.setCellValue(headers[i]);
} cell.setCellStyle(style);
}
if (datas != null && datas.size() > 0) {// 渲染数据 }
CellStyle style = workbook.createCellStyle();
for (int index = 0, size = datas.size(); index < size; index++) { if (datas != null && datas.size() > 0) {// 渲染数据
Object[] data = datas.get(index); CellStyle style = workbook.createCellStyle();
if (data != null && data.length > 0) { for (int index = 0, size = datas.size(); index < size; index++) {
row = sheet.createRow(line++); Object[] data = datas.get(index);
row.setHeightInPoints(20); if (data != null && data.length > 0) {
row = sheet.createRow(line++);
int length = data.length; row.setHeightInPoints(20);
if (length > maxColumn) {
maxColumn = length; int length = data.length;
} if (length > maxColumn) {
maxColumn = length;
for (int i = 0; i < length; i++) { }
style.setWrapText(true); //关键
style.setFont(font); for (int i = 0; i < length; i++) {
cell = row.createCell(i); style.setWrapText(true); //关键
cell.setCellValue(data[i] == null ? null : data[i].toString()); style.setFont(font);
cell.setCellStyle(style); cell = row.createCell(i);
style.setAlignment(HorizontalAlignment.CENTER_SELECTION); cell.setCellValue(data[i] == null ? null : data[i].toString());
} cell.setCellStyle(style);
} style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
} }
} }
}
for (int i = 0; i < maxColumn; i++) { }
sheet.autoSizeColumn(i);
} for (int i = 0; i < maxColumn; i++) {
sheet.autoSizeColumn(i);
return workbook; }
}
return workbook;
}
} }
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