定量值分析报表V1.0

master
zhaoxiaolin 12 months ago
parent 256c6eaac8
commit f3711dd081

@ -2,18 +2,11 @@ package com.op.common.core.utils.poi;
import com.alibaba.fastjson2.JSONObject;
import com.op.common.core.domain.ExcelCol;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -35,14 +28,36 @@ public class ExcelMapUtil {
}else{
sheet = workbook.createSheet(sheetName);
}
// //创建主标题行(第一行)
// Row sheetTitleRow = sheet.createRow(0);
// Cell titleCell = sheetTitleRow.createCell(0);//创建第一行第一个单元格
// titleCell.setCellValue(title);//传值
// titleCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式
// //主标题行合并单元格
// CellRangeAddress cellAddresses = new CellRangeAddress(0, 0, 0, colSize - 1);
// sheet.addMergedRegion(cellAddresses);
if(title != null){//定量分析
String[] title1s = title.split(",");
int rangeVal = colSize/title1s.length;
//创建主标题行(第一行)
Row sheetTitleRow = sheet.createRow(0);
Cell titleCell0 = sheetTitleRow.createCell(0);//创建第一行第一个单元格
titleCell0.setCellValue("");//传值
titleCell0.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式
//遍历表头名称,创建表头单元格
for (int i = 0; i < title1s.length; i++) {
Cell titleCell = sheetTitleRow.createCell(i*rangeVal+1);//创建第一行第一个单元格
titleCell.setCellValue(title1s[i]);//传值
titleCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式
//主标题行合并单元格
CellRangeAddress cellAddresses = new CellRangeAddress(0, 0, i*rangeVal+1, (i+1)*rangeVal);
sheet.addMergedRegion(cellAddresses);
}
//创建表头行(第二行)
Row sheetHeadRow = sheet.createRow(1);//1
//遍历表头名称,创建表头单元格
for (int i = 0; i < colSize; i++) {
sheet.setColumnWidth(i, (excelCol.get(i).getWidth()) * 256);//宽度单位是字符的256分之一
Cell headCell = sheetHeadRow.createCell(i);
headCell.setCellValue(excelCol.get(i).getTitle());//传值
headCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式
}
}else {
//创建表头行(第二行)
Row sheetHeadRow = sheet.createRow(0);//1
//遍历表头名称,创建表头单元格
@ -52,6 +67,7 @@ public class ExcelMapUtil {
headCell.setCellValue(excelCol.get(i).getTitle());//传值
headCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式
}
}
//将data中的值填充到excel
int rowNum = sheet.getLastRowNum()+1;
@ -65,12 +81,15 @@ public class ExcelMapUtil {
for (int i = 0 ; i < colSize ; i++ ){
Cell dataCell = dataRow.createCell(i);
dataCell.setCellStyle(getDataFont(workbook));
if(title!=null){//定量分析
dataCell.setCellValue(getValue(jsonObject.get(excelCol.get(i).getField())));
}else{
if(i>=2){
dataCell.setCellValue(getValueNum(jsonObject.get(excelCol.get(i).getField())));
}else{
dataCell.setCellValue(getValue(jsonObject.get(excelCol.get(i).getField())));
}
}
}
iterator.remove();
rowNum++;
@ -110,6 +129,7 @@ public class ExcelMapUtil {
cellStyle.setFont(font);
cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);//设置水平居中
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置垂直居中
cellStyle.setWrapText(true);//设置单元格内容自动换行
return cellStyle;
}

@ -346,7 +346,7 @@ public class MesReportWorkController extends BaseController {
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, list);
workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, list);
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();

@ -105,7 +105,7 @@ public class ProOrderController extends BaseController {
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, null);
workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, null);
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();

