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;
import java.io.Serializable;
import java.util.Date;
/**
* 商户信息
* @ClassName: EnterpriseInfo

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description:

* @author guojuxing 

* @return java.lang.String


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

* @Description:

* @author guojuxing 

* @return java.lang.String


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

* @Description: 

* @author guojuxing

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

*/
@Activate(group = {CommonConstants.PROVIDER})
public class ServiceValidateFilter implements Filter {
@Override
......
......@@ -8,7 +8,13 @@ import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
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)
public class UserTokenFilter implements Filter {
@Override
......
......@@ -2,7 +2,13 @@ package com.gic.enterprise.response;
import com.gic.api.base.commons.ServiceResponse;
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 static ServiceResponse failure(Error error) {
return ServiceResponse.failure(error.getErrorCode(), error.getErrorMsg());
......
package com.gic.enterprise.utils;
import com.gic.commons.util.Md5Util;
/**
* 自动产生密码
* @ClassName: AutoCreatePasswordUtils

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

*/
public class UserDetailUtils {
public static UserDetail getUserDetail(){
return UserContext.getContext().get();
......
package com.gic.enterprise.exception;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
......@@ -24,33 +21,13 @@ import com.gic.enterprise.error.ErrorCode;
* 全局异常处理类
*
* @author hua
*/
*
*/
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
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
......
......@@ -5,7 +5,13 @@ import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 跨域处理
* @ClassName: CrossFilter

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

*/
public class AuthInterceptor extends HandlerInterceptorAdapter {
private static final Logger log = LogManager.getLogger(AuthInterceptor.class);
......@@ -48,7 +54,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String token = UserContext.getContext().getToken();
log.info("权限拦截token:{}", token);
RpcContext.getContext().getAttachments().put(Constants.USER_TOKEN, token);
System.out.println(JSON.toJSONString(RpcContext.getContext().getArguments()));
// 更新redis
UserContext.getContext().refresh();
......@@ -94,55 +99,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
}
//接口调用,操作项类型的操作,需要 获取操作模块,一级、二级的ID和名称
if (isOperationItemRequest) {
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);
}
setOperationModule(request, userDetail);
}
//超级管理员不限制
......@@ -172,6 +129,58 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
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) {
MenuInfo temp = tempMap.get(menuId.toString());
if (temp != null) {
......
package com.gic.enterprise.jsonSeralizer;
package com.gic.enterprise.jsonseralizer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -6,9 +6,23 @@ import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* 数据处理
* @ClassName: AbstractJsonSerializer

* @Description: 

* @author guojuxing

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

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

* @Description:

* @author guojuxing
* @param value

* @return java.lang.String


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

* @Description: 

* @author guojuxing

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

*/
public class EncryptJsonSerializer extends AbstractJsonSerializer {
@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 {
this.params.putAll(request.getParameterMap());
this.modifyParameterValues();
}
//重载一个构造方法
/**
* 重载一个构造方法
* @param request
* @param extendParams
*/
public ParameterRequestWrapper(HttpServletRequest request , Map<String , Object> extendParams) {
this(request);
addAllParameters(extendParams);//这里将扩展参数写入参数表
//这里将扩展参数写入参数表
addAllParameters(extendParams);
}
public void modifyParameterValues(){//将parameter的值去除空格后重写回去
/**
* 将parameter的值去除空格后重写回去
*/
public void modifyParameterValues(){
Set<String> set =params.keySet();
Iterator<String> it=set.iterator();
while(it.hasNext()){
......@@ -41,8 +50,13 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper {
}
}
/**
* 重写getParameter,代表参数从当前类中的map获取
* @param name
* @return
*/
@Override
public String getParameter(String name) {//重写getParameter,代表参数从当前类中的map获取
public String getParameter(String name) {
String[]values = params.get(name);
if(values == null || values.length == 0) {
return null;
......@@ -55,13 +69,22 @@ public class ParameterRequestWrapper extends HttpServletRequestWrapper {
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()) {
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 instanceof String[]) {
params.put(name , (String[])value);
......
......@@ -3,7 +3,13 @@ package com.gic.enterprise.response;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.Error;
/**
* 返回对象包装
* @ClassName: EnterpriseRestResponse

* @Description: 

* @author guojuxing

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

*/
public class EnterpriseRestResponse extends RestResponse {
public static RestResponse failure(ServiceResponse serviceResponse){
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage(), serviceResponse.getResult());
......
......@@ -4,15 +4,29 @@
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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/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/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>
<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.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>
</beans>
package com.gic.download.constants;
/**
* 二维码
* @ClassName: QrcodeTypeEnum

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

*/
public class QrcodeContent implements Serializable {
private String customParams;
private String content;
private String title;
/**
* 如果是门店 这个值和title一致 如果是导购 这个值是导购所在的门店的名称
*/
private String titleTmp;
public String getCustomParams() {
return customParams;
......@@ -30,4 +40,12 @@ public class QrcodeContent implements Serializable {
public void setTitle(String 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;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 二维码
* @ClassName: QrcodeQO

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

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

* @Description:

* @author guojuxing
* @param row

* @return void

* @throws IOException

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

* @Description: 

* @author guojuxing

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

*/
public class ExcelUtils {
/**
* logger
......@@ -437,18 +443,18 @@ public class ExcelUtils {
* @throws FileNotFoundException
*/
public static HSSFWorkbook readWorkbook(InputStream ins) throws IOException, FileNotFoundException {
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
ByteArrayOutputStream byteOoutputStream = new ByteArrayOutputStream();
BufferedInputStream bis = new BufferedInputStream(ins);
byte[] by = new byte[512];
int t = bis.read(by, 0, by.length);
while (t > 0) {
// read 512
byteOS.write(by, 0, 512);
byteOoutputStream.write(by, 0, 512);
t = bis.read(by, 0, by.length);
}
byteOS.close();
InputStream byteIS = new ByteArrayInputStream(byteOS.toByteArray());
HSSFWorkbook wbDest = new HSSFWorkbook(byteIS);
byteOoutputStream.close();
InputStream byteInputStream = new ByteArrayInputStream(byteOoutputStream.toByteArray());
HSSFWorkbook wbDest = new HSSFWorkbook(byteInputStream);
return wbDest;
}
......@@ -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类
*
* @author Administrator
......
......@@ -3,7 +3,13 @@ package com.gic.download.utils;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.download.utils.log.LogUtils;
/**
* controller添加日志
* @ClassName: OperationResultUtils

* @Description: 

* @author guojuxing

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

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

* @Description: 

* @author guojuxing

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

*/
public abstract class QrcodeDownload {
private static final Logger log = LogManager.getLogger(QrcodeDownload.class);
private static final int width = 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 WIDTH = 1280;
private static final int HEIGHT = 1280;
/**
* 默认是黑色
*/
private static final int QRCOLOR = 0xFF000000;
/**
* 背景颜色
*/
private static final int BGWHITE = 0xFFFFFFFF;
private static final int PAGE_SIZE = 1000;
private QrcodeQO qrcodeQO = null;
private Integer total;
......@@ -87,9 +99,9 @@ public abstract class QrcodeDownload {
file.createNewFile();
}
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++){
List<QrcodeContent> contentList = getContent(i, pageSize);
List<QrcodeContent> contentList = getContent(i, PAGE_SIZE);
if(CollectionUtils.isEmpty(contentList)){
break;
}
......@@ -173,15 +185,15 @@ public abstract class QrcodeDownload {
}
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){
int expireSecond = Integer.valueOf((endTime.getTime() - System.currentTimeMillis())/1000+"");
qRcodeURL = this.weixinBaseFunService.getTemporaryQRcodeURL(appkey, qrCodeId + "", expireSecond);
qRcodeUrl = this.weixinBaseFunService.getTemporaryQRcodeURL(appkey, qrCodeId + "", expireSecond);
}else {
qRcodeURL = this.weixinBaseFunService.getQRcodeURL(appkey, qrCodeId + "");
qRcodeUrl = this.weixinBaseFunService.getQRcodeURL(appkey, qrCodeId + "");
}
if(qRcodeURL.isSuccess()){
return createQrcode(qRcodeURL.getResult(), userDetail.getEnterpriseInfo().getLogo(), title);
if(qRcodeUrl.isSuccess()){
return createQrcode(qRcodeUrl.getResult(), userDetail.getEnterpriseInfo().getLogo(), title);
}
return null;
}
......@@ -198,17 +210,26 @@ public abstract class QrcodeDownload {
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);
private byte[] createQrcode(String url, String logoPic, String logoName) {
byte[] imageByte = null;
String format = "png";// 图像类型
// 图像类型
String format = "png";
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
try {
BufferedImage bim = getQR_CODEBufferedImage(url, BarcodeFormat.QR_CODE, width, height, hints);
imageByte = addLogo_QRCode(bim, getPicByte(logoPic), logoName, format);
BufferedImage bim = getQrCodeBufferedImage(url, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, hints);
imageByte = addLogoQrCode(bim, getPicByte(logoPic), logoName, format);
return imageByte;
} catch (Exception e) {
log.error("创建二维码失败", e);
......@@ -229,11 +250,11 @@ public abstract class QrcodeDownload {
InputStream in = conn.getInputStream();
return IOUtils.toByteArray(in);
} catch (IOException e) {
e.printStackTrace();
log.warn(e);
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
log.warn(e);
return null;
}
}
......@@ -251,7 +272,7 @@ public abstract class QrcodeDownload {
* 图片后缀名
* @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 {
/**
* 读取二维码图片,并构建绘图对象
......@@ -260,16 +281,15 @@ public abstract class QrcodeDownload {
Graphics2D g = image.createGraphics();
if (StringUtils.isNotEmpty(logoName)) {
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);
int _width = g.getFontMetrics().stringWidth(logoName);
int widthTemp = g.getFontMetrics().stringWidth(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 = outImage;
}
if (logoPic != null) {
......@@ -296,18 +316,15 @@ public abstract class QrcodeDownload {
// 开始绘制图片
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(logo, x, y, widthLogo, heightLogo, null);
// g.drawRoundRect(x,y,widthLogo,heightLogo,15,15);
g.drawRect(x, y, widthLogo, heightLogo);
// logo边框大小
g.setStroke(new BasicStroke(2));
// logo边框颜色
g.setColor(Color.WHITE);
g.drawRect(x, y, widthLogo, heightLogo);
// g.dispose();
logo.flush();
image.flush();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
......@@ -319,7 +336,6 @@ public abstract class QrcodeDownload {
ImageIO.write(image, format, baos);
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
return null;
......@@ -340,7 +356,7 @@ public abstract class QrcodeDownload {
* 设置参数
* @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) {
MultiFormatWriter multiFormatWriter = null;
BitMatrix bm = null;
......@@ -360,7 +376,7 @@ public abstract class QrcodeDownload {
}
}
} catch (WriterException e) {
e.printStackTrace();
log.warn(e);
}
return image;
}
......
......@@ -13,7 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 日志工具
* @ClassName: LogUtils

* @Description: 

* @author guojuxing

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

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