<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
~
|
~ Copyright (c) 2018-2025, ztt All rights reserved.
|
~
|
~ Redistribution and use in source and binary forms, with or without
|
~ modification, are permitted provided that the following conditions are met:
|
~
|
~ Redistributions of source code must retain the above copyright notice,
|
~ this list of conditions and the following disclaimer.
|
~ Redistributions in binary form must reproduce the above copyright
|
~ notice, this list of conditions and the following disclaimer in the
|
~ documentation and/or other materials provided with the distribution.
|
~ Neither the name of the pig4cloud.com developer nor the names of its
|
~ contributors may be used to endorse or promote products derived from
|
~ this software without specific prior written permission.
|
~ Author: ztt
|
~
|
-->
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.chinaztt.mes.quality.mapper.TestReportMapper">
|
|
<resultMap id="reportMap" type="com.chinaztt.mes.quality.entity.TestReport">
|
<id property="id" column="id"/>
|
<result property="testTaskId" column="test_task_id"/>
|
<result property="testResult" column="test_result"/>
|
<result property="testTime" column="test_time"/>
|
<result property="testUser" column="test_user"/>
|
<result property="testCount" column="test_count"/>
|
<result property="remark" column="remark"/>
|
<result property="orderNo" column="order_no"/>
|
|
<result property="partNo" column="part_no"/>
|
<result property="partDesc" column="part_desc"/>
|
<result property="partSpecs" column="part_specs"/>
|
<result property="templateNo" column="template_no"/>
|
<result property="templateDesc" column="template_desc"/>
|
</resultMap>
|
<resultMap id="reportMapDTO" type="com.chinaztt.mes.quality.dto.ReportDTO">
|
<id property="id" column="id"/>
|
<result property="testTaskId" column="test_task_id"/>
|
<result property="testResult" column="test_result"/>
|
<result property="testTime" column="test_time"/>
|
<result property="testUser" column="test_user"/>
|
<result property="testCount" column="test_count"/>
|
<result property="remark" column="remark"/>
|
<result property="orderNo" column="order_no"/>
|
|
<result property="partNo" column="part_no"/>
|
<result property="partDesc" column="part_desc"/>
|
<result property="partSpecs" column="part_specs"/>
|
<result property="templateNo" column="template_no"/>
|
<result property="templateDesc" column="template_desc"/>
|
<result property="partBath" column="part_bath"/>
|
<result property="number" column="number"/>
|
<result property="remarks" column="remarks"/>
|
<result property="updateUser" column="update_user"/>
|
<result property="updateTime" column="update_time"/>
|
<result property="type" column="type"/>
|
</resultMap>
|
<select id="selectDtoById" resultType="com.chinaztt.mes.quality.dto.ReportDTO">
|
select * from quality_test_report where id=#{id} and quality_test_report.active=true
|
</select>
|
|
<sql id="reportPage">
|
SELECT
|
qtr.*,
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
where qtr.active=true
|
</sql>
|
<select id="getReportPage" resultMap="reportMap">
|
select * from (<include refid="reportPage"/>) a
|
<if test="ew.emptyOfWhere == false">
|
<where>
|
${ew.SqlSegment}
|
</where>
|
|
</if>
|
</select>
|
|
<select id="getReportAndItemsPage" resultType="Map">
|
SELECT
|
a.*,
|
o.*
|
FROM
|
(SELECT
|
qtr.*,
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
where qtr.active=true and B.qtpl_desc=#{templateName}) a
|
LEFT JOIN (
|
SELECT
|
<foreach collection="nameList" item="name" index="index">
|
MAX(CASE WHEN qtri.test_items=#{name} THEN qtri.test_value ELSE '' END) as "#{name}",
|
</foreach>
|
qtri.test_report_id
|
FROM
|
quality_test_report_items qtri
|
left join quality_test_report qtr on qtri.test_report_id=qtr."id"
|
group by qtri.test_report_id
|
) o
|
ON a."id"=o.test_report_id
|
|
</select>
|
<select id="getTestResultPage" resultMap="reportMapDTO">
|
SELECT
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
where qtr.active=true
|
<if test="ew.emptyOfWhere == false">
|
and ${ew.SqlSegment}
|
</if>
|
GROUP BY
|
A.part_no ,
|
A.description ,
|
A.specs ,
|
B.qtpl_no ,
|
B.qtpl_desc
|
</select>
|
<select id="getTestResult" resultType="com.chinaztt.mes.quality.dto.ReportItemsDTO">
|
select DISTINCT test_items from quality_test_report_items where test_report_id in (
|
SELECT DISTINCT
|
A.test_report_id
|
FROM
|
quality_test_report_items A,
|
quality_test_report b,
|
quality_inspection_task T
|
WHERE
|
T.part_id =#{id}
|
AND A.test_report_id = b.ID
|
AND b.test_task_id = T.ID
|
)
|
</select>
|
<select id="getTestValue" resultType="com.alibaba.fastjson.JSONObject">
|
SELECT
|
*
|
FROM
|
crosstab ( 'SELECT
|
A.test_report_id,
|
E.part_no,
|
F.qtpl_desc,
|
E.part_name,
|
E.specs,
|
b.test_task_id ,
|
b.test_result,
|
b.test_time ,
|
b.test_user ,
|
b.test_count,
|
b.remark,
|
b.order_no ,
|
A.test_items ,
|
A.test_value
|
FROM
|
quality_test_report_items A,
|
quality_test_report b,
|
quality_inspection_task T,
|
basic_part E,
|
quality_template F
|
WHERE
|
T.part_id = ${partId}
|
AND A.test_report_id = b.ID
|
AND b.test_task_id = T.ID
|
AND E.id = T.part_id
|
AND F.id = T.template_id', '
|
select DISTINCT test_items from quality_test_report_items where test_report_id in (
|
SELECT DISTINCT
|
A.test_report_id
|
FROM
|
quality_test_report_items A,
|
quality_test_report b,
|
quality_inspection_task T
|
WHERE
|
T.part_id = ${partId}
|
AND A.test_report_id = b.ID
|
AND b.test_task_id = T.ID)' ) AS ( ${query.testItems} );
|
</select>
|
<select id="getTest" resultType="com.chinaztt.mes.quality.dto.ReportItemsDTO">
|
SELECT array_to_string(array_agg(test_items),',') as test_items FROM(
|
SELECT
|
'"test_report_id" int8,"partNo" VARCHAR,"templateDesc" VARCHAR,"partDesc" VARCHAR,"partSpecs" VARCHAR,"testTaskId" int8,"testResult" VARCHAR,"testTime" TIMESTAMP,"testUser" VARCHAR,"testCount" VARCHAR,"remark" VARCHAR,"orderNo" VARCHAR' AS test_items UNION ALL
|
SELECT DISTINCT
|
'"' || test_items || '" VARCHAR'
|
FROM
|
quality_test_report_items
|
WHERE
|
test_report_id IN (
|
SELECT DISTINCT A
|
.test_report_id
|
FROM
|
quality_test_report_items A,
|
quality_test_report b,
|
quality_inspection_task T
|
WHERE
|
T.part_id = #{id}
|
AND A.test_report_id = b.ID
|
AND b.test_task_id = T.ID
|
)
|
)E
|
</select>
|
<select id="getTestReportProcessingPage" resultMap="reportMapDTO">
|
SELECT
|
qtr.*,
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc,
|
D."number",
|
D.remarks,
|
D."type",
|
D.update_time,
|
D.update_user
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
LEFT JOIN quality_test_report_processing D ON D.quality_test_report_id = qtr."id"
|
where qtr.active=true
|
AND qtr.test_result ='不合格'
|
<if test="ew.emptyOfWhere == false">
|
and ${ew.SqlSegment}
|
</if>
|
</select>
|
<select id="getReportById" resultMap="reportMapDTO">
|
SELECT
|
qtr.*,
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc,
|
D."number",
|
D.remarks,
|
D."type",
|
D.update_time,
|
D.update_user
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
LEFT JOIN quality_test_report_processing D ON D.quality_test_report_id = qtr."id"
|
where qtr.active=true
|
AND qtr."id" =#{id}
|
</select>
|
<select id="getTestReportResult" resultMap="reportMapDTO">
|
SELECT
|
A.part_no part_no,
|
A.description part_desc,
|
A.specs part_specs,
|
B.qtpl_no template_no,
|
B.qtpl_desc template_desc
|
FROM
|
quality_test_report qtr
|
LEFT JOIN quality_inspection_task C ON qtr.test_task_id = C."id"
|
LEFT JOIN basic_part A ON C.part_id =A."id"
|
LEFT JOIN quality_template B ON C.template_id =B."id"
|
where qtr.active=true
|
GROUP BY
|
A.part_no ,
|
A.description ,
|
A.specs ,
|
B.qtpl_no ,
|
B.qtpl_desc
|
</select>
|
</mapper>
|