Commit c0974ffd by guojuxing

部分pmd

parent d0a11c02
......@@ -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();
......
......@@ -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);
......@@ -93,6 +99,37 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
}
//接口调用,操作项类型的操作,需要 获取操作模块,一级、二级的ID和名称
if (isOperationItemRequest) {
setOperationModule(request, userDetail);
}
//超级管理员不限制
if (userDetail.getUserInfo().getSuperAdmin().intValue() == 1) {
return true;
}
//判断是否有权限
Map<String, Object> menuUrlMap = userDetail.getMenuUrlMap();
if (menuUrlMap == null || menuUrlMap.isEmpty()) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
if (isOperationItemRequest) {
//说明是操作项
//如果匹配上了,说明是没权限
if (menuUrlMap.containsKey(uri)) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
} else {
//说明是页面
//如果没有匹配上,说明没权限
if (!menuUrlMap.containsKey(uri)) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
}
return true;
}
private void setOperationModule(HttpServletRequest request, UserDetail userDetail) {
List<MenuInfo> menuInfoList = userDetail.getMenuInfoList();
Map<String, MenuInfo> moduleUrlMap = userDetail.getModuleUrlMap();
//页面路径
......@@ -144,33 +181,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
}
}
//超级管理员不限制
if (userDetail.getUserInfo().getSuperAdmin().intValue() == 1) {
return true;
}
//判断是否有权限
Map<String, Object> menuUrlMap = userDetail.getMenuUrlMap();
if (menuUrlMap == null || menuUrlMap.isEmpty()) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
if (isOperationItemRequest) {
//说明是操作项
//如果匹配上了,说明是没权限
if (menuUrlMap.containsKey(uri)) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
} else {
//说明是页面
//如果没有匹配上,说明没权限
if (!menuUrlMap.containsKey(uri)) {
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
}
return true;
}
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;
package com.gic.enterprise.jsonseralizer;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -7,7 +7,13 @@ 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 {
......
......@@ -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());
......
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;
......
......@@ -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,");
......
......@@ -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);
......@@ -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,14 +316,12 @@ 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) {
......@@ -338,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;
......
......@@ -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);
......
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