李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
<?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.chinaztt.mes.quality.mapper.AuditingMapper">
    <resultMap id="auditingMap" type="com.chinaztt.mes.quality.dto.AuditingDetailReportDTO">
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="unit" column="unit"/>
        <result property="sn" column="sn"/>
        <result property="productQuantity" column="product_quantity"/>
        <result property="inspQuantity" column="insp_quantity"/>
        <result property="checkStatus" column="check_status"/>
        <result property="isQualified" column="is_qualified"/>
        <result property="processMode" column="process_mode"/>
        <result property="isPackaging" column="is_packaging"/>
        <result property="isStock" column="is_stock"/>
        <result property="isOut" column="is_out"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
 
    <select id="getAuditingDetail" resultMap="auditingMap">
        select bp.part_no                                                                            as part_no,
               bp.part_name                                                                          as part_name,
               bp.unit                                                                               as unit,
               ppo.out_batch_no                                                                      as sn,
               ppo.product_qty                                                                       as product_quantity,
               case when qr.check_state = '01checked' then ppo.product_qty else 0 end                as insp_quantity,
               case when qr.check_state = '01checked' then '是' else '否' end                        as check_status,
               case
                   when qr.check_state = '00uncheck' then '待检测'
                   when qr.check_state = '01checked' and qst.is_qualified is true then '合格'
                   when qr.check_state = '01checked' and qst.is_qualified is false then '不合格' end as is_qualified,
               case
                   when qr.check_state = '01checked' and qupp.process_mode = '0' then '返工'
                   when qr.check_state = '01checked' and qupp.process_mode = '1' then '返修'
                   when
                       qr.check_state = '01checked' and qupp.process_mode = '2' then '报废'
                   when qr.check_state = '01checked' and qupp.process_mode = '3' then '让步放行' end as process_mode,
               case when wp.id is null then '否' else '是' end                                       as is_packaging,
               case when wp.is_confirm is true then '是' else '否' end                               as is_stock,
               ppm.create_time                                                                       as create_time
        from production_product_main ppm
                 left join production_product_output ppo on ppm.id = ppo.product_main_id
                 left join quality_apply_part qap on qap.system_no = ppo.system_no
                 left join quality_unqualified_process qupp on qap.id = qupp.apply_part_id
                 left join quality_apply qa on qa.id = qap.apply_id
                 left join quality_report qr on qr.id = qap.report_id
                 left join (select qs.*
                            from quality_result qs
                            where qs.id in (select max(id)
                                            from quality_result qs2
                                            group by qs2.part_batch_no)) qst
                           on qst.system_no = qap.system_no and qa.apply_type = qst.apply_type
                 left join warehouse_packaging wp on wp.part_batch_no = ppo.out_batch_no
                 left join basic_part bp on bp.id = ppo.part_id
        where ppm.state = '02submitted'
          and bp.id in (select distinct part_id from plan_master_production_schedule)
          and qst.id is not null
          and ppm.create_time  <![CDATA[ >= ]]> #{begin}
          and ppm.create_time  <![CDATA[ <= ]]> #{end};
    </select>
</mapper>