mitao
2025-03-14 08f1b1f1804a8bd833d42f257908d80e88387b55
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
<?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.panzhihua.sangeshenbian.dao.MessageNotificationMapper">
 
    
    <select id="list" resultType="com.panzhihua.sangeshenbian.model.entity.MessageNotification">
        select
            a.id,
            a.title,
            IF(a.undertaker_type = 1, b1.region_name, IF(a.undertaker_type = 2, b2.region_name, IF(a.undertaker_type = 3, b3.name, IF(a.undertaker_type = 4, b4.name, b5.name)))) as undertakerUser,
            a.phone,
            ifnull(d4.name, ifnull(d3.name, ifnull(d2.name, d1.name))) as department,
            e.name as `position`,
            a.response_time as responseTime,
            a.prompt_type as promptType,
            a.read_status as readStatus
        from sgsb_message_notification a
        left join sys_user b5 on (a.undertaker_user_id = b5.user_id and a.undertaker_type = 5)
        left join com_act b4 on (a.undertaker_user_id = b4.community_id and a.undertaker_type = 4)
        left join com_street b3 on (a.undertaker_user_id = b3.street_id and a.undertaker_type = 3)
        left join bc_region b2 on (a.undertaker_user_id = b2.region_code and a.undertaker_type = 2)
        left join bc_region b1 on (a.undertaker_user_id = b1.region_code and a.undertaker_type = 1)
        left join sgsb_system_user c on (a.phone = c.phone)
        left join sgsb_department d1 on (c.one_department_id = d1.id)
        left join sgsb_department d2 on (c.two_department_id = d2.id)
        left join sgsb_department d3 on (c.three_department_id = d3.id)
        left join sgsb_department d4 on (c.four_department_id = d4.id)
        left join sgsb_system_post e on (c.system_post_id = e.id)
        where a.undertaker_type = #{query.undertakerType} and a.undertaker_user_id = #{query.userId}
        <if test="query.title != null and query.title != ''">
            and a.title like concat('%', #{query.title}, '%')
        </if>
        <if test="query.undertakerUser != null and query.undertakerUser != ''">
            and (b5.name like concat('%', #{query.undertakerUser}, '%') or b4.name like concat('%', #{query.undertakerUser}, '%') or b3.name like concat('%', #{query.undertakerUser}, '%') or
            b2.region_name like concat('%', #{query.undertakerUser}, '%') or b1.region_name like concat('%', #{query.undertakerUser}, '%'))
        </if>
        <if test="query.phone != null and query.phone != ''">
            and a.phone like concat('%', #{query.phone}, '%')
        </if>
        <if test="query.departmentId != null">
            and (c.one_department_id = #{query.departmentId} or c.two_department_id = #{query.departmentId} or
                 c.three_department_id = #{query.departmentId} or c.four_department_id = #{query.departmentId})
        </if>
        <if test="query.position != null">
            and c.system_post_id = #{query.position}
        </if>
        order by a.read_status asc, a.create_time desc
    </select>
</mapper>