Ver código fonte

更新获取登录ID逻辑

master
牧羊人 4 anos atrás
pai
commit
163db1314c
7 arquivos alterados com 67 adições e 18 exclusões
  1. +5
    -5
      src/main/java/com/taauav/front/controller/FrontBaseController.java
  2. +1
    -1
      src/main/java/com/taauav/front/controller/LSReportController.java
  3. +3
    -5
      src/main/java/com/taauav/front/controller/LSUserController.java
  4. +1
    -2
      src/main/java/com/taauav/front/service/ILSReportService.java
  5. +5
    -5
      src/main/java/com/taauav/front/service/impl/LSReportServiceImpl.java
  6. +26
    -0
      src/main/java/com/taauav/front/utils/LoginUtils.java
  7. +26
    -0
      src/main/java/com/taauav/front/utils/ServletUtils.java

+ 5
- 5
src/main/java/com/taauav/front/controller/FrontBaseController.java Ver arquivo

@@ -13,10 +13,10 @@ import javax.servlet.http.HttpServletRequest;
*/
public class FrontBaseController {

/**
* 登录用户ID
*/
public Integer userId;
// /**
// * 登录用户ID
// */
// public Integer userId;

/**
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
@@ -26,7 +26,7 @@ public class FrontBaseController {
System.out.println("初始化基类");
String token = request.getHeader("token");
Claims data = JwtUtil.parseJWT(token);
this.userId = Integer.valueOf(data.get("id").toString());
// this.userId = Integer.valueOf(data.get("id").toString());
}

}

+ 1
- 1
src/main/java/com/taauav/front/controller/LSReportController.java Ver arquivo

@@ -30,7 +30,7 @@ public class LSReportController extends FrontBaseController {
*/
@PostMapping("/index")
public Response index(@RequestBody(required = false) LSReportQuery query) {
return reportService.getList(query, this.userId);
return reportService.getList(query);
}

/**

+ 3
- 5
src/main/java/com/taauav/front/controller/LSUserController.java Ver arquivo

@@ -7,6 +7,7 @@ import com.taauav.common.util.FunctionUtils;
import com.taauav.common.util.JwtUtil;
import com.taauav.common.util.StringUtils;
import com.taauav.front.dto.UpdatePwdDto;
import com.taauav.front.utils.LoginUtils;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -30,10 +31,7 @@ public class LSUserController extends FrontBaseController {
*/
@PostMapping("/info")
public Response info(HttpServletRequest request) {
String token = request.getHeader("token");
Claims data = JwtUtil.parseJWT(token);
Integer userId = Integer.valueOf(data.get("id").toString());
LsAdmin adminInfo = adminService.getById(userId);
LsAdmin adminInfo = adminService.getById(LoginUtils.getAdminId());
return response.success(adminInfo);
}

@@ -46,7 +44,7 @@ public class LSUserController extends FrontBaseController {
@PostMapping("/editPassword")
public Response editPassword(@RequestBody UpdatePwdDto updatePwdDto) {
// 获取个人信息
LsAdmin adminInfo = adminService.getById(this.userId);
LsAdmin adminInfo = adminService.getById(LoginUtils.getAdminId());
if (adminInfo == null) {
return response.failure("用户信息不存在");
}

+ 1
- 2
src/main/java/com/taauav/front/service/ILSReportService.java Ver arquivo

@@ -19,10 +19,9 @@ public interface ILSReportService extends IBaseService<TauvReport> {
* 获取报告列表
*
* @param query 查询条件
* @param userId 用户ID
* @return
*/
Response getList(LSReportQuery query, Integer userId);
Response getList(LSReportQuery query);

/**
* 获取报告详情

+ 5
- 5
src/main/java/com/taauav/front/service/impl/LSReportServiceImpl.java Ver arquivo

@@ -15,6 +15,7 @@ import com.taauav.common.util.StringUtils;
import com.taauav.front.mapper.LSReportMapper;
import com.taauav.front.query.LSReportQuery;
import com.taauav.front.service.ILSReportService;
import com.taauav.front.utils.LoginUtils;
import com.taauav.front.vo.LSReportInfoVo;
import com.taauav.front.vo.LSReportListVo;
import com.taauav.front.vo.LSReportQuestionFileListVo;
@@ -79,11 +80,10 @@ public class LSReportServiceImpl extends BaseServiceImpl<LSReportMapper, TauvRep
* 获取报告列表
*
* @param query 查询条件
* @param userId 用户ID
* @return
*/
@Override
public Response getList(LSReportQuery query, Integer userId) {
public Response getList(LSReportQuery query) {
// 查询条件
QueryWrapper<TauvReport> queryWrapper = new QueryWrapper<>();
// 报告编号
@@ -121,12 +121,12 @@ public class LSReportServiceImpl extends BaseServiceImpl<LSReportMapper, TauvRep
queryWrapper.eq("mark", 1);

// 数据权限
if (userId != 1) {
if (LoginUtils.getAdminId() != 1) {
List<BigInteger> driverAreaList = new ArrayList<>();
// 获取当前登录人员信息
LsAdmin lsAdmin = lsAdminMapper.selectById(userId);
LsAdmin lsAdmin = lsAdminMapper.selectById(LoginUtils.getAdminId());
// 遍历数据权限
Map<Integer, String> map = adminService.getAdminAuthData(userId);
Map<Integer, String> map = adminService.getAdminAuthData(LoginUtils.getAdminId());
for (Map.Entry<Integer, String> entry : map.entrySet()) {
if (entry.getKey() == 1) {
// 查看本人负责的河湖

+ 26
- 0
src/main/java/com/taauav/front/utils/LoginUtils.java Ver arquivo

@@ -0,0 +1,26 @@
package com.taauav.front.utils;

import com.taauav.common.util.JwtUtil;
import com.taauav.common.util.StringUtils;
import io.jsonwebtoken.Claims;

/**
* 封路信息工具类
*/
public class LoginUtils {

/**
* 获取登录用户ID
*
* @return
*/
public static Integer getAdminId() {
String token = ServletUtils.getRequest().getHeader("token");
Claims data = JwtUtil.parseJWT(token);
if (!StringUtils.isEmpty(data.get("id").toString())) {
return Integer.valueOf(data.get("id").toString());
}
return 0;
}

}

+ 26
- 0
src/main/java/com/taauav/front/utils/ServletUtils.java Ver arquivo

@@ -0,0 +1,26 @@
package com.taauav.front.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* Servlet工具类
*/
public class ServletUtils {

/**
* 获取request
*/
public static HttpServletRequest getRequest() {
return getRequestAttributes().getRequest();
}

public static ServletRequestAttributes getRequestAttributes() {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
return (ServletRequestAttributes) attributes;
}

}

Carregando…
Cancelar
Salvar