@ -8,15 +8,19 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.op.common.core.domain.ExcelCol;
import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.poi.ExcelMapUtil;
import com.op.quality.domain.QcCheckProject;
import com.op.quality.domain.QcCheckType;
import com.op.system.api.domain.quality.ChartDTO;
import com.op.system.api.domain.quality.ChartSeriesDTO;
import com.op.system.api.domain.quality.FactoryDto;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -240,7 +244,7 @@ public class QcStaticTableController extends BaseController {
return qcStaticTableService.getSupplierList(typeCode);
}
@GetMapping("/getProjectList/{checkType}")
@GetMapping("/getProjectOptionList/{checkType}")
public List<QcStaticTable> getProjectList(@PathVariable("checkType") String checkType) {
return qcStaticTableService.getProjectList(checkType);
}
@ -323,4 +327,63 @@ public class QcStaticTableController extends BaseController {
public QcStaticTable getDLTableAvgInfo(QcStaticTable qcStaticTable) {
return qcStaticTableService.getDLTableAvgInfo(qcStaticTable);
}
@PostMapping("/exportDLTable")
public void exportDLTable(HttpServletResponse response, QcStaticTable qcStaticTable) {
QcStaticTable resultInfo = qcStaticTableService.getDLTableAvgInfo(qcStaticTable);
//第一行标题
List<String> title1Cols = resultInfo.getTitleCol1();
//第二行标题
List<String> title2Cols = resultInfo.getTitleCol2();
String titleRow1 = String.join(",", title1Cols);
//表格结构数据
ArrayList<ExcelCol> excelCols = new ArrayList<>();
excelCols.add(new ExcelCol("日期","ymdms",30));
List<String> titleKeys = new ArrayList<>();
for(int m = 0; m<title1Cols.size(); m++){
for(int n=0; n< title2Cols.size(); n++){
excelCols.add(new ExcelCol(title2Cols.get(n),"mcode"+m+"Pcode"+n,20));
titleKeys.add("mcode"+m+"Pcode"+n);
}
}
//第三行开始数据
List<HashMap> list = new ArrayList<>();
//具体数据
List<HashMap> dxData = resultInfo.getDxData();
for(HashMap mapdto:dxData){
list.add(mapdto);
List<HashMap> detailMap0 = (List<HashMap>) mapdto.get("details");
HashMap detailMap1 = new HashMap();
for(String titleKey:titleKeys){
detailMap1.put(titleKey,detailMap0.get(0).get(titleKey+"Detail"));
}
if(StringUtils.isNotBlank((String)detailMap1.get(titleKeys.get(0)))){
list.add(detailMap1);
}
}
String titleName = "定量检测项测量值";
SXSSFWorkbook workbook = null;
try {
//设置响应头
response.setHeader("Content-disposition",
"attachment; filename="+ titleName);
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelMapUtil.initWorkbook(titleName, titleRow1, excelCols, list);
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
}finally {
if (workbook!=null){
workbook.dispose();
}
}
}
}

