zzw
2023-12-01 e023474fc9bcc726ed558a0623f1316dddc13152
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
73
74
75
76
77
78
79
80
81
82
83
84
85
<?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.zt.modules.sys.dao.SysDeptDao">
 
    <select id="getAll" resultType="com.zt.core.sys.model.SysDept">
        select a.dept_id as id
             ,a.dept_name as name
             ,a.parent_id as pid
             ,a.dept_code as code
             ,a.ancestors as pids
             ,a.dept_type as nature
             ,a.order_num as sort
             ,(select t2.dept_name from SYS_DEPT t2 where t2.dept_id=a.parent_id) parentName
             ,(select t2.dept_name from SYS_DEPT t2 where t2.dept_id = a.parent_id) companyName
        from SYS_DEPT a
        where a.del_flag = 0
        order by a.dept_type, a.order_num asc
    </select>
 
    <select id="getList" resultType="com.zt.core.sys.model.SysDept">
        select a.dept_id as id
        ,a.dept_name as name
        ,a.dept_code as code
        ,a.parent_id as pid
        ,a.ancestors as pids
        ,a.dept_type as nature
        ,a.order_num as sort
        ,(select t2.dept_name from SYS_DEPT t2 where t2.dept_id=a.parent_id) parentName
        from SYS_DEPT a
        where a.del_flag=0
<!--        <if test="isCompany != null">
            and a.is_company = #{isCompany}
        </if>
        <if test="companyId != null">
            and a.company_id = #{companyId}
        </if>
        <if test="tenantId != null">
            and a.tenant_id = #{tenantId}
        </if>-->
        <if test="deptIds != null">
            and a.id in
            <foreach item="id" collection="deptIds" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        order by a.order_num asc
    </select>
 
    <select id="getById" resultType="com.zt.core.sys.model.SysDept">
        select a.dept_id as id
             ,a.dept_name as name
             ,a.dept_code as code
             ,a.parent_id as pid
             ,a.ancestors as pids
             ,a.dept_type as nature
             ,a.order_num as sort
             ,(select t2.dept_name from SYS_DEPT t2 where t2.dept_id=a.parent_id) parentName
        from SYS_DEPT a
        where a.del_flag=0
            and a.dept_id = #{value}
    </select>
 
    <select id="getListByParent" resultType="com.zt.core.sys.model.SysDept">
        select a.dept_id as id
        ,a.dept_name as name
        ,a.dept_code as code
        ,a.parent_id as pid
        ,a.ancestors as pids
        ,a.dept_type as nature
        ,a.order_num as sort
        ,(select t2.dept_name from SYS_DEPT t2 where t2.dept_id=a.parent_id) parentName
        from SYS_DEPT a
        where a.del_flag=0
        <if test="pCode != null">
            and parent_id in (select dept_id from SYS_DEPT where  dept_CODE= #{pCode})
        </if>
        <if test="code != null">
            and  dept_CODE= #{code}
        </if>
        <if test="pId != null">
            and parent_id = #{pId}
        </if>
    </select>
</mapper>