liding
2026-11-05 d28a5401ac1e2995ec6de12a81395aa5d05b040a
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
<?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="com.ruoyi.process.mapper.InspectionOrderBindingMapper">
    <select id="lockRequestUser" resultType="java.lang.Integer">
        select id from `user` where id = #{userId} for update
    </select>
 
    <select id="selectByRequest" resultType="com.ruoyi.process.pojo.InspectionOrderBinding">
        select *
        from cnas_inspection_order_binding
        where request_user_id = #{userId} and request_id = #{requestId}
        limit 1
    </select>
 
    <select id="selectByOrderIdForUpdate" resultType="com.ruoyi.process.pojo.InspectionOrderBinding">
        select *
        from cnas_inspection_order_binding
        where ins_order_id = #{insOrderId} limit 1
        for
        update
    </select>
 
    <select id="pageBindings" resultType="com.ruoyi.process.dto.InspectionOrderBindingDto">
        select b.*, cio.inspection_order_code, io.entrust_code, io.state as order_state, io.ins_result,
               case
                   when total_product_counts.total_count is null or total_product_counts.total_count = 0 then '0%'
                   else concat(round(ifnull(approved_product_counts.approved_count, 0) /
                                     total_product_counts.total_count * 100, 2), '%')
               end as ins_progress,
               ifnull(report_counts.report_count, 0) as report_count
        from cnas_inspection_order_binding b
        join cnas_inspection_order cio on cio.inspection_order_id = b.inspection_order_id
        left join ins_order io on io.id = b.ins_order_id
        left join (select ins_sample.ins_order_id, count(*) as total_count
                   from ins_product join ins_sample on ins_product.ins_sample_id = ins_sample.id
                   where ins_product.state = 1 group by ins_sample.ins_order_id) total_product_counts
                  on total_product_counts.ins_order_id = b.ins_order_id
        left join (select ins_sample.ins_order_id, count(*) as approved_count
                   from ins_product join ins_sample on ins_product.ins_sample_id = ins_sample.id
                   where ins_product.state = 1 and ins_product.ins_result is not null
                   group by ins_sample.ins_order_id) approved_product_counts
                  on approved_product_counts.ins_order_id = b.ins_order_id
        left join (select ins_order_id, count(*) as report_count from ins_report
                   where is_ratify = 1 group by ins_order_id) report_counts
                  on report_counts.ins_order_id = b.ins_order_id
        where b.inspection_order_id = #{inspectionOrderId}
        <if test="includeDeleted == null or includeDeleted == false">
            and b.order_deleted = 0
        </if>
        order by b.create_time desc, b.id desc
    </select>
</mapper>