|
|
|
@ -558,6 +558,102 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService {
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public QcStaticTable getDLTableCPKInfo(QcStaticTable qcStaticTable) {
|
|
|
|
|
QcStaticTable dto = new QcStaticTable();
|
|
|
|
|
//第一列日期
|
|
|
|
|
List<String> days = this.getDays(qcStaticTable.getYmArrayStart(),
|
|
|
|
|
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));
|
|
|
|
|
//表头:第一行
|
|
|
|
|
List<String> colName1 = titleList.stream().map(QcStaticTable::getMaterialName).distinct().collect(Collectors.toList());
|
|
|
|
|
List<String> colCode1 = titleList.stream().map(QcStaticTable::getMaterialCode).distinct().collect(Collectors.toList());
|
|
|
|
|
dto.setTitleCol1(colName1);
|
|
|
|
|
//表头:第二行
|
|
|
|
|
List<String> colName2 = titleList.stream().map(QcStaticTable::getRuleName).distinct().collect(Collectors.toList());
|
|
|
|
|
List<String> colCode2 = titleList.stream().map(QcStaticTable::getProjectNo).distinct().collect(Collectors.toList());
|
|
|
|
|
dto.setTitleCol2(colName2);
|
|
|
|
|
|
|
|
|
|
//给折线图取上下限制
|
|
|
|
|
if(qcStaticTable.getProjectNoArray()!=null){
|
|
|
|
|
qcStaticTable.setProjectNo(qcStaticTable.getProjectNoArray()[0]);
|
|
|
|
|
QcStaticTable upandown = qcStaticTableMapper.getUpAndDown(qcStaticTable);
|
|
|
|
|
if(upandown!=null){
|
|
|
|
|
dto.setUpperDiff(upandown.getUpperDiff());
|
|
|
|
|
dto.setDownDiff(upandown.getDownDiff());
|
|
|
|
|
}else{
|
|
|
|
|
dto.setUpperDiff(BigDecimal.ZERO);
|
|
|
|
|
dto.setDownDiff(BigDecimal.ZERO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//cpk列表
|
|
|
|
|
List<HashMap> dxData = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (String day : days) {
|
|
|
|
|
HashMap result = new HashMap();
|
|
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
String key = colCode1.get(m) + "-" + colCode2.get(n) + "-" + day;
|
|
|
|
|
QcStaticTable avgdto = titleMap.get(key);
|
|
|
|
|
if (avgdto != null) {
|
|
|
|
|
String avgArrayStr = avgdto.getQuality().replace("[", "")
|
|
|
|
|
.replace("]", "")
|
|
|
|
|
.replace("\"", "");
|
|
|
|
|
List<String> avgArray = Arrays.asList(avgArrayStr.split(","));
|
|
|
|
|
double[] data = avgArray.stream()
|
|
|
|
|
.mapToDouble(Double::parseDouble) // 将String转换为double
|
|
|
|
|
.toArray(); // 转换为double数组 ;
|
|
|
|
|
double USL = dto.getUpperDiff().doubleValue();
|
|
|
|
|
double LSL = dto.getDownDiff().doubleValue();
|
|
|
|
|
double cpk = calculateCpk(data,USL,LSL);
|
|
|
|
|
BigDecimal cpkVal = new BigDecimal(Double.toString(cpk)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
result.put("mcode" + m + "Pcode" + n, cpkVal);
|
|
|
|
|
} else {
|
|
|
|
|
result.put("mcode" + m + "Pcode" + n, "0.00");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dxData.add(result);
|
|
|
|
|
}
|
|
|
|
|
dto.setDxData(dxData);
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算CPK
|
|
|
|
|
public static double calculateCpk(double[] data, double USL, double LSL) {
|
|
|
|
|
double mean = calculateMean(data);
|
|
|
|
|
double stdDev = calculateStandardDeviation(data);
|
|
|
|
|
double cpkUpper = (USL - mean) / (3 * stdDev);
|
|
|
|
|
double cpkLower = (mean - LSL) / (3 * stdDev);
|
|
|
|
|
return Math.min(cpkUpper, cpkLower);
|
|
|
|
|
}
|
|
|
|
|
// 计算均值
|
|
|
|
|
public static double calculateMean(double[] data) {
|
|
|
|
|
double sum = 0.0;
|
|
|
|
|
for (double a : data) {
|
|
|
|
|
sum += a;
|
|
|
|
|
}
|
|
|
|
|
return sum / data.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算标准差
|
|
|
|
|
public static double calculateStandardDeviation(double[] data) {
|
|
|
|
|
double mean = calculateMean(data);
|
|
|
|
|
double temp = 0;
|
|
|
|
|
for (double a : data) {
|
|
|
|
|
temp += (a - mean) * (a - mean);
|
|
|
|
|
}
|
|
|
|
|
return Math.sqrt(temp / (data.length - 1));
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public List<QcStaticTable> getProjectList(String checkType) {
|
|
|
|
|