Browse Source

数据权限

yangyue 1 year ago
parent
commit
3b81e44d35

+ 24 - 4
duty-service/src/main/java/cn/com/taiji/duty/controller/DutyLoginLogController.java

@@ -2,11 +2,10 @@ package cn.com.taiji.duty.controller;
 
 
 import cn.com.taiji.duty.model.*;
+import cn.com.taiji.duty.service.IDutyAccountService;
 import cn.com.taiji.duty.service.IDutyLoginLogService;
 import cn.com.taiji.duty.service.IDutyOperLogService;
-import cn.com.taiji.duty.utils.AjaxResult;
-import cn.com.taiji.duty.utils.HttpStatus;
-import cn.com.taiji.duty.utils.TableDataInfo;
+import cn.com.taiji.duty.utils.*;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
@@ -15,13 +14,17 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -43,6 +46,12 @@ public class DutyLoginLogController {
     @Autowired
     private IDutyOperLogService operLogService;
 
+    @Autowired
+    protected StringRedisTemplate redisTemplate;
+
+    @Autowired
+    private IDutyAccountService accountService;
+
     @ApiOperation("登录日志查询")
     @GetMapping("search")
     public AjaxResult search(Long id) {
@@ -54,7 +63,18 @@ public class DutyLoginLogController {
 
     @ApiOperation("登录日志列表")
     @PostMapping("list")
-    public TableDataInfo list(@RequestBody DutyLoginLogVo vo) {
+    public TableDataInfo list(HttpServletRequest request, @RequestBody DutyLoginLogVo vo) {
+        String token = JwtUtils.getToken(request);
+        String username = redisTemplate.opsForValue().get(token);
+        DutyAccount account = accountService.findByUsername(username);
+        if (account != null) {
+            List<DutyRole> roles = account.getRoles();
+            List<String> stringList = roles.parallelStream().map(DutyRole::getPermissionValue).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+            String join = StringUtils.join(stringList, ",");
+            if (join.contains("ZBY")) {
+                vo.setDeptId(account.getDept().getId());
+            }
+        }
         PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
         List<DutyLoginLog> list = loginLogService.queryList(vo);
         TableDataInfo rspData = new TableDataInfo();

+ 1 - 0
duty-service/src/main/java/cn/com/taiji/duty/controller/DutyNoticeInfoController.java

@@ -84,6 +84,7 @@ public class DutyNoticeInfoController {
             List<String> stringList = roles.parallelStream().map(DutyRole::getPermissionValue).filter(Objects::nonNull).distinct().collect(Collectors.toList());
             String join = StringUtils.join(stringList, ",");
             if (join.contains("ZBY")) {
+                vo.setStatus("1");
                 PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
                 list = infoService.queryReadStatusList(one.getId(), vo);
             } else {

+ 25 - 8
duty-service/src/main/java/cn/com/taiji/duty/controller/DutyOperLogController.java

@@ -1,14 +1,10 @@
 package cn.com.taiji.duty.controller;
 
 
-import cn.com.taiji.duty.model.DutyLoginLog;
-import cn.com.taiji.duty.model.DutyLoginLogVo;
-import cn.com.taiji.duty.model.DutyOperLog;
-import cn.com.taiji.duty.model.DutyOperLogVo;
+import cn.com.taiji.duty.model.*;
+import cn.com.taiji.duty.service.IDutyAccountService;
 import cn.com.taiji.duty.service.IDutyOperLogService;
-import cn.com.taiji.duty.utils.AjaxResult;
-import cn.com.taiji.duty.utils.HttpStatus;
-import cn.com.taiji.duty.utils.TableDataInfo;
+import cn.com.taiji.duty.utils.*;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
@@ -17,13 +13,17 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -42,6 +42,12 @@ public class DutyOperLogController {
     @Autowired
     private IDutyOperLogService operLogService;
 
+    @Autowired
+    protected StringRedisTemplate redisTemplate;
+
+    @Autowired
+    private IDutyAccountService accountService;
+
     @ApiOperation("操作日志查询")
     @GetMapping("search")
     public AjaxResult search(Long id) {
@@ -53,7 +59,18 @@ public class DutyOperLogController {
 
     @ApiOperation("操作日志列表")
     @PostMapping("list")
-    public TableDataInfo list(@RequestBody DutyOperLogVo vo) {
+    public TableDataInfo list(HttpServletRequest request, @RequestBody DutyOperLogVo vo) {
+        String token = JwtUtils.getToken(request);
+        String username = redisTemplate.opsForValue().get(token);
+        DutyAccount account = accountService.findByUsername(username);
+        if (account != null) {
+            List<DutyRole> roles = account.getRoles();
+            List<String> stringList = roles.parallelStream().map(DutyRole::getPermissionValue).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+            String join = StringUtils.join(stringList, ",");
+            if (join.contains("ZBY")) {
+                vo.setDeptId(account.getDept().getId());
+            }
+        }
         PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
         List<DutyOperLog> list = operLogService.queryList(vo);
         TableDataInfo rspData = new TableDataInfo();