Browse Source

'登录日志、操作日志模块新增数据权限管理-DataScope的功能'

james 1 year ago
parent
commit
98d33465fe

+ 1 - 1
base-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java

@@ -116,7 +116,7 @@ public class DataScopeAspect
             {
                 if (StringUtils.isNotBlank(userAlias))
                 {
-                    sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
+                    sqlString.append(StringUtils.format(" OR {}.create_by = {} ", userAlias, user.getUserName()));
                 }
                 else
                 {

+ 17 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/domain/SysLogininfor.java

@@ -2,6 +2,7 @@ package com.usky.system.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.usky.common.core.bean.BaseEntity;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -12,7 +13,7 @@ import java.util.Map;
  *
  * @author ruoyi
  */
-public class SysLogininfor
+public class SysLogininfor extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
 
@@ -45,6 +46,11 @@ public class SysLogininfor
      */
     private Integer tenantId;
 
+    /**
+     * 创建人
+     */
+    private String createBy;
+
     public String getSearchValue() {
         return searchValue;
     }
@@ -152,4 +158,14 @@ public class SysLogininfor
     {
         this.tenantId = tenantId;
     }
+
+    public String getCreateBy()
+    {
+        return createBy;
+    }
+
+    public void setCreateBy(String createBy)
+    {
+        this.createBy = createBy;
+    }
 }

+ 17 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/domain/SysOperLog.java

@@ -2,6 +2,7 @@ package com.usky.system.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.usky.common.core.bean.BaseEntity;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -13,7 +14,7 @@ import java.util.Map;
  * 
  * @author yq
  */
-public class SysOperLog
+public class SysOperLog extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
 
@@ -80,6 +81,11 @@ public class SysOperLog
      */
     private Integer tenantId;
 
+    /**
+     * 创建人
+     */
+    private String createBy;
+
     public String getSearchValue() {
         return searchValue;
     }
@@ -298,4 +304,14 @@ public class SysOperLog
     {
         this.tenantId = tenantId;
     }
+
+    public String getCreateBy()
+    {
+        return createBy;
+    }
+
+    public void setCreateBy(String createBy)
+    {
+        this.createBy = createBy;
+    }
 }

+ 1 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/SysLoginService.java

