Commit f272d2f1 authored by qinhu's avatar qinhu

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

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