cnas-process/src/main/resources/mapper/InspectionOrderMapper.xml
@@ -5,21 +5,53 @@
    <!--检验委托单分页查询-->
    <select id="pageInspectionOrder" resultType="com.ruoyi.process.dto.InspectionOrderDto">
        select *
        from (select *
        from cnas_inspection_order
        order by create_time desc) a
        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="getInsOrderOnInspection" resultType="com.ruoyi.inspect.pojo.InsOrder">
    <!--成品下单选择尚未绑定的检验委托单-->
    <select id="pageUnboundInspectionOrder" resultType="com.ruoyi.process.pojo.InspectionOrder">
        select *
        from (select *
        from ins_order
        where state = 4 and ifs_inventory_id is null
        order by entrust_code desc) a
        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>