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
<?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.InspectionOrderMapper">
 
    <!--检验委托单分页查询-->
    <select id="pageInspectionOrder" resultType="com.ruoyi.process.dto.InspectionOrderDto">
        select *
        from (
            select cio.*,
                   case when cio.ins_order_id is null then 0 else 1 end as binding_status,
                   io.state as order_state,
                   io.ins_result as ins_result,
                   case
                       when cio.ins_order_id is null then null
                       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,
                   case
                       when cio.file_url is not null and trim(cio.file_url) != '' then 2
                       when approved_report.id is not null then 1
                       else 0
                   end as report_status
            from cnas_inspection_order cio
                     left join ins_order io on cio.ins_order_id = io.id
                     left join (select max(id) as id, ins_order_id
                                from ins_report
                                where is_ratify = 1
                                group by ins_order_id) approved_report on approved_report.ins_order_id = io.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 = io.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 = io.id
            order by cio.create_time desc
        ) a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <!--成品下单选择尚未绑定的检验委托单-->
    <select id="pageUnboundInspectionOrder" resultType="com.ruoyi.process.pojo.InspectionOrder">
        select *
        from (
            select *
            from cnas_inspection_order
            where ins_order_id is null
            order by create_time desc
        ) a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>