Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?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.matrix.system.common.dao.SysRolePwoerFnDao">
    <!-- 定义SysRolePwoerFn 的复杂关联map -->
    <resultMap type="com.matrix.system.common.bean.SysRolePwoerFn" id="SysRolePwoerFnMap">
            <id property="rpfId" column="rpf_id" />
            <result property="roleId" column="role_id" />
            <result property="fnId" column="fn_id" />
            <result property="rpfBtns" column="rpf_btns" />
    </resultMap>
    
     
    
    
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.matrix.system.common.bean.SysRolePwoerFn"
        useGeneratedKeys="true" keyProperty="rpfId">
        INSERT INTO sys_role_pwoer_fn (
            create_by,
            create_time,
            update_by,
            update_time,
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        )
    VALUES (
            #{createBy},
            now(),
            #{updateBy},
            now(),
            #{rpfId},
            #{roleId},
            #{fnId},
            #{rpfBtns}
    )
    </insert>
    
    
    
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO sys_role_pwoer_fn (
            create_by,
            create_time,
            update_by,
            update_time,
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        )
    VALUES 
    <foreach collection="list" item="item" index="index" separator=",">(
            #{item.createBy},
            now(),
            #{item.updateBy},
            now(),
            #{item.rpfId},
            #{item.roleId},
            #{item.fnId},
            #{item.rpfBtns}
    )</foreach>
    </insert>
    
    
    
    
    
    <!--  根据Map更新 部分更新   -->
    <update id="updateByMap" parameterType="java.util.HashMap" >
        UPDATE sys_role_pwoer_fn
        <set>
            update_time=now(),
            <if test="_parameter.containsKey('updateBy')">
            update_by=#{updateBy},
            </if>
            <if test="_parameter.containsKey('roleId')">
                    role_id = #{roleId},
                </if>        
            <if test="_parameter.containsKey('fnId')">
                    fn_id = #{fnId},
                </if>        
            <if test="_parameter.containsKey('rpfBtns')">
                    rpf_btns = #{rpfBtns},
                </if>        
        </set>
        WHERE rpf_id=#{rpfId} 
    </update>
    
    
    
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="Long">
        UPDATE sys_role_pwoer_fn
        <set>
                update_time=now(),
                <if test="updateBy!=null">
                    update_by  = #{btnKey},
                </if>
                <if test="(roleId!=null and roleId!='') or (roleId!='' and roleId==0)">
                    role_id = #{roleId},
                </if>        
                <if test="(fnId!=null and fnId!='') or (fnId!='' and fnId==0)">
                    fn_id = #{fnId},
                </if>        
                <if test="(rpfBtns!=null and rpfBtns!='') or (rpfBtns!='' and rpfBtns==0)">
                    rpf_btns = #{rpfBtns},
                </if>        
        </set>
        WHERE rpf_id=#{rpfId} 
    </update>
    
    
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from sys_role_pwoer_fn where  rpf_id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="Long">
        DELETE FROM sys_role_pwoer_fn
        where  rpf_id=#{rpfId} 
    </delete>
    
    <!-- 根据对象删除-->
    <delete id="deleteByModel" parameterType="Long">
        DELETE FROM sys_role_pwoer_fn
        <where>
        <if test="record!=null">
            <if test="(record.rpfId!=null and record.rpfId!='') or (record.rpfId!='' and record.rpfId==0)">
                and rpf_id = #{record.rpfId} 
            </if>
            <if test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)">
                and role_id = #{record.roleId} 
            </if>
            <if test="(record.fnId!=null and record.fnId!='') or (record.fnId!='' and record.fnId==0)">
                and fn_id = #{record.fnId} 
            </if>
            <if test="(record.rpfBtns!=null and record.rpfBtns!='') or (record.rpfBtns!='' and record.rpfBtns==0)">
                and rpf_btns = #{record.rpfBtns} 
            </if>
        </if>
        </where>
    </delete>
    <delete id="deleteByFns">
        DELETE a
        FROM
        sys_role_pwoer_fn a , sys_role b
        WHERE
        a.role_id = b.role_id
        and b.company_id=#{companyId}
        and a.fn_id in <foreach collection="list" index="index" item="item" open="("
                                     separator="," close=")">
        #{item}
    </foreach>
    </delete>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="SysRolePwoerFnMap">
        select 
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        from sys_role_pwoer_fn
        <where>
        <if test="record!=null">
            <if test="(record.rpfId!=null and record.rpfId!='') or (record.rpfId!='' and record.rpfId==0)">
                and rpf_id  = #{record.rpfId} 
            </if>
            <if test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)">
                and role_id  = #{record.roleId} 
            </if>
            <if test="(record.fnId!=null and record.fnId!='') or (record.fnId!='' and record.fnId==0)">
                and fn_id  = #{record.fnId} 
            </if>
            <if test="(record.rpfBtns!=null and record.rpfBtns!='') or (record.rpfBtns!='' and record.rpfBtns==0)">
                and rpf_btns  = #{record.rpfBtns} 
            </if>
        </if>
        </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
    
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer">
    select count(*)
    from sys_role_pwoer_fn
        <where>
        <if test="record!=null">
            <if test="(record.rpfId!=null and record.rpfId!='') or (record.rpfId!='' and record.rpfId==0)">
            and rpf_id = #{record.rpfId} 
            </if>
            <if test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)">
            and role_id = #{record.roleId} 
            </if>
            <if test="(record.fnId!=null and record.fnId!='') or (record.fnId!='' and record.fnId==0)">
            and fn_id = #{record.fnId} 
            </if>
            <if test="(record.rpfBtns!=null and record.rpfBtns!='') or (record.rpfBtns!='' and record.rpfBtns==0)">
            and rpf_btns = #{record.rpfBtns} 
            </if>
        </if>
        </where>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="SysRolePwoerFnMap">
        select 
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        from sys_role_pwoer_fn
        where  rpf_id=#{rpfId} 
    </select>    
    
    
    <!-- 根据id 锁表查询-->
    <select id="selectForUpdate" resultMap="SysRolePwoerFnMap">
        select 
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        from sys_role_pwoer_fn
        where  rpf_id=#{rpf_id} 
        for update
    </select>    
    
    
    
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="SysRolePwoerFnMap">
        select 
            rpf_id,
            role_id,
            fn_id,
            rpf_btns
        from sys_role_pwoer_fn
        <where>
        <if test="record!=null">
            <if test="(record.rpfId!=null and record.rpfId!='') or (record.rpfId!='' and record.rpfId==0)">
                and rpf_id = #{record.rpfId} 
            </if>
            <if test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)">
                and role_id = #{record.roleId} 
            </if>
            <if test="(record.fnId!=null and record.fnId!='') or (record.fnId!='' and record.fnId==0)">
                and fn_id = #{record.fnId} 
            </if>
            <if test="(record.rpfBtns!=null and record.rpfBtns!='') or (record.rpfBtns!='' and record.rpfBtns==0)">
                and rpf_btns = #{record.rpfBtns} 
            </if>
        </if>
        </where>
    </select>
</mapper>