Quellcode durchsuchen

日志查询-权限

WXF vor 2 Jahren
Ursprung
Commit
d7296ec367

+ 3 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/ctrl/LogCtrl.java

@@ -8,6 +8,7 @@ import api.common.pojo.po.log.LogSystemPO;
 import com.css.simulation.resource.log.service.LogService;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,6 +23,7 @@ public class LogCtrl {
 
     @RequestMapping("/getLoginLogPageList")
     @ResponseBody
+    @PreAuthorize("@AuthorityCheck.admin()")
     public ResponseBodyVO<PageInfo<LogLoginPO>> getLoginLogPageList(@RequestBody LogPageParam pageParam){
         ResponseBodyVO<PageInfo<LogLoginPO>> response = new ResponseBodyVO<PageInfo<LogLoginPO>>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(logService.getLoginLogPageList(pageParam));
@@ -30,6 +32,7 @@ public class LogCtrl {
 
     @RequestMapping("/getOperationLogPageList")
     @ResponseBody
+    @PreAuthorize("@AuthorityCheck.adminAndUser()")
     public ResponseBodyVO<PageInfo<LogOperationPO>> getOperationLogPageList(@RequestBody LogPageParam pageParam){
         ResponseBodyVO<PageInfo<LogOperationPO>> response = new ResponseBodyVO<PageInfo<LogOperationPO>>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(logService.getOperationLogPageList(pageParam));

+ 3 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/mapper/LogMapper.java

@@ -21,9 +21,12 @@ public interface LogMapper {
 
     List<LogOperationPO> getOperationLogPageList(LogPageParam pageParam);
 
+    List<LogOperationPO> getUserOperationLogPageList(LogPageParam pageParam);
+
     List<LogSystemPO> getSystemLogPageList(LogPageParam pageParam);
 
     void insertSystemLog(LogSystemPO po);
 
     List<LineChartVO> getAccessCount(@Param("dateBegin") String dateBegin);
+
 }

+ 10 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/log/service/LogService.java

@@ -9,7 +9,6 @@ import api.common.pojo.po.log.LogOperationPO;
 import api.common.pojo.po.log.LogSystemPO;
 import api.common.pojo.po.model.VehicleTempPO;
 import api.common.pojo.po.scene.SystemScenePackagePO;
-import api.common.pojo.po.scene.SystemUserScenePO;
 import api.common.pojo.po.system.ClusterPO;
 import api.common.pojo.po.system.ParameterPO;
 import api.common.pojo.po.system.UserPO;
@@ -26,9 +25,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 
 @Service
@@ -64,7 +63,15 @@ public class LogService {
      */
     public PageInfo<LogOperationPO> getOperationLogPageList(LogPageParam pageParam) {
         PageUtil.setPageInfo(pageParam);
-        List<LogOperationPO> list = logMapper.getOperationLogPageList(pageParam);
+        List<LogOperationPO> list = new ArrayList<>();
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        if(DictConstants.ROLE_CODE_UESR.equals(roleCode)){//普通用户
+            String currentUserId = AuthUtil.getCurrentUserId();
+            pageParam.setContent(currentUserId);//借用该字段传递当前用户id
+            list = logMapper.getUserOperationLogPageList(pageParam);
+        }else{//管理员
+            list = logMapper.getOperationLogPageList(pageParam);
+        }
         //字典翻译
         Map<String, Map<String, String>> dictMaps = dictService.getDictMapsByTypes(LogConstants.MODULE_TYPE + "," + LogConstants.OPERATION_TYPE);
         list.forEach(po ->{

+ 30 - 0
simulation-resource-server/src/main/resources/mapper/log/LogMapper.xml

@@ -72,6 +72,36 @@
         ORDER BY create_time DESC
     </select>
 
+    <select id="getUserOperationLogPageList" parameterType="api.common.pojo.param.log.LogPageParam" resultType="api.common.pojo.po.log.LogOperationPO">
+        select
+          o.id,
+          o.user_id,
+          o.username,
+          o.ip,
+          o.module,
+          o.operation_type,
+          o.create_time
+        FROM log_operation o
+        JOIN system_user u ON o.user_id = u.id AND u.create_user_id = #{content,jdbcType=VARCHAR}
+        WHERE 1=1
+        <if test="username != null and username != ''">
+            and o.username like CONCAT('%',#{username,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="module != null and module != ''">
+            and o.module = #{module,jdbcType=VARCHAR}
+        </if>
+        <if test="operationType != null and operationType != ''">
+            and o.operation_type = #{operationType,jdbcType=VARCHAR}
+        </if>
+        <if test="createTimeBegin != null and createTimeBegin != ''">
+            and DATE(o.create_time) &gt;= #{createTimeBegin}
+        </if>
+        <if test="createTimeEnd != null and createTimeBegin != ''">
+            and DATE(o.create_time) &lt;= #{createTimeEnd}
+        </if>
+        ORDER BY o.create_time DESC
+    </select>
+
     <select id="getSystemLogPageList" parameterType="api.common.pojo.param.log.LogPageParam" resultType="api.common.pojo.po.log.LogSystemPO">
         SELECT
           id,