liujie
2026-01-14 f976a39b294f8c7dd60bcd2c661983c0dcc97fc6
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
<?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.estate.expert.admin.domain.repository.ScreenAccountMybatisMapper">
    
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.estate.expert.admin.domain.business.screenaccount.ScreenAccount">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="account" property="account" />
        <result column="password" property="password" />
        <result column="type" property="type" />
        <result column="client_project_ids" property="clientProjectIds" />
        <result column="state" property="state" />
        <result column="creator_id" property="creatorId" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="deleted" property="deleted" />
    </resultMap>
    
    <!-- 根据名称模糊查询ScreenAccount列表 -->
    <select id="findByName" parameterType="java.lang.String" resultMap="BaseResultMap">
        select * from screen_account 
        where deleted = false 
        <if test="name != null and name != ''">
            and name like concat('%', #{name}, '%')
        </if>
        order by create_time desc
    </select>
    
    <!-- 根据条件动态查询ScreenAccount列表 -->
    <select id="findByConditions" resultMap="BaseResultMap">
        select * from screen_account 
        where deleted = false
        <if test="name != null and name != ''">
            and name like concat('%', #{name}, '%')
        </if>
        <if test="type != null">
            and type = #{type}
        </if>
        <if test="state != null">
            and state = #{state}
        </if>
        <if test="clientProjectIds != null and clientProjectIds != ''">
            and client_project_ids like concat('%', #{clientProjectIds}, '%')
        </if>
        order by update_time desc
    </select>
    <select id="list" resultType="com.estate.expert.admin.domain.business.screenaccount.ScreenAccountDto">
        select id,
        name,
        type,
        state,
        deleted,
        create_time as createTime,
        creator_id,
        account,
        password,
        update_time as updateTime,
        client_project_ids as clientProjectIds
        from screen_account where deleted = false
        <if test="name != null and name != ''">
            and name like concat('%', #{name}, '%')
        </if>
 
        <if test="type != null ">
            and type  = #{type}
        </if>
 
        <!-- 处理clientListIds数组参数 -->
        <if test="clientListIds != null and clientListIds.size() > 0 and projectIds == null">
            <foreach collection="clientListIds" item="id" separator="OR" open="and (">
                FIND_IN_SET(#{id}, client_project_ids) > 0
            </foreach>
            )
        </if>
        <!-- 处理projectIds数组参数 -->
        <if test="clientListIds == null and projectIds != null and projectIds.size() > 0">
            <foreach collection="projectIds" item="id" separator="OR" open="and (">
                FIND_IN_SET(#{id}, client_project_ids) > 0
            </foreach>
            )
        </if>
        <!-- 处理clientListIds和projectIds都不为空的情况 -->
        <if test="clientListIds != null and clientListIds.size() > 0 and projectIds != null and projectIds.size() > 0">
            <foreach collection="clientListIds" item="id" separator="OR" open="and (">
                FIND_IN_SET(#{id}, client_project_ids) > 0
            </foreach>
            OR
            <foreach collection="projectIds" item="id" separator="OR">
                FIND_IN_SET(#{id}, client_project_ids) > 0
            </foreach>
            )
        </if>
        order by create_time desc
 
    </select>
    <select id="getClientNameList" resultType="java.lang.String">
        select name from client where id in
        <foreach collection="ids" item="id" separator="," close=")" open="(">
            #{id}
        </foreach>
 
    </select>
    <select id="getProjectNameList" resultType="java.lang.String">
        select name from project where id in
        <foreach collection="ids" item="id" separator="," close=")" open="(">
            #{id}
        </foreach>
    </select>
    <select id="getUserFromMobile"
            resultType="com.estate.expert.admin.domain.business.screenaccount.ScreenAccount">
        select * from screen_account where deleted = false and account = #{mobile}
    </select>
</mapper>