1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
<?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.landtool.lanbase.modules.sys.dao.SysResourceDao">
 
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.landtool.lanbase.modules.sys.entity.SysResource" id="resourceMap">
        <result property="resourceid" column="RESOURCEID"/>
        <result property="appid" column="APPID"/>
        <result property="resourcercode" column="RESOURCERCODE"/>
        <result property="resourcername" column="RESOURCERNAME"/>
        <result property="description" column="DESCRIPTION"/>
        <result property="rcreateuser" column="RCREATEUSER"/>
        <result property="rcreatedate" column="RCREATEDATE"/>
        <result property="systemName" column="SYSTEMNAME"/>
    </resultMap>
    
    <sql id="resourceColumns">
        sr.resourceid,
         sr.appid,
          sr.resourcercode,
          sr.resourcername,
          sr.description,
          sr.rcreateuser,
          sr.rcreatedate
    </sql>
    
    <select id="queryObject" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select 
        <include refid="resourceColumns"/>,
        ss.APPFULLNAME AS SYSTEMNAME from SYS_RESOURCE sr left join SYS_SYSTEMINFO ss on sr.appid=ss.appid  where RESOURCEID = #{value}
    </select>
 
    <select id="queryList" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select * from (
            SELECT *
            FROM(
                SELECT ROW_NUMBER() OVER(ORDER BY B.rcreatedate desc) AS rownumber,B.*
                    FROM (
    
                        SELECT
                        <include refid="resourceColumns" />,
                                ss.APPFULLNAME AS SYSTEMNAME
                        FROM SYS_RESOURCE sr
                        LEFT JOIN SYS_SYSTEMINFO  ss ON sr.appid=ss.appid
                        <where>
                        <if test="resourcername != null and resourcername!=''">
                             AND RESOURCERNAME LIKE ('%' || #{resourcername} || '%')
                        </if>
                        <if test="appid != null and appid!=''">
                             AND cast(sr.appid as varchar) = #{appid}
                        </if>
                        <if test="resourcercode != null and resourcercode!=''">
                             AND resourcercode LIKE ('%' || #{resourcercode} || '%')
                        </if>
                        </where>
    
                ) B
            ) A
            WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
        )a order by  
        <choose>
            <when test="sidx != null and sidx != ''">
                ${sidx} ${order}
            </when>
            <otherwise>
                rcreatedate desc
            </otherwise>
        </choose>
    </select>
    
    <select id="queryListByAppId" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select <include refid="resourceColumns" />,ss.APPFULLNAME AS SYSTEMNAME from SYS_RESOURCE sr
                LEFT join SYS_SYSTEMINFO  ss on sr.appid=ss.appid
                where 1=1 AND sr.appid = #{appid}
    </select>
    
     <select id="queryTotal" resultType="int">
        select count(*) from SYS_RESOURCE sr left join SYS_SYSTEMINFO  ss on sr.appid=ss.appid
        where 1=1
                <if test="resourcername != null and resourcername!=''">
                    AND RESOURCERNAME LIKE ('%' || #{resourcername} || '%')
                </if>
                <if test="appid != null and appid!=''">
                     AND cast(sr.appid as varchar) = #{appid}
                </if>
                <if test="resourcercode != null and resourcercode!=''">
                    AND resourcercode LIKE ('%' || #{resourcercode} || '%')
                </if>
                
    </select>
     
    <insert id="save" parameterType="com.landtool.lanbase.modules.sys.entity.SysResource">
        insert into SYS_RESOURCE
        (
            APPID, 
            RESOURCERCODE, 
            RESOURCERNAME, 
            DESCRIPTION,  
            RCREATEUSER, 
            RCREATEDATE
        )
        values
        (
            #{appid,jdbcType=BIGINT}, 
            #{resourcercode,jdbcType=BIGINT}, 
            #{resourcername,jdbcType=VARCHAR}, 
            #{description,jdbcType=VARCHAR},  
            #{rcreateuser}, 
            #{rcreatedate}
        )
    </insert>
     
    <update id="update" parameterType="com.landtool.lanbase.modules.sys.entity.SysResource">
        update SYS_RESOURCE
        <set>
            <if test="appid != null">APPID = #{appid}, </if>
            <if test="resourcercode != null">RESOURCERCODE = #{resourcercode}, </if>
            <if test="resourcername != null">RESOURCERNAME = #{resourcername}, </if>
            <if test="description != null">DESCRIPTION = #{description}, </if>
            <if test="rcreateuser != null">RCREATEUSER = #{rcreateuser}, </if>
            <if test="rcreatedate != null">RCREATEDATE = #{rcreatedate}</if>
        </set>
        where RESOURCEID = #{resourceid}
    </update>
    
    <delete id="delete">
        delete from SYS_RESOURCE where RESOURCEID = #{value}
    </delete>
    
    <delete id="deleteBatch">
        delete from SYS_RESOURCE where RESOURCEID in
        <foreach item="resourceid" collection="array" open="(" separator="," close=")">
            #{resourceid}
        </foreach>
    </delete>
    
    
    <select id="getInfoById" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select * from SYS_RESOURCE where RESOURCEID = #{resourceid}
    </select>
    
    
    
    <select id="queryListByRoldId" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select sr.* from SYS_RESOURCE sr join SYS_ROLERESOURCE srs on sr.resourceid=srs.resourceid and srs.roleid=#{roleId}
    </select>
 
   <select id="queryListByUserId"  resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
       select a.* from
       (SELECT * from SYS_RESOURCE
       <where>
       <if test="appId != null and appId!=''" >
           appid = #{appId}
       </if>
           </where>
       )  a left join
       (select resourceid from SYS_ROLERESOURCE
       <where>
           <if test="userId != null and userId!=''">
           roleid in (select roleid from SYS_ROLEGROUP where groupid = (select groupid from ORG_USERGROUP where userid = #{userId}))
           </if>
       </where>
       )
        b on (a.resourceid = b.resourceid)
   </select>
   
 
    <select id="queryResources" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        SELECT
            <include refid="resourceColumns"/>
        FROM SYS_RESOURCE sr
        INNER JOIN SYS_ROLERESOURCE srr ON sr.RESOURCEID = srr.RESOURCEID
        INNER JOIN SYS_ROLE sr2 ON srr.ROLEID = sr2.ROLEID
        INNER JOIN SYS_ROLEGROUP srg ON srg.ROLEID = sr2.ROLEID
        INNER JOIN ORG_GROUP og ON srg.GROUPID = og.GROUPID
        INNER JOIN ORG_USERGROUP oug ON og.GROUPID = oug.GROUPID
        INNER JOIN ORG_USER ou  ON  oug.USERID = ou.USERID
        <where>
            <if test="userId != null">
                AND ou.USERID = #{userId}
            </if>
        </where>
    </select>
    
     <select id="querySysResourceWithSEQ" resultType="int">
        SELECT currval('SYS_RESOURCE_SEQ') FROM DUAL
    </select>
    
    <select id="queryObjectByName" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        select * from SYS_RESOURCE where RESOURCERNAME = #{resourcename} and APPID = #{appid}
    </select>
    
    <select id="queryResourceByUserAndCode" resultType="com.landtool.lanbase.modules.sys.entity.SysResource">
        SELECT
            distinct(sr.resourceid), sr.appid, sr.resourcercode, sr.resourcername, sr.description, sr.rcreateuser, sr.rcreatedate
        FROM SYS_RESOURCE sr
        INNER JOIN SYS_ROLERESOURCE srr ON sr.RESOURCEID = srr.RESOURCEID
        INNER JOIN SYS_ROLE sr2 ON srr.ROLEID = sr2.ROLEID
        INNER JOIN SYS_ROLEGROUP srg ON srg.ROLEID = sr2.ROLEID
        INNER JOIN ORG_GROUP og ON srg.GROUPID = og.GROUPID
        INNER JOIN ORG_USERGROUP oug ON og.GROUPID = oug.GROUPID
        INNER JOIN ORG_USER ou  ON  oug.USERID = ou.USERID
        where ou.USERID = #{userid} and sr.resourcercode = #{resourcercode}
    </select>
</mapper>