|
@@ -8,6 +8,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.om.constant.RedisConstant;
|
|
|
import com.om.entity.dto.EmployeeDto;
|
|
|
import com.om.entity.dto.LoginDto;
|
|
|
import com.om.entity.dto.UpdatePassDTO;
|
|
@@ -16,6 +17,7 @@ import com.om.service.IDepartmentService;
|
|
|
import com.om.service.IEmployeeService;
|
|
|
import com.om.service.IMenuService;
|
|
|
import com.om.utils.Constants;
|
|
|
+import com.om.utils.JwtUtils;
|
|
|
import com.om.utils.Result;
|
|
|
import com.om.utils.TokenUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -27,12 +29,11 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -45,16 +46,19 @@ public class EmployeeController {
|
|
|
RedisTemplate redisTemplate;
|
|
|
IMenuService menuService;
|
|
|
|
|
|
+ static JwtUtils jwtUtils;
|
|
|
|
|
|
@Autowired
|
|
|
public EmployeeController(IEmployeeService employeeService,
|
|
|
IDepartmentService departmentService,
|
|
|
RedisTemplate redisTemplate,
|
|
|
- IMenuService menuService) {
|
|
|
+ IMenuService menuService,
|
|
|
+ JwtUtils jwtUtils) {
|
|
|
this.employeeService = employeeService;
|
|
|
this.departmentService = departmentService;
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
this.menuService = menuService;
|
|
|
+ this.jwtUtils = jwtUtils;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -85,9 +89,15 @@ public class EmployeeController {
|
|
|
static void copyObject(@RequestBody @Validated LoginDto loginDto, Employee employee,
|
|
|
RedisTemplate redisTemplate, IMenuService menuService) {
|
|
|
BeanUtil.copyProperties(employee, loginDto, true);
|
|
|
- String jwt = TokenUtils.genToken(employee.getEmployeeid().toString(), employee.getPassword());
|
|
|
- redisTemplate.opsForValue().set("JWT_" + jwt, JSON.toJSON(employee), 2, TimeUnit.HOURS);
|
|
|
- loginDto.setToken(jwt);
|
|
|
+
|
|
|
+ //生成token
|
|
|
+ Map<String, Object> claims = new HashMap<>();
|
|
|
+ claims.put("a_id",employee.getEmployeeid());
|
|
|
+ String token = jwtUtils.generateToken(claims);
|
|
|
+ //把token存入到redis中
|
|
|
+ String key = RedisConstant.ADMIN_TOKEN_PREFIX + employee.getEmployeeid();
|
|
|
+ redisTemplate.opsForValue().set(key,token,RedisConstant.ADMIN_TOKEN_TTL, TimeUnit.SECONDS);
|
|
|
+ loginDto.setToken(token);
|
|
|
loginDto.setMenus(menuService.getRoleMenu(employee.getRole()));
|
|
|
}
|
|
|
|