Commit 11ce7a31 by 陶光胜

Merge branch 'developer' into 'master'

Developer

See merge request !2
parents 73af2972 071ff681
...@@ -11,13 +11,12 @@ ...@@ -11,13 +11,12 @@
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-enterprise-base-api</artifactId> <artifactId>gic-enterprise-base-api</artifactId>
<version>4.0-SNAPSHOT</version> <version>${libraryVersion}</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<libraryVersion>4.0-SNAPSHOT</libraryVersion> <libraryVersion>4.0-SNAPSHOT</libraryVersion>
<gic-redis-data>4.0-SNAPSHOT</gic-redis-data>
</properties> </properties>
<distributionManagement> <distributionManagement>
<repository> <repository>
...@@ -58,11 +57,6 @@ ...@@ -58,11 +57,6 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-log-api</artifactId>
<version>${gic-log-api}</version>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-commons</artifactId> <artifactId>gic-commons</artifactId>
<version>${gic-commons}</version> <version>${gic-commons}</version>
</dependency> </dependency>
...@@ -111,6 +105,14 @@ ...@@ -111,6 +105,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
......
package com.gic.enterprise.base; package com.gic.enterprise.base;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* *
...@@ -64,6 +65,10 @@ public class UserResourceInfo implements Serializable { ...@@ -64,6 +65,10 @@ public class UserResourceInfo implements Serializable {
private Integer smsSignResource; private Integer smsSignResource;
private String smsSignResourceJson; private String smsSignResourceJson;
private List<Long> cardConfigIdList;
private List<Long> appletConfigIdList;
private List<Long> serviceConfigIdList;
public Long getStoreResource() { public Long getStoreResource() {
return storeResource; return storeResource;
} }
...@@ -135,4 +140,28 @@ public class UserResourceInfo implements Serializable { ...@@ -135,4 +140,28 @@ public class UserResourceInfo implements Serializable {
public void setUserResource(Long userResource) { public void setUserResource(Long userResource) {
this.userResource = userResource; this.userResource = userResource;
} }
public List<Long> getCardConfigIdList() {
return cardConfigIdList;
}
public void setCardConfigIdList(List<Long> cardConfigIdList) {
this.cardConfigIdList = cardConfigIdList;
}
public List<Long> getAppletConfigIdList() {
return appletConfigIdList;
}
public void setAppletConfigIdList(List<Long> appletConfigIdList) {
this.appletConfigIdList = appletConfigIdList;
}
public List<Long> getServiceConfigIdList() {
return serviceConfigIdList;
}
public void setServiceConfigIdList(List<Long> serviceConfigIdList) {
this.serviceConfigIdList = serviceConfigIdList;
}
} }
...@@ -8,4 +8,8 @@ public class Constants { ...@@ -8,4 +8,8 @@ public class Constants {
public static String TOKEN_KEY = "enterprise:user:"; public static String TOKEN_KEY = "enterprise:user:";
public static Integer NORMAL_STATUS = 1; public static Integer NORMAL_STATUS = 1;
public static Integer DEL_STATUS = 0; public static Integer DEL_STATUS = 0;
/**
* 中国国际区码
*/
public static String NATION_CODE = "+86";
} }
package com.gic.enterprise.utils; package com.gic.enterprise.utils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.utils.ReferenceConfigCache; import org.apache.dubbo.config.utils.ReferenceConfigCache;
...@@ -32,7 +34,11 @@ public class AsyncCallbackUtils { ...@@ -32,7 +34,11 @@ public class AsyncCallbackUtils {
public static void callBack(Object obj, String interfaceUrl, String method) { public static void callBack(Object obj, String interfaceUrl, String method) {
logger.info("回调:{},接口路径:{},接口方法名称:{}" ,JSONObject.toJSONString(obj), interfaceUrl, method); logger.info("回调:{},接口路径:{},接口方法名称:{}" ,JSONObject.toJSONString(obj), interfaceUrl, method);
RegistryConfig registry = new RegistryConfig(); RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://10.105.220.75:2199"); //todo 上线修改zookeeper地址
Config config = ConfigService.getConfig("COMMON.4.0-gic-properties");
String zkHost = config.getProperty("zookeeper.host", "");
String zkPort = config.getProperty("zookeeper.port", "");
registry.setAddress("zookeeper://"+zkHost+":"+zkPort);
registry.setCheck(false); registry.setCheck(false);
ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
reference.setInterface(interfaceUrl); reference.setInterface(interfaceUrl);
......
...@@ -51,4 +51,9 @@ public class CreateRandomUtils { ...@@ -51,4 +51,9 @@ public class CreateRandomUtils {
} }
return sb.toString(); return sb.toString();
} }
public static String createSerialNumber() {
//2个随机数+时间+4个随机数
return CreateRandomUtils.generateNumberStr(2) + System.currentTimeMillis() + CreateRandomUtils.generateNumberStr(4);
}
} }
...@@ -11,13 +11,14 @@ ...@@ -11,13 +11,14 @@
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-enterprise-common</artifactId> <artifactId>gic-enterprise-common</artifactId>
<version>4.0-SNAPSHOT</version> <version>${libraryVersion}</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<libraryVersion>4.0-SNAPSHOT</libraryVersion> <libraryVersion>4.0-SNAPSHOT</libraryVersion>
<maven.test.skip>true</maven.test.skip>
</properties> </properties>
<distributionManagement> <distributionManagement>
<repository> <repository>
...@@ -99,6 +100,14 @@ ...@@ -99,6 +100,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -49,6 +49,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -49,6 +49,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
String token = UserContext.getContext().getToken(); String token = UserContext.getContext().getToken();
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())); System.out.println(JSON.toJSONString(RpcContext.getContext().getArguments()));
...@@ -57,6 +58,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -57,6 +58,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
if (!(object.getClass().isAssignableFrom(HandlerMethod.class))) { if (!(object.getClass().isAssignableFrom(HandlerMethod.class))) {
return true; return true;
} }
//获取uri
String uri = request.getRequestURI();
log.info("权限拦截token url:{}", uri);
HandlerMethod handler = (HandlerMethod) object; HandlerMethod handler = (HandlerMethod) object;
//免登录接口路由 //免登录接口路由
IgnoreLogin ignoreLogin = handler.getMethodAnnotation(IgnoreLogin.class); IgnoreLogin ignoreLogin = handler.getMethodAnnotation(IgnoreLogin.class);
...@@ -64,8 +70,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -64,8 +70,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return true; return true;
} }
//获取uri
String uri = request.getRequestURI();
//操作项标志位 //操作项标志位
String isControl = request.getHeader("isControl"); String isControl = request.getHeader("isControl");
//是否是操作项请求 //是否是操作项请求
...@@ -93,6 +97,8 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -93,6 +97,8 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
//页面路径 //页面路径
String moduleUrl = request.getHeader("Referer"); String moduleUrl = request.getHeader("Referer");
log.info("完整路由:{}", moduleUrl); log.info("完整路由:{}", moduleUrl);
//用于下载接口的路径
request.setAttribute("moduleMenuUrl", moduleUrl);
//project_url_for_web + menu_url //project_url_for_web + menu_url
moduleUrl = getModuleUrl(moduleUrl); moduleUrl = getModuleUrl(moduleUrl);
log.info("操作模块的路由:{}", moduleUrl); log.info("操作模块的路由:{}", moduleUrl);
...@@ -100,6 +106,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -100,6 +106,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
MenuInfo menuInfo = moduleUrlMap.get(moduleUrl); MenuInfo menuInfo = moduleUrlMap.get(moduleUrl);
if (menuInfo != null) { if (menuInfo != null) {
Map<String, MenuInfo> tempMap = listToMap(menuInfoList); Map<String, MenuInfo> tempMap = listToMap(menuInfoList);
log.info("接口的菜单信息:{}", JSON.toJSONString(menuInfo));
Integer temp = menuInfo.getMenuId(); Integer temp = menuInfo.getMenuId();
//获取第二层级的页面 //获取第二层级的页面
...@@ -113,14 +120,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -113,14 +120,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String secondLevelMenuName = "无"; String secondLevelMenuName = "无";
int firstLevelMenuId; int firstLevelMenuId;
String firstLevelMenuName; String firstLevelMenuName;
//用于下载文件,跳转到频道页的地址
String secondLevelUrl = "https://four.gicdev.com";
//如果是第二级的 //如果是第二级的
if (menuInfo.getLevel().intValue() == 2) { if (tempMap.get(temp.toString()).getLevel().intValue() == 2) {
MenuInfo secondMenuInfo = tempMap.get(temp.toString()); MenuInfo secondMenuInfo = tempMap.get(temp.toString());
secondLevelMenuId = secondMenuInfo.getMenuId(); secondLevelMenuId = secondMenuInfo.getMenuId();
secondLevelMenuName = secondMenuInfo.getMenuName(); secondLevelMenuName = secondMenuInfo.getMenuName();
secondLevelUrl = secondLevelUrl + secondMenuInfo.getProjectUrlForWeb() + secondMenuInfo.getMenuUrl();
//获取第一层级的页面 //获取第一层级的页面
temp = getOperationModule(secondMenuInfo.getMenuId(), tempMap); temp = getOperationModule(secondMenuInfo.getMenuId(), tempMap);
firstLevelMenuId = tempMap.get(temp.toString()).getMenuId(); firstLevelMenuId = tempMap.get(temp.toString()).getMenuId();
...@@ -131,13 +135,10 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -131,13 +135,10 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
firstLevelMenuId = firstMenuInfo.getMenuId(); firstLevelMenuId = firstMenuInfo.getMenuId();
secondLevelMenuId = firstMenuInfo.getMenuId(); secondLevelMenuId = firstMenuInfo.getMenuId();
firstLevelMenuName = firstMenuInfo.getMenuName(); firstLevelMenuName = firstMenuInfo.getMenuName();
secondLevelUrl = secondLevelUrl + firstMenuInfo.getProjectUrlForWeb() + firstMenuInfo.getMenuUrl();
} }
log.info("一级页面的ID和名称:{},{}", firstLevelMenuId, firstLevelMenuName); log.info("一级页面的ID和名称:{},{}", firstLevelMenuId, firstLevelMenuName);
log.info("二级页面的ID和名称:{},{}", secondLevelMenuId, secondLevelMenuName); log.info("二级页面的ID和名称:{},{}", secondLevelMenuId, secondLevelMenuName);
log.info("二级页面的地址:{}", secondLevelUrl);
request.setAttribute("moduleMenuId", secondLevelMenuId); request.setAttribute("moduleMenuId", secondLevelMenuId);
request.setAttribute("moduleMenuUrl", secondLevelUrl);
request.setAttribute("moduleMenuName", firstLevelMenuName + "-" + secondLevelMenuName); request.setAttribute("moduleMenuName", firstLevelMenuName + "-" + secondLevelMenuName);
} }
} }
......
package com.gic.enterprise.jsonSeralizer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
public abstract class AbstractJsonSerializer extends JsonSerializer<String> {
protected abstract String serializerData(String value);
@Override
public void serialize(String o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
if(o != null){
String result = this.serializerData(o);
jsonGenerator.writeString(result);
}
}
}
package com.gic.enterprise.jsonSeralizer;
import com.gic.enterprise.utils.UserDetail;
import com.gic.enterprise.utils.UserDetailUtils;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
public class EncryptJsonSerializer extends AbstractJsonSerializer {
@Override
protected String serializerData(String text){
if (StringUtils.isEmpty(text)) {
return text;
}
if (ensureRiskMode()) {
// 风险模式
return text;
} else {
// 安全模式
return encrypt(text);
}
}
private boolean ensureRiskMode() {
UserDetail userDetail = UserDetailUtils.getUserDetail();
String redisKey = "enterprise:riskMode:" + userDetail.getEnterpriseId() + ":" + userDetail.getUserId();
RedissonClient redisClient = RedisUtil.getRedisClient();
RBucket<Object> bucket = redisClient.getBucket(redisKey);
return bucket.get() != null;
}
private String encrypt(String data) {
if (StringUtils.isBlank(data)) {
return data;
}
//手机号或者会员卡号 第5-8位用*代替
int length = data.length();
if (length > 8) {
return data.substring(0, 4) + "****" + data.substring(8);
} else if (length > 4) {
return data.substring(0, 4) + "****";
} else {
return "****";
}
}
}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-enterprise-download</artifactId> <artifactId>gic-enterprise-download</artifactId>
<version>4.0-SNAPSHOT</version> <version>${libraryVersion}</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
...@@ -77,13 +77,18 @@ ...@@ -77,13 +77,18 @@
<dependency> <dependency>
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-thirdparty-sdk</artifactId> <artifactId>gic-thirdparty-sdk</artifactId>
<version>4.0-SNAPSHOT</version> <version>${gic-thirdparty-sdk}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-platform-config</artifactId> <artifactId>gic-platform-config</artifactId>
<version>${gic-platform-config}</version> <version>${gic-platform-config}</version>
</dependency> </dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-wechat-business-api</artifactId>
<version>${gic-wechat-business-api}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
...@@ -124,6 +129,14 @@ ...@@ -124,6 +129,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
......
package com.gic.download.constants;
public enum QrcodeTypeEnum {
STORE(1, "门店二维码"),
CLERK(2, "导购二维码");
QrcodeTypeEnum(Integer type, String desc){
this.type = type;
this.desc = desc;
}
private Integer type;
private String desc;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
package com.gic.download.dto;
import java.io.Serializable;
/**
* 下载中心记录
* @ClassName: DownloadReportTempDTO

* @Description: 

* @author guojuxing

* @date 2020/2/3 4:55 PM

*/
public class DownloadReportTempDTO implements Serializable{
private static final long serialVersionUID = -4845073563932941443L;
/**
* 报告类型 1:完整数据, 2:脱敏数据, 3:二维码
*/
private Integer dataType;
/**
* 数据总量
*/
private Integer dataCount;
public Integer getDataType() {
return dataType;
}
public void setDataType(Integer dataType) {
this.dataType = dataType;
}
public Integer getDataCount() {
return dataCount;
}
public void setDataCount(Integer dataCount) {
this.dataCount = dataCount;
}
}
package com.gic.download.qo;
import java.io.Serializable;
import java.util.List;
/**
* 下载导出文件参数列表类
* @ClassName: DownloadExcelQO

* @Description: 

* @author guojuxing

* @date 2020/4/8 2:05 PM

*/
public class DownloadExcelQO implements Serializable{
private static final long serialVersionUID = 6989738912564565045L;
/**
* 临时路径
*/
private String tempPath;
/**
* 报表ID
*/
private Integer reportId;
/**
* 导出的文件名称
*/
private String fileName;
/**
* 导出的文件后缀code,详情看ExcelExtensionEnum枚举类
*/
private Integer excelExtensionCode;
/**
* 第一行的名称列表(一层标题结构)
*/
private List<String> headerList;
/**
* 2层标题结构所需要参数
*/
private List<HeaderQO> headers;
/**
* 字段名称
*/
private List<String> propertyNameList;
/**
* 需要加密的字段
*/
private List<String> needEncryptField;
/**
* 列宽,默认null
*/
private List<Integer> columnWidth = null;
public String getTempPath() {
return tempPath;
}
public DownloadExcelQO setTempPath(String tempPath) {
this.tempPath = tempPath;
return this;
}
public Integer getReportId() {
return reportId;
}
public DownloadExcelQO setReportId(Integer reportId) {
this.reportId = reportId;
return this;
}
public String getFileName() {
return fileName;
}
public DownloadExcelQO setFileName(String fileName) {
this.fileName = fileName;
return this;
}
public Integer getExcelExtensionCode() {
return excelExtensionCode;
}
public DownloadExcelQO setExcelExtensionCode(Integer excelExtensionCode) {
this.excelExtensionCode = excelExtensionCode;
return this;
}
public List<String> getHeaderList() {
return headerList;
}
public DownloadExcelQO setHeaderList(List<String> headerList) {
this.headerList = headerList;
return this;
}
public List<HeaderQO> getHeaders() {
return headers;
}
public DownloadExcelQO setHeaders(List<HeaderQO> headers) {
this.headers = headers;
return this;
}
public List<String> getPropertyNameList() {
return propertyNameList;
}
public DownloadExcelQO setPropertyNameList(List<String> propertyNameList) {
this.propertyNameList = propertyNameList;
return this;
}
public List<String> getNeedEncryptField() {
return needEncryptField;
}
public DownloadExcelQO setNeedEncryptField(List<String> needEncryptField) {
this.needEncryptField = needEncryptField;
return this;
}
public List<Integer> getColumnWidth() {
return columnWidth;
}
public DownloadExcelQO setColumnWidth(List<Integer> columnWidth) {
this.columnWidth = columnWidth;
return this;
}
}
package com.gic.download.qo;
import java.io.Serializable;
import java.util.List;
/**
* 二级表头类
* @ClassName: HeaderQO

* @Description: 

* @author guojuxing

* @date 2020/4/8 11:37 AM

*/
public class HeaderQO implements Serializable{
private static final long serialVersionUID = 1804894825368314534L;
private String headName;
private List<String> sonHeadName;
public HeaderQO() {
}
public HeaderQO(String headName, List<String> sonHeadName) {
this.headName = headName;
this.sonHeadName = sonHeadName;
}
public String getHeadName() {
return headName;
}
public HeaderQO setHeadName(String headName) {
this.headName = headName;
return this;
}
public List<String> getSonHeadName() {
return sonHeadName;
}
public HeaderQO setSonHeadName(List<String> sonHeadName) {
this.sonHeadName = sonHeadName;
return this;
}
}
package com.gic.download.qo;
import java.io.Serializable;
public class QrcodeContent implements Serializable {
private String customParams;
private String content;
private String title;
public String getCustomParams() {
return customParams;
}
public void setCustomParams(String customParams) {
this.customParams = customParams;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
package com.gic.download.qo;
import org.apache.commons.lang.StringUtils;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
public class QrcodeQO implements Serializable {
private Integer h5 = 0;
private String appletIds;
private String fwhIds;
private String scenesValueIds;
private Integer type; //1临时二维码 2永久二维码
private Date endTime;
private List<QrcodeContent> content;
private String callBackService;
private String callBackMethod;
private String fileName;
public Integer getH5() {
return h5;
}
public void setH5(Integer h5) {
if(h5 != null && StringUtils.isNotBlank(h5+"")){
this.h5 = h5;
}
}
public String getAppletIds() {
return appletIds;
}
public void setAppletIds(String appletIds) {
this.appletIds = appletIds;
}
public String getFwhIds() {
return fwhIds;
}
public void setFwhIds(String fwhIds) {
this.fwhIds = fwhIds;
}
public String getScenesValueIds() {
return scenesValueIds;
}
public void setScenesValueIds(String scenesValueIds) {
this.scenesValueIds = scenesValueIds;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public List<QrcodeContent> getContent() {
return content;
}
public void setContent(List<QrcodeContent> content) {
this.content = content;
}
public String getCallBackService() {
return callBackService;
}
public void setCallBackService(String callBackService) {
this.callBackService = callBackService;
}
public String getCallBackMethod() {
return callBackMethod;
}
public void setCallBackMethod(String callBackMethod) {
this.callBackMethod = callBackMethod;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
...@@ -12,6 +12,7 @@ import java.util.regex.Pattern; ...@@ -12,6 +12,7 @@ import java.util.regex.Pattern;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import com.gic.download.dto.DownloadReportTempDTO;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -71,6 +72,7 @@ public class DataDownloadUtils { ...@@ -71,6 +72,7 @@ public class DataDownloadUtils {

 */ 
 */
public static Integer createDownloadReport(DownloadReport dto) { public static Integer createDownloadReport(DownloadReport dto) {
DownloadReportDTO record = EntityUtil.changeEntityNew(DownloadReportDTO.class, dto); DownloadReportDTO record = EntityUtil.changeEntityNew(DownloadReportDTO.class, dto);
LOGGER.info("服务对象是否为空:{}", dataDownloadUtils.downloadReportApiService == null);
ServiceResponse<Integer> result = dataDownloadUtils.downloadReportApiService.saveDownloadReport(record); ServiceResponse<Integer> result = dataDownloadUtils.downloadReportApiService.saveDownloadReport(record);
if (result.isSuccess()) { if (result.isSuccess()) {
return result.getResult(); return result.getResult();
...@@ -83,6 +85,25 @@ public class DataDownloadUtils { ...@@ -83,6 +85,25 @@ public class DataDownloadUtils {
} }
/** /**
* 根据ID获取记录,获取现在数据类型和总数信息
* @param reportId
* @return
*/
public static DownloadReportTempDTO getByReportId(Integer reportId) {
ServiceResponse<DownloadReportDTO> reportResult = dataDownloadUtils.downloadReportApiService
.getDownloadReport(reportId);
if (reportResult.isSuccess()) {
DownloadReportDTO report = reportResult.getResult();
DownloadReportTempDTO temp = new DownloadReportTempDTO();
temp.setDataCount(report.getDataCount());
temp.setDataType(report.getDataType());
return temp;
}
LOGGER.info("根据reportId获取数据错误:{}", JSON.toJSONString(reportResult));
return null;
}
/**
* 初始化下载工具类 * 初始化下载工具类
* @param initParams * @param initParams
* @throws IOException * @throws IOException
...@@ -151,7 +172,8 @@ public class DataDownloadUtils { ...@@ -151,7 +172,8 @@ public class DataDownloadUtils {
writer.flush(); writer.flush();
String fieldCode = "/" + System.currentTimeMillis() + "_" + params.getFileName() + ".csv"; String fieldCode = "/" + System.currentTimeMillis() + "_" + params.getFileName() + ".csv";
//文件存进腾讯云 //文件存进腾讯云
String url = FileOperateUtils.simpleUploadFileFromLocal(csvFile, fieldCode, BucketNameEnum.REPORT_50000.getName()); String url = FileOperateUtils.simpleUploadFileFromLocal(csvFile, fieldCode,
BucketNameEnum.REPORT_50000.getName());
if (StringUtils.isNotBlank(url)) { if (StringUtils.isNotBlank(url)) {
url = "https://" + url; url = "https://" + url;
} }
...@@ -299,8 +321,8 @@ public class DataDownloadUtils { ...@@ -299,8 +321,8 @@ public class DataDownloadUtils {
* @param fileUrl * @param fileUrl
*/ */
public static void uploadFile(Integer reportId, String fileUrl) { public static void uploadFile(Integer reportId, String fileUrl) {
ServiceResponse<Integer> result = dataDownloadUtils.downloadReportApiService ServiceResponse<Integer> result = dataDownloadUtils.downloadReportApiService.updateDownloadUrl(reportId,
.updateDownloadUrl(reportId, fileUrl); fileUrl);
if (!result.isSuccess()) { if (!result.isSuccess()) {
throw new CommonException(result); throw new CommonException(result);
} }
......
...@@ -7,6 +7,9 @@ import java.util.*; ...@@ -7,6 +7,9 @@ import java.util.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.gic.download.constants.ExcelExtensionEnum; import com.gic.download.constants.ExcelExtensionEnum;
import com.gic.download.dto.DownloadReportTempDTO;
import com.gic.download.qo.DownloadExcelQO;
import com.gic.download.qo.HeaderQO;
import com.gic.thirdparty.BucketNameEnum; import com.gic.thirdparty.BucketNameEnum;
import com.gic.thirdparty.FileOperateUtils; import com.gic.thirdparty.FileOperateUtils;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
...@@ -19,8 +22,7 @@ import org.apache.http.client.utils.DateUtils; ...@@ -19,8 +22,7 @@ import org.apache.http.client.utils.DateUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class DownloadUtils { public class DownloadUtils {
...@@ -125,6 +127,44 @@ public class DownloadUtils { ...@@ -125,6 +127,44 @@ public class DownloadUtils {
* @date 2017年3月16日 上午11:47:31 * @date 2017年3月16日 上午11:47:31
*/ */
protected <T> void download(String tempPath, Integer reportId, String fileName, Integer excelExtensionCode, List<String> headerList, List<String> propertyNameList, DownloadDataLoader<T> loader, List<String> needEncryptField, List<Integer> columnWidth) throws Exception { protected <T> void download(String tempPath, Integer reportId, String fileName, Integer excelExtensionCode, List<String> headerList, List<String> propertyNameList, DownloadDataLoader<T> loader, List<String> needEncryptField, List<Integer> columnWidth) throws Exception {
downloadCommon(new DownloadExcelQO().setTempPath(tempPath).setReportId(reportId).setFileName(fileName)
.setExcelExtensionCode(excelExtensionCode).setHeaderList(headerList).setPropertyNameList(propertyNameList)
.setNeedEncryptField(needEncryptField).setColumnWidth(columnWidth), loader);
}
/**
* 下载文件,2层标题结构
* @Title: downloadOfDoubleHeaderTitle

* @Description:

* @author guojuxing
* @param tempPath 临时路径
* @param reportId 报表中心ID
* @param fileName 文件名称
* @param excelExtensionCode Excel文件扩展名 枚举 ExcelExtensionEnum
* @param headerList 表头名称 2层标题结构
* @param propertyNameList 字段名
* @param loader 数据加载类
* @param needEncryptField 需要加密的字段,每一个元素存的是字段,如phone(电话)
* @param columnWidth
列宽
* @return void


*/
protected <T> void downloadOfDoubleHeaderTitle(String tempPath, Integer reportId, String fileName, Integer excelExtensionCode, List<HeaderQO> headerList, List<String> propertyNameList, DownloadDataLoader<T> loader, List<String> needEncryptField, List<Integer> columnWidth) throws Exception {
downloadCommon(new DownloadExcelQO().setTempPath(tempPath).setReportId(reportId).setFileName(fileName)
.setExcelExtensionCode(excelExtensionCode).setHeaders(headerList).setPropertyNameList(propertyNameList)
.setNeedEncryptField(needEncryptField).setColumnWidth(columnWidth), loader);
}
private <T> void downloadCommon(DownloadExcelQO param, DownloadDataLoader<T> loader) throws Exception {
Integer reportId = param.getReportId();
String fileName = param.getFileName();
Integer excelExtensionCode = param.getExcelExtensionCode();
List<String> headerList = param.getHeaderList();
List<HeaderQO> headers = param.getHeaders();
List<String> propertyNameList = param.getPropertyNameList();
List<String> needEncryptField = param.getNeedEncryptField();
String tempPath = param.getTempPath();
//是否是2层标题结构
boolean isDoubleHeaderTitle = CollectionUtils.isNotEmpty(headers);
if (StringUtils.isEmpty(fileName) || loader == null || CollectionUtils.isEmpty(propertyNameList)) { if (StringUtils.isEmpty(fileName) || loader == null || CollectionUtils.isEmpty(propertyNameList)) {
throw new RuntimeException("参数错误。FileName:" + fileName + ",DataLoader:" + loader + ",PropertyName:" + propertyNameList); throw new RuntimeException("参数错误。FileName:" + fileName + ",DataLoader:" + loader + ",PropertyName:" + propertyNameList);
...@@ -163,10 +203,21 @@ public class DownloadUtils { ...@@ -163,10 +203,21 @@ public class DownloadUtils {
} }
}; };
writeOutputStream(loader, propertyNameList, writer, needEncryptField); writeOutputStream(loader, propertyNameList, writer, needEncryptField, reportId);
// 写入excel // 写入excel
if (!ExcelUtils.setExcelInfo(sheet, columnWidth, headerList, rows)) { if (isDoubleHeaderTitle) {
throw new IOException("设置导出文件内容失败。"); CellStyle style = workbook.createCellStyle();
//// 指定单元格居中对齐
style.setAlignment(HorizontalAlignment.CENTER);
// 指定单元格垂直居中对齐
style.setVerticalAlignment(VerticalAlignment.CENTER);
if (!ExcelUtils.setHeaderTitle(style, sheet, param.getColumnWidth(), headers, rows)) {
throw new IOException("设置导出文件内容失败。");
}
} else {
if (!ExcelUtils.setExcelInfo(sheet, param.getColumnWidth(), headerList, rows)) {
throw new IOException("设置导出文件内容失败。");
}
} }
workbook.write(out); workbook.write(out);
...@@ -184,7 +235,7 @@ public class DownloadUtils { ...@@ -184,7 +235,7 @@ public class DownloadUtils {
// 写文件头 // 写文件头
writer.write(headerList); writer.write(headerList);
// 写文件 // 写文件
writeOutputStream(loader, propertyNameList, writer, needEncryptField); writeOutputStream(loader, propertyNameList, writer, needEncryptField, reportId);
} else { } else {
writer = new Writer() { writer = new Writer() {
@Override @Override
...@@ -197,12 +248,14 @@ public class DownloadUtils { ...@@ -197,12 +248,14 @@ public class DownloadUtils {
// 写文件头 // 写文件头
writer.write(headerList); writer.write(headerList);
// 写文件 // 写文件
writeOutputStream(loader, propertyNameList, writer, needEncryptField); writeOutputStream(loader, propertyNameList, writer, needEncryptField, reportId);
} }
out.flush(); out.flush();
tempFile.deleteOnExit(); tempFile.deleteOnExit();
//上传文件 //上传文件
String fieldCode = "/" + System.currentTimeMillis() + "_" + fileName + ExcelExtensionEnum.getExtensionByCode(excelExtensionCode); SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHHmmss");
String fieldCode = "/" + fileName + "_" + sdf.format(new Date()) + ExcelExtensionEnum.getExtensionByCode(excelExtensionCode);
LOGGER.info("上传文件到腾讯云,文件名:" + fieldCode);
//文件存进腾讯云 //文件存进腾讯云
String url = FileOperateUtils.simpleUploadFileFromLocal(tempFile, fieldCode, BucketNameEnum.REPORT_50000.getName()); String url = FileOperateUtils.simpleUploadFileFromLocal(tempFile, fieldCode, BucketNameEnum.REPORT_50000.getName());
if (org.apache.commons.lang.StringUtils.isNotBlank(url)) { if (org.apache.commons.lang.StringUtils.isNotBlank(url)) {
...@@ -246,8 +299,9 @@ public class DownloadUtils { ...@@ -246,8 +299,9 @@ public class DownloadUtils {
} }
protected <T> void writeOutputStream(DownloadDataLoader<T> loader, List<String> propertyNames, protected <T> void writeOutputStream(DownloadDataLoader<T> loader, List<String> propertyNames,
Writer writer, List<String> needEncryptField) throws Exception { Writer writer, List<String> needEncryptField, Integer reportId) throws Exception {
DownloadReportTempDTO tempReport = DataDownloadUtils.getByReportId(reportId);
int pageNum = 1; int pageNum = 1;
int maxLength = 102400; int maxLength = 102400;
while (maxLength -- > 0) { while (maxLength -- > 0) {
...@@ -273,8 +327,11 @@ public class DownloadUtils { ...@@ -273,8 +327,11 @@ public class DownloadUtils {
// 将属性值转换成字符串 // 将属性值转换成字符串
String convertValue = loader.convertProperty(bean, name, property); String convertValue = loader.convertProperty(bean, name, property);
//加密处理 //加密处理
if (needEncryptField != null && needEncryptField.contains(name)) { //如果不是完整数据,则需要加密处理
convertValue = encrypt(convertValue); if (tempReport != null && tempReport.getDataType().intValue() != 1) {
if (needEncryptField != null && needEncryptField.contains(name)) {
convertValue = encrypt(convertValue);
}
} }
// 组装成row // 组装成row
result.add(convertValue); result.add(convertValue);
......
...@@ -7,15 +7,14 @@ import java.util.*; ...@@ -7,15 +7,14 @@ import java.util.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.gic.download.qo.HeaderQO;
import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class ExcelUtils { public class ExcelUtils {
/** /**
...@@ -69,7 +68,6 @@ public class ExcelUtils { ...@@ -69,7 +68,6 @@ public class ExcelUtils {
continue; continue;
} }
String columnValue = object.toString(); String columnValue = object.toString();
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(columnValue); cell.setCellValue(columnValue);
} }
return true; return true;
...@@ -146,6 +144,55 @@ public class ExcelUtils { ...@@ -146,6 +144,55 @@ public class ExcelUtils {
return true; return true;
} }
public static boolean setHeaderTitle(CellStyle cellStyle, Sheet sheet, List<Integer> columnWidth, List<HeaderQO> headerList, List<?> content) {
if (sheet == null) {
logger.info("sheet is null");
return false;
}
// 设置sheet格式
setSheetStyle(sheet, columnWidth);
Row row1 = sheet.createRow(0);
Row row2 = sheet.createRow(1);
for (int i = 0, n = 0, length = headerList.size(); i < length; i ++) {
Cell cell1 = row1.createCell(n);
List<String> sonHeader = headerList.get(i).getSonHeadName();
String value = headerList.get(i).getHeadName();
cell1.setCellValue(value);
cell1.setCellStyle(cellStyle);
//2层标题
if (CollectionUtils.isEmpty(sonHeader)) {
//单标题
Cell cell2 = row2.createCell(n);
cell2.setCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 1, n, n));
n++;
continue;
}
//创建第一行大标题
sheet.addMergedRegion(new CellRangeAddress(0, 0, n, (n + sonHeader.size() - 1)));
//赋值
for (int j = 0, sonLength = sonHeader.size(); j < sonLength; j ++) {
Cell cell2 = row2.createCell(n++);
cell2.setCellStyle(cellStyle);
cell2.setCellValue(sonHeader.get(j));
}
}
// 如果内容为空 则退出
if (content == null || content.isEmpty()) {
logger.info("content is null,cannot write excel");
return true;
}
int indexRow = 2;
for (Object rowContent : content) {
Row row = sheet.createRow(indexRow++);
setRowInfo(row, rowContent);
}
return true;
}
/** /**
* 導出到excel * 導出到excel
* *
......
package com.gic.download.utils;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.ToolUtil;
import com.gic.download.qo.QrcodeContent;
import com.gic.download.qo.QrcodeQO;
import com.gic.enterprise.context.RequestContext;
import com.gic.enterprise.dto.DownloadReportDTO;
import com.gic.enterprise.dto.QrcodeDTO;
import com.gic.enterprise.service.DownloadReportApiService;
import com.gic.enterprise.service.QrCodeApiService;
import com.gic.enterprise.utils.UserDetail;
import com.gic.enterprise.utils.UserDetailUtils;
import com.gic.thirdparty.BucketNameEnum;
import com.gic.thirdparty.FileOperateUtils;
import com.gic.wechat.business.api.service.fwh.WeixinBaseFunService;
import com.gic.wechat.business.api.service.wxa.WeixinWxaFunService;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
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 QrcodeQO qrcodeQO = null;
private Integer total;
private int qrcodeType;
private DownloadReportApiService downloadReportApiService;
private WeixinBaseFunService weixinBaseFunService;
private WeixinWxaFunService weixinWxaFunService;
private QrCodeApiService qrCodeApiService;
public void takeQrcode(QrcodeQO qrcodeQO, int total, int qrcodeType,
DownloadReportApiService downloadReportApiService,
WeixinBaseFunService weixinBaseFunService,
WeixinWxaFunService weixinWxaFunService,
QrCodeApiService qrCodeApiService){
this.qrcodeQO = qrcodeQO;
this.downloadReportApiService = downloadReportApiService;
this.weixinBaseFunService = weixinBaseFunService;
this.weixinWxaFunService = weixinWxaFunService;
this.qrCodeApiService = qrCodeApiService;
this.total = total;
this.qrcodeType = qrcodeType;
Integer reportId = this.saveDownloadLog();
String fileId = ToolUtil.randomUUID();
String filePath = RequestContext.getContext().getRequest().getSession().getServletContext().getRealPath("/qrcode");
filePath += File.separator + UserDetailUtils.getUserDetail().getEnterpriseId() + File.separator + fileId+File.separator+qrcodeQO.getFileName()+".zip";
takeQrcodeTask(filePath, reportId, qrcodeQO.getFileName(), UserDetailUtils.getUserDetail());
}
private void takeQrcodeTask(final String filePath, final Integer reportId, final String fileName,final UserDetail userDetail){
ExecutorPoolSingleton.getInstance().executeTask(new Runnable() {
@Override
public void run() {
try {
File file = new File(filePath);
if(!file.exists()){
file.getParentFile().mkdirs();
file.createNewFile();
}
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
int pages = total%pageSize > 0 ? total/pageSize+1 : total/pageSize;
for(int i = 1; i<= pages; i++){
List<QrcodeContent> contentList = getContent(i, pageSize);
if(CollectionUtils.isEmpty(contentList)){
break;
}
for(QrcodeContent content : contentList){
QrcodeDTO dto = EntityUtil.changeEntityByJSON(QrcodeDTO.class, qrcodeQO);
dto.setEnterpriseId(userDetail.getEnterpriseId());
dto.setCustomParams(content.getCustomParams());
dto.setContent(content.getContent());
dto.setFileId(ToolUtil.randomUUID());
dto.setQrCodeType(qrcodeType);
ServiceResponse<Integer> response = qrCodeApiService.saveQrcodeDownload(dto);
if (response.isSuccess()) {
Integer qrcodeId = response.getResult();
if (qrcodeQO.getH5() == 1) {
byte[] h5Qrcode = createH5Qrcode(content.getContent(), content.getTitle(), userDetail);
ZipEntry e = new ZipEntry(content.getTitle() + File.separator + content.getTitle() + ".jpg");
zipOutputStream.putNextEntry(e);
zipOutputStream.write(h5Qrcode);
zipOutputStream.flush();
}
if (StringUtils.isNotBlank(dto.getFwhIds())) {
String[] fwhArr = dto.getFwhIds().split(",");
for (String s : fwhArr) {
byte[] fwhQrcode = createFwhQrcode(qrcodeId, dto.getType(), s, dto.getEndTime(), content.getTitle(), userDetail);
if(fwhQrcode != null){
ZipEntry e = new ZipEntry(content.getTitle() + File.separator + s + File.separator + content.getTitle() + ".jpg");
zipOutputStream.putNextEntry(e);
zipOutputStream.write(fwhQrcode);
zipOutputStream.flush();
}
}
}
if (StringUtils.isNotBlank(dto.getAppletIds())) {
String appletPath = content.getContent();
if(StringUtils.isBlank(appletPath)){
appletPath = "pages/index/index";
}
appletPath += "?qrcodeParam="+qrcodeId;
String[] appletArr = dto.getAppletIds().split(",");
for (String s : appletArr) {
byte[] appletQrcode = createAppletQrcode(s, appletPath);
if(appletQrcode != null){
ZipEntry e = new ZipEntry(content.getTitle() + File.separator + s + File.separator + content.getTitle() + ".jpg");
zipOutputStream.putNextEntry(e);
zipOutputStream.write(appletQrcode);
zipOutputStream.flush();
}
}
}
}
}
}
zipOutputStream.flush();
zipOutputStream.closeEntry();
zipOutputStream.close();
String url = FileOperateUtils.simpleUploadFileFromLocal(file, fileName+".zip", BucketNameEnum.COMPRESS_60000.getName());
downloadReportApiService.updateDownloadUrl(reportId, "https://"+url);
}catch (Exception e) {
log.warn("下载二维码异常:", e);
}
}
});
}
private Integer saveDownloadLog(){
DownloadReportDTO reportDTO = new DownloadReportDTO();
reportDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
reportDTO.setApplyUserId(UserDetailUtils.getUserDetail().getUserId());
reportDTO.setReportStartTime(null);
reportDTO.setReportEndTime(null);
reportDTO.setFileName(qrcodeQO.getFileName());
reportDTO.setDataContent("二维码");
reportDTO.setDataUrl("-");
reportDTO.setDataType(3);
reportDTO.setDataCount(total);
ServiceResponse<Integer> response = downloadReportApiService.saveDownloadReport(reportDTO);
if(response.isSuccess() && response.getResult() != null){
return response.getResult();
}
return 0;
}
private byte[] createFwhQrcode(Integer qrCodeId, int type, String appkey, Date endTime, String title, UserDetail userDetail){
ServiceResponse<String> qRcodeURL = null;
if(type == 1){
int expireSecond = Integer.valueOf((endTime.getTime() - System.currentTimeMillis())/1000+"");
qRcodeURL = this.weixinBaseFunService.getTemporaryQRcodeURL(appkey, qrCodeId + "", expireSecond);
}else {
qRcodeURL = this.weixinBaseFunService.getQRcodeURL(appkey, qrCodeId + "");
}
if(qRcodeURL.isSuccess()){
return createQrcode(qRcodeURL.getResult(), userDetail.getEnterpriseInfo().getLogo(), title);
}
return null;
}
private byte[] createAppletQrcode(String appkey, String path){
ServiceResponse<Map<String, Object>> wxaQrcode = this.weixinWxaFunService.createWxaQrcode(appkey, path, 1280);
if(wxaQrcode.isSuccess()){
Map<String, Object> result = wxaQrcode.getResult();
return (byte[]) result.get("content");
}
return null;
}
private byte[] createH5Qrcode(String content, String title, UserDetail userDetail){
return createQrcode(content, userDetail.getEnterpriseInfo().getLogo(), title);
}
protected abstract List<QrcodeContent> getContent(int pageSize, int pageNum);
private byte[] createQrcode(String url, String logoPic, String logoName) {
byte[] imageByte = null;
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);
return imageByte;
} catch (Exception e) {
log.error(e.getMessage());
return imageByte;
}
}
private byte[] getPicByte(String imgUrl) {
if(StringUtils.isBlank(imgUrl)){
return null;
}
HttpURLConnection conn = null;
try {
URL url = new URL(imgUrl);
try {
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
InputStream in = conn.getInputStream();
return IOUtils.toByteArray(in);
} catch (IOException e) {
e.printStackTrace();
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
/**
* 生成LOGO二维码图片
*
* @param bim
* 图片对象
* @param logoPic
* logo图片
* @param logoName
* logo名称
* @param format
* 图片后缀名
* @return
*/
private byte[] addLogo_QRCode(BufferedImage bim, byte[] logoPic, String logoName, String format) {
try {
/**
* 读取二维码图片,并构建绘图对象
*/
BufferedImage image = bim;
Graphics2D g = image.createGraphics();
if (StringUtils.isNotEmpty(logoName)) {
g.setColor(Color.BLACK);
g.setFont(new Font("宋体", Font.BOLD, 50)); // 字体、字型、字号
// int _height=outg.getFontMetrics().getHeight();
log.info("logoName1:"+logoName);
int _width = g.getFontMetrics().stringWidth(logoName);
log.info("logoName2:"+logoName);
g.drawString(logoName, (width - _width) / 2, height - 60); // 画文字
// outg.dispose();
image.flush();
// image = outImage;
}
if (logoPic != null) {
/**
* 读取Logo图片
*/
try {
BufferedImage logo = ImageIO.read(new ByteArrayInputStream(logoPic));
/**
* 设置logo的大小,本人设置为二维码图片的20%,因为过大会盖掉二维码
*/
int widthLogo = (int) Math.floor(logo.getWidth(null) > image.getWidth() * 1.5 / 10
? (image.getWidth() * 1.5 / 10) : logo.getWidth(null));
int heightLogo = (int) Math.floor(logo.getHeight(null) > image.getHeight() * 1.5 / 10
? (image.getHeight() * 1.5 / 10) : logo.getWidth(null));
/**
* logo放在中心
*/
int x = (int) Math.floor((image.getWidth() - widthLogo) / 2);
int y = (int) Math.floor((image.getHeight() - heightLogo) / 2);
/**
* logo放在右下角
*/
// 开始绘制图片
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());
}
}
g.dispose();
image.flush();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.flush();
ImageIO.write(image, format, baos);
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
return null;
}
/**
* 生成二维码bufferedImage图片
*
* @param content
* 编码内容
* @param barcodeFormat
* 编码类型
* @param width
* 图片宽度
* @param height
* 图片高度
* @param hints
* 设置参数
* @return
*/
private BufferedImage getQR_CODEBufferedImage(String content, BarcodeFormat barcodeFormat, int width, int height,
Map<EncodeHintType, ?> hints) {
MultiFormatWriter multiFormatWriter = null;
BitMatrix bm = null;
BufferedImage image = null;
try {
multiFormatWriter = new MultiFormatWriter();
// 参数顺序分别为:编码内容,编码类型,生成图片宽度,生成图片高度,设置参数
bm = multiFormatWriter.encode(content, barcodeFormat, width, height, hints);
int w = bm.getWidth();
int h = bm.getHeight();
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
// 开始利用二维码数据创建Bitmap图片,分别设为黑(0xFFFFFFFF)白(0xFF000000)两色
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
image.setRGB(x, y, bm.get(x, y) ? QRCOLOR : BGWHITE);
}
}
} catch (WriterException e) {
e.printStackTrace();
}
return image;
}
}
...@@ -36,27 +36,33 @@ public class LogUtils { ...@@ -36,27 +36,33 @@ public class LogUtils {

 */ 
 */
public static void createLog(String content, String operationObject) { public static void createLog(String content, String operationObject) {
UserDetail userDetail = UserDetailUtils.getUserDetail(); UserDetail userDetail = UserDetailUtils.getUserDetail();
SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date()); logDTO.setCreateTime(new Date());
//操作人 //操作人
logDTO.setUserId(Long.valueOf(userDetail.getUserInfo().getUserId())); logDTO.setUserId(Long.valueOf(userDetail.getUserInfo().getUserId()));
logDTO.setUserName(userDetail.getUserInfo().getUserName()); logDTO.setUserName(userDetail.getUserInfo().getUserName());
//操作内容 //操作内容
logDTO.setContent(content); logDTO.setContent(content);
//为了search查询,暂时用这个字段存
logDTO.setInterfaceName(content);
////操作对象
logDTO.setBusinessName(operationObject);
//操作模块 //操作模块
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");
if (moduleMenuId != null) { if (moduleMenuId != null) {
logDTO.setRelationId(Long.valueOf(moduleMenuId)); logDTO.setRelationId(Long.valueOf(moduleMenuId));
logDTO.setProject(moduleMenuName);
} else { } else {
LOGGER.info("操作模块数据有误"); LOGGER.info("操作模块数据有误");
} }
//操作对象 //账号(手机号)
logDTO.setRemark1(userDetail.getUserInfo().getPhoneAreaCode());
//账号(手机号)? logDTO.setRemark2(userDetail.getUserInfo().getPhoneNumber());
logDTO.setEnterpriesId(Long.valueOf(userDetail.getEnterpriseInfo().getEnterpriseId())); logDTO.setEnterpriseId(Long.valueOf(userDetail.getEnterpriseInfo().getEnterpriseId()));
logDTO.setEnterpriseName(userDetail.getEnterpriseInfo().getEnterpriseName()); logDTO.setEnterpriseName(userDetail.getEnterpriseInfo().getEnterpriseName());
ExecutorPoolSingleton.getInstance().executeTask(new Runnable() { ExecutorPoolSingleton.getInstance().executeTask(new Runnable() {
@Override @Override
...@@ -77,14 +83,17 @@ public class LogUtils { ...@@ -77,14 +83,17 @@ public class LogUtils {

 */ 
 */
public static void createLog(String content, String operationObject, String username, Integer enterpriseId, String enterpriseName) { public static void createLog(String content, String operationObject, String username, Integer enterpriseId, String enterpriseName) {
UserDetail userDetail = UserDetailUtils.getUserDetail(); UserDetail userDetail = UserDetailUtils.getUserDetail();
SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date()); logDTO.setCreateTime(new Date());
//操作人 //操作人
// logDTO.setUserId(Long.valueOf(userDetail.getUserInfo().getUserId())); // logDTO.setUserId(Long.valueOf(userDetail.getUserInfo().getUserId()));
logDTO.setUserName(username); logDTO.setUserName(username);
//操作内容 //操作内容
logDTO.setContent(content); logDTO.setContent(content);
//
logDTO.setBusinessName(operationObject);
//操作模块 //操作模块
// 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");
...@@ -97,7 +106,7 @@ public class LogUtils { ...@@ -97,7 +106,7 @@ public class LogUtils {
//账号(手机号)? //账号(手机号)?
logDTO.setEnterpriesId(Long.valueOf(enterpriseId)); logDTO.setEnterpriseId(Long.valueOf(enterpriseId));
logDTO.setEnterpriseName(enterpriseName); logDTO.setEnterpriseName(enterpriseName);
ExecutorPoolSingleton.getInstance().executeTask(new Runnable() { ExecutorPoolSingleton.getInstance().executeTask(new Runnable() {
@Override @Override
......
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