From 613dd76a3aded439f1002d904d85d8332ddb03d1 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 17 Sep 2020 15:22:29 +0800
Subject: [PATCH] 登陆获取信息分离,webToken添加redis
---
src/main/java/com/moral/controller/WebController.java | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 102 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/moral/controller/WebController.java b/src/main/java/com/moral/controller/WebController.java
index de4f6df..fde7b89 100644
--- a/src/main/java/com/moral/controller/WebController.java
+++ b/src/main/java/com/moral/controller/WebController.java
@@ -1,6 +1,10 @@
package com.moral.controller;
+import com.auth0.jwt.exceptions.JWTDecodeException;
+import com.moral.common.exception.WebAuthException;
import com.moral.common.util.BeanUtils;
+import com.moral.common.util.RedisHashUtil;
+import com.moral.common.util.WebTokenUtils;
import com.moral.common.webAnno.UserLoginToken;
import com.moral.entity.AreaNames;
import com.moral.entity.Organization;
@@ -8,13 +12,13 @@
import com.moral.service.DictionaryDataService;
import com.moral.service.OrganizationService;
import com.moral.service.WebTokenService;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.moral.util.LatLngTransformation;
+import jdk.nashorn.internal.runtime.logging.Logger;
+import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,11 +38,99 @@
OrganizationService organizationService;
@Resource
WebTokenService webTokenService;
+ @Resource
+ RedisHashUtil redisHashUtil;
- @RequestMapping("login")
- public Map<String, Object> login(HttpServletRequest request){
+ @PostMapping("login")
+ public Map<String, Object> login(@RequestBody Map<String, Object> parameters) {
Map<String, Object> resultMap = new HashMap<String, Object>();
- Map<String, Object> parameters = getParametersStartingWith(request, null);
+ if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
+ resultMap.put("msg", "������������������������������������");
+ resultMap.put("accountId", -1);
+ } else {
+ resultMap = accountService.webLogin(parameters);
+ String accountId = String.valueOf(resultMap.get("accountId"));
+ if (!accountId.equals("-1")) {
+ redisHashUtil.deleteMapVal("webToken",accountId);
+ resultMap.put("token", webTokenService.getToken(accountId));
+ }
+ }
+ return resultMap;
+ }
+
+ @UserLoginToken
+ @PostMapping("logout")
+ public Map<String, Object> logout(HttpServletRequest request) {
+ Map<String, Object> resultMap = new HashMap<>();
+ String token = request.getHeader("token");
+ String id = WebTokenUtils.getIdBytoken(token);
+ redisHashUtil.addMapOne("webToken", String.valueOf(id),token);
+ resultMap.put("msg", "������������!");
+ return resultMap;
+ }
+
+ @UserLoginToken
+ @GetMapping("getAccountInfo")
+ public Map<String, Object> getAccountInfo(HttpServletRequest request) {
+ String token = request.getHeader("token");
+ String id = "";
+ try {
+ id = WebTokenUtils.getIdBytoken(token);
+ } catch (JWTDecodeException e) {
+ throw new WebAuthException("401,token������");
+ }
+ Map<String, Object> resultMap = accountService.getAccountInfoById(id);
+ Object orgId = resultMap.get("orgId");
+ if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) {
+ StringBuilder areaNamesBuilder = new StringBuilder("������");
+ //���������������������������������
+ if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) {
+ //���������������������������������������������������
+ Organization organization = organizationService.getOrganizationById((Integer) orgId);
+ if (organization.getAreaNames() != null) {
+ Map<String, String> areaNameMap = BeanUtils.beanToMap(organization.getAreaNames());
+ List<String> names = areaNameMap.entrySet().stream().filter(item -> {
+ return item.getValue() != null;
+ }).map(item -> {
+ return item.getValue();
+ }).collect(Collectors.toList());
+ AreaNames areaNames = organization.getAreaNames();
+ areaNamesBuilder.append("/");
+ areaNamesBuilder.append(String.join("/", names));
+ }
+ // ������������
+ if (organization.getRank() != null && organization.getRank() == 0) {
+ resultMap.put("type", "enterprise");
+ } else {
+ resultMap.put("type", "government");
+ }
+ Number mapAreaCode = null;
+ if (organization.getVillageCode() != null) {
+ mapAreaCode = organization.getVillageCode();
+ } else if (organization.getTownCode() != null) {
+ mapAreaCode = organization.getTownCode();
+ } else if (organization.getAreaCode() != null) {
+ mapAreaCode = organization.getAreaCode();
+ } else if (organization.getCityCode() != null) {
+ mapAreaCode = organization.getCityCode();
+ } else if (organization.getProvinceCode() != null) {
+ mapAreaCode = organization.getProvinceCode();
+ }
+ resultMap.put("mapAreaCode", mapAreaCode.toString());
+ }
+ resultMap.put("mapPath", areaNamesBuilder.toString());
+ String accountId = String.valueOf(resultMap.get("accountId"));
+ resultMap.put("token", webTokenService.getToken(accountId));
+ }
+ return resultMap;
+ }
+
+ //������
+ @UserLoginToken
+ @RequestMapping("getAccountInfoTest")
+ public Map<String, Object> getAccountInfoTest(@RequestBody Map<String, Object> parameters) {
+ Map<String, Object> resultMap = new HashMap<String, Object>();
+ System.out.println(parameters);
if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
resultMap.put("msg", "������������������������������������");
resultMap.put("accountId", -1);
@@ -84,8 +176,8 @@
resultMap.put("mapAreaCode", mapAreaCode.toString());
}
resultMap.put("mapPath", areaNamesBuilder.toString());
- String accountId= String.valueOf(resultMap.get("accountId"));
- resultMap.put("token",webTokenService.getToken(accountId));
+ String accountId = String.valueOf(resultMap.get("accountId"));
+ resultMap.put("token", webTokenService.getToken(accountId));
}
}
return resultMap;
@@ -93,7 +185,7 @@
@UserLoginToken
@GetMapping("test")
- public String add(){
+ public String add() {
return "test success!";
}
}
--
Gitblit v1.8.0