@ -154,6 +154,33 @@ public class QcCheckTaskProduce extends BaseEntity {
private String productType;
private String confirmManCode;
private String confirmManName;
private String confirm;
private String confirmRemark;
private String confirmTime;
public String getConfirm() {
return confirm;
}
public void setConfirm(String confirm) {
this.confirm = confirm;
}
public String getConfirmRemark() {
return confirmRemark;
}
public void setConfirmRemark(String confirmRemark) {
this.confirmRemark = confirmRemark;
}
public String getConfirmTime() {
return confirmTime;
}
public void setConfirmTime(String confirmTime) {
this.confirmTime = confirmTime;
}
public String getConfirmManCode() {
return confirmManCode;

@ -104,6 +104,15 @@ public class QcStaticTable extends BaseEntity {
private List<String> titleCol2;
private List<HashMap> dxData;
private List<HashMap> details;
private String[] projectNoArray;
public String[] getProjectNoArray() {
return projectNoArray;
}
public void setProjectNoArray(String[] projectNoArray) {
this.projectNoArray = projectNoArray;
}
public List<HashMap> getDetails() {
return details;

@ -480,7 +480,6 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService {
qcStaticTable.getYmArrayEnd(),"ymd");
qcStaticTable.setDataType("ymd");
List<QcStaticTable> titleList = qcStaticTableMapper.getDLTableTitle(qcStaticTable);
Map<String, QcStaticTable> titleMap = titleList.stream().collect(Collectors.toMap(QcStaticTable::getYearMonth, (a) -> a));
//表头:第一行
@ -498,7 +497,7 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService {
HashMap result = new HashMap();
List<HashMap> detailsData = new ArrayList<>();
HashMap detailResult = new HashMap();
result.put("ymdms",day+"均值");
result.put("ymdms",day+" AVG");
int i=0,j=0;
for(int m=0;m<colCode1.size();m++){
for(int n=0;n<colCode2.size();n++){

@ -39,6 +39,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="noOkQuality" column="noOk_quality"/>
<result property="reason" column="reason" />
<result property="productType" column="product_type" />
<result property="confirm" column="confirm" />
<result property="confirmManCode" column="confirm_man_code" />
<result property="confirmManName" column="confirm_man_name" />
<result property="confirmRemark" column="confirm_remark" />
<result property="confirmTime" column="confirm_time" />
</resultMap>
<resultMap type="QcCheckReportIncome" id="QcCheckReportIncomeResult">
@ -86,7 +91,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
check_man_code, check_man_name, check_time, check_result, status, attr1,
attr2, attr3, attr4, create_by, create_time, update_by, update_time,
factory_code, del_flag , check_type,sample_quality,noOk_quality,
aNoOkquality,bNoOkquality,cNoOkquality,reason,product_type
aNoOkquality,bNoOkquality,cNoOkquality,reason,product_type,
confirm,confirm_man_code,confirm_man_name,confirm_remark ,confirm_time
from qc_check_task
</sql>
@ -167,7 +173,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
qct.confirm_man_name confirmManName
from qc_check_task qct
left join pro_order_workorder pow on qct.order_no = pow.workorder_code
where check_type = 'checkTypeSCXJ'
where check_type = 'checkTypeSCXJ' and qct.del_flag = '0' and pow.del_flag = '0'
and CONVERT(varchar(10),income_time, 120) = CONVERT(varchar(10),GETDATE(), 120)
and pow.status = 'w2' and pow.parent_order = '0'
group by qct.factory_code,

@ -282,9 +282,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
qctd.rule_name, qctd.project_no,qctd.actual_value
from qc_check_task qct
left join qc_check_task_detail qctd on qct.record_id = qctd.belong_to
where qct.check_type = 'checkTypeLL' and qctd.property_code = '1' and qct.check_time is not null
where qct.check_type = #{checkType} and qctd.property_code = '1' and qct.check_time is not null
<if test="ymArrayStart != null "> and CONVERT(varchar(10),qct.income_time, 120) >= CONVERT(varchar(10),#{ymArrayStart}, 120)</if>
<if test="ymArrayEnd != null "> and CONVERT(varchar(10),#{ymArrayEnd}, 120)>=CONVERT(varchar(10),qct.income_time, 120)</if>
<if test="projectNoArray != null "> and qctd.project_id in(
<foreach collection="projectNoArray" separator="," item="projectId">
#{projectId}
</foreach>
)
</if>
<if test="orderNo != null ">
and qct.order_no = #{orderNo}
</if>
<if test="materialCode != null ">
and qct.material_code = #{materialCode}
</if>
<if test="supplierCode != null ">
and qct.supplier_code = #{supplierCode}
</if>
) t
WHERE t.material_code = q.material_code and t.project_no = q.project_no and t.ymdms=q.ymdms
FOR xml path('')
@ -297,13 +313,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
qctd.rule_name,qctd.project_no,qctd.actual_value
from qc_check_task qct
left join qc_check_task_detail qctd on qct.record_id = qctd.belong_to
where qct.check_type = 'checkTypeLL' and qctd.property_code = '1' and qct.check_time is not null
where qct.check_type = #{checkType} and qctd.property_code = '1' and qct.check_time is not null
<if test="ymArrayStart != null "> and CONVERT(varchar(10),qct.income_time, 120) >= CONVERT(varchar(10),#{ymArrayStart}, 120)</if>
<if test="ymArrayEnd != null "> and CONVERT(varchar(10),#{ymArrayEnd}, 120)>=CONVERT(varchar(10),qct.income_time, 120)</if>
<if test="projectNoArray != null "> and qctd.project_id in(
<foreach collection="projectNoArray" separator="," item="projectId">
#{projectId}
</foreach>
)
</if>
<if test="orderNo != null ">
and qct.order_no = #{orderNo}
</if>
<if test="materialCode != null ">
and qct.material_code = #{materialCode}
</if>
<if test="supplierCode != null ">
and qct.supplier_code = #{supplierCode}
</if>
) q
GROUP BY q.material_code,q.material_name, q.ymdms,q.rule_name,q.project_no
</select>
<select id="getProjectList" resultType="com.op.quality.domain.QcStaticTable">
select qcp.id recordId,
qcp.rule_name ruleName
from qc_check_type_project qctp
left join qc_check_project qcp on qctp.project_id = qcp.id
where qctp.type_id = #{checkType} and qctp.property_code = '1'
and qctp.material_code is null
</select>
</mapper>

@ -199,7 +199,7 @@ public class BaseEquipmentController extends BaseController {
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, null);
workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, null);
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();

Loading…
Cancel
Save