Commit 2ba1f8dd by guojuxing

Merge remote-tracking branch 'origin/developer' into developer

parents 77ef3116 23327ce8
......@@ -12,9 +12,9 @@ public class HiveDataDownloadDTO implements Serializable {
private String sql;
/**申请人用户id*/
private Integer applyUserId;
/**数据源**/
/**数据源(频道页),用 "-" 隔开上级和本级**/
private String dataContent;
/**报告类型***/
/**报告类型 1:完整数据, 2:脱敏数据, 3:二维码***/
private Integer dataType;
/**可以尝试用request.getHeader("Referer")获取dataUrl**/
private String dataUrl;
......
......@@ -34,6 +34,18 @@ public interface DownloadReportService {
* @throws
*/
Integer updateDownloadUrl(Integer downloadReportId, String downloadUrl);
/**
* updateDownloadUrl
* @Title: updateDownloadUrl
* @Description:
* @author taogs
* @param downloadReportId
* @param downloadUrl
* @return java.lang.Integer
* @throws
*/
Integer updateDownloadUrl(Integer downloadReportId, String downloadUrl, Integer count);
/**
* listDownloadReport
* @Title: listDownloadReport
......@@ -87,4 +99,16 @@ public interface DownloadReportService {
* @throws
*/
void updateDownloadStatus(String reportId, DownloadReportStatusEnum downloadReportStatusEnum);
/**
* updateDataCount
* @Title: updateDataCount
* @Description:
* @author taogs
* @param reportId
* @param count
* @return void
* @throws
*/
void updateDataCount(Integer reportId, Integer count);
}
......@@ -42,9 +42,17 @@ public class DownloadReportServiceImpl implements DownloadReportService {
@Override
public Integer updateDownloadUrl(Integer downloadReportId, String downloadUrl) {
return updateDownloadUrl(downloadReportId, downloadUrl, null);
}
@Override
public Integer updateDownloadUrl(Integer downloadReportId, String downloadUrl, Integer count) {
TabDownloadReport downloadReport = new TabDownloadReport();
downloadReport.setDownloadReportId(downloadReportId);
downloadReport.setDownloadUrl(downloadUrl);
if(count != null){
downloadReport.setDataCount(count);
}
return tabDownloadReportMapper.updateByPrimaryKeySelective(downloadReport);
}
......@@ -111,6 +119,14 @@ public class DownloadReportServiceImpl implements DownloadReportService {
tabDownloadReportMapper.updateByPrimaryKeySelective(downloadReport);
}
@Override
public void updateDataCount(Integer reportId, Integer count) {
TabDownloadReport downloadReport = new TabDownloadReport();
downloadReport.setReportId(reportId.toString());
downloadReport.setDataCount(count);
tabDownloadReportMapper.updateByPrimaryKeySelective(downloadReport);
}
private String getReportId() {
String reportId = CreateRandomUtils.generateNumberStr(8);
TabDownloadReport downloadReport = new TabDownloadReport();
......
......@@ -249,4 +249,5 @@ public class DownloadReportApiServiceImpl implements DownloadReportApiService {
map.put(reportId, System.currentTimeMillis());
return ServiceResponse.success();
}
}
......@@ -71,7 +71,9 @@ public class HiveDataDownloadApiServiceImpl implements HiveDataDownloadApiServic
@Override
public ServiceResponse<Integer> createDownloadTask(HiveDataDownloadDTO hiveDataDownloadDTO) {
ServiceResponse<Integer> response = downloadReportApiService.saveDownloadReport(EntityUtil.changeEntityByJSON(DownloadReportDTO.class, hiveDataDownloadDTO));
DownloadReportDTO downloadReportDTO = EntityUtil.changeEntityByJSON(DownloadReportDTO.class, hiveDataDownloadDTO);
downloadReportDTO.setDataCount(0);
ServiceResponse<Integer> response = downloadReportApiService.saveDownloadReport(downloadReportDTO);
if(!response.isSuccess()){
return response;
}
......@@ -108,7 +110,7 @@ public class HiveDataDownloadApiServiceImpl implements HiveDataDownloadApiServic
stat.execute("REFRESH TABLE " + task.getTableName()); // 强制刷新表结构 防止数据出错
ResultSet rs = stat.executeQuery(task.getHiveSql());
String url = FileUtils.createFile(rs, task.getDataType(), task.getDesenField(), task.getFileName(), task.getExcelExtension());
downloadReportService.updateDownloadUrl(Integer.valueOf(task.getReportId()), url);
downloadReportService.updateDownloadUrl(Integer.valueOf(task.getReportId()), url, rs.getRow());
} catch (Exception e) {
log.warn("下载数据出现异常", e);
// 任务状态修改
......
package com.gic.enterprise.service.outer;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.enterprise.constant.DownloadReportDataTypeEnum;
import com.gic.enterprise.constant.ExcelExtensionEnum;
import com.gic.enterprise.dto.HiveDataDownloadDTO;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.EnterpriseInitService;
import com.gic.enterprise.service.HiveDataDownloadApiService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* @author guojx
* @date 2019/7/16 6:31 PM
*/
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class HiveDataDownloadApiServiceImplTest extends AbstractJUnit4SpringContextTests{
@Autowired
HiveDataDownloadApiService hiveDataDownloadApiService;
@Test
public void hiveDataDownload() throws Exception {
HiveDataDownloadDTO dataDownloadDTO = new HiveDataDownloadDTO();
dataDownloadDTO.setEnterpriseId(1166);
dataDownloadDTO.setApplyUserId(13805);
dataDownloadDTO.setDataContent("用户-用户列表");
dataDownloadDTO.setDataType(DownloadReportDataTypeEnum.COMPLETE_DATA.getCode());
dataDownloadDTO.setDataUrl("https://four.gicdev.com/member-tag/member-tag/tag-val-edit?id=264137629747888139&name=111111");
//dataDownloadDTO.setDesenField();
dataDownloadDTO.setExcelExtension(ExcelExtensionEnum.CSV.getCode());
dataDownloadDTO.setFileName("boom hive test");
dataDownloadDTO.setSql("select order_id as '订单号' from extract_order_information");
ServiceResponse<Integer> downloadTask = hiveDataDownloadApiService.createDownloadTask(dataDownloadDTO);
System.out.println("downloadTask = " + JSON.toJSONString(downloadTask));
}
}
\ No newline at end of file
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