Commit c04e306b authored by linruibiao's avatar linruibiao

Merge remote-tracking branch 'origin/develop' into develop

parents 9f89f026 c5425d26
......@@ -30,4 +30,9 @@ public final class SlmConstants {
*/
public static final Integer DATA_DELETED = -1;
/**
* 请求头token的key名称
*/
public static final String TOKEN_PREFIX = "X-Token";
}
......@@ -20,14 +20,12 @@
package com.syc.slm.common.core.util;
import com.syc.slm.common.core.constant.CommonConstants;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import javax.sound.midi.SysexMessage;
import java.io.Serializable;
/**
......
package com.syc.slm.common.core.util;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Maps;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.Map;
......@@ -18,121 +20,77 @@ import java.util.Map;
* @author : lin
* @date : 2021-04-13 10:15
**/
@Slf4j
public final class RestTemplateUtils {
private static final RestTemplate REST_TEMPLATE = new RestTemplate();
public static <TResult>TResult get(String url, Map<String, String> headerMap, final Type resultType, Map<String, ?> uriVariables) {
// public static <TResult>TResult get(String url, Map<String, String> headerMap, final Type resultType, Map<String, ?> uriVariables) {
// try {
// ResponseEntity<String> response = get(url, headerMap, String.class, uriVariables);
// if(HttpStatus.OK.value() == response.getStatusCodeValue()){
// if(resultType.equals(String.class)) {
// return (TResult)response.getBody();
// }
// return SlmConstants.gson.fromJson(response.getBody(), resultType);
// }
// } catch (Exception e) {
// log.error("出错啦,{}",e);
// throw new SysException("出错啦,请联系管理员",e.toString());
// }
// return null;
// }
public static <TResult>TResult get(String url, final Type resultType, Map<String, ?> uriVariables) {
try {
ResponseEntity<String> response = get(url, headerMap, String.class, uriVariables);
if(response.getStatusCodeValue()==200){
// 获取token以及在请求头加上token
HttpServletRequest request = ServletUtils.getHttpServletRequest();
Map<String, String> headerMap = ServletUtils.getHeaderMap(request);
if(CollectionUtils.isEmpty(headerMap)){
throw new SysException("头部不能为空");
}
String token =request.getHeader(SlmConstants.TOKEN_PREFIX);
if(StringUtils.isBlank(token)){
throw new SysException("token不能为空");
}
Map<String, String> headMap = Maps.newHashMap();
headMap.put(SlmConstants.TOKEN_PREFIX, token);
ResponseEntity<String> response = get(url, headMap, String.class, uriVariables);
log.info("请求结果是=============:{}",response.getBody());
if(HttpStatus.OK.value() == response.getStatusCodeValue()){
if(resultType.equals(String.class)) {
return (TResult)response.getBody();
}
return SlmConstants.gson.fromJson(response.getBody(), resultType);
}
}
catch (Exception e) {
e.printStackTrace();
} catch (Exception e) {
log.error("出错啦,{}",e);
throw new SysException("出错啦,请联系管理员",e.toString());
}
return null;
}
public static <TResult>TResult post(String url, Map<String, String> headerMap,Object requestBody, final Type resultType, Map<String, ?> uriVariables) {
try {
ResponseEntity<String> response = post(url, headerMap, requestBody,String.class, uriVariables);
if(response.getStatusCodeValue()==200){
if(HttpStatus.OK.value() == response.getStatusCodeValue()){
if(resultType.equals(String.class)) {
return (TResult)response.getBody();
}
return SlmConstants.gson.fromJson(response.getBody(), resultType);
}
}
catch (Exception e) {
e.printStackTrace();
} catch (Exception e) {
log.error("出错啦,{}",e);
throw new SysException("出错啦,请联系管理员",e.toString());
}
return null;
}
//#region ----------------------------------GET-------------------------------------------------------
/**
* GET请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(String url, Class<T> responseType) {
return REST_TEMPLATE.getForEntity(url, responseType);
}
/**
* GET请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.getForEntity(url, responseType, uriVariables);
}
/**
* GET请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Map<String, ?> uriVariables) {
return REST_TEMPLATE.getForEntity(url, responseType, uriVariables);
}
/**
* 带请求头的GET请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return get(url, httpHeaders, responseType, uriVariables);
}
/**
* 带请求头的GET请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的GET请求调用方式
*
......@@ -161,9 +119,6 @@ public final class RestTemplateUtils {
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
}
//#endregion
//#region ----------------------------------POST-------------------------------------------------------
/**
* POST请求调用方式
......@@ -176,77 +131,6 @@ public final class RestTemplateUtils {
return REST_TEMPLATE.postForEntity(url, HttpEntity.EMPTY, responseType);
}
/**
* POST请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType) {
return REST_TEMPLATE.postForEntity(url, requestBody, responseType);
}
/**
* POST请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.postForEntity(url, requestBody, responseType, uriVariables);
}
/**
* POST请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
return REST_TEMPLATE.postForEntity(url, requestBody, responseType, uriVariables);
}
/**
* 带请求头的POST请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return post(url, httpHeaders, requestBody, responseType, uriVariables);
}
/**
* 带请求头的POST请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return post(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的POST请求调用方式
......@@ -279,18 +163,6 @@ public final class RestTemplateUtils {
return post(url, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的POST请求调用方式
*
* @param url 请求URL
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的POST请求调用方式
......@@ -304,355 +176,7 @@ public final class RestTemplateUtils {
public static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
}
//#endregion
//#region ----------------------------------PUT-------------------------------------------------------
/**
* PUT请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, Class<T> responseType, Object... uriVariables) {
return put(url, HttpEntity.EMPTY, responseType, uriVariables);
}
/**
* PUT请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
return put(url, requestEntity, responseType, uriVariables);
}
/**
* PUT请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
return put(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的PUT请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return put(url, httpHeaders, requestBody, responseType, uriVariables);
}
/**
* 带请求头的PUT请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return put(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的PUT请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return put(url, httpHeaders, requestBody, responseType, uriVariables);
}
/**
* 带请求头的PUT请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return put(url, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的PUT请求调用方式
*
* @param url 请求URL
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的PUT请求调用方式
*
* @param url 请求URL
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
}
//#endregion
//#region ----------------------------------DELETE-------------------------------------------------------
/**
* DELETE请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Object... uriVariables) {
return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
}
/**
* DELETE请求调用方式
*
* @param url 请求URL
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Map<String, ?> uriVariables) {
return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
}
/**
* DELETE请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* DELETE请求调用方式
*
* @param url 请求URL
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return delete(url, httpHeaders, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Map<String, ?> uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return delete(url, httpHeaders, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return delete(url, httpHeaders, requestBody, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAll(headers);
return delete(url, httpHeaders, requestBody, responseType, uriVariables);
}
/**
* 带请求头的DELETE请求调用方式
*
* @param url 请求URL
* @param headers 请求头参数
* @param requestBody 请求参数体
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
return delete(url, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的DELETE请求调用方式
*
* @param url 请求URL
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
}
/**
* 自定义请求头和请求体的DELETE请求调用方式
*
* @param url 请求URL
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,与Map中的key对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
return REST_TEMPLATE.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
}
//#endregion
//#region ----------------------------------通用方法-------------------------------------------------------
/**
* 通用调用方式
*
* @param url 请求URL
* @param method 请求方法类型
* @param requestEntity 请求头和请求体封装对象
* @param responseType 返回对象类型
* @param uriVariables URL中的变量,按顺序依次对应
* @return ResponseEntity 响应对象封装类
*/
public static <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
return REST_TEMPLATE.exchange(url, method, requestEntity, responseType, uriVariables);
}
/**
* 通用调用方式
......
......@@ -14,8 +14,6 @@ import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.nio.channels.SelectableChannel;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.function.Supplier;
......@@ -44,11 +42,11 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
if(CollectionUtils.isEmpty(headerMap)){
throw new SysException("头部不能为空");
}
String token =request.getHeader("X-Token");
String token =request.getHeader(SlmConstants.TOKEN_PREFIX);
if(StringUtils.isBlank(token)){
throw new SysException("token不能为空");
}
Object currentUser = request.getSession().getAttribute(token);
Object currentUser = request.getAttribute(token);
CurrentUser user =null;
if(ObjectUtils.isNotEmpty(currentUser)){
user= SlmConstants.gson.fromJson(currentUser.toString(),CurrentUser.class);
......
......@@ -31,7 +31,6 @@ import java.util.function.Supplier;
* @date : 2021-04-06 09:09
**/
@Slf4j
public class BaseRestController {
@Value("${dc_client.host}")
......@@ -80,7 +79,7 @@ public class BaseRestController {
}
}
log.info("请求头参数--->>>>"+SlmConstants.gson.toJson(headers));
String token=request.getHeader("X-Token");
String token=request.getHeader(SlmConstants.TOKEN_PREFIX);
if(!uri.contains("tokens")) {
if (StringUtils.isEmpty(token)) {
throw new SysException("token不能为空");
......@@ -88,15 +87,12 @@ public class BaseRestController {
log.info("获取用户信息");
NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<CurrentUser> result = RestTemplateUtils.get(getUrl, heads, new TypeToken<R<CurrentUser>>() {
R<CurrentUser> result = RestTemplateUtils.get(getUrl, new TypeToken<R<CurrentUser>>() {
}.getType(), uriVariables);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(result.detach()));
request.setAttribute(token,SlmConstants.gson.toJson(result.detach()));
}
......@@ -109,8 +105,8 @@ public class BaseRestController {
return NetResponseUtils.call(supplier);
}
CurrentUser getCurrentUser(HttpServletRequest request){
String token=request.getHeader("X-Token");
return SlmConstants.gson.fromJson(request.getSession().getAttribute(token).toString(),CurrentUser.class);
protected CurrentUser getCurrentUser (HttpServletRequest request){
String token=request.getHeader(SlmConstants.TOKEN_PREFIX);
return SlmConstants.gson.fromJson(request.getAttribute(token).toString(),CurrentUser.class);
}
}
......@@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/{appId}/panel-configs")
@RestController
@Api(value = "仪表板样式以及数据配置", tags = "仪表板样式以及数据配置")
public class InstrumentPanelConfigController {
public class InstrumentPanelConfigController extends BaseRestController {
@Autowired
private InstrumentPanelConfigService instrumentPanelConfigService;
......
......@@ -3,6 +3,7 @@ package com.syc.slm.slmbi.handler;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.exception.SysException;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -32,4 +33,16 @@ public class SysExceptionHandler {
return R.bad(e.getMsg(),e.getDebugMsg());
}
/**
* mybaits抛出的异常,以及SysMetaObjectHandler自定义抛出的异常
* @param e
* @return
*/
@ExceptionHandler(MyBatisSystemException.class)
@ResponseBody
public R<Object> handleMyBatisSystemException(MyBatisSystemException e) {
log.info(e.getMessage());
return R.bad(e.getCause().getCause().getMessage(),e.getMessage());
}
}
......@@ -2,6 +2,7 @@ package com.syc.slm.slmbi.service.impl;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.service.DeptService;
......@@ -28,13 +29,11 @@ public class DeptServiceImpl implements DeptService {
public List<DeptVo> selectPositionList(String uri, String token, String appId, String deptName) {
log.info("部门查询uri:---------------->"+uri);
log.info("部门查询token:---------------->"+token);
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("deptName",deptName);
uriVariables.put("appId",appId);
R<List<DeptVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
R<List<DeptVo>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -3,6 +3,7 @@ package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.syc.slm.common.core.constant.SlmConstants;
......@@ -165,6 +166,9 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
tree.setId(entity.getId());
if (StringUtils.isNotEmpty(group.getParentId())) {
InstrumentPanelTree panelTree = treeService.getById(group.getParentId());
if (ObjectUtils.isEmpty(panelTree)){
throw new SysException(group.getParentId() + ",上级不存在");
}
if (SlmConstants.DATA_DELETED.equals(panelTree.getRecordStatus())) {
throw new SysException(panelTree.getName() + ",已不存在,请刷新页面");
}
......
......@@ -415,11 +415,9 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
private R<Map<String,String>> setDeptAndRole(CurrentUser user,String uri){
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",user.getToken());
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
return RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
return RestTemplateUtils.get(uri, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
}
......@@ -27,13 +27,11 @@ public class PositionServiceImpl implements PositionService {
@Override
public List<PositionVo> selectPositionList(String uri ,String token,String appId,String name) {
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("positionName",name);
uriVariables.put("appId",appId);
R<List<PositionVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
R<List<PositionVo>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -26,12 +26,10 @@ import java.util.Map;
public class UserServiceImpl implements UserService {
@Override
public List<UserTreeVo> selectUserList(String appId,String uri,String token,String userName) {
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("userName",userName);
uriVariables.put("appId",appId);
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri,new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -53,10 +53,8 @@ public class VariableServiceImpl implements VariableService {
p.put("isCustomer",null);
p.put("current",variableDTO.getCurrent()+"");
p.put("size",variableDTO.getSize()+"");
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......@@ -104,9 +102,7 @@ public class VariableServiceImpl implements VariableService {
p.put("warranty_status", null);
p.put("page_num", queryPageDTO.getCurrent() + "");
p.put("page_size", queryPageDTO.getSize() + "");
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......@@ -140,11 +136,9 @@ public class VariableServiceImpl implements VariableService {
if(StringUtils.isBlank(variableDTO.getFormat())) {
throw new SysException(" 请填入时间格式");
}
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", user.getToken());
Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType());
uriVariables.put("appId",user.getAppId());
R<Map<String, List<Map<String, Object>>>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, List<Map<String, Object>>>>>() {}.getType(), uriVariables);
R<Map<String, List<Map<String, Object>>>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, List<Map<String, Object>>>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -187,12 +181,10 @@ public class VariableServiceImpl implements VariableService {
throw new SysException("统计维度为时间,请填入时间格式");
}
}
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", user.getToken());
Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType());
uriVariables.put("appId",user.getAppId());
R<List<Map<String, Object>>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), uriVariables);
R<List<Map<String, Object>>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -260,11 +252,10 @@ public class VariableServiceImpl implements VariableService {
}
private R<Map<String,String>> setDeptAndRole(CurrentUser user,String uri){
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",user.getToken());
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
return RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
return RestTemplateUtils.get(uri,new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
}
......@@ -3,7 +3,7 @@ spring:
name: slm-bi
profiles:
active:
- local
- dev
freemarker:
cache: false
template-loader-path: classpath:/templates/ftl/
......
......@@ -21,7 +21,7 @@
</resultMap>
<delete id="batchUpdateGroupByIds">
update instrument_panel_group set record_status =#{recordStatus}
<if test="groupIds!=null">
<if test="groupIds!=null and groupIds.size() > 0">
where id IN (
<foreach collection="groupIds" item="id" separator=",">
#{id}
......@@ -35,7 +35,7 @@
</select>
<select id="selectGroupByIds" resultType="com.syc.slm.slmbi.vo.PanelTreeNodeVo">
select id,`name`,parent_id,'group' node_type from instrument_panel_group
<if test="finalPanelIds!=null">
<if test="finalPanelIds!=null and finalPanelIds.size() > 0">
where id IN (
<foreach collection="finalPanelIds" item="id" separator=",">
#{id}
......
......@@ -23,7 +23,7 @@
</resultMap>
<update id="batchUpdatePanelByIds">
update instrument_panel set record_status =#{recordStatus}
<if test="panelIds!=null">
<if test="panelIds!=null and panelIds.size() > 0">
where id IN (
<foreach collection="panelIds" item="id" separator=",">
#{id}
......@@ -52,7 +52,7 @@
group_id parent_id,
'panel' node_type
from instrument_panel
<if test="finalPanelIds!=null">
<if test="finalPanelIds!=null and finalPanelIds.size() > 0">
where id IN (
<foreach collection="finalPanelIds" item="id" separator=",">
#{id}
......
......@@ -21,7 +21,7 @@
</resultMap>
<update id="batchUpdateTreeByIds">
update instrument_panel_tree set record_status =#{recordStatus}
<if test="treeIds!=null">
<if test="treeIds!=null and treeIds.size() > 0">
where id IN (
<foreach collection="treeIds" item="id" separator=",">
#{id}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment