baoshiwei
2025-05-20 eafecc3ac0227960f2b8fa377be27f066e10e50f
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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.shlanbao.qms.mapper.LbTestResultMapper">
    <!-- 根据产品型号、批次号、检测项目和 createTime 时间段查询测试结果 -->
    <select id="selectByProdModelAndConditions" resultType="cn.shlanbao.qms.domain.vo.LbTestResultVo">
        SELECT tr.*
        FROM lb_test_result tr
        JOIN lb_batch b ON tr.batch_code = b.batch_code
        <where>
            <if test="ew.prodModel != null and ew.prodModel != ''">
                AND b.prod_model = #{ew.prodModel}
            </if>
            <if test="ew.batchCode != null and ew.batchCode != ''">
                AND tr.batch_code LIKE CONCAT('%', #{ew.batchCode}, '%')
            </if>
            <if test="ew.testItem != null and ew.testItem != ''">
                <choose>
                    <when test="ew.testItem.contains(','.toString())">
                        AND tr.test_item IN
                        <foreach collection="ew.testItem.split(',')" item="item" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </when>
                    <otherwise>
                        AND tr.test_item = #{ew.testItem}
                    </otherwise>
                </choose>
            </if>
            <if test="ew.params.beginCreateTime != null and ew.params.endCreateTime != null">
                AND tr.create_time BETWEEN
                    DATE_FORMAT(#{ew.params.beginCreateTime}, '%Y-%m-%d 00:00:00') AND
                    DATE_FORMAT(#{ew.params.endCreateTime}, '%Y-%m-%d 23:59:59')
            </if>
 
        </where>
        ORDER BY tr.create_time ASC
    </select>
</mapper>