质量CPK

master
zhaoxiaolin 8 months ago
parent a6cf1c1632
commit af49b3dead

@ -343,6 +343,12 @@ public class QcStaticTableController extends BaseController {
return qcStaticTableService.getDLTableAvgInfo(qcStaticTable);
}
@GetMapping("/getDLTableCPKInfo")
@Log(title = "定量值分析CPK", businessType = BusinessType.QUERY)
public QcStaticTable getDLTableCPKInfo(QcStaticTable qcStaticTable) {
return qcStaticTableService.getDLTableCPKInfo(qcStaticTable);
}
@PostMapping("/exportDLTable")
public void exportDLTable(HttpServletResponse response, QcStaticTable qcStaticTable) {

@ -8,6 +8,7 @@ import com.op.quality.domain.QcProCheck;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
/**
@ -43,4 +44,6 @@ public interface QcProCheckMapper {
List<QcProCheck> getHFnames(QcProCheck qcProCheck);
String getWeightInfo(QcCheckTaskDetail qcCheckTaskDetail);
BigDecimal getMesReportQuality(String orderNo);
}

@ -46,5 +46,7 @@ public interface IQcStaticTableService {
QcStaticTable getDLTableAvgInfo(QcStaticTable qcStaticTable);
QcStaticTable getDLTableCPKInfo(QcStaticTable qcStaticTable);
List<QcStaticTable> getProjectList(String checkType);
}

@ -133,7 +133,12 @@ public class QcProCheckServiceImpl implements QcProCheckService {
if (StringUtils.isEmpty(dto.getWorkorderCodeSap())) {
dto.setWorkorderCodeSap(dto.getOrderNo());
}
if("checkTypeCP".equals(qcCheckTaskIncome.getCheckType())){//成品检验数量取实际产量
dto.setQuality(qcProCheckMapper.getMesReportQuality(qcCheckTaskIncome.getOrderNo()));
}
}
return dtos;
}

@ -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) {

@ -204,7 +204,7 @@
from qc_check_task where record_id = #{recordId}
</select>
<select id="getXJTaskInfo" resultType="com.op.quality.domain.QcCheckReportIncome">
SELECT
SELECT top 1
c.check_type checkType,
c.quality,
c.unit,
@ -217,11 +217,7 @@
FROM
qc_check_task c
where c.check_type='checkTypeSCXJ' and c.order_no = #{orderNo}
GROUP BY
c.order_no,c.supplier_name,c.supplier_code,c.material_name,
c.material_code,c.income_time,
c.check_type,
c.quality,c.unit
order by c.income_time desc
</select>
<select id="getLastXJTaskInfo" resultType="com.op.quality.domain.QcCheckReportIncome">
SELECT

@ -276,12 +276,13 @@
<if test="checkManCode != null and checkManCode != ''">and qctu.check_man_code = #{checkManCode}</if>
<if test="checkStatus != null and checkStatus != ''">and qct.check_status in (${checkStatus})</if>
and (
CONVERT(varchar(10),qct.create_time, 120) = CONVERT(varchar(10),GETDATE(), 120)
or CONVERT(varchar(10),qct.create_time, 120) = CONVERT(varchar(10),DATEADD(DAY, -1, GETDATE()), 120)
<!--CONVERT(varchar(10),qct.create_time, 120) = CONVERT(varchar(10),GETDATE(), 120) or-->
CONVERT(varchar(10),qct.create_time, 120) >= CONVERT(varchar(10),DATEADD(DAY, -1, GETDATE()), 120)
)
</where>
order by qct.create_time desc
</select>
<select id="getQcProCheckList" resultType="com.op.quality.domain.QcProCheck">
SELECT q1.machine_code AS machineCode,
MIN(q1.machine_name) AS machineName,
@ -390,5 +391,10 @@
select actual_value from qc_check_task_detail
where record_id = #{recordId}
</select>
<select id="getMesReportQuality" resultType="java.math.BigDecimal">
select sum(quantity_feedback) from mes_report_work
where workorder_code = #{orderNo}
and del_flag='0' and parent_order = '0'
</select>
</mapper>

@ -49,7 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.wx_id,
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password,
u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.wx_id,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u

Loading…
Cancel
Save