Crunchy
2024-04-22 a7a6a0c332f268010b4da0161cdee80acf9bc4ce
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
<?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.yuanchu.mom.mapper.DepartmentMapper">
    <select id="selectDepartment" resultType="com.yuanchu.mom.dto.DepartmentDto">
        SELECT id, name, father_id
        FROM department
    </select>
 
    <select id="showUserById" resultType="com.yuanchu.mom.dto.UserDto">
        select * from (select id, name, age, email, phone,depart_id
        from user where state=1 and SUBSTRING_INDEX(depart_id, ',', -1) in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach> ) a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="selectSonById" resultType="java.lang.Integer">
        SELECT au.id
        FROM (SELECT * FROM department WHERE father_id IS NOT NULL) au,
             (SELECT @father_id := #{id}) pd
        WHERE FIND_IN_SET(father_id, @father_id) > 0
                  AND @father_id := concat(@father_id, ',', id)
        UNION
        SELECT id
        FROM department
        WHERE id = #{id}
        ORDER BY id
    </select>
</mapper>