multi-tenancy

This commit is contained in:
MaxKey
2021-12-12 17:21:58 +08:00
parent df81c2ed68
commit c490551aef
104 changed files with 986 additions and 441 deletions

View File

@@ -20,6 +20,7 @@
*/
package org.maxkey.persistence.mapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,18 +34,18 @@ import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
*/
public interface ReportMapper extends IJpaBaseMapper<JpaBaseEntity> {
public Integer analysisDay(String reportParameter);
public Integer analysisNewUsers(String reportParameter);
public Integer analysisOnlineUsers(String reportParameter);
public Integer analysisActiveUsers(String reportParameter);
public Integer analysisDay(HashMap<String,Object> reportParameter);
public Integer analysisNewUsers(HashMap<String,Object> reportParameter);
public Integer analysisOnlineUsers(HashMap<String,Object> reportParameter);
public Integer analysisActiveUsers(HashMap<String,Object> reportParameter);
public List<Map<String,Object>> analysisDayHour(String reportParameter);
public List<Map<String,Object>> analysisDayHour(HashMap<String,Object> reportParameter);
public List<Map<String,Object>> analysisMonth(String reportParameter);
public List<Map<String,Object>> analysisMonth(HashMap<String,Object> reportParameter);
public List<Map<String,Object>> analysisBrowser(Map<String,Object> reportParameter);
public List<Map<String,Object>> analysisBrowser(HashMap<String,Object> reportParameter);
public List<Map<String,Object>> analysisApp(Map<String,Object> reportParameter );
public List<Map<String,Object>> analysisApp(HashMap<String,Object> reportParameter );
}

View File

