刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
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
<?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="jnpf.limsMapper.LimsWendingxingWanchengMapper">
 
    <resultMap id="jihuaZhixingCountMap" type="jnpf.limsEntity.LimsWendingxingJihuaZhixingCountRow">
        <id property="kaocaJihuaId" column="kaoca_jihua_id"/>
        <result property="totalCount" column="total_count"/>
        <result property="yizhixingCount" column="yizhixing_count"/>
    </resultMap>
 
    <resultMap id="jianyanCountMap" type="jnpf.limsEntity.LimsWendingxingJianyanCountRow">
        <id property="wendingxingJiluId" column="wendingxing_jilu_id"/>
        <result property="qingyandanCount" column="qingyandan_count"/>
        <result property="jianyanXiangCount" column="jianyan_xiang_count"/>
        <result property="jianyanJieguoLuruCount" column="jianyan_jieguo_luru_count"/>
    </resultMap>
 
    <!-- 用主键游标分页,避免前一批状态更新后结果集收缩导致 OFFSET 跳行。 -->
    <select id="selectJihuaZhixingPage" resultMap="jihuaZhixingCountMap">
        SELECT a.kaoca_jihua_id,
               COUNT(*) AS total_count,
               COUNT(*) FILTER (WHERE a.shifou_yizhixing = 'yes') AS yizhixing_count
        FROM lims_wendingxing_kaoca_jihua_zhouqi a
        INNER JOIN lims_wendingxing_kaoca_jihua b
                ON b.f_id = a.kaoca_jihua_id
        WHERE a.f_delete_mark IS NULL
          AND b.f_delete_mark IS NULL
          AND b.biz_status IN ('enabled', 'end_checking')
          AND a.shifou_jixu_zhixing &lt;&gt; 'no'
          <if test="lastJihuaId != null and lastJihuaId != ''">
              AND a.kaoca_jihua_id &gt; #{lastJihuaId}
          </if>
        GROUP BY a.kaoca_jihua_id
        ORDER BY a.kaoca_jihua_id ASC
        LIMIT #{pageSize}
    </select>
 
    <select id="selectJianyanCounts" resultMap="jianyanCountMap">
        WITH filtered_a AS (
            SELECT DISTINCT f_id, wendingxing_jilu_id
            FROM lims_qingyandan
            WHERE qingyan_fenlei = 'wendingxing'
              AND wendingxing_jilu_id IN
              <foreach collection="jihuaIds" item="id" open="(" separator="," close=")">
                  #{id}
              </foreach>
        )
        SELECT a.wendingxing_jilu_id,
               COUNT(DISTINCT (a.f_id)) AS qingyandan_count,
               COUNT(b.f_id) AS jianyan_xiang_count,
               COUNT(b.f_id) FILTER (
                   WHERE NULLIF(BTRIM(b.jianyan_jieguo), '') IS NOT NULL
               ) AS jianyan_jieguo_luru_count
        FROM filtered_a a
        LEFT JOIN public.lims_jianyan_xiang b
               ON b.qingyandan_id = a.f_id
        GROUP BY a.wendingxing_jilu_id
        ORDER BY a.wendingxing_jilu_id
    </select>
 
    <select id="updateJihuaYiwanchengReturning" resultType="java.lang.String">
        UPDATE lims_wendingxing_kaoca_jihua
        SET biz_status = 'yiwancheng'
        WHERE f_delete_mark IS NULL
          AND biz_status IN ('enabled', 'end_checking')
          AND f_id IN
          <foreach collection="jihuaIds" item="id" open="(" separator="," close=")">
              #{id}
          </foreach>
        RETURNING f_id
    </select>
 
    <select id="selectCompletionDetails" resultType="jnpf.limsEntity.LimsStabilityCompletionRow">
        SELECT p.f_id AS id,
               p.f_tenant_id AS tenantId,
               p.f_creator_user_id AS creatorUserId,
               p.bianhao AS planCode,
               p.kaoca_mingcheng AS planName,
               p.yangpin_mingcheng AS sampleName,
               STRING_AGG(DISTINCT NULLIF(c.pihao, ''), '、') AS batchNo,
               p.zhouqi_leixing_id AS stabilityType,
               COUNT(c.f_id) AS cycleCount
        FROM lims_wendingxing_kaoca_jihua p
        LEFT JOIN lims_wendingxing_kaoca_jihua_zhouqi c
               ON c.kaoca_jihua_id = p.f_id
              AND (c.f_delete_mark IS NULL OR c.f_delete_mark &lt;&gt; 1)
              AND (c.shifou_jixu_zhixing IS NULL OR c.shifou_jixu_zhixing &lt;&gt; 'no')
        WHERE p.f_id IN
        <foreach collection="jihuaIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        GROUP BY p.f_id, p.f_tenant_id, p.f_creator_user_id, p.bianhao,
                 p.kaoca_mingcheng, p.yangpin_mingcheng, p.zhouqi_leixing_id
    </select>
</mapper>