lyh
2025-07-03 2a30092c6e1efa28b5ca29a1b518356a08b4044c
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?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="org.jeecg.modules.system.mapper.SysDictMapper">
 
    <!-- 通过字典code获取字典数据 -->
    <select id="queryDictItemsByCode" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
           select s.item_value as "value",s.item_text as "text" from sys_dict_item s
           where dict_id = (select id from sys_dict where dict_code = #{code})
           order by s.sort_order asc
    </select>
 
    <!-- 通过字典code获取有效的字典数据项 -->
    <select id="queryEnableDictItemsByCode" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
           select s.item_value as "value",s.item_text as "text" from sys_dict_item s
           where dict_id = (select id from sys_dict where dict_code = #{code})
           and s.status = 1
           order by s.sort_order asc
    </select>
 
    <!-- 通过多个字典code获取字典数据 -->
    <select id="queryDictItemsByCodeList" parameterType="String" resultType="org.jeecg.common.system.vo.DictModelMany">
        SELECT
            dict.dict_code,
            item.item_text AS "text",
            item.item_value AS "value"
        FROM
            sys_dict_item item
        INNER JOIN sys_dict dict ON dict.id = item.dict_id
        WHERE dict.dict_code IN (
            <foreach item="dictCode" collection="dictCodeList" separator=",">
                #{dictCode}
            </foreach>
        )
        ORDER BY item.sort_order ASC
    </select>
 
    <!-- 通过字典code获取字典数据 -->
    <select id="queryDictTextByKey" parameterType="String"  resultType="String">
           select s.item_text from sys_dict_item s
           where s.dict_id = (select id from sys_dict where dict_code = #{code})
           and s.item_value = #{key}
    </select>
 
    <!-- 通过字典code获取字典数据,可批量查询 -->
    <select id="queryManyDictByKeys" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModelMany">
        SELECT
            dict.dict_code,
            item.item_text AS "text",
            item.item_value AS "value"
        FROM
            sys_dict_item item
        INNER JOIN sys_dict dict ON dict.id = item.dict_id
        WHERE dict.dict_code IN (
            <foreach item="dictCode" collection="dictCodeList" separator=",">
                #{dictCode}
            </foreach>
        )
        AND item.item_value IN (
            <foreach item="key" collection="keys" separator=",">
                #{key}
            </foreach>
        )
    </select>
 
    <!--通过查询指定table的 text code 获取字典-->
    <select id="queryTableDictItemsByCode" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
           select ${text} as "text",${code} as "value" from ${table}
    </select>
 
    <!--通过查询指定table的 text code 获取字典(指定查询条件)-->
    <select id="queryTableDictItemsByCodeAndFilter" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
           select ${text} as "text",${code} as "value" from ${table}
        <if test="filterSql != null and filterSql != ''">
            where ${filterSql}
        </if>
    </select>
 
    <!--通过查询指定table的 text code key 获取字典值-->
    <select id="queryTableDictTextByKey" parameterType="String" resultType="String">
           select ${text} as "text" from ${table} where ${code}= #{key}
    </select>
 
    <!--通过查询指定table的 text code key 获取字典值,可批量查询
    <select id="queryTableDictTextByKeys" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text", ${code} as "value" from ${table} where ${code} IN (
            <foreach item="key" collection="keys" separator=",">
                #{key}
            </foreach>
        )
    </select>-->
 
    <!--通过查询指定table的 text code key 获取字典值,包含value
    <select id="queryTableDictByKeys" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text", ${code} as "value" from ${table} where ${code} in
        <foreach item="key" collection="keyArray" open="(" separator="," close=")">
            #{key}
        </foreach>
    </select>-->
 
    <!-- 重复校验 sql语句 -->
    <select id="duplicateCheckCountSql" resultType="Long" parameterType="org.jeecg.modules.system.model.DuplicateCheckVo">
        SELECT COUNT(*) FROM ${tableName} WHERE ${fieldName} = #{fieldVal} and id &lt;&gt; #{dataId}
    </select>
 
    <!-- 重复校验 sql语句 -->
    <select id="duplicateCheckCountSqlNoDataId" resultType="Long" parameterType="org.jeecg.modules.system.model.DuplicateCheckVo">
        SELECT COUNT(*) FROM ${tableName} WHERE ${fieldName} = #{fieldVal}
    </select>
 
    <!-- 查询部门信息 作为字典数据 -->
    <select id="queryAllDepartBackDictModel" resultType="org.jeecg.common.system.vo.DictModel">
        select id as "value",depart_name as "text" from sys_depart where del_flag = '0'
    </select>
 
        <!-- 查询用户信息 作为字典数据 -->
    <select id="queryAllUserBackDictModel" resultType="org.jeecg.common.system.vo.DictModel">
        select username as "value",realname as "text" from sys_user where del_flag = '0'
    </select>
 
    <!--通过查询指定table的 text code 获取字典数据,且支持关键字查询
    <select id="queryTableDictItems" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text",${code} as "value" from ${table} where ${text} like #{keyword}
    </select> -->
 
    <!-- 根据表名、显示字段名、存储字段名、父ID查询树 -->
    <select id="queryTreeList" parameterType="Object" resultType="org.jeecg.modules.system.model.TreeSelectModel">
        select ${text} as "title",
               ${code} as "key",
                <!-- udapte-begin-author:taoyan date:20211115 for: 自定义树控件只显示父节点,子节点无法展开 (此处还原不可再改) /issues/I4HZAL -->
               <if test="hasChildField != null and hasChildField != ''">
                   <choose>
                       <when test="converIsLeafVal!=null and converIsLeafVal==1">
                           (case when ${hasChildField} = '1' then 0 else 1 end) as isLeaf,
                       </when>
                       <otherwise>
                           ${hasChildField} as isLeaf,
                       </otherwise>
                   </choose>
               </if>
                <!-- udapte-end-author:taoyan date:20211115 for: 自定义树控件只显示父节点,子节点无法展开 (此处还原不可再改) /issues/I4HZAL -->
               ${pidField} as parentId
               from ${table}
               where
               <!-- udapte-begin-author:sunjianlei date:20220110 for: 【JTC-597】自定义树查询条件查不出数据 -->
               <if test="query == null">
                   <choose>
                       <when test="pid != null and pid != ''">
                           ${pidField} = #{pid}
                       </when>
                       <otherwise>
                           (${pidField} = '' OR ${pidField} IS NULL)
                       </otherwise>
                   </choose>
               </if>
               <if test="query!= null">
                   1 = 1
                   <foreach collection="query.entrySet()" item="value"  index="key" >
                       and ${key} LIKE #{value}
                   </foreach>
                     <!-- udapte-end-author:sunjianlei date:20220615 for: 【issues/3709】自定义树查询条件没有处理父ID,没有树状结构了 -->
                     <choose>
                         <when test="pid != null and pid != ''">
                             and ${pidField} = #{pid}
                         </when>
                         <otherwise>
                             and (${pidField} = '' OR ${pidField} IS NULL)
                         </otherwise>
                     </choose>
                    <!-- udapte-end-author:sunjianlei date:20220615 for: 【issues/3709】自定义树查询条件没有处理父ID,没有树状结构了 -->
               </if>
               <!-- udapte-end-author:sunjianlei date:20220110 for: 【JTC-597】自定义树查询条件查不出数据 -->
    </select>
 
 
    <!-- 分页查询字典表数据 -->
    <select id="queryDictTablePageList" parameterType="Object" resultType="org.jeecg.common.system.vo.DictModel">
        select ${query.text} as "text",${query.code} as "value" from ${query.table}
        where 1 = 1
        <if test="query.keyword != null and query.keyword != ''">
            <bind name="bindKeyword" value="'%'+query.keyword+'%'"/>
            and (${query.text} like #{bindKeyword} or ${query.code} like #{bindKeyword})
        </if>
        <if test="query.codeValue != null and query.codeValue != ''">
            and ${query.code} = #{query.codeValue}
        </if>
    </select>
 
    <!--通过查询指定table的 text code 获取字典数据,且支持关键字和自定义查询条件查询 分页-->
    <select id="queryTableDictWithFilter" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text", ${code} as "value" from ${table}
        <if test="filterSql != null and filterSql != ''">
            ${filterSql}
        </if>
    </select>
 
    <!--通过查询指定table的 text code 获取字典数据,且支持关键字和自定义查询条件查询 获取所有 -->
    <select id="queryAllTableDictItems" parameterType="String"  resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text", ${code} as "value" from ${table}
        <if test="filterSql != null and filterSql != ''">
            ${filterSql}
        </if>
    </select>
 
 
    <!-- 查询字典表的数据 支持设置过滤条件、设置存储值作为in查询条件 -->
    <select id="queryTableDictByKeysAndFilterSql" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel">
        select ${text} as "text", ${code} as "value" from ${table} where ${code} IN (
        <foreach item="key" collection="codeValues" separator=",">
            #{key}
        </foreach>
        )
        <if test="filterSql != null and filterSql != ''">
            and ${filterSql}
        </if>
    </select>
    <select id="queryTableFieldByParams" resultType="java.util.Map">
        select ${columns},${paramName} as paramValue
        from ${table} where ${paramName} in
        <foreach item="key" collection="paramValues" open="(" separator="," close=")">
            #{key}
        </foreach>
    </select>
    <select id="queryTableDictTextBySubSql" resultType="java.lang.String">
        select ${text} as "text" from ${table} where ${subSql}
    </select>
</mapper>