@@ -232,6 +232,7 @@ public class SysLoginService {
         logininfor.setUserName(username);
         logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
         logininfor.setMsg(message);
+        logininfor.setCreateBy(username);
 
         LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.select(SysUser::getDeptId)

+ 3 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysLogininforServiceImpl.java

@@ -1,6 +1,7 @@
 package com.usky.system.service.impl;
 
 
+import com.ruoyi.common.datascope.annotation.DataScope;
 import com.usky.common.core.util.StringUtils;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.common.security.utils.SecurityUtils;
@@ -48,6 +49,7 @@ public class SysLogininforServiceImpl extends AbstractCrudService<SysLogininforM
      * @param logininfor 访问日志对象
      * @return 登录记录集合
      */
+    @DataScope(deptAlias = "d",userAlias = "d")
     @Override
     public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor)
     {
@@ -61,6 +63,7 @@ public class SysLogininforServiceImpl extends AbstractCrudService<SysLogininforM
      * @return 登录记录导出集合
      */
     @Override
+    @DataScope(deptAlias = "d",userAlias = "d")
     public List<SysLoginExportVO> selectLogininforListExport(SysLogininfor logininfor)
     {
         return logininforMapper.selectLogininforListExport(logininfor);

+ 4 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysOperLogServiceImpl.java

@@ -1,6 +1,7 @@
 package com.usky.system.service.impl;
 
 
+import com.ruoyi.common.datascope.annotation.DataScope;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.system.domain.SysOperLog;
@@ -35,6 +36,7 @@ public class SysOperLogServiceImpl extends AbstractCrudService<SysOperLogMapper,
     public void insertOperlog(SysOperLog operLog)
     {
         operLog.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue());
+        operLog.setCreateBy(operLog.getOperName());
 
         operLog.setTenantId(SecurityUtils.getTenantId());
         Date now = new Date();
@@ -49,6 +51,7 @@ public class SysOperLogServiceImpl extends AbstractCrudService<SysOperLogMapper,
      * @return 操作日志集合
      */
     @Override
+    @DataScope(deptAlias = "d",userAlias = "d")
     public List<SysOperLog> selectOperLogList(SysOperLog operLog)
     {
         return operLogMapper.selectOperLogList(operLog);
@@ -61,6 +64,7 @@ public class SysOperLogServiceImpl extends AbstractCrudService<SysOperLogMapper,
      * @return 操作日志集合
      */
     @Override
+    @DataScope(deptAlias = "d",userAlias = "d")
     public List<SysOperLogExportVO> selectOperLogListExport(SysOperLog operLog)
     {
         return operLogMapper.selectOperLogListExport(operLog);

+ 8 - 2
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysLogininforMapper.xml

@@ -13,6 +13,7 @@
 		<result property="accessTime"    column="access_time"       />
 		<result property="deptId"        column="dept_id"           />
 		<result property="tenantId"      column="tenant_id"         />
+		<result property="createBy"      column="create_by"         />
 	</resultMap>
 
 	<insert id="insertLogininfor" parameterType="com.usky.system.domain.SysLogininfor">
@@ -25,6 +26,7 @@
 			<if test="accessTime != null"> access_time, </if>
 			<if test="deptId != null"> dept_id, </if>
 			<if test="tenantId != null"> tenant_id, </if>
+			<if test="createBy != null"> create_by, </if>
 		</trim>
 		values
 		<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -35,11 +37,12 @@
 			<if test="accessTime != null"> #{accessTime},</if>
 			<if test="deptId != null"> #{deptId},</if>
 			<if test="tenantId != null"> #{tenantId},</if>
+			<if test="createBy != null"> #{createBy},</if>
 		</trim>
 	</insert>
 
 	<select id="selectLogininforList" parameterType="com.usky.system.domain.SysLogininfor" resultMap="SysLogininforResult">
-		select info_id, user_name, ipaddr, status, msg, access_time from sys_logininfor
+		select info_id, user_name, ipaddr, status, msg, access_time from sys_logininfor d
 		<where>
 			<if test="ipaddr != null and ipaddr != ''">
 				AND ipaddr like concat('%', #{ipaddr}, '%')
@@ -56,12 +59,14 @@
 			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
 				and date_format(access_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
 			</if>
+			<!-- 数据范围过滤 -->
+			${params.dataScope}
 		</where>
 		order by info_id desc
 	</select>
 
 	<select id="selectLogininforListExport" parameterType="com.usky.system.domain.SysLogininfor" resultType="com.usky.system.service.vo.SysLoginExportVO">
-		select info_id, ipaddr, user_name, (case status when '0' then '成功' else '失败' end) as status, msg, access_time from sys_logininfor
+		select info_id, ipaddr, user_name, (case status when '0' then '成功' else '失败' end) as status, msg, access_time from sys_logininfor d
 		<where>
 			<if test="ipaddr != null and ipaddr != ''">
 				AND ipaddr like concat('%', #{ipaddr}, '%')
@@ -78,6 +83,7 @@
 			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
 				and date_format(access_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
 			</if>
+			${params.dataScope}
 		</where>
 		order by info_id desc
 	</select>

+ 7 - 0
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysOperLogMapper.xml

@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="operTime"       column="oper_time"      />
 		<result property="deptId"         column="dept_id"        />
 		<result property="tenantId"       column="tenant_id"      />
+		<result property="createBy"       column="create_by"      />
 	</resultMap>
 
 	<sql id="selectOperLogVo">
@@ -50,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="operTime != null"> oper_time, </if>
 			<if test="deptId != null"> dept_id, </if>
 			<if test="tenantId != null"> tenant_id, </if>
+			<if test="createBy != null"> create_by, </if>
 		</trim>
 		values
 		<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -70,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="operTime != null"> #{operTime},</if>
 			<if test="deptId != null"> #{deptId},</if>
 			<if test="tenantId != null"> #{tenantId},</if>
+			<if test="createBy != null"> #{createBy},</if>
 		</trim>
 	</insert>
 	
@@ -100,6 +103,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
 				and date_format(oper_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
 			</if>
+			<!-- 数据范围过滤 -->
+			${params.dataScope}
 		</where>
 		order by oper_id desc
 	</select>
@@ -132,6 +137,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
 				and date_format(oper_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
 			</if>
+			<!-- 数据范围过滤 -->
+			${params.dataScope}
 		</where>
 		order by oper_id desc
 	</select>