Commit 9470ea1d by 陶光胜

Merge branch 'developer' into 'master'

Developer

See merge request !29
parents 9e548db7 686a8ed2
package com.gic.cloud.data.hook.api.dto;
import java.util.Date;
/**
* dh_decrypt_key
*/
public class DhDecryptKey {
/**
*
*/
private Integer id;
/**
*
*/
private String enterpriseId;
/**
*
*/
private String publicKey;
/**
*
*/
private String privateKey;
/**
*
*/
private Date createTime;
/**
*
*/
private Date expireTime;
/**
*
*/
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public String getPublicKey() {
return publicKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public String getPrivateKey() {
return privateKey;
}
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getExpireTime() {
return expireTime;
}
public void setExpireTime(Date expireTime) {
this.expireTime = expireTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package com.gic.cloud.data.hook.api.service;
import com.gic.cloud.data.hook.api.dto.DhDecryptKey;
public interface DecryptKeyService {
void saveDecryKey(String enterpriseId, String publicKey, String privateKey);
DhDecryptKey getKeyByEnterpriseId(String enterpriseId);
}
...@@ -79,4 +79,10 @@ public interface IFreeQueryService { ...@@ -79,4 +79,10 @@ public interface IFreeQueryService {
FreeQuerySource getFreeQuerySource(String enterpriseId); FreeQuerySource getFreeQuerySource(String enterpriseId);
void initTask(); void initTask();
List<String> listFilterPhoneField();
List<String> listFilterPhoneAndCardNoField();
List<String> listFilterUserName();
} }
...@@ -39,16 +39,34 @@ ...@@ -39,16 +39,34 @@
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>
<version>3.10-FINAL</version> <version>3.10-FINAL</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>gic-cloud-data-hook-api</artifactId> <artifactId>gic-cloud-data-hook-api</artifactId>
<version>${gic-cloud-data-hook-api}</version> <version>${gic-cloud-data-hook-api}</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gic</groupId> <groupId>com.gic</groupId>
<artifactId>data-shield-sdk</artifactId> <artifactId>data-shield-sdk</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!--<dependency> <!--<dependency>
<groupId>data-shield</groupId> <groupId>data-shield</groupId>
...@@ -92,6 +110,14 @@ ...@@ -92,6 +110,14 @@
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
</exclusion> </exclusion>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
...@@ -107,6 +133,30 @@ ...@@ -107,6 +133,30 @@
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
</exclusion> </exclusion>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-thirdparty-sdk</artifactId>
<version>${gic-thirdparty-sdk}</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
......
...@@ -60,7 +60,7 @@ public class DecryptUtils { ...@@ -60,7 +60,7 @@ public class DecryptUtils {
} }
for(FlatQueryCondition condition : allFields){ for(FlatQueryCondition condition : allFields){
if(condition.getFieldMark().equals(columnName)){ if(condition.getFieldMark().equals(columnName)){
if(FreeQueryServiceImpl.FILETERS_USER_NAME.contains(condition.getFieldName())){ if(FilterFieldUtils.FILETERS_USER_NAME.contains(condition.getFieldName())){
return true; return true;
} }
} }
......
package com.gic.cloud.data.hook.service;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Component
public class FilterFieldUtils {
/** 脱敏字段 */
public static List<String> FILTERS_PHONE_ONLY = Arrays.asList("mobile", "phone", "enterprise_name", "phone_number", "receive_phone_number", "use_phone_number", "friend_phone_num","from_phone_num");
/** 脱敏字段 */
public static List<String> FILTERS_PHONE_AND_CARD = Arrays.asList("card_num", "mobile", "phone", "enterprise_name", "phone_number", "receive_phone_number","receive_card_num","use_phone_number", "use_card_num","friend_card_num","from_card_num", "friend_phone_num","from_phone_num");
public static List<String> FILETERS_USER_NAME = Arrays.asList("member_name","children_name","mbr_name","receive_member_name","use_member_name","name","bb_name","friend_mbr_name","from_mbr_name");
ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1,
new BasicThreadFactory.Builder().namingPattern("loadFilterFieldTimer-%d").daemon(true).build());
@PostConstruct
public void init(){
initTimer();
}
private void initTimer(){
timer.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
Config config = ConfigService.getConfig("application");
String phoneNumberField = config.getProperty("phoneNumberField", "");
String cardNumField = config.getProperty("cardNumField", "");
String userNameField = config.getProperty("userNameField", "");
if(StringUtils.isNotBlank(phoneNumberField)){
FILTERS_PHONE_ONLY = Arrays.asList(phoneNumberField.split(","));
FILTERS_PHONE_AND_CARD = new ArrayList<>();
for(String s : phoneNumberField.split(",")){
FILTERS_PHONE_AND_CARD.add(s);
}
}
if(StringUtils.isNotBlank(cardNumField)){
for(String s : cardNumField.split(",")){
FILTERS_PHONE_AND_CARD.add(s);
}
}
if(StringUtils.isNotBlank(userNameField)){
FILETERS_USER_NAME = Arrays.asList(userNameField.split(","));
}
}
}, 5, 5, TimeUnit.SECONDS);
}
}
...@@ -2,8 +2,11 @@ package com.gic.cloud.data.hook.service; ...@@ -2,8 +2,11 @@ package com.gic.cloud.data.hook.service;
import com.gic.cloud.data.hook.api.service.IFlatQueryTableService; import com.gic.cloud.data.hook.api.service.IFlatQueryTableService;
import com.gic.qcloud.BucketNameEnum;
import com.gic.qcloud.FileUploadUtil;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -16,29 +19,24 @@ public class TestHive { ...@@ -16,29 +19,24 @@ public class TestHive {
private static org.slf4j.Logger logger= LoggerFactory.getLogger(IFlatQueryTableService.class); private static org.slf4j.Logger logger= LoggerFactory.getLogger(IFlatQueryTableService.class);
public static void main(String[] args) { public static void main(String[] args) {
// String url = "jdbc:hive2://115.159.205.44:10015/data_test"; String sql = "select from tab_gic_store limit 10000";
// try { String curLimit = "";
// System.out.println("准备连接"); if(sql.indexOf("limit")>0 || sql.indexOf("LIMIT")>0){
// Class.forName("org.apache.hive.jdbc.HiveDriver"); int start = 0;
// Connection conn = DriverManager.getConnection(url, "hadoop", ""); if(sql.indexOf("limit")>0){
// System.out.println("连接成功"); start = sql.indexOf("limit") + 6;
// String sql = "show tables"; } else {
// System.out.println("SQL: "+sql); start = sql.indexOf("LIMIT") + 6;
// Statement stmt = conn.createStatement(); }
// ResultSet rs = stmt.executeQuery(sql); curLimit = sql.substring(start);
// while(rs.next()){ if(curLimit.indexOf(",") > 0){
// System.out.println(rs.getString(1)); curLimit = curLimit.substring(curLimit.indexOf(",")+1);
// } }
// if(Integer.valueOf(curLimit) > 1000){
// System.out.println("处理结束"); curLimit = 1000+"";
// } catch (Exception e) { }
// e.printStackTrace();
// }
try {
Class.forName("org.apache.logging.log4j.core.LoggerContext");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} }
System.out.println("sql = " + sql + " limit " + curLimit);
} }
......
package com.gic.cloud.data.hook.service.dao;
import com.gic.cloud.data.hook.api.dto.DhDecryptKey;
import org.apache.ibatis.annotations.Param;
public interface DhDecryptKeyMapper {
/**
* 根据主键删除
*
* @param id 主键
* @return 更新条目数
*/
int deleteByPrimaryKey(Integer id);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insert(DhDecryptKey record);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insertSelective(DhDecryptKey record);
/**
* 根据主键查询
*
* @param id 主键
* @return 实体对象
*/
DhDecryptKey selectByPrimaryKey(Integer id);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKeySelective(DhDecryptKey record);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKey(DhDecryptKey record);
DhDecryptKey selectByEnterpriseId(@Param("enterpriseId") String enterpriseId);
}
package com.gic.cloud.data.hook.service.impl;
import com.gic.cloud.data.hook.api.service.DecryptKeyService;
import com.gic.cloud.data.hook.service.dao.DhDecryptKeyMapper;
import com.gic.cloud.data.hook.api.dto.DhDecryptKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Date;
@Service("decryptKeyService")
public class DecryptKeyServiceImpl implements DecryptKeyService {
@Autowired
private DhDecryptKeyMapper dhDecryptKeyMapper;
@Override
public void saveDecryKey(String enterpriseId, String publicKey, String privateKey) {
DhDecryptKey key = new DhDecryptKey();
key.setEnterpriseId(enterpriseId);
key.setPublicKey(publicKey);
key.setPrivateKey(privateKey);
key.setCreateTime(new Date());
key.setUpdateTime(new Date());
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Date time = calendar.getTime();
key.setExpireTime(time);
dhDecryptKeyMapper.insertSelective(key);
}
@Override
public DhDecryptKey getKeyByEnterpriseId(String enterpriseId) {
return dhDecryptKeyMapper.selectByEnterpriseId(enterpriseId);
}
}
...@@ -14,6 +14,8 @@ import com.gic.cloud.data.hook.service.dao.FreeQueryRecordDao; ...@@ -14,6 +14,8 @@ import com.gic.cloud.data.hook.service.dao.FreeQueryRecordDao;
import com.gic.cloud.data.hook.service.dao.FreeQuerySourceDao; import com.gic.cloud.data.hook.service.dao.FreeQuerySourceDao;
import com.gic.cloud.data.hook.service.entity.CsvDataFilterMode; import com.gic.cloud.data.hook.service.entity.CsvDataFilterMode;
import com.gic.cloud.data.hook.service.entity.CsvResultSetHelper; import com.gic.cloud.data.hook.service.entity.CsvResultSetHelper;
import com.gic.qcloud.BucketNameEnum;
import com.gic.qcloud.FileUploadUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper; import com.opencsv.ResultSetHelper;
...@@ -52,14 +54,6 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -52,14 +54,6 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
/** csv / xls 下载目录 */ /** csv / xls 下载目录 */
public static final String SAVE_FOLDER = "/usr/local/data-hook-file"; public static final String SAVE_FOLDER = "/usr/local/data-hook-file";
/** 脱敏字段 */
public static final List<String> FILTERS_PHONE_ONLY = Arrays.asList("mobile", "phone", "enterprise_name", "phone_number", "receive_phone_number", "use_phone_number", "friend_phone_num","from_phone_num");
/** 脱敏字段 */
public static final List<String> FILTERS_PHONE_AND_CARD = Arrays.asList("card_num", "mobile", "phone", "enterprise_name", "phone_number", "receive_phone_number","receive_card_num","use_phone_number", "use_card_num","friend_card_num","from_card_num", "friend_phone_num","from_phone_num");
public static final List<String> FILETERS_USER_NAME = Arrays.asList("member_name","children_name","mbr_name","receive_member_name","use_member_name","name","bb_name","friend_mbr_name","from_mbr_name");
@Autowired @Autowired
IDownloadTaskService downloadTaskService; IDownloadTaskService downloadTaskService;
...@@ -70,8 +64,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -70,8 +64,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
*/ */
public static List<String> getFieldsFilters(Integer desensiType) { public static List<String> getFieldsFilters(Integer desensiType) {
if (desensiType == DataDesensiType.PHONE_ONLY) { if (desensiType == DataDesensiType.PHONE_ONLY) {
return FILTERS_PHONE_ONLY; return FilterFieldUtils.FILTERS_PHONE_ONLY;
} else return FILTERS_PHONE_AND_CARD; } else return FilterFieldUtils.FILTERS_PHONE_AND_CARD;
} }
/** 是否为脱敏字段 */ /** 是否为脱敏字段 */
...@@ -79,7 +73,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -79,7 +73,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
List<String> fieldsFilter = getFieldsFilters(desensiType); List<String> fieldsFilter = getFieldsFilters(desensiType);
log.debug("isFilterFields:", JSON.toJSONString(fieldsFilter) + "-" + desensiType +"-"+ fieldName); log.debug("isFilterFields:", JSON.toJSONString(fieldsFilter) + "-" + desensiType +"-"+ fieldName);
for (String filter : fieldsFilter) { for (String filter : fieldsFilter) {
if (fieldName.contains(filter)) return true; if (fieldName.equals(filter)) return true;
} // FOR OVER } // FOR OVER
return false; return false;
} }
...@@ -236,8 +230,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -236,8 +230,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
Object filedValue; Object filedValue;
if (queryDataType == QueryDataType.SAFE && FreeQueryServiceImpl.isFilterFields(desensiType, fieldName)) {//手机号和卡号 if (queryDataType == QueryDataType.SAFE && FreeQueryServiceImpl.isFilterFields(desensiType, fieldName)) {//手机号和卡号
filedValue = "******"; filedValue = "******";
}else if(queryDataType == QueryDataType.SAFE && FILETERS_USER_NAME.contains(fieldName)){//用户名 }else if(queryDataType == QueryDataType.SAFE && FilterFieldUtils.FILETERS_USER_NAME.contains(fieldName)){//用户名
filedValue = DecryptUtils.dataSecurityProcessUserName(rs.getString(fieldName)); filedValue = DecryptUtils.dataSecurityProcessUserName(rs.getString(i+1));
} else { } else {
switch (metaData.getColumnType(i + 1)) { switch (metaData.getColumnType(i + 1)) {
case Types.TIMESTAMP: case Types.TIMESTAMP:
...@@ -250,7 +244,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -250,7 +244,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
filedValue = rs.getTimestamp(fieldName) != null ? timeFormat.format(new Date(rs.getTimestamp(fieldName).getTime())) : ""; filedValue = rs.getTimestamp(fieldName) != null ? timeFormat.format(new Date(rs.getTimestamp(fieldName).getTime())) : "";
break; break;
default: default:
filedValue = rs.getObject(fieldName); filedValue = rs.getObject(i+1);
} // SWITCH OVER } // SWITCH OVER
} // IF ELSE } // IF ELSE
result.add(fieldName, filedValue); result.add(fieldName, filedValue);
...@@ -356,6 +350,21 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -356,6 +350,21 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} }
} }
@Override
public List<String> listFilterPhoneField() {
return FilterFieldUtils.FILTERS_PHONE_ONLY;
}
@Override
public List<String> listFilterPhoneAndCardNoField() {
return FilterFieldUtils.FILTERS_PHONE_AND_CARD;
}
@Override
public List<String> listFilterUserName() {
return FilterFieldUtils.FILETERS_USER_NAME;
}
private static SimpleDateFormat datetimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat datetimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); private static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
...@@ -412,7 +421,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -412,7 +421,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
//CSVWriter csvWriter = new CSVWriter(new FileWriter(csvPath), '\t'); //CSVWriter csvWriter = new CSVWriter(new FileWriter(csvPath), '\t');
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(originalFilePath), Charset.forName("GBK")); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(originalFilePath), Charset.forName("GBK"));
ResultSetHelper helper = new CsvResultSetHelper(task.getQueryDataType() == QueryDataType.FULL ? CsvDataFilterMode.NONE : CsvDataFilterMode.DESENSI, FreeQueryServiceImpl.getFieldsFilters(condition.getDesensiType()), null); String queryDataType = task.getQueryDataType() == QueryDataType.FULL ? CsvDataFilterMode.NONE : CsvDataFilterMode.DESENSI;
ResultSetHelper helper = new CsvResultSetHelper(queryDataType, FreeQueryServiceImpl.getFieldsFilters(condition.getDesensiType()), null, null, null);
CSVWriter writer = new CSVWriter(out, ','); CSVWriter writer = new CSVWriter(out, ',');
writer.setResultService(helper); writer.setResultService(helper);
writer.writeAll(rs, true); writer.writeAll(rs, true);
...@@ -441,8 +451,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -441,8 +451,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
//row.createCell(j).setCellValue(c); //row.createCell(j).setCellValue(c);
String cName = rs.getMetaData().getColumnName(j+1); String cName = rs.getMetaData().getColumnName(j+1);
if (task.getQueryDataType() == QueryDataType.SAFE if (task.getQueryDataType() == QueryDataType.SAFE
&& (FreeQueryServiceImpl.isFilterFields(condition.getDesensiType(), cName) || FreeQueryServiceImpl.FILETERS_USER_NAME.contains(cName))) { && (FreeQueryServiceImpl.isFilterFields(condition.getDesensiType(), cName) || FilterFieldUtils.FILETERS_USER_NAME.contains(cName))) {
if(FreeQueryServiceImpl.FILETERS_USER_NAME.contains(cName)){ if(FilterFieldUtils.FILETERS_USER_NAME.contains(cName)){
row.createCell(j).setCellValue(DecryptUtils.dataSecurityProcessUserName(rs.getString(j+1))); row.createCell(j).setCellValue(DecryptUtils.dataSecurityProcessUserName(rs.getString(j+1)));
} else { } else {
row.createCell(j).setCellValue("******"); row.createCell(j).setCellValue("******");
...@@ -474,7 +484,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -474,7 +484,7 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
wb.dispose(); // SXSSFWorkbook 没有 close 方法 wb.dispose(); // SXSSFWorkbook 没有 close 方法
log.debug("runDownloadTask.run", "已生成自定义查询下载文件 " + condition.getTaskId() + ".xlsx"); log.debug("runDownloadTask.run", "已生成自定义查询下载文件 " + condition.getTaskId() + ".xlsx");
} }
String cloudFileUrl = "";
if (task.getUseCompress().equals(Global.YES)) { if (task.getUseCompress().equals(Global.YES)) {
log.debug("runDownloadTask.run", "准备生成自定义查询压缩文件 " + condition.getTaskId() + ".zip"); log.debug("runDownloadTask.run", "准备生成自定义查询压缩文件 " + condition.getTaskId() + ".zip");
String zipFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".zip"; String zipFilePath = SAVE_FOLDER + "/" + condition.getTaskId() + ".zip";
...@@ -504,13 +514,16 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -504,13 +514,16 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
zos.closeEntry(); zos.closeEntry();
zos.close(); zos.close();
} }
cloudFileUrl = FileUploadUtil.simpleUploadFileFromLocal(zipFile, task.getId(), BucketNameEnum.COMPRESS_60000.getName());
} else {
cloudFileUrl = FileUploadUtil.simpleUploadFileFromLocal(new File(originalFilePath), task.getId(), BucketNameEnum.REPORT_50000.getName());
} }
log.debug("上传腾讯云", "地址为:"+cloudFileUrl);
task.setStatus(DownloadTaskStatus.COMPLISHED); task.setStatus(DownloadTaskStatus.COMPLISHED);
task.setOverTime(new java.util.Date()); task.setOverTime(new java.util.Date());
String taskFileExt = task.getUseCompress().equals(Global.YES) ? ".zip" : task.getFormat().equals(DownloadFileFormat.CSV) ? ".csv" : ".xlsx"; String taskFileExt = task.getUseCompress().equals(Global.YES) ? ".zip" : task.getFormat().equals(DownloadFileFormat.CSV) ? ".csv" : ".xlsx";
task.setFilePath(task.getId() + taskFileExt); task.setFilePath(cloudFileUrl);
DownloadTaskServiceImpl.getInstance().updateDownloadTask(task); DownloadTaskServiceImpl.getInstance().updateDownloadTask(task);
} catch (Exception ex) { } catch (Exception ex) {
...@@ -611,4 +624,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService { ...@@ -611,4 +624,8 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
} }
public static void main(String[] args){
long startTs = (System.currentTimeMillis() / 60*1000 + 1) * 60*1000 - System.currentTimeMillis();
System.out.println("startTs = " + startTs);
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gic.cloud.data.hook.service.dao.DhDecryptKeyMapper">
<resultMap id="BaseResultMap" type="com.gic.cloud.data.hook.api.dto.DhDecryptKey">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="enterprise_id" jdbcType="VARCHAR" property="enterpriseId" />
<result column="public_key" jdbcType="VARCHAR" property="publicKey" />
<result column="private_key" jdbcType="VARCHAR" property="privateKey" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, enterprise_id, public_key, private_key, create_time, expire_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from dh_decrypt_key
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from dh_decrypt_key
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.cloud.data.hook.api.dto.DhDecryptKey">
insert into dh_decrypt_key (id, enterprise_id, public_key,
private_key, create_time, expire_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{enterpriseId,jdbcType=VARCHAR}, #{publicKey,jdbcType=VARCHAR},
#{privateKey,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{expireTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.cloud.data.hook.api.dto.DhDecryptKey">
insert into dh_decrypt_key
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="enterpriseId != null">
enterprise_id,
</if>
<if test="publicKey != null">
public_key,
</if>
<if test="privateKey != null">
private_key,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="expireTime != null">
expire_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="enterpriseId != null">
#{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="publicKey != null">
#{publicKey,jdbcType=VARCHAR},
</if>
<if test="privateKey != null">
#{privateKey,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.cloud.data.hook.api.dto.DhDecryptKey">
update dh_decrypt_key
<set>
<if test="enterpriseId != null">
enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
</if>
<if test="publicKey != null">
public_key = #{publicKey,jdbcType=VARCHAR},
</if>
<if test="privateKey != null">
private_key = #{privateKey,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.cloud.data.hook.api.dto.DhDecryptKey">
update dh_decrypt_key
set enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
public_key = #{publicKey,jdbcType=VARCHAR},
private_key = #{privateKey,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByEnterpriseId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from dh_decrypt_key
where enterprise_id=#{enterpriseId} and now() &lt; expire_time
</select>
</mapper>
\ No newline at end of file
...@@ -54,15 +54,16 @@ ...@@ -54,15 +54,16 @@
FROM FROM
<include refid="queryTables"/> <include refid="queryTables"/>
<include refid="queryJoins"/> <include refid="queryJoins"/>
where 1=1
<if test="fuzzy != '' "> <if test="fuzzy != '' ">
<bind name="pattern" value="'%' + fuzzy + '%'" /> <bind name="pattern" value="'%' + fuzzy + '%'" />
WHERE and
q.table_id LIKE #{pattern} (q.table_id LIKE #{pattern}
OR q.name LIKE #{pattern} OR q.name LIKE #{pattern}
OR q.description LIKE #{pattern} OR q.description LIKE #{pattern})
</if> </if>
<if test="authTables != null and authTables.size()>0"> <if test="authTables != null and authTables.size()>0">
where q.table_id in and q.table_id in
<foreach close=")" collection="authTables" index="index" item="item" open="(" separator=","> <foreach close=")" collection="authTables" index="index" item="item" open="(" separator=",">
#{item} #{item}
</foreach> </foreach>
......
...@@ -12,10 +12,7 @@ import com.gic.cloud.data.hook.api.entity.FlatQueryCondition; ...@@ -12,10 +12,7 @@ import com.gic.cloud.data.hook.api.entity.FlatQueryCondition;
import com.gic.cloud.data.hook.api.entity.FlatQueryExecuteRequest; import com.gic.cloud.data.hook.api.entity.FlatQueryExecuteRequest;
import com.gic.cloud.data.hook.api.entity.GeneralResult; import com.gic.cloud.data.hook.api.entity.GeneralResult;
import com.gic.cloud.data.hook.api.entity.Global; import com.gic.cloud.data.hook.api.entity.Global;
import com.gic.cloud.data.hook.api.service.IFlatQueryResultService; import com.gic.cloud.data.hook.api.service.*;
import com.gic.cloud.data.hook.api.service.IFlatQueryTableService;
import com.gic.cloud.data.hook.api.service.IMyFlatQueryService;
import com.gic.cloud.data.hook.api.service.SearchLogService;
import com.gic.enterprise.api.constant.StoreWidget; import com.gic.enterprise.api.constant.StoreWidget;
import com.gic.enterprise.api.dto.EnterpriseSettingDTO; import com.gic.enterprise.api.dto.EnterpriseSettingDTO;
import com.gic.enterprise.api.dto.StoreWidgetDTO; import com.gic.enterprise.api.dto.StoreWidgetDTO;
...@@ -74,6 +71,8 @@ public class FlatQueryController { ...@@ -74,6 +71,8 @@ public class FlatQueryController {
private RightService rightService; private RightService rightService;
@Autowired @Autowired
private SearchLogService searchLogService; private SearchLogService searchLogService;
@Autowired
private IFreeQueryService freeQueryService;
/** 查询表定义及下载量等信息 /** 查询表定义及下载量等信息
...@@ -217,14 +216,14 @@ public class FlatQueryController { ...@@ -217,14 +216,14 @@ public class FlatQueryController {
if(dataPermission != null){ if(dataPermission != null){
for(FlatQueryCondition condition : queryConditions){ for(FlatQueryCondition condition : queryConditions){
if(dataPermission == 1){ if(dataPermission == 1){
if(FILTERS_PHONE_ONLY.contains(condition.getFieldName())){ if(freeQueryService.listFilterPhoneField().contains(condition.getFieldName())){
condition.setEnableEncrypt(true); condition.setEnableEncrypt(true);
}else { }else {
condition.setEnableEncrypt(false); condition.setEnableEncrypt(false);
} }
} }
if(dataPermission == 2){ if(dataPermission == 2){
if(FILTERS_PHONE_AND_CARD.contains(condition.getFieldName())){ if(freeQueryService.listFilterPhoneAndCardNoField().contains(condition.getFieldName())){
condition.setEnableEncrypt(true); condition.setEnableEncrypt(true);
} else { } else {
condition.setEnableEncrypt(false); condition.setEnableEncrypt(false);
......
...@@ -160,7 +160,8 @@ public class FreeQueryController { ...@@ -160,7 +160,8 @@ public class FreeQueryController {
dto.setStartTime(new Date()); dto.setStartTime(new Date());
Integer dataPermission = this.enterpriseService.getEnterpriseSettingByEnterpriseId(SessionContextUtils.getLoginUserEnterpriseId()).getDataPermission(); Integer dataPermission = this.enterpriseService.getEnterpriseSettingByEnterpriseId(SessionContextUtils.getLoginUserEnterpriseId()).getDataPermission();
System.out.println("!!!!!!!!:"+dataPermission); System.out.println("!!!!!!!!:"+dataPermission);
FreeQueryResult freeQueryResult = this.freeQueryService.getFreeQueryResult("SELECT tmpTable.* FROM (" + sql + ") AS tmpTable LIMIT 1000", enterpriseId, queryDataType, dataPermission); sql = parseSql(sql);
FreeQueryResult freeQueryResult = this.freeQueryService.getFreeQueryResult(sql, enterpriseId, queryDataType, dataPermission);
dto.setEndTime(new Date()); dto.setEndTime(new Date());
this.searchLogService.saveLog(dto); this.searchLogService.saveLog(dto);
return freeQueryResult; return freeQueryResult;
...@@ -182,6 +183,31 @@ public class FreeQueryController { ...@@ -182,6 +183,31 @@ public class FreeQueryController {
return this.freeQueryService.buildFreeQueryDownloadTask(userId, name, amount, format, sql, enterpriseId, useCompress, dataType, applyId, desensiType); return this.freeQueryService.buildFreeQueryDownloadTask(userId, name, amount, format, sql, enterpriseId, useCompress, dataType, applyId, desensiType);
} }
private String parseSql(String sql){
String curLimit = "1000";
if(sql.indexOf("information_schema.columns") > 0){
sql = "SELECT tmpTable.* FROM (" + sql + ") AS tmpTable LIMIT 1000";
} else {
if(sql.indexOf("limit")>0 || sql.indexOf("LIMIT")>0){
int start = 0;
if(sql.indexOf("limit")>0){
start = sql.indexOf("limit") + 6;
} else {
start = sql.indexOf("LIMIT") + 6;
}
curLimit = sql.substring(start);
if(curLimit.indexOf(",") > 0){
curLimit = curLimit.substring(curLimit.indexOf(",")+1);
}
if(Integer.valueOf(curLimit) > 1000){
curLimit = 1000+"";
}
}
sql = sql + " limit " + curLimit;
}
return sql;
}
/** 获取指定表明的所有字段 /** 获取指定表明的所有字段
* @param tableName * @param tableName
* @param request * @param request
......
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