郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?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.gkhy.safePlatform.account.repository.DepartmentInfoRepository" >
 
    <resultMap id="DepartmentDO" type="com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfoDO">
        <result property="id" column="id"/>
        <result property="name" column="name" />
        <result property="code" column="code" />
        <result property="info" column="info" />
        <result property="parentId" column="parent_id" />
        <result property="status" column="status" />
        <result property="level" column="level" />
    </resultMap>
 
    <resultMap id="DepartmentInfo" type="com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo">
        <result property="id" column="id"/>
        <result property="name" column="name" />
        <result property="code" column="code" />
        <result property="info" column="info" />
        <result property="parentId" column="parent_id" />
        <result property="gmtCreate" column="gmt_create" />
        <result property="gmtModified" column="gmt_modified" />
        <result property="status" column="status"/>
        <result property="level" column="level"/>
    </resultMap>
 
    <insert id="insertDepartmentInfo"
            parameterType="com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo"
            keyProperty="id"
            useGeneratedKeys="true">
        insert into
        sys_department
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="name != null" >
                name,
            </if>
            <if test="code != null" >
                code,
            </if>
            <if test="info != null" >
                info,
            </if>
            <if test="parentId != null" >
                parent_id,
            </if>
            <if test="status != null" >
                status,
            </if>
            <if test="level != null" >
                level,
            </if>
            <if test="gmtCreate != null" >
                gmt_create,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="name != null" >
                #{name},
            </if>
            <if test="code != null" >
                #{code},
            </if>
            <if test="info != null" >
                #{info},
            </if>
            <if test="parentId != null" >
                #{parentId},
            </if>
            <if test="status != null" >
                #{status},
            </if>
            <if test="level != null" >
                #{level},
            </if>
            <if test="gmtCreate != null" >
                #{gmtCreate},
            </if>
        </trim>
 
 
</insert>
    <update id="updateDepartmentInfo" parameterType="com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfoDO">
        update sys_department
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="code != null">
                code = #{code},
            </if>
            <if test="info != null">
                info = #{info},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="level != null">
                level = #{level},
            </if>
            <if test="parentId != null">
                parent_id = #{parentId},
            </if>
            <if test="gmtModified != null" >
                gmt_modified = #{gmtModified},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
 
    </update>
 
 
    <select id="getDepartmentListByStatus"
            parameterType="long"
            resultMap="DepartmentDO">
        select
        department.id,
        department.name,
        department.info,
        department.code,
        department.status,
        department.level,
        department.parent_id
        from sys_department as department
        <where>
            status = #{status}
        </where>
 
    </select>
    <select id="getDepartmentInfoById" parameterType="long" resultMap="DepartmentInfo">
        select
        department.id,
        department.name,
        department.code,
        department.info,
        department.status,
        department.level,
        department.parent_id,
        department.gmt_create,
        department.gmt_modified
        from sys_department as department
        where department.id = #{id}
        and department.status = 1
    </select>
    <select id="listDepartmentByParentId"
            parameterType="long"
            resultMap="DepartmentDO">
      select
        department.id,
        department.name,
        department.code,
        department.info,
        department.status,
        department.level,
        department.parent_id
        from sys_department as department
        where 1 = 1
        and department.status = 1
        <choose>
            <when test="parentId != null">
                and department.parent_id = #{parentId}
            </when>
            <otherwise>
                and department.parent_id is null
            </otherwise>
        </choose>
    </select>
    <select id="getDepartmentInfoDOById"
            parameterType="long"
            resultMap="DepartmentDO">
        select
        department.id,
        department.name,
        department.code,
        department.info,
        department.status,
        department.level,
        department.parent_id
        from sys_department as department
        where department.id = #{id}
    </select>
    <select id="getParentDepartmentInfoDOByDepId"
            parameterType="long"
            resultMap="DepartmentDO">
        select
        parentDep.id,
        parentDep.name,
        parentDep.code,
        parentDep.info,
        parentDep.status,
        parentDep.level,
        parentDep.parent_id
        from sys_department as department
        inner join sys_department as parentDep on parentDep.id = department.parent_id
        where department.id = #{id}
    </select>
 
    <select id="listSubDepIdsByParentId"
            parameterType="long"
            resultType="java.lang.Long">
        select
        id
        from sys_department
        where status = 1
        and parent_id = #{depId}
 
 
    </select>
</mapper>