yangys
2024-04-02 1a77b1a7c072b136925d6d73c4d8f017ca016e3a
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
<?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.qianwen.smartman.modules.andon.mapper.AndonTypeMapper">
 
    <select id="andonTypeList" resultType="com.qianwen.smartman.modules.andon.vo.AndonTypeVO">
        select bat.id,
               bat.code,
               bat.name,
               bat.remark,
               count(bdat.id) as bindingCount
        from blade_andon_type bat
                 left join blade_device_andon_type bdat on bat.id = bdat.andon_type_id and bdat.is_deleted = 0
        where bat.is_deleted = 0
        <if test="keyword != null and keyword != ''">
            and (bat.code like CONCAT(#{keyword}, '%')
            or bat.name like CONCAT(#{keyword}, '%'))
        </if>
        group by bat.id, bat.code, bat.name, bat.remark, bat.create_time
        order by bat.create_time desc, bat.code desc
    </select>
 
    <select id="allDeviceTypes" resultType="com.qianwen.smartman.modules.andon.vo.BindingDeviceTypeVO">
        select bdt.code,
               bdt.name
        from blade_device_type bdt
                 left join blade_device_andon_type bdat on bdt.id = bdat.device_type_id and bdat.is_deleted = 0
        where bdat.andon_type_id = #{typeId}
        order by bdt.name asc
    </select>
 
    <select id="workBanding" resultType="com.qianwen.smartman.modules.andon.vo.AndonTypeVO">
        select bat.id,
               bat.code,
               bat.name,
               bat.remark
        from blade_andon_type bat
                 left join blade_device_andon_type bdat on bdat.andon_type_id = bat.id and bdat.is_deleted = 0
                 left join blade_device_type bdt on bdat.device_type_id = bdt.id and bdt.is_deleted = 0
                 left join blade_machine bm on bdt.id = bm.machine_type_id and bm.is_deleted = 0
                 left join blade_workstation_of_machine bwom on bm.id = bwom.machine_id
        where bat.is_deleted = 0
          and bwom.workstation_id = #{workstationId}
    </select>
 
    <select id="detail" resultType="com.qianwen.smartman.modules.andon.vo.AndonTypeDetailVO">
        select bat.id,
               bat.code,
               bat.name,
               bat.remark,
        <if test="_databaseId=='mysql'">
               group_concat(bdt.id)   deviceIds,
               group_concat(bdt.code) deviceCodes,
               group_concat(bdt.name) deviceNames
        </if>
        <if test="_databaseId=='dm'">
            WM_CONCAT(bdt.id)   deviceIds,
            WM_CONCAT(bdt.code) deviceCodes,
            WM_CONCAT(bdt.name) deviceNames
        </if>
        <if test="_databaseId=='oracle'">
            LISTAGG ( DISTINCT (bdt.id), ',' ) WITHIN GROUP ( ORDER BY bdt.id ) AS deviceIds,
            LISTAGG ( DISTINCT (bdt.code), ',' ) WITHIN GROUP ( ORDER BY bdt.code ) AS deviceCodes,
            LISTAGG ( DISTINCT (bdt.name), ',' ) WITHIN GROUP ( ORDER BY bdt.name ) AS deviceNames
        </if>
        from blade_andon_type bat
                 left join blade_device_andon_type bdat on bat.id = bdat.andon_type_id and bdat.is_deleted = 0
                 left join blade_device_type bdt on bdat.device_type_id = bdt.id and bdt.is_deleted = 0
        where bat.is_deleted = 0
          and bat.id = #{typeId}
        group by bat.id, bat.code, bat.name, bat.remark
    </select>
</mapper>