|
@@ -1,26 +1,35 @@
|
|
package com.free.controller;
|
|
package com.free.controller;
|
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
+import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
import com.free.dto.LoginDTO;
|
|
import com.free.dto.LoginDTO;
|
|
import com.free.dto.PasswordUpdateDTO;
|
|
import com.free.dto.PasswordUpdateDTO;
|
|
import com.free.entity.system.Admin;
|
|
import com.free.entity.system.Admin;
|
|
import com.free.entity.system.Customer;
|
|
import com.free.entity.system.Customer;
|
|
|
|
+import com.free.entity.system.Role;
|
|
import com.free.frame.CustomizationException;
|
|
import com.free.frame.CustomizationException;
|
|
import com.free.frame.ExceptionEnum;
|
|
import com.free.frame.ExceptionEnum;
|
|
import com.free.frame.ResponseFormat;
|
|
import com.free.frame.ResponseFormat;
|
|
import com.free.service.system.AdminService;
|
|
import com.free.service.system.AdminService;
|
|
import com.free.service.system.CustomerService;
|
|
import com.free.service.system.CustomerService;
|
|
|
|
+import com.free.service.system.MenusService;
|
|
|
|
+import com.free.service.system.RoleService;
|
|
import com.free.utils.BcryptUtil;
|
|
import com.free.utils.BcryptUtil;
|
|
import com.free.utils.JwtUtil;
|
|
import com.free.utils.JwtUtil;
|
|
|
|
|
|
@@ -31,7 +40,8 @@ import io.swagger.annotations.ApiOperation;
|
|
@RequestMapping
|
|
@RequestMapping
|
|
@Api(tags = "登录服务")
|
|
@Api(tags = "登录服务")
|
|
public class LoginController {
|
|
public class LoginController {
|
|
-
|
|
|
|
|
|
+ /** 超级管理员编码 */
|
|
|
|
+ private String isSuperAdminCode = "0";
|
|
/** 管理员登录类型 */
|
|
/** 管理员登录类型 */
|
|
private String adminLoginType = "Admin";
|
|
private String adminLoginType = "Admin";
|
|
/** 客服人员登录类型 */
|
|
/** 客服人员登录类型 */
|
|
@@ -43,6 +53,12 @@ public class LoginController {
|
|
@Autowired
|
|
@Autowired
|
|
private CustomerService customerService;
|
|
private CustomerService customerService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MenusService menusService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RoleService roleService;
|
|
|
|
+
|
|
@ApiOperation("客服服务登录")
|
|
@ApiOperation("客服服务登录")
|
|
@PostMapping("/kf/login/{type}")
|
|
@PostMapping("/kf/login/{type}")
|
|
public Object login(@PathVariable String type, @RequestBody @Valid LoginDTO data) {
|
|
public Object login(@PathVariable String type, @RequestBody @Valid LoginDTO data) {
|
|
@@ -122,12 +138,73 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据token,查询出用户的权限,目录
|
|
* 根据token,查询出用户的权限,目录
|
|
|
|
+ *
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
+ @GetMapping("/tokenView")
|
|
public Object tokenView() {
|
|
public Object tokenView() {
|
|
Map userMap = JwtUtil.getDetails(null);
|
|
Map userMap = JwtUtil.getDetails(null);
|
|
- // TODO: 找出用户,再找到角色,转换成列表
|
|
|
|
-
|
|
|
|
- return ResponseFormat.success();
|
|
|
|
|
|
+ Map<String, Object> returnData = new HashMap<>();
|
|
|
|
+ /**
|
|
|
|
+ * 1.用户信息;
|
|
|
|
+ * 2.用户类型;
|
|
|
|
+ * 3-1.管理员用户:
|
|
|
|
+ * 4.查看是否是超级管理员(is_super = 0):
|
|
|
|
+ * 5-1: 是超级管理员 - 递归获取所有目录,全部显示
|
|
|
|
+ * 5-2: 不是超级管理员 - 根据设置角色 获取指定目录
|
|
|
|
+ * 3-2.客服人员:
|
|
|
|
+ * 4.根据角色获取指定目录
|
|
|
|
+ */
|
|
|
|
+ Long user_id = Long.valueOf(String.valueOf(userMap.get("id")));
|
|
|
|
+ String type = (String) userMap.get("type");
|
|
|
|
+ Map<String, Object> userInfo = null;
|
|
|
|
+ if (this.adminLoginType.equals(type)) {
|
|
|
|
+ // 判断是否是超级管理员
|
|
|
|
+ String is_super = (String) userMap.get("is_super");
|
|
|
|
+ if (this.isSuperAdminCode.equals(is_super)) {
|
|
|
|
+ List menus = this.menusService.recursionMenus();
|
|
|
|
+ returnData.put("menus", menus);
|
|
|
|
+ return ResponseFormat.success(returnData);
|
|
|
|
+ }
|
|
|
|
+ // 不是超级管理员,那也是管理员,查出管理员信息,之后一起处理
|
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("id", user_id);
|
|
|
|
+ qw.eq("is_use", "0");
|
|
|
|
+ userInfo = this.adminService.getMap(qw);
|
|
|
|
+ } else if (this.customerService.equals(type)) {
|
|
|
|
+ // 查客服人员最新信息
|
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("id", user_id);
|
|
|
|
+ qw.eq("is_use", "0");
|
|
|
|
+ userInfo = this.customerService.getMap(qw);
|
|
|
|
+ }
|
|
|
|
+ if (null == userInfo) {
|
|
|
|
+ // 没有用户说明: 1.token有问题;2.用户数据有问题
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.TOKEN_ERROR);
|
|
|
|
+ }
|
|
|
|
+ // 根据角色获取目录
|
|
|
|
+ Long role = Long.valueOf(String.valueOf(userInfo.get("role")));
|
|
|
|
+ QueryWrapper roleQW = new QueryWrapper<>();
|
|
|
|
+ roleQW.eq("id", role);
|
|
|
|
+ roleQW.eq("is_use", "0");
|
|
|
|
+ Role userRole = this.roleService.getOne(roleQW);
|
|
|
|
+ if (null == userRole) {
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.USER_ROLE_NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ ArrayNode menus = userRole.getMenu();
|
|
|
|
+ // 根据前端选择的route_name进行目录的查询
|
|
|
|
+ List menusRouteNameList = new ArrayList();
|
|
|
|
+ for (int i = 0; i < menus.size(); i++) {
|
|
|
|
+ JsonNode e = menus.get(i);
|
|
|
|
+ String route_name = e.textValue();
|
|
|
|
+ menusRouteNameList.add(route_name);
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper menuQW = new QueryWrapper<>();
|
|
|
|
+ menuQW.in("route_name", menusRouteNameList);
|
|
|
|
+ menuQW.eq("is_use", "0");
|
|
|
|
+ List menusList = this.menusService.list(menuQW);
|
|
|
|
+ List returnMenus = this.menusService.recursionMenus(menusList);
|
|
|
|
+ returnData.put("menus", returnMenus);
|
|
|
|
+ return ResponseFormat.success(returnData);
|
|
}
|
|
}
|
|
}
|
|
}
|