李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?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>