@@ -17,6 +17,7 @@
package org.maxkey.persistence.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -28,36 +29,36 @@ import org.springframework.stereotype.Repository;
@Repository
public class ReportService extends JpaBaseService<JpaBaseEntity>{
public Integer analysisDay(String reportParameter) {
public Integer analysisDay(HashMap<String,Object> reportParameter) {
return getMapper().analysisDay(reportParameter);
};
public Integer analysisNewUsers(String reportParameter) {
public Integer analysisNewUsers(HashMap<String,Object> reportParameter) {
return getMapper().analysisNewUsers(reportParameter);
};
public Integer analysisOnlineUsers(String reportParameter) {
public Integer analysisOnlineUsers(HashMap<String,Object> reportParameter) {
return getMapper().analysisOnlineUsers(reportParameter);
};
public Integer analysisActiveUsers(String reportParameter) {
public Integer analysisActiveUsers(HashMap<String,Object> reportParameter) {
return getMapper().analysisActiveUsers(reportParameter);
};
public List<Map<String,Object>> analysisDayHour(String reportParameter){
public List<Map<String,Object>> analysisDayHour(HashMap<String,Object> reportParameter){
return getMapper().analysisDayHour(reportParameter);
}
public List<Map<String,Object>> analysisMonth(String reportParameter){
public List<Map<String,Object>> analysisMonth(HashMap<String,Object> reportParameter){
return getMapper().analysisMonth(reportParameter);
}
public List<Map<String,Object>> analysisBrowser(Map<String,Object> reportParameter){
public List<Map<String,Object>> analysisBrowser(HashMap<String,Object> reportParameter){
return getMapper().analysisBrowser(reportParameter);
}
public List<Map<String,Object>> analysisApp(Map<String,Object> reportParameter){
public List<Map<String,Object>> analysisApp(HashMap<String,Object> reportParameter){
return getMapper().analysisApp(reportParameter);
}

View File

@@ -24,8 +24,7 @@
*
from
mxk_accounts
where
(1=1)
where instid = #{instId}
<include refid="where_statement"/>
</select>
@@ -33,9 +32,11 @@
select
*
from mxk_userinfo u
where not exists(
where u.instid = #{instId}
and not exists(
select 1 from mxk_accounts ac
where ac.appid = #{appId}
and ac.instid = #{instId}
and ac.userid = u.id
and ac.createtype='automatic'
)
@@ -49,13 +50,14 @@
<delete id="deleteByStrategy" parameterType="AccountsStrategy" >
delete from mxk_accounts ac
where ac.createtype = 'automatic'
where ac.instid = #{instId}
and ac.createtype = 'automatic'
and ac.appid = #{appId}
and ac.strategyid = #{id}
and not exists(
select 1
from mxk_userinfo u
where 1 = 1
where instid = #{instId}
and u.id=ac.userid
<if test="filters != null and filters != ''">
and (${filters})

View File

@@ -23,8 +23,9 @@
from
mxk_accounts_strategy mas,
mxk_apps ma
where
mas.appid = ma.id
where ma.instid = #{instId}
and mas.instid = #{instId}
and mas.appid = ma.id
<include refid="where_statement"/>
</select>

View File

@@ -7,8 +7,9 @@
from
mxk_apps_cas_details cd,
mxk_apps app
where
status = 1
where app.instid = #{instId}
and cd.instid = #{instId}
and app.status = 1
and cd.id = app.id
and (
app.id = #{value}

View File

@@ -8,8 +8,9 @@
from
mxk_apps_form_based_details fbd,
mxk_apps app
where
app.id = #{value}
where app.instId = #{instId}
and fbd.instId = #{instId}
and app.id = #{value}
and fbd.id = #{value}
and fbd.id = app.id
and status = 1

View File

@@ -8,11 +8,12 @@
from
mxk_apps_jwt_details jd,
mxk_apps app
where
app.id = #{value}
and jd.id = #{value}
and jd.id = app.id
and status = 1
where app.instid = #{instId}
and jd.instid = #{instId}
and app.id = #{value}
and jd.id = #{value}
and status = 1
and jd.id = app.id
</select>
</mapper>

View File

@@ -30,8 +30,7 @@
*
from
mxk_apps
where
(1=1)
where instid = #{instId}
<include refid="where_statement"/>
order by sortindex
</select>
@@ -79,7 +78,8 @@
status,
logouturl,
logouttype
logouttype,
instid
)values(
#{id},
#{name},
@@ -120,7 +120,8 @@
#{status},
#{logoutUrl},
#{logoutType}
#{logoutType},
#{instId}
)
</insert>
@@ -179,6 +180,9 @@
where
app.id=gp.appid
and gp.groupid=g.id
and app.instid = #{instId}
and gp.instid = #{instId}
and g.instid = #{instId}
and app.visible != 0
and (
g.id='ROLE_ALL_USER'

View File

@@ -24,8 +24,9 @@
from
mxk_apps_saml_v20_details svd,
mxk_apps app
where
app.id = #{value}
where app.instid = #{instId}
and svd.instid = #{instId}
and app.id = #{value}
and svd.id = #{value}
and svd.id = app.id
and app.status = 1

View File

@@ -8,8 +8,9 @@
from
mxk_apps_token_based_details tbd,
mxk_apps app
where
app.id = #{value}
where app.instid = #{instId}
and tbd.instid = #{instId}
and app.id = #{value}
and tbd.id = #{value}
and tbd.id = app.id
and status = 1

View File

@@ -50,7 +50,7 @@
u.status
from
mxk_userinfo u
where 1 = 1
where instid = #{instId}
</select>
<select id="memberInGroup" parameterType="GroupMember" resultType="GroupMember">
@@ -92,7 +92,9 @@
mxk_userinfo u,
mxk_groups g,
mxk_group_member gm
where 1 = 1
where u.instid = #{instId}
and g.instid = #{instId}
and gm.instid = #{instId}
<if test="groupId != null and groupId != ''">
and gm.groupid = #{groupId}
and g.id = #{groupId}

View File

@@ -35,7 +35,9 @@
mxk_apps apps,
mxk_group_privileges gp
where
gp.appid=apps.id
apps.instid = #{instId}
and gp.instid = #{instId}
and gp.appid = apps.id
and gp.groupid = #{groupId}
<include refid="where_statement"/>
</select>

View File

@@ -18,8 +18,7 @@
*
from
`mxk_groups`
where
(1=1)
where instid = #{instId}
<include refid="where_statement"/>
</select>
@@ -28,8 +27,8 @@
*
from
`mxk_groups`
where
dynamic = '1'
where instid = #{instId}
and dynamic = '1'
<include refid="where_statement"/>
</select>
@@ -37,7 +36,7 @@
<update id="logisticDelete" parameterType="Groups" >
update `mxk_groups` set
status = '2'
where 1 = 1
where instid = #{instId}
<if test="id != null">
and id = #{id}
</if>
@@ -48,7 +47,10 @@
<update id="logisticBatchDelete" parameterType="java.util.List">
update `mxk_groups` set status='2' where id in
update `mxk_groups`
set status='2'
where instid = #{instId}
and id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
@@ -62,12 +64,14 @@
mxk_userinfo u,
mxk_groups g,
mxk_group_member gm
where 1 = 1
and gm.memberid = #{value}
and u.id = #{value}
and gm.type in( 'USER','USER-DYNAMIC')
and gm.groupid = g.id
and gm.memberid = u.id
where u.instid = #{instId}
and g.instid = #{instId}
and gm.instid = #{instId}
and gm.memberid = #{value}
and u.id = #{value}
and gm.type in( 'USER','USER-DYNAMIC')
and gm.groupid = g.id
and gm.memberid = u.id
</select>

View File

@@ -53,7 +53,7 @@
select
*
from mxk_history_connector
where 1 = 1
where instid = #{instId}
<include refid="where_statement"/>
order by synctime desc

View File

@@ -45,7 +45,7 @@
date_format(logintime, '%Y-%m-%d %H:%i:%s') as logintime
from mxk_history_login_apps
where 1 = 1
where instid = #{instId}
<include refid="dao_where_statement"/>
order by logintime desc

View File

@@ -57,7 +57,7 @@
date_format(logintime, '%Y-%m-%d %H:%i:%s') as logintime,
date_format(logouttime, '%Y-%m-%d %H:%i:%s') as logouttime
from mxk_history_login
where 1 = 1
where instid = #{instId}
<include refid="dao_where_statement"/>
order by logintime desc
@@ -83,7 +83,8 @@
date_format(logintime, '%Y-%m-%d %H:%i:%s') as logintime,
date_format(logouttime, '%Y-%m-%d %H:%i:%s') as logouttime
from mxk_history_login
where sessionstatus = 1
where instid = #{instId}
and sessionstatus = 1
<include refid="dao_where_statement"/>

View File

@@ -28,7 +28,7 @@
select
*
from mxk_history_synchronizer
where 1 = 1
where instid = #{instId}
<include refid="where_statement"/>
order by synctime desc

View File

@@ -46,7 +46,7 @@
createddate,
createdby
from mxk_history_logs
where 1 = 1
where instid = #{instId}
<include refid="where_statement"/>
order by createddate desc

View File

@@ -19,7 +19,7 @@
from
mxk_notices
where
(1=1)
instid = #{instId}
<include refid="where_statement"/>
order by modifieddate desc
</select>
@@ -29,6 +29,7 @@
*
from
mxk_notices
where instid = #{instId}
order by modifieddate desc
limit 1
</select>

View File

@@ -24,7 +24,7 @@
select
*
from mxk_organizations
where 1 = 1
where instid = #{instId}
<include refid="dao_where_statement"/>
order by sortindex,id
</select>
@@ -34,14 +34,14 @@
select
*
from mxk_organizations
where 1 = 1
where instid = #{instId}
<include refid="dao_where_statement"/>
order by sortindex,id
</select>
<update id="logisticDelete" parameterType="Organizations" >
update mxk_organizations set status = '2'
where 1 = 1
where instid = #{instId}
<if test="id != null and id != '' ">
and id = #{id}
</if>
@@ -57,8 +57,10 @@
</update>
<update id="logisticBatchDelete" parameterType="java.util.List">
UPDATE MXK_ORGANIZATIONS SET STATUS = '2'
WHERE ID IN
UPDATE MXK_ORGANIZATIONS
SET STATUS = '2'
WHERE instid = #{instId}
and id in
<foreach collection="ids" item="selectId" open="(" separator="," close=")">
#{selectId}
</foreach>

View File

@@ -2,69 +2,70 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.maxkey.persistence.mapper.ReportMapper" >
<!-- DAY COUNT 一天访问量 -->
<select id="analysisDay" parameterType="String" resultType="Integer">
<select id="analysisDay" parameterType="java.util.HashMap" resultType="Integer">
select
count(id) reportcount
from mxk_history_login
where
date(logintime) =curdate()
where instid = #{instId}
and date(logintime) =curdate()
</select>
<!-- 本月新用户统计 -->
<select id="analysisNewUsers" parameterType="String" resultType="Integer">
<select id="analysisNewUsers" parameterType="java.util.HashMap" resultType="Integer">
select
count(*) reportcount
from mxk_userinfo
where
last_day(createddate) =last_day(curdate())
where instid = #{instId}
and last_day(createddate) =last_day(curdate())
</select>
<!-- 在线用户统计 -->
<select id="analysisOnlineUsers" parameterType="String" resultType="Integer">
<select id="analysisOnlineUsers" parameterType="java.util.HashMap" resultType="Integer">
select
count(*) reportcount
from mxk_userinfo
where online = 1
where instid = #{instId}
and online = 1
and now() - lastlogintime between 1 and 10000
</select>
<!-- 30天活跃用户统计 -->
<select id="analysisActiveUsers" parameterType="String" resultType="Integer">
<select id="analysisActiveUsers" parameterType="java.util.HashMap" resultType="Integer">
select
count(*) reportcount
from mxk_userinfo
where
date(lastlogintime) >date_add(curdate(), interval - day(curdate()) -31 day)
where instid = #{instId}
and date(lastlogintime) >date_add(curdate(), interval - day(curdate()) -31 day)
</select>
<!-- DAY HOUR COUNT 当天每小时 -->
<select id="analysisDayHour" parameterType="String" resultType="Map">
<select id="analysisDayHour" parameterType="java.util.HashMap" resultType="Map">
select
count(id) reportcount,
hour(logintime) reportstring
from mxk_history_login
where
date(logintime) =curdate()
where instid = #{instId}
and date(logintime) =curdate()
group by reportstring
order by reportstring
</select>
<!-- 30 DAY COUNT 最近30天每天访问量-->
<select id="analysisMonth" parameterType="String" resultType="Map">
<select id="analysisMonth" parameterType="java.util.HashMap" resultType="Map">
select
count(id) reportcount,
date(logintime) reportstring
from mxk_history_login
where
date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
where instid = #{instId}
and date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
group by reportstring
order by reportstring
</select>
<!-- 30天浏览器的访问统计 -->
<select id="analysisBrowser" parameterType="Map" resultType="Map">
<select id="analysisBrowser" parameterType="java.util.HashMap" resultType="Map">
select
count(id) reportcount,
coalesce(browser,'Other') reportstring
from mxk_history_login
where
date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
where instid = #{instId}
and date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
group by reportstring
order by reportcount desc
</select>
@@ -75,8 +76,8 @@
count(id) reportcount,
appname
from mxk_history_login_apps
where
date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
where instid = #{instId}
and date(logintime) >date_add(curdate(), interval - day(curdate()) -31 day)
group by appname order by reportcount desc
</select>

View File

@@ -25,7 +25,9 @@
from
mxk_resources res, mxk_apps app
where
(1=1) and res.appid=app.id
res.instid = #{instId}
and app.instid = #{instId}
and res.appid=app.id
<include refid="where_statement"/>
order by res.sortindex
</select>
@@ -34,7 +36,7 @@
<update id="logisticDelete" parameterType="Resources" >
update mxk_resources set
status = '2'
where 1 = 1
where instid = #{instId}
<if test="id != null">
and id = #{id}
</if>
@@ -45,7 +47,10 @@
<update id="logisticBatchDelete" parameterType="java.util.List">
update mxk_resources set status='2' where id in
update mxk_resources
set status='2'
where instid = #{instId}
and id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>

View File

@@ -50,7 +50,7 @@
u.status
from
mxk_userinfo u
where 1 = 1
where instid = #{instId}
</select>
<select id="memberInRole" parameterType="RoleMember" resultType="RoleMember">
@@ -93,7 +93,9 @@
mxk_userinfo u,
mxk_roles r,
mxk_role_member rm
where 1 = 1
where u.instid = #{instId}
and r.instid = #{instId}
and rm.instid = #{instId}
<if test="roleId != null and roleId != ''">
and rm.roleid = #{roleId}
and r.id = #{roleId}

View File

@@ -15,9 +15,9 @@
select
*
from
`mxk_groups`
where
dynamic = '1'
mxk_roles
where instid = #{instId}
and dynamic = '1'
<include refid="where_statement"/>
</select>
@@ -27,7 +27,7 @@
from
mxk_roles
where
(1=1)
instid = #{instId}
<include refid="where_statement"/>
</select>
@@ -35,7 +35,7 @@
<update id="logisticDelete" parameterType="Roles" >
update mxk_roles set
status = '2'
where 1 = 1
where instid = #{instId}
<if test="id != null">
and id = #{id}
</if>
@@ -46,7 +46,10 @@
<update id="logisticBatchDelete" parameterType="java.util.List">
update mxk_roles set status='2' where id in
update mxk_roles
set status='2'
where instid = #{instId}
and id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
@@ -58,8 +61,8 @@
*
from
mxk_role_permissions
where
status = 1
where instid = #{instId}
and status = 1
<if test="id != null and id != ''">
and id = #{id}
</if>
@@ -73,17 +76,20 @@
</select>
<update id="logisticDeleteRolePermissions" parameterType="java.util.List">
update mxk_role_permissions set status=9 where id in
update mxk_role_permissions
set status=9
where instid = #{instId}
and id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item.id}
</foreach>
</update>
<insert id="insertRolePermissions" parameterType="java.util.List">
insert into mxk_role_permissions ( id,appid,roleid,resourceid,status)
insert into mxk_role_permissions ( id,appid,roleid,resourceid,status,instid)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id},#{item.appId},#{item.roleId},#{item.resourceId},#{item.status})
(#{item.id},#{item.appId},#{item.roleId},#{item.resourceId},#{item.status},#{item.instId})
</foreach>
</insert>

View File

@@ -19,7 +19,7 @@
from
mxk_socials_provider
where
(1=1)
instid = #{instId}
<include refid="where_statement"/>
order by sortindex
</select>

View File

@@ -17,7 +17,7 @@
from
mxk_synchronizers
where
(1=1)
instid = #{instId}
<include refid="where_statement"/>
</select>

View File

@@ -19,7 +19,7 @@
from
mxk_userinfo_adjunct
where
(1=1)
instid = #{instId}
<include refid="where_statement"/>
</select>
@@ -27,7 +27,7 @@
<update id="logisticDelete" parameterType="UserInfoAdjoint" >
update mxk_userinfo_adjunct set
status = '2'
where 1 = 1
where instid = #{instId}
<if test="id != null">
and id = #{id}
</if>
@@ -38,7 +38,10 @@
<update id="logisticBatchDelete" parameterType="java.util.List">
update mxk_userinfo_adjunct set status='2' where id in
update mxk_userinfo_adjunct
set status='2'
where instid = #{instId}
and id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>

View File

@@ -51,8 +51,7 @@
status
from
mxk_userinfo
where
(1=1)
where instid = #{instId}
<if test="username != null and username != ''">
and username = #{username}
</if>
@@ -251,13 +250,17 @@
<select id="loadDeptsByUserId" parameterType="string" resultType="Organizations">
select o.* , 1 isPrimary from mxk_organizations o,mxk_userinfo u
where o.id=u.departmentid
where o.instid = #{instId}
and u.instid = #{instId}
and o.id=u.departmentid
and u.id=#{value}
union all
select o.* , 0 isPrimary from mxk_organizations o,mxk_userinfo_adjunct ua
where o.id=ua.departmentid
where o.instid = #{instId}
and ua.instid = #{instId}
and o.id=ua.departmentid
and ua.userid=#{value}
</select>