Commit 5e6dbb23 by 陶光胜

Merge branch 'developer' into 'master'

Developer

See merge request !7
parents 7300e49b c647aeb9
...@@ -2,7 +2,13 @@ package com.gic.enterprise.base; ...@@ -2,7 +2,13 @@ package com.gic.enterprise.base;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
/**
* 商户信息
* @ClassName: EnterpriseInfo

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:15 AM

*/
public class EnterpriseInfo implements Serializable { public class EnterpriseInfo implements Serializable {
/** /**
* 企业主键 * 企业主键
......
...@@ -2,7 +2,13 @@ package com.gic.enterprise.base; ...@@ -2,7 +2,13 @@ package com.gic.enterprise.base;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
/**
* 登录用户信息
* @ClassName: UserInfo

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:15 AM

*/
public class UserInfo implements Serializable { public class UserInfo implements Serializable {
/** /**
......
package com.gic.enterprise.constants; package com.gic.enterprise.constants;
/**
* 常量
* @ClassName: Constants

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:13 AM

*/
public class Constants { public class Constants {
public static String INDEX_ENTERPRISEID = "test-enterprise-20190716"; public static String INDEX_ENTERPRISEID = "test-enterprise-20190716";
public static String STORE_SCENECODE = "store"; public static String STORE_SCENECODE = "store";
......
...@@ -5,7 +5,13 @@ import org.apache.logging.log4j.Logger; ...@@ -5,7 +5,13 @@ import org.apache.logging.log4j.Logger;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
/**
* session
* @ClassName: RequestContext

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:16 AM

*/
public class RequestContext { public class RequestContext {
private static final Logger log = LogManager.getLogger(RequestContext.class); private static final Logger log = LogManager.getLogger(RequestContext.class);
private ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<>(); private ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<>();
......
...@@ -12,7 +12,13 @@ import javax.servlet.http.Cookie; ...@@ -12,7 +12,13 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/**
* session
* @ClassName: UserContext

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:16 AM

*/
public class UserContext { public class UserContext {
/** /**
* 有效期4小时 * 有效期4小时
......
package com.gic.enterprise.error; package com.gic.enterprise.error;
/**
* 错误
* @ClassName: Error

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:04 AM

*/
public interface Error { public interface Error {
/**
* 获取错误code
* @Title: getErrorCode

* @Description:

* @author guojuxing 

* @return java.lang.String


*/
String getErrorCode(); String getErrorCode();
/**
* 获取错误信息
* @Title: getErrorMsg

* @Description:

* @author guojuxing 

* @return java.lang.String


*/
String getErrorMsg(); String getErrorMsg();
} }
...@@ -10,7 +10,13 @@ import org.apache.dubbo.rpc.*; ...@@ -10,7 +10,13 @@ import org.apache.dubbo.rpc.*;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
/**
* 数据处理
* @ClassName: ServiceValidateFilter

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:11 AM

*/
@Activate(group = {CommonConstants.PROVIDER}) @Activate(group = {CommonConstants.PROVIDER})
public class ServiceValidateFilter implements Filter { public class ServiceValidateFilter implements Filter {
@Override @Override
......
...@@ -8,7 +8,13 @@ import org.apache.dubbo.common.extension.Activate; ...@@ -8,7 +8,13 @@ import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*; import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.filter.ConsumerContextFilter; import org.apache.dubbo.rpc.filter.ConsumerContextFilter;
/**
* session
* @ClassName: UserTokenFilter

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:12 AM

*/
@Activate(group = {CommonConstants.CONSUMER}, order = -1000) @Activate(group = {CommonConstants.CONSUMER}, order = -1000)
public class UserTokenFilter implements Filter { public class UserTokenFilter implements Filter {
@Override @Override
......
...@@ -2,7 +2,13 @@ package com.gic.enterprise.response; ...@@ -2,7 +2,13 @@ package com.gic.enterprise.response;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.enterprise.error.Error; import com.gic.enterprise.error.Error;
/**
* 包装类
* @ClassName: EnterpriseServiceResponse

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:13 AM

*/
public class EnterpriseServiceResponse<T> extends ServiceResponse<T> { public class EnterpriseServiceResponse<T> extends ServiceResponse<T> {
public static ServiceResponse failure(Error error) { public static ServiceResponse failure(Error error) {
return ServiceResponse.failure(error.getErrorCode(), error.getErrorMsg()); return ServiceResponse.failure(error.getErrorCode(), error.getErrorMsg());
......
package com.gic.enterprise.utils; package com.gic.enterprise.utils;
import com.gic.commons.util.Md5Util; import com.gic.commons.util.Md5Util;
/**
* 自动产生密码
* @ClassName: AutoCreatePasswordUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:43 AM

*/
public class AutoCreatePasswordUtils { public class AutoCreatePasswordUtils {
/** /**
......
package com.gic.enterprise.utils; package com.gic.enterprise.utils;
/**
* token
* @ClassName: TokenUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:13 AM

*/
public class TokenUtils { public class TokenUtils {
private static ThreadLocal<String> tokenThreadLocal = new ThreadLocal<>(); private static ThreadLocal<String> tokenThreadLocal = new ThreadLocal<>();
......
...@@ -8,7 +8,13 @@ import com.gic.enterprise.base.UserResourceInfo; ...@@ -8,7 +8,13 @@ import com.gic.enterprise.base.UserResourceInfo;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* session
* @ClassName: UserDetail

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:15 AM

*/
public class UserDetail implements Serializable { public class UserDetail implements Serializable {
private Integer userId = 2222; private Integer userId = 2222;
private UserInfo userInfo; private UserInfo userInfo;
......
package com.gic.enterprise.utils; package com.gic.enterprise.utils;
import com.gic.enterprise.context.UserContext; import com.gic.enterprise.context.UserContext;
/**
* session
* @ClassName: UserDetailUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:14 AM

*/
public class UserDetailUtils { public class UserDetailUtils {
public static UserDetail getUserDetail(){ public static UserDetail getUserDetail(){
return UserContext.getContext().get(); return UserContext.getContext().get();
......
package com.gic.enterprise.exception; package com.gic.enterprise.exception;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
...@@ -24,33 +21,13 @@ import com.gic.enterprise.error.ErrorCode; ...@@ -24,33 +21,13 @@ import com.gic.enterprise.error.ErrorCode;
* 全局异常处理类 * 全局异常处理类
* *
* @author hua * @author hua
*/ *
*/
@ControllerAdvice @ControllerAdvice
@ResponseBody @ResponseBody
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private static Logger logger = LogManager.getLogger(GlobalExceptionHandler.class); private static Logger logger = LogManager.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public RestResponse controllerException(HttpServletResponse response, Exception ex) {
logger.error("err", ex);
RestResponse failureResponse = getRestResponse(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMsg());
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter printWriter = new PrintWriter(baos)) {
ex.printStackTrace(printWriter);
}
try {
sb.append(baos.toString());
} catch (Exception ignored) {
}
if (sb.length() == 0) {
sb.append(ex.getMessage());
}
// 输出详细错误信息,便于调试
failureResponse.setDetailError(sb.toString());
return failureResponse;
}
/** /**
* 参数校验异常统一处理 * 参数校验异常统一处理
* @param e * @param e
......
...@@ -5,7 +5,13 @@ import java.io.IOException; ...@@ -5,7 +5,13 @@ import java.io.IOException;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
/**
* 跨域处理
* @ClassName: CrossFilter

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:16 AM

*/
public class CrossFilter implements Filter{ public class CrossFilter implements Filter{
@Override @Override
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
...@@ -13,10 +19,10 @@ public class CrossFilter implements Filter{ ...@@ -13,10 +19,10 @@ public class CrossFilter implements Filter{
} }
@Override @Override
public void doFilter(ServletRequest _request, ServletResponse _response, FilterChain chain) public void doFilter(ServletRequest requestFrom, ServletResponse responseFrom, FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) _request; HttpServletRequest request = (HttpServletRequest) requestFrom;
HttpServletResponse response = (HttpServletResponse) _response; HttpServletResponse response = (HttpServletResponse) responseFrom;
String origin = request.getHeader("Origin"); String origin = request.getHeader("Origin");
if (null != origin) { if (null != origin) {
response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Origin", origin);
......
...@@ -3,7 +3,13 @@ package com.gic.enterprise.filter; ...@@ -3,7 +3,13 @@ package com.gic.enterprise.filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/**
* 拦截
* @ClassName: FilterConfig

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:16 AM

*/
@Configuration @Configuration
public class FilterConfig { public class FilterConfig {
@Bean @Bean
......
...@@ -22,7 +22,13 @@ import java.util.HashMap; ...@@ -22,7 +22,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* 权限拦截
* @ClassName: AuthInterceptor

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:15 AM

*/
public class AuthInterceptor extends HandlerInterceptorAdapter { public class AuthInterceptor extends HandlerInterceptorAdapter {
private static final Logger log = LogManager.getLogger(AuthInterceptor.class); private static final Logger log = LogManager.getLogger(AuthInterceptor.class);
...@@ -48,7 +54,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -48,7 +54,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String token = UserContext.getContext().getToken(); String token = UserContext.getContext().getToken();
log.info("权限拦截token:{}", token); log.info("权限拦截token:{}", token);
RpcContext.getContext().getAttachments().put(Constants.USER_TOKEN, token); RpcContext.getContext().getAttachments().put(Constants.USER_TOKEN, token);
System.out.println(JSON.toJSONString(RpcContext.getContext().getArguments()));
// 更新redis // 更新redis
UserContext.getContext().refresh(); UserContext.getContext().refresh();
...@@ -94,55 +99,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -94,55 +99,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
} }
//接口调用,操作项类型的操作,需要 获取操作模块,一级、二级的ID和名称 //接口调用,操作项类型的操作,需要 获取操作模块,一级、二级的ID和名称
if (isOperationItemRequest) { if (isOperationItemRequest) {
List<MenuInfo> menuInfoList = userDetail.getMenuInfoList(); setOperationModule(request, userDetail);
Map<String, MenuInfo> moduleUrlMap = userDetail.getModuleUrlMap();
//页面路径
String moduleUrl = request.getHeader("Referer");
log.info("完整路由:{}", moduleUrl);
//用于下载接口的路径
request.setAttribute("moduleMenuUrl", moduleUrl);
//project_url_for_web + menu_url
moduleUrl = getModuleUrl(moduleUrl);
log.info("操作模块的路由:{}", moduleUrl);
//获取当前操作项数据
MenuInfo menuInfo = moduleUrlMap.get(moduleUrl);
if (menuInfo != null) {
Map<String, MenuInfo> tempMap = listToMap(menuInfoList);
log.info("接口的菜单信息:{}", JSON.toJSONString(menuInfo));
Integer temp = menuInfo.getMenuId();
//获取第二层级的页面
if (menuInfo.getLevel().intValue() > 2) {
temp = getOperationModule(menuInfo.getMenuId(), tempMap);
while (tempMap.get(temp.toString()).getLevel().intValue() != 2) {
temp = getOperationModule(tempMap.get(temp.toString()).getMenuId(), tempMap);
}
}
int secondLevelMenuId = 0;
String secondLevelMenuName = "无";
int firstLevelMenuId;
String firstLevelMenuName;
//如果是第二级的
if (tempMap.get(temp.toString()).getLevel().intValue() == 2) {
MenuInfo secondMenuInfo = tempMap.get(temp.toString());
secondLevelMenuId = secondMenuInfo.getMenuId();
secondLevelMenuName = secondMenuInfo.getMenuName();
//获取第一层级的页面
temp = getOperationModule(secondMenuInfo.getMenuId(), tempMap);
firstLevelMenuId = tempMap.get(temp.toString()).getMenuId();
firstLevelMenuName = tempMap.get(temp.toString()).getMenuName();
} else {
//第一级
MenuInfo firstMenuInfo = tempMap.get(temp.toString());
firstLevelMenuId = firstMenuInfo.getMenuId();
secondLevelMenuId = firstMenuInfo.getMenuId();
firstLevelMenuName = firstMenuInfo.getMenuName();
}
log.info("一级页面的ID和名称:{},{}", firstLevelMenuId, firstLevelMenuName);
log.info("二级页面的ID和名称:{},{}", secondLevelMenuId, secondLevelMenuName);
request.setAttribute("moduleMenuId", secondLevelMenuId);
request.setAttribute("moduleMenuName", firstLevelMenuName + "-" + secondLevelMenuName);
}
} }
//超级管理员不限制 //超级管理员不限制
...@@ -172,6 +129,58 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -172,6 +129,58 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return true; return true;
} }
private void setOperationModule(HttpServletRequest request, UserDetail userDetail) {
List<MenuInfo> menuInfoList = userDetail.getMenuInfoList();
Map<String, MenuInfo> moduleUrlMap = userDetail.getModuleUrlMap();
//页面路径
String moduleUrl = request.getHeader("Referer");
log.info("完整路由:{}", moduleUrl);
//用于下载接口的路径
request.setAttribute("moduleMenuUrl", moduleUrl);
//project_url_for_web + menu_url
moduleUrl = getModuleUrl(moduleUrl);
log.info("操作模块的路由:{}", moduleUrl);
//获取当前操作项数据
MenuInfo menuInfo = moduleUrlMap.get(moduleUrl);
if (menuInfo != null) {
Map<String, MenuInfo> tempMap = listToMap(menuInfoList);
log.info("接口的菜单信息:{}", JSON.toJSONString(menuInfo));
Integer temp = menuInfo.getMenuId();
//获取第二层级的页面
if (menuInfo.getLevel().intValue() > 2) {
temp = getOperationModule(menuInfo.getMenuId(), tempMap);
while (tempMap.get(temp.toString()).getLevel().intValue() != 2) {
temp = getOperationModule(tempMap.get(temp.toString()).getMenuId(), tempMap);
}
}
int secondLevelMenuId = 0;
String secondLevelMenuName = "无";
int firstLevelMenuId;
String firstLevelMenuName;
//如果是第二级的
if (tempMap.get(temp.toString()).getLevel().intValue() == 2) {
MenuInfo secondMenuInfo = tempMap.get(temp.toString());
secondLevelMenuId = secondMenuInfo.getMenuId();
secondLevelMenuName = secondMenuInfo.getMenuName();
//获取第一层级的页面
temp = getOperationModule(secondMenuInfo.getMenuId(), tempMap);
firstLevelMenuId = tempMap.get(temp.toString()).getMenuId();
firstLevelMenuName = tempMap.get(temp.toString()).getMenuName();
} else {
//第一级
MenuInfo firstMenuInfo = tempMap.get(temp.toString());
firstLevelMenuId = firstMenuInfo.getMenuId();
secondLevelMenuId = firstMenuInfo.getMenuId();
firstLevelMenuName = firstMenuInfo.getMenuName();
}
log.info("一级页面的ID和名称:{},{}", firstLevelMenuId, firstLevelMenuName);
log.info("二级页面的ID和名称:{},{}", secondLevelMenuId, secondLevelMenuName);
request.setAttribute("moduleMenuId", secondLevelMenuId);
request.setAttribute("moduleMenuName", firstLevelMenuName + "-" + secondLevelMenuName);
}
}
private static Integer getOperationModule(Integer menuId, Map<String, MenuInfo> tempMap) { private static Integer getOperationModule(Integer menuId, Map<String, MenuInfo> tempMap) {
MenuInfo temp = tempMap.get(menuId.toString()); MenuInfo temp = tempMap.get(menuId.toString());
if (temp != null) { if (temp != null) {
......
package com.gic.enterprise.jsonSeralizer; package com.gic.enterprise.jsonseralizer;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
...@@ -6,9 +6,23 @@ import com.fasterxml.jackson.databind.JsonSerializer; ...@@ -6,9 +6,23 @@ import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException; import java.io.IOException;
/**
* 数据处理
* @ClassName: AbstractJsonSerializer

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:11 AM

*/
public abstract class AbstractJsonSerializer extends JsonSerializer<String> { public abstract class AbstractJsonSerializer extends JsonSerializer<String> {
/**
* 序列化数据
* @Title: serializerData

* @Description:

* @author guojuxing
* @param value

* @return java.lang.String


*/
protected abstract String serializerData(String value); protected abstract String serializerData(String value);
@Override @Override
......
package com.gic.enterprise.jsonSeralizer; package com.gic.enterprise.jsonseralizer;
import com.gic.enterprise.utils.UserDetail; import com.gic.enterprise.utils.UserDetail;
...@@ -7,7 +7,13 @@ import com.gic.redis.data.util.RedisUtil; ...@@ -7,7 +7,13 @@ import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
/**
* 加密
* @ClassName: EncryptJsonSerializer

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:45 AM

*/
public class EncryptJsonSerializer extends AbstractJsonSerializer { public class EncryptJsonSerializer extends AbstractJsonSerializer {
@Override @Override
......
package com.gic.enterprise.jsonseralizer;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
/**
* 登录
* @ClassName: LongTypeConverter

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:45 AM

*/
@Component
public class LongTypeConverter {
@Bean
public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter(){
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
/**
* 序列换成json时,将所有的long变成string
* 因为js中得数字类型不能包含所有的java long值
*/
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
// SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// objectMapper.setDateFormat(fmt);
objectMapper.registerModule(simpleModule);
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return jackson2HttpMessageConverter;
}
}
...@@ -24,13 +24,22 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper { ...@@ -24,13 +24,22 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper {
this.params.putAll(request.getParameterMap()); this.params.putAll(request.getParameterMap());
this.modifyParameterValues(); this.modifyParameterValues();
} }
//重载一个构造方法
/**
* 重载一个构造方法
* @param request
* @param extendParams
*/
public ParameterRequestWrapper(HttpServletRequest request , Map<String , Object> extendParams) { public ParameterRequestWrapper(HttpServletRequest request , Map<String , Object> extendParams) {
this(request); this(request);
addAllParameters(extendParams);//这里将扩展参数写入参数表 //这里将扩展参数写入参数表
addAllParameters(extendParams);
} }
public void modifyParameterValues(){//将parameter的值去除空格后重写回去 /**
* 将parameter的值去除空格后重写回去
*/
public void modifyParameterValues(){
Set<String> set =params.keySet(); Set<String> set =params.keySet();
Iterator<String> it=set.iterator(); Iterator<String> it=set.iterator();
while(it.hasNext()){ while(it.hasNext()){
...@@ -41,8 +50,13 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper { ...@@ -41,8 +50,13 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper {
} }
} }
/**
* 重写getParameter,代表参数从当前类中的map获取
* @param name
* @return
*/
@Override @Override
public String getParameter(String name) {//重写getParameter,代表参数从当前类中的map获取 public String getParameter(String name) {
String[]values = params.get(name); String[]values = params.get(name);
if(values == null || values.length == 0) { if(values == null || values.length == 0) {
return null; return null;
...@@ -55,13 +69,22 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper { ...@@ -55,13 +69,22 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper {
return params.get(name); return params.get(name);
} }
public void addAllParameters(Map<String , Object>otherParams) {//增加多个参数 /**
* 增加多个参数
* @param otherParams
*/
public void addAllParameters(Map<String , Object>otherParams) {
for(Map.Entry<String , Object>entry : otherParams.entrySet()) { for(Map.Entry<String , Object>entry : otherParams.entrySet()) {
addParameter(entry.getKey() , entry.getValue()); addParameter(entry.getKey() , entry.getValue());
} }
} }
public void addParameter(String name , Object value) {//增加参数 /**
* 增加参数
* @param name
* @param value
*/
public void addParameter(String name , Object value) {
if(value != null) { if(value != null) {
if(value instanceof String[]) { if(value instanceof String[]) {
params.put(name , (String[])value); params.put(name , (String[])value);
......
...@@ -3,7 +3,13 @@ package com.gic.enterprise.response; ...@@ -3,7 +3,13 @@ package com.gic.enterprise.response;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse; import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.Error; import com.gic.enterprise.error.Error;
/**
* 返回对象包装
* @ClassName: EnterpriseRestResponse

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:12 AM

*/
public class EnterpriseRestResponse extends RestResponse { public class EnterpriseRestResponse extends RestResponse {
public static RestResponse failure(ServiceResponse serviceResponse){ public static RestResponse failure(ServiceResponse serviceResponse){
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage(), serviceResponse.getResult()); return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage(), serviceResponse.getResult());
......
...@@ -4,15 +4,29 @@ ...@@ -4,15 +4,29 @@
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:interceptors> <mvc:interceptors>
<bean class="com.gic.enterprise.interceptor.RequestInteceptor"></bean> <bean class="com.gic.enterprise.interceptor.RequestInteceptor"></bean>
<bean class="com.gic.commons.interceptor.HeaderTagInterceptor"/>
<bean class="com.gic.enterprise.interceptor.AuthInterceptor"></bean> <bean class="com.gic.enterprise.interceptor.AuthInterceptor"></bean>
<bean class="com.gic.commons.interceptor.HeaderTagInterceptor"/>
<mvc:interceptor>
<!-- 拦截所有的请求,这个必须写在前面,也就是写在【不拦截】的上面 -->
<mvc:mapping path="/**" />
<!-- 但是排除下面这些,也就是不拦截请求 -->
<mvc:exclude-mapping path="/login" />
<mvc:exclude-mapping path="/logout" />
<mvc:exclude-mapping path="/list-enterprise-by-phone" />
<mvc:exclude-mapping path="/login-user-menu" />
<mvc:exclude-mapping path="/login-user-operation-item" />
<mvc:exclude-mapping path="/get-login-user-info" />
<mvc:exclude-mapping path="/login-for-operation" />
<bean class="com.gic.commons.interceptor.HeaderSignInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors> </mvc:interceptors>
</beans> </beans>
package com.gic.download.constants; package com.gic.download.constants;
/**
* 二维码
* @ClassName: QrcodeTypeEnum

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:44 AM

*/
public enum QrcodeTypeEnum { public enum QrcodeTypeEnum {
/**
* 门店二维码
*/
STORE(1, "门店二维码"), STORE(1, "门店二维码"),
/**
* 导购二维码
*/
CLERK(2, "导购二维码"); CLERK(2, "导购二维码");
QrcodeTypeEnum(Integer type, String desc){ QrcodeTypeEnum(Integer type, String desc){
......
...@@ -36,4 +36,9 @@ public class DownloadReportTempDTO implements Serializable{ ...@@ -36,4 +36,9 @@ public class DownloadReportTempDTO implements Serializable{
public void setDataCount(Integer dataCount) { public void setDataCount(Integer dataCount) {
this.dataCount = dataCount; this.dataCount = dataCount;
} }
@Override
public String toString() {
return super.toString();
}
} }
package com.gic.download.qo; package com.gic.download.qo;
import java.io.Serializable; import java.io.Serializable;
/**
* 二维码
* @ClassName: QrcodeContent

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:44 AM

*/
public class QrcodeContent implements Serializable { public class QrcodeContent implements Serializable {
private String customParams; private String customParams;
private String content; private String content;
private String title; private String title;
/**
* 如果是门店 这个值和title一致 如果是导购 这个值是导购所在的门店的名称
*/
private String titleTmp;
public String getCustomParams() { public String getCustomParams() {
return customParams; return customParams;
...@@ -30,4 +40,12 @@ public class QrcodeContent implements Serializable { ...@@ -30,4 +40,12 @@ public class QrcodeContent implements Serializable {
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
public String getTitleTmp() {
return titleTmp;
}
public void setTitleTmp(String titleTmp) {
this.titleTmp = titleTmp;
}
} }
...@@ -5,13 +5,22 @@ import org.apache.commons.lang.StringUtils; ...@@ -5,13 +5,22 @@ import org.apache.commons.lang.StringUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/**
* 二维码
* @ClassName: QrcodeQO

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:44 AM

*/
public class QrcodeQO implements Serializable { public class QrcodeQO implements Serializable {
private Integer h5 = 0; private Integer h5 = 0;
private String appletIds; private String appletIds;
private String fwhIds; private String fwhIds;
private String scenesValueIds; private String scenesValueIds;
private Integer type; //1临时二维码 2永久二维码 /**
* 1临时二维码 2永久二维码
*/
private Integer type;
private Date endTime; private Date endTime;
private List<QrcodeContent> content; private List<QrcodeContent> content;
private String callBackService; private String callBackService;
......
...@@ -27,7 +27,13 @@ import com.gic.enterprise.exception.CommonException; ...@@ -27,7 +27,13 @@ import com.gic.enterprise.exception.CommonException;
import com.gic.enterprise.service.DownloadReportApiService; import com.gic.enterprise.service.DownloadReportApiService;
import com.gic.thirdparty.BucketNameEnum; import com.gic.thirdparty.BucketNameEnum;
import com.gic.thirdparty.FileOperateUtils; import com.gic.thirdparty.FileOperateUtils;
/**
* 下载
* @ClassName: DataDownloadUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:43 AM

*/
@Component @Component
public class DataDownloadUtils { public class DataDownloadUtils {
private static final Logger LOGGER = LogManager.getLogger(DataDownloadUtils.class); private static final Logger LOGGER = LogManager.getLogger(DataDownloadUtils.class);
...@@ -37,6 +43,8 @@ public class DataDownloadUtils { ...@@ -37,6 +43,8 @@ public class DataDownloadUtils {
@Autowired @Autowired
private DownloadReportApiService downloadReportApiService; private DownloadReportApiService downloadReportApiService;
private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]*");
@PostConstruct @PostConstruct
public void init() { public void init() {
dataDownloadUtils = this; dataDownloadUtils = this;
...@@ -216,8 +224,6 @@ public class DataDownloadUtils { ...@@ -216,8 +224,6 @@ public class DataDownloadUtils {
Object o = DataDownloadUtils.getFieldValue(dataList.get(i), fieldName); Object o = DataDownloadUtils.getFieldValue(dataList.get(i), fieldName);
if (o == null) { if (o == null) {
sb.append(","); sb.append(",");
} else if (o.toString().equals("-1")) {
sb.append(",");
} else if (o instanceof Double) { } else if (o instanceof Double) {
DecimalFormat format = new DecimalFormat("0.00"); DecimalFormat format = new DecimalFormat("0.00");
sb.append(format.format(o) + ","); sb.append(format.format(o) + ",");
...@@ -226,8 +232,7 @@ public class DataDownloadUtils { ...@@ -226,8 +232,7 @@ public class DataDownloadUtils {
} else if (o instanceof Date) { } else if (o instanceof Date) {
sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(o) + "\t,"); sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(o) + "\t,");
} else { } else {
Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = NUMBER_PATTERN.matcher(o.toString());
Matcher isNum = pattern.matcher(o.toString());
if (isNum.matches()) { if (isNum.matches()) {
if (o.toString().length() >= 12) { if (o.toString().length() >= 12) {
sb.append(o + "\t,"); sb.append(o + "\t,");
...@@ -296,7 +301,7 @@ public class DataDownloadUtils { ...@@ -296,7 +301,7 @@ public class DataDownloadUtils {
.getMethod("get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1), null); .getMethod("get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1), null);
return method.invoke(obj, null); return method.invoke(obj, null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOGGER.warn(e);
} }
return result; return result;
} }
...@@ -309,7 +314,7 @@ public class DataDownloadUtils { ...@@ -309,7 +314,7 @@ public class DataDownloadUtils {
field.setAccessible(true); field.setAccessible(true);
return field; return field;
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
e.printStackTrace(); LOGGER.warn(e);
} }
} }
return null; return null;
......
...@@ -28,7 +28,13 @@ import java.io.IOException; ...@@ -28,7 +28,13 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/**
* 下载工具
* @ClassName: DownloadUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:43 AM

*/
public class DownloadUtils { public class DownloadUtils {
private static final Logger LOGGER = LogManager.getLogger(DownloadUtils.class); private static final Logger LOGGER = LogManager.getLogger(DownloadUtils.class);
...@@ -144,6 +150,15 @@ public class DownloadUtils { ...@@ -144,6 +150,15 @@ public class DownloadUtils {
protected static interface Writer { protected static interface Writer {
/**
* 写数据
* @Title: write

* @Description:

* @author guojuxing
* @param row

* @return void

* @throws IOException

*/
public void write(Collection<String> row) throws IOException; public void write(Collection<String> row) throws IOException;
} }
...@@ -239,7 +254,8 @@ public class DownloadUtils { ...@@ -239,7 +254,8 @@ public class DownloadUtils {
DataDownloadUtils.mkDir(new File(tempPath)); DataDownloadUtils.mkDir(new File(tempPath));
File file = new File(tempPath); File file = new File(tempPath);
//初始化数据 //初始化数据
if (fileName.length() < 3) { int leastPrefixStringLength = 3;
if (fileName.length() < leastPrefixStringLength) {
//如果长度太短 //如果长度太短
fileName = fileName + "__"; fileName = fileName + "__";
} }
...@@ -509,9 +525,12 @@ public class DownloadUtils { ...@@ -509,9 +525,12 @@ public class DownloadUtils {
} }
//手机号或者会员卡号 第5-8位用*代替 //手机号或者会员卡号 第5-8位用*代替
int length = data.length(); int length = data.length();
if (length > 8) {
boolean isGreaterThanEight = length > 8;
boolean isGreaterThanFour = length > 4;
if (isGreaterThanEight) {
return data.substring(0, 4) + "****" + data.substring(8); return data.substring(0, 4) + "****" + data.substring(8);
} else if (length > 4) { } else if (isGreaterThanFour) {
return data.substring(0, 4) + "****"; return data.substring(0, 4) + "****";
} else { } else {
return "****"; return "****";
......
...@@ -16,7 +16,13 @@ import org.apache.logging.log4j.Logger; ...@@ -16,7 +16,13 @@ import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
/**
* excel
* @ClassName: ExcelUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:59 AM

*/
public class ExcelUtils { public class ExcelUtils {
/** /**
* logger * logger
...@@ -437,18 +443,18 @@ public class ExcelUtils { ...@@ -437,18 +443,18 @@ public class ExcelUtils {
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public static HSSFWorkbook readWorkbook(InputStream ins) throws IOException, FileNotFoundException { public static HSSFWorkbook readWorkbook(InputStream ins) throws IOException, FileNotFoundException {
ByteArrayOutputStream byteOS = new ByteArrayOutputStream(); ByteArrayOutputStream byteOoutputStream = new ByteArrayOutputStream();
BufferedInputStream bis = new BufferedInputStream(ins); BufferedInputStream bis = new BufferedInputStream(ins);
byte[] by = new byte[512]; byte[] by = new byte[512];
int t = bis.read(by, 0, by.length); int t = bis.read(by, 0, by.length);
while (t > 0) { while (t > 0) {
// read 512 // read 512
byteOS.write(by, 0, 512); byteOoutputStream.write(by, 0, 512);
t = bis.read(by, 0, by.length); t = bis.read(by, 0, by.length);
} }
byteOS.close(); byteOoutputStream.close();
InputStream byteIS = new ByteArrayInputStream(byteOS.toByteArray()); InputStream byteInputStream = new ByteArrayInputStream(byteOoutputStream.toByteArray());
HSSFWorkbook wbDest = new HSSFWorkbook(byteIS); HSSFWorkbook wbDest = new HSSFWorkbook(byteInputStream);
return wbDest; return wbDest;
} }
...@@ -463,50 +469,6 @@ public class ExcelUtils { ...@@ -463,50 +469,6 @@ public class ExcelUtils {
} }
/** /**
* 判断单元格的格式
*
* @param cell
* 单元格
* @return String 将excel各种单元格的类型转换为String类型
*/
public static String getCellStringValue(HSSFCell cell) {
// 转换后单元格的值
String value = "";
if (cell != null) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
value = sdf.format(date);
} else {
DecimalFormat formatter = new DecimalFormat("########");
value = formatter.format(cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_FORMULA:
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
value = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
default:
break;
}
}
return value;
}
/**
* 到出excel的Helper类 * 到出excel的Helper类
* *
* @author Administrator * @author Administrator
......
...@@ -3,7 +3,13 @@ package com.gic.download.utils; ...@@ -3,7 +3,13 @@ package com.gic.download.utils;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse; import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.download.utils.log.LogUtils; import com.gic.download.utils.log.LogUtils;
/**
* controller添加日志
* @ClassName: OperationResultUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:43 AM

*/
public class OperationResultUtils { public class OperationResultUtils {
public static final String LOG_NEW = "新增"; public static final String LOG_NEW = "新增";
......
...@@ -40,14 +40,26 @@ import java.util.List; ...@@ -40,14 +40,26 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
/**
* 二维码下载
* @ClassName: QrcodeDownload

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:45 AM

*/
public abstract class QrcodeDownload { public abstract class QrcodeDownload {
private static final Logger log = LogManager.getLogger(QrcodeDownload.class); private static final Logger log = LogManager.getLogger(QrcodeDownload.class);
private static final int width = 1280; private static final int WIDTH = 1280;
private static final int height = 1280; private static final int HEIGHT = 1280;
private static final int QRCOLOR = 0xFF000000; // 默认是黑色 /**
private static final int BGWHITE = 0xFFFFFFFF; // 背景颜色 * 默认是黑色
private static final int pageSize = 1000; */
private static final int QRCOLOR = 0xFF000000;
/**
* 背景颜色
*/
private static final int BGWHITE = 0xFFFFFFFF;
private static final int PAGE_SIZE = 1000;
private QrcodeQO qrcodeQO = null; private QrcodeQO qrcodeQO = null;
private Integer total; private Integer total;
...@@ -87,9 +99,9 @@ public abstract class QrcodeDownload { ...@@ -87,9 +99,9 @@ public abstract class QrcodeDownload {
file.createNewFile(); file.createNewFile();
} }
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(file)); ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
int pages = total%pageSize > 0 ? total/pageSize+1 : total/pageSize; int pages = total%PAGE_SIZE > 0 ? total/PAGE_SIZE+1 : total/PAGE_SIZE;
for(int i = 1; i<= pages; i++){ for(int i = 1; i<= pages; i++){
List<QrcodeContent> contentList = getContent(i, pageSize); List<QrcodeContent> contentList = getContent(i, PAGE_SIZE);
if(CollectionUtils.isEmpty(contentList)){ if(CollectionUtils.isEmpty(contentList)){
break; break;
} }
...@@ -173,15 +185,15 @@ public abstract class QrcodeDownload { ...@@ -173,15 +185,15 @@ public abstract class QrcodeDownload {
} }
private byte[] createFwhQrcode(Integer qrCodeId, int type, String appkey, Date endTime, String title, UserDetail userDetail){ private byte[] createFwhQrcode(Integer qrCodeId, int type, String appkey, Date endTime, String title, UserDetail userDetail){
ServiceResponse<String> qRcodeURL = null; ServiceResponse<String> qRcodeUrl = null;
if(type == 1){ if(type == 1){
int expireSecond = Integer.valueOf((endTime.getTime() - System.currentTimeMillis())/1000+""); int expireSecond = Integer.valueOf((endTime.getTime() - System.currentTimeMillis())/1000+"");
qRcodeURL = this.weixinBaseFunService.getTemporaryQRcodeURL(appkey, qrCodeId + "", expireSecond); qRcodeUrl = this.weixinBaseFunService.getTemporaryQRcodeURL(appkey, qrCodeId + "", expireSecond);
}else { }else {
qRcodeURL = this.weixinBaseFunService.getQRcodeURL(appkey, qrCodeId + ""); qRcodeUrl = this.weixinBaseFunService.getQRcodeURL(appkey, qrCodeId + "");
} }
if(qRcodeURL.isSuccess()){ if(qRcodeUrl.isSuccess()){
return createQrcode(qRcodeURL.getResult(), userDetail.getEnterpriseInfo().getLogo(), title); return createQrcode(qRcodeUrl.getResult(), userDetail.getEnterpriseInfo().getLogo(), title);
} }
return null; return null;
} }
...@@ -198,17 +210,26 @@ public abstract class QrcodeDownload { ...@@ -198,17 +210,26 @@ public abstract class QrcodeDownload {
return createQrcode(content, userDetail.getEnterpriseInfo().getLogo(), title); return createQrcode(content, userDetail.getEnterpriseInfo().getLogo(), title);
} }
/**
* 获取数据
* @Title: getContent

* @Description:

* @author guojuxing
* @param pageSize
* @param pageNum

* @return java.util.List<com.gic.download.qo.QrcodeContent>


*/
protected abstract List<QrcodeContent> getContent(int pageSize, int pageNum); protected abstract List<QrcodeContent> getContent(int pageSize, int pageNum);
private byte[] createQrcode(String url, String logoPic, String logoName) { private byte[] createQrcode(String url, String logoPic, String logoName) {
byte[] imageByte = null; byte[] imageByte = null;
String format = "png";// 图像类型 // 图像类型
String format = "png";
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
try { try {
BufferedImage bim = getQR_CODEBufferedImage(url, BarcodeFormat.QR_CODE, width, height, hints); BufferedImage bim = getQrCodeBufferedImage(url, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, hints);
imageByte = addLogo_QRCode(bim, getPicByte(logoPic), logoName, format); imageByte = addLogoQrCode(bim, getPicByte(logoPic), logoName, format);
return imageByte; return imageByte;
} catch (Exception e) { } catch (Exception e) {
log.error("创建二维码失败", e); log.error("创建二维码失败", e);
...@@ -229,11 +250,11 @@ public abstract class QrcodeDownload { ...@@ -229,11 +250,11 @@ public abstract class QrcodeDownload {
InputStream in = conn.getInputStream(); InputStream in = conn.getInputStream();
return IOUtils.toByteArray(in); return IOUtils.toByteArray(in);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); log.warn(e);
return null; return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); log.warn(e);
return null; return null;
} }
} }
...@@ -251,7 +272,7 @@ public abstract class QrcodeDownload { ...@@ -251,7 +272,7 @@ public abstract class QrcodeDownload {
* 图片后缀名 * 图片后缀名
* @return * @return
*/ */
private byte[] addLogo_QRCode(BufferedImage bim, byte[] logoPic, String logoName, String format) { private byte[] addLogoQrCode(BufferedImage bim, byte[] logoPic, String logoName, String format) {
try { try {
/** /**
* 读取二维码图片,并构建绘图对象 * 读取二维码图片,并构建绘图对象
...@@ -260,16 +281,15 @@ public abstract class QrcodeDownload { ...@@ -260,16 +281,15 @@ public abstract class QrcodeDownload {
Graphics2D g = image.createGraphics(); Graphics2D g = image.createGraphics();
if (StringUtils.isNotEmpty(logoName)) { if (StringUtils.isNotEmpty(logoName)) {
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.setFont(new Font("宋体", Font.BOLD, 50)); // 字体、字型、字号 // 字体、字型、字号
g.setFont(new Font("宋体", Font.BOLD, 50));
// int _height=outg.getFontMetrics().getHeight();
log.info("logoName1:"+logoName); log.info("logoName1:"+logoName);
int _width = g.getFontMetrics().stringWidth(logoName); int widthTemp = g.getFontMetrics().stringWidth(logoName);
log.info("logoName2:"+logoName); log.info("logoName2:"+logoName);
g.drawString(logoName, (width - _width) / 2, height - 60); // 画文字 // 画文字
// outg.dispose(); g.drawString(logoName, (WIDTH - widthTemp) / 2, HEIGHT - 60);
image.flush(); image.flush();
// image = outImage;
} }
if (logoPic != null) { if (logoPic != null) {
...@@ -296,18 +316,15 @@ public abstract class QrcodeDownload { ...@@ -296,18 +316,15 @@ public abstract class QrcodeDownload {
// 开始绘制图片 // 开始绘制图片
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(logo, x, y, widthLogo, heightLogo, null); g.drawImage(logo, x, y, widthLogo, heightLogo, null);
// g.drawRoundRect(x,y,widthLogo,heightLogo,15,15);
g.drawRect(x, y, widthLogo, heightLogo); g.drawRect(x, y, widthLogo, heightLogo);
// logo边框大小 // logo边框大小
g.setStroke(new BasicStroke(2)); g.setStroke(new BasicStroke(2));
// logo边框颜色 // logo边框颜色
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.drawRect(x, y, widthLogo, heightLogo); g.drawRect(x, y, widthLogo, heightLogo);
// g.dispose();
logo.flush(); logo.flush();
image.flush(); image.flush();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
} }
} }
...@@ -319,7 +336,6 @@ public abstract class QrcodeDownload { ...@@ -319,7 +336,6 @@ public abstract class QrcodeDownload {
ImageIO.write(image, format, baos); ImageIO.write(image, format, baos);
return baos.toByteArray(); return baos.toByteArray();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
} }
return null; return null;
...@@ -340,7 +356,7 @@ public abstract class QrcodeDownload { ...@@ -340,7 +356,7 @@ public abstract class QrcodeDownload {
* 设置参数 * 设置参数
* @return * @return
*/ */
private BufferedImage getQR_CODEBufferedImage(String content, BarcodeFormat barcodeFormat, int width, int height, private BufferedImage getQrCodeBufferedImage(String content, BarcodeFormat barcodeFormat, int width, int height,
Map<EncodeHintType, ?> hints) { Map<EncodeHintType, ?> hints) {
MultiFormatWriter multiFormatWriter = null; MultiFormatWriter multiFormatWriter = null;
BitMatrix bm = null; BitMatrix bm = null;
...@@ -360,7 +376,7 @@ public abstract class QrcodeDownload { ...@@ -360,7 +376,7 @@ public abstract class QrcodeDownload {
} }
} }
} catch (WriterException e) { } catch (WriterException e) {
e.printStackTrace(); log.warn(e);
} }
return image; return image;
} }
......
...@@ -13,7 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,7 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
/**
* 日志工具
* @ClassName: LogUtils

* @Description: 

* @author guojuxing

* @date 2020/9/15 10:43 AM

*/
@Component @Component
public class LogUtils { public class LogUtils {
private static final Logger LOGGER = LogManager.getLogger(LogUtils.class); private static final Logger LOGGER = LogManager.getLogger(LogUtils.class);
...@@ -100,6 +106,8 @@ public class LogUtils { ...@@ -100,6 +106,8 @@ public class LogUtils {
//账号(手机号) //账号(手机号)
logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode()); logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode());
logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber()); logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber());
//用以查询区分运营人员
logDTO.setRemark3(userDetail.getUserInfo().getLoginType().toString());
logDTO.setEnterpriseId(Long.valueOf(userDetail.getEnterpriseInfo().getEnterpriseId())); logDTO.setEnterpriseId(Long.valueOf(userDetail.getEnterpriseInfo().getEnterpriseId()));
logDTO.setEnterpriseName(userDetail.getEnterpriseInfo().getEnterpriseName()); logDTO.setEnterpriseName(userDetail.getEnterpriseInfo().getEnterpriseName());
...@@ -139,6 +147,8 @@ public class LogUtils { ...@@ -139,6 +147,8 @@ public class LogUtils {
//账号(手机号) //账号(手机号)
logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode()); logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode());
logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber()); logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber());
//用以查询区分运营人员
logDTO.setRemark3(userDetail.getUserInfo().getLoginType().toString());
//操作模块 //操作模块
// String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName"); // String moduleMenuName = (String) RequestContext.getContext().getRequest().getAttribute("moduleMenuName");
// Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId"); // Integer moduleMenuId = (Integer) RequestContext.getContext().getRequest().getAttribute("moduleMenuId");
......
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