Commit 79975002 by 陈健智

上传任务调整

parent 07da5aee
package com.zhiwei.brandkbs2.aop;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.model.ResponseResult;
......@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.Objects;
/**
* @author cjz
......@@ -34,7 +36,7 @@ public class AopDownloadTask {
@Resource(name = "downloadTaskServiceImpl")
DownloadTaskService downloadTaskService;
@Around(value = "execution(public * com..controller..app..AppDownloadController.*(..)))")
@Around(value = "execution(public * com..controller..app..AppDownloadController.*(..)) || execution(public * com..controller..app..AppToolsetController.getBatchArticleSummary(..)))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
Signature signature = joinPoint.getSignature();
Method method = ((MethodSignature) signature).getMethod();
......@@ -53,7 +55,11 @@ public class AopDownloadTask {
ExceptionCast.cast(CommonCodeEnum.FAIL, "下载异常", e);
}
// 更新下载任务
if (Objects.equals(method.getName(), "getBatchArticleSummary")){
fileAddress = JSONObject.parseObject(((ResponseResult) proceed).getData().toString()).getString("filePath");
}else {
fileAddress = ((ResponseResult) proceed).getData().toString();
}
downloadTaskService.updateDownloadTask(taskId, 100, DownloadTask.Status.FINISH.getName(), fileAddress);
return proceed;
}
......
......@@ -32,8 +32,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
......@@ -90,12 +89,12 @@ public class AppDownloadController extends BaseController {
HttpEntity<String> requestEntity = new HttpEntity<>(getHeaders());
HttpEntity<org.springframework.core.io.Resource> entity = restTemplate.exchange(yuqingInterface + "/upload/template/form?projectId=" + project.getBrandLinkedGroupId(), HttpMethod.GET,
requestEntity, org.springframework.core.io.Resource.class);
String fileAddress = null;
// excel写入至指定路径
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, project.getProjectName(), UserThreadLocal.getNickname(), project.getBrandName() + "_稿件模板");
if (null != entity.getBody()) {
String fileName = getFileNamePrefix() + project.getBrandName() + "_稿件模板";
fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, entity.getBody().getInputStream());
EasyExcelUtil.write(filePath, entity.getBody().getInputStream());
}
return ResponseResult.success(fileAddress);
return ResponseResult.success(filePath);
} catch (Exception e) {
log.error("稿件上传-稿件模板下载异常", e);
return ResponseResult.failure("稿件上传-稿件模板下载异常");
......@@ -113,12 +112,13 @@ public class AppDownloadController extends BaseController {
String formType = info.getString("formType");
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(getHeaders());
HttpEntity<org.springframework.core.io.Resource> entity = restTemplate.exchange(yuqingInterface + "/upload/list/download/file/" + id + "?formType=" + formType, HttpMethod.GET, requestEntity, org.springframework.core.io.Resource.class);
String fileAddress = null;
// excel写入至指定路径
String projectName = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), id + "_" + formType);
if (null != entity.getBody()) {
String fileName = getFileNamePrefix() + id + "_" + formType;
fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, entity.getBody().getInputStream());
EasyExcelUtil.write(filePath, entity.getBody().getInputStream());
}
return ResponseResult.success(fileAddress);
return ResponseResult.success(filePath);
} catch (Exception e) {
log.error("稿件上传-下载表格上传信息", e);
return ResponseResult.failure("稿件上传下载表格上传信息");
......@@ -132,9 +132,11 @@ public class AppDownloadController extends BaseController {
String projectId = UserThreadLocal.getProjectId();
List<ExportWordDTO> list = highWordService.downloadWord(projectId);
ProjectVO projectVO = projectService.getProjectVOById(projectId);
String fileName = getFileNamePrefix() + projectVO.getBrandName() + "_高频关键词";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportWordDTO.class, list);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectVO.getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), projectVO.getBrandName() + "_高频关键词");
EasyExcelUtil.write(filePath, "sheet1", ExportWordDTO.class, list);
return ResponseResult.success(filePath);
}
@ApiOperation("舆情列表高亮关键词")
......@@ -144,9 +146,11 @@ public class AppDownloadController extends BaseController {
String projectId = UserThreadLocal.getProjectId();
List<ExportWordDTO> list = highlightWordService.downloadWord(projectId);
ProjectVO projectVO = projectService.getProjectVOById(projectId);
String fileName = getFileNamePrefix() + projectVO.getBrandName() + "_舆情列表高亮关键词";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportWordDTO.class, list);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectVO.getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), projectVO.getBrandName() + "_舆情列表高亮关键词");
EasyExcelUtil.write(filePath, "sheet1", ExportWordDTO.class, list);
return ResponseResult.success(filePath);
}
@ApiOperation("用户行为列表")
......@@ -162,10 +166,11 @@ public class AppDownloadController extends BaseController {
@RequestParam(value = "behavior", defaultValue = "true") boolean behavior) {
List<ExportBehaviorDTO> downloadList = behaviorService.download(startTime, endTime, behavior);
String behaviorName = behavior ? "后台" : "前台";
String sheetName = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getProjectName() + "_" + behaviorName;
String fileName = getFileNamePrefix() + behaviorName + "_用户行为";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, sheetName, ExportBehaviorDTO.class, downloadList);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), behaviorName + "_用户行为");
EasyExcelUtil.write(filePath, "sheet1", ExportBehaviorDTO.class, downloadList);
return ResponseResult.success(filePath);
}
@ApiOperation("用户操作记录列表")
......@@ -178,10 +183,11 @@ public class AppDownloadController extends BaseController {
public ResponseResult downloadLogRecordList(@RequestParam("startTime") long startTime,
@RequestParam("endTime") long endTime) {
List<ExportUserLogRecordDTO> list = behaviorService.downloadUserLogRecord(startTime, endTime);
String sheetName = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getProjectName() + "_操作记录";
String fileName = getFileNamePrefix() + "操作记录";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, sheetName, ExportUserLogRecordDTO.class, list);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), "操作记录");
EasyExcelUtil.write(filePath, "sheet1", ExportUserLogRecordDTO.class, list);
return ResponseResult.success(filePath);
}
@ApiOperation("渠道列表")
......@@ -200,10 +206,11 @@ public class AppDownloadController extends BaseController {
@RequestParam(value = "show", required = false) Boolean show,
@RequestParam(value = "keyword", defaultValue = "") String keyword) {
List<ExportChannelDTO> downloadChannelList = channelService.findDownloadChannelList(contendId, emotion, platform, show, keyword);
String brandName = projectService.getProjectByContendId(UserThreadLocal.getProjectId(), contendId).getBrandName();
String fileName = getFileNamePrefix() + brandName + "_渠道列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, brandName, ExportChannelDTO.class, downloadChannelList);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), "渠道列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportChannelDTO.class, downloadChannelList);
return ResponseResult.success(filePath);
}
@ApiOperation("渠道稿件列表")
......@@ -212,9 +219,11 @@ public class AppDownloadController extends BaseController {
@Auth(role = RoleEnum.COMMON_ADMIN)
public ResponseResult downloadArticleList(@RequestParam(value = "channelId") String channelId) {
List<ExportAdminChannelArticleDTO> downloadChannelArticleList = channelService.findDownloadChannelArticleList(channelId);
String fileName = getFileNamePrefix() + channelId + "_渠道稿件列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, channelId, ExportAdminChannelArticleDTO.class, downloadChannelArticleList);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), channelId + "_渠道稿件列表数据");
EasyExcelUtil.write(filePath, channelId, ExportAdminChannelArticleDTO.class, downloadChannelArticleList);
return ResponseResult.success(filePath);
}
@ApiOperation("渠道事件列表")
......@@ -223,9 +232,11 @@ public class AppDownloadController extends BaseController {
@Auth(role = RoleEnum.COMMON_ADMIN)
public ResponseResult downloadEventList(@RequestParam(value = "channelId") String channelId) {
List<ExportAdminChannelEventDTO> downloadChannelEventList = channelService.findDownloadChannelEventList(channelId);
String fileName = getFileNamePrefix() + channelId + "_渠道事件列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, channelId, ExportAdminChannelEventDTO.class, downloadChannelEventList);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), channelId + "_渠道事件列表数据");
EasyExcelUtil.write(filePath, channelId, ExportAdminChannelEventDTO.class, downloadChannelEventList);
return ResponseResult.success(filePath);
}
@ApiOperation("全网搜使用记录")
......@@ -237,16 +248,17 @@ public class AppDownloadController extends BaseController {
Long endTime = json.getLong("endTime");
boolean day = json.getBooleanValue("day");
List<JSONObject> collect = wholeSearchService.outputUsedList(personal, startTime, endTime, day);
String fileName = getFileNamePrefix() + startTime + "_" + endTime + "使用记录";
String fileAddress = null;
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), startTime + "_" + endTime + "使用记录");
if (personal) {
List<ExportWholeSearchRecordDTO> list = collect.stream().map(ExportWholeSearchRecordDTO::createFromJSONObject).collect(Collectors.toList());
fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet", ExportWholeSearchRecordDTO.class, list);
EasyExcelUtil.write(filePath, "sheet1", ExportWholeSearchRecordDTO.class, list);
} else {
List<ExportLineDTO> list = collect.stream().map(ExportLineDTO::createFromJSONObject).collect(Collectors.toList());
fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet", ExportLineDTO.class, list);
EasyExcelUtil.write(filePath, "sheet1", ExportLineDTO.class, list);
}
return ResponseResult.success(fileAddress);
return ResponseResult.success(filePath);
}
@ApiOperation("项目关键词")
......@@ -255,10 +267,10 @@ public class AppDownloadController extends BaseController {
@Auth(role = RoleEnum.SUPER_ADMIN)
public ResponseResult downloadArticles(@PathVariable("pid") String pid) {
ProjectVO project = projectService.getProjectVOById(pid);
String fileName = getFileNamePrefix() + project.getBrandName() + "_命中关键词";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1",
UploadKeywordDTO.class, UploadKeywordDTO.change2This(project.getHitKeywords()));
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, project.getProjectName(), UserThreadLocal.getNickname(), project.getBrandName() + "_命中关键词");
EasyExcelUtil.write(filePath, "sheet1", UploadKeywordDTO.class, UploadKeywordDTO.change2This(project.getHitKeywords()));
return ResponseResult.success(filePath);
}
@ApiOperation("舆情库原始数据")
......@@ -266,9 +278,11 @@ public class AppDownloadController extends BaseController {
@LogRecord(description = "舆情库-原始数据导出", values = {"startTime", "endTime", "keyword", "platforms", "searchField"}, entity = true, arguments = true)
public ResponseResult exportOriginList(@RequestBody MarkSearchDTO markSearchDTO) {
Pair<String, List<ExportAppYuqingDTO>> stringListPair = markDataService.downloadYuqingMarkList(markSearchDTO);
String fileName = getFileNamePrefix() + stringListPair.getLeft() + "_原始数据列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), stringListPair.getLeft() + "_原始数据列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(filePath);
}
@ApiOperation("舆情库有效舆情数据")
......@@ -276,9 +290,11 @@ public class AppDownloadController extends BaseController {
@LogRecord(description = "舆情库-有效舆情导出", values = {"startTime", "endTime", "customTags", "field", "keyword", "politicsLevel", "mainBodyType", "platforms", "region", "tags"}, entity = true, arguments = true)
public ResponseResult exportYuqingMarkList(@RequestBody MarkSearchDTO markSearchDTO) {
Pair<String, List<ExportAppYuqingDTO>> stringListPair = markDataService.downloadYuqingMarkList(markSearchDTO);
String fileName = getFileNamePrefix() + stringListPair.getLeft() + "_舆情列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), stringListPair.getLeft() + "_舆情列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(filePath);
}
@ApiOperation("渠道库文章列表")
......@@ -294,9 +310,11 @@ public class AppDownloadController extends BaseController {
@RequestParam("channelId") String channelId,
@RequestParam(value = "contendId", defaultValue = "0") String contendId) {
List<ExportAppChannelArticleDTO> exportAppChannelArticleDTOS = channelService.downloadArticlesByTime(startTime, endTime, channelId, contendId);
String fileName = getFileNamePrefix() + channelId + "稿件列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportAppChannelArticleDTO.class, exportAppChannelArticleDTOS);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), channelId + "稿件列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportAppChannelArticleDTO.class, exportAppChannelArticleDTOS);
return ResponseResult.success(filePath);
}
@ApiOperation("渠道库事件列表")
......@@ -312,18 +330,22 @@ public class AppDownloadController extends BaseController {
@RequestParam("channelId") String channelId,
@RequestParam(value = "contendId", defaultValue = "0") String contendId) {
List<ExportAppChannelEventDTO> exportAppChannelEventDTOS = channelService.downloadEventsByTime(startTime, endTime, channelId, contendId);
String fileName = getFileNamePrefix() + channelId + "事件列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportAppChannelEventDTO.class, exportAppChannelEventDTOS);
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), channelId + "事件列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportAppChannelEventDTO.class, exportAppChannelEventDTOS);
return ResponseResult.success(filePath);
}
@ApiOperation("竞品库竞品舆情")
@PostMapping(value = "/contend/mark")
public ResponseResult exportContendMarkList(@RequestBody MarkSearchDTO markSearchDTO) {
Pair<String, List<ExportAppYuqingDTO>> stringListPair = markDataService.downloadContendMarkList(markSearchDTO);
String fileName = getFileNamePrefix() + stringListPair.getLeft() + "_舆情列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(fileAddress);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), "舆情列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight());
return ResponseResult.success(filePath);
}
@ApiOperation("全网搜舆情")
......@@ -347,12 +369,28 @@ public class AppDownloadController extends BaseController {
}
}
List<ExportSearchWholeDTO> exportList = markDataService.exportSearchWhole(dto);
String fileName = getFileNamePrefix() + "全网搜舆情列表数据";
String fileAddress = EasyExcelUtil.saveExcelWithPath(brandkbsFilePath, fileName, "sheet1", ExportSearchWholeDTO.class, exportList);
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), "全网搜舆情列表数据");
EasyExcelUtil.write(filePath, "sheet1", ExportSearchWholeDTO.class, exportList);
if (dto.isExternalDataSource()) {
wholeSearchService.decreaseRecord(dto.getSearch(), WholeSearchRecord.UsedType.output, exportList.size());
}
return ResponseResult.success(fileAddress);
return ResponseResult.success(filePath);
}
@ApiOperation("摘要提取批量模板")
@GetMapping(value = "/article-summary/template")
public ResponseResult downloadArticleSummaryTemplate() {
List<List<String>> head = new ArrayList<>();
head.add(Collections.singletonList("序号"));
head.add(Collections.singletonList("链接"));
head.add(Collections.singletonList("文章内容"));
// excel写入至指定路径
String projectName = projectService.getProjectById(UserThreadLocal.getProjectId()).getProjectName();
String filePath = EasyExcelUtil.generateExcelFilePath(brandkbsFilePath, projectName, UserThreadLocal.getNickname(), "摘要提取批量模板");
EasyExcelUtil.dynamicHeadWrite(filePath, "模板", head, Collections.emptyList());
return ResponseResult.success(filePath);
}
private HttpHeaders getHeaders() {
......@@ -361,8 +399,4 @@ public class AppDownloadController extends BaseController {
httpHeaders.set("Content-Type", "application/json");
return httpHeaders;
}
private String getFileNamePrefix(){
return UserThreadLocal.getProjectId() + "_" + UserThreadLocal.getNickname() + "_" + System.currentTimeMillis() + "_";
}
}
......@@ -8,6 +8,7 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO;
import com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO;
import com.zhiwei.brandkbs2.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -113,6 +114,28 @@ public class EasyExcelUtil {
}
/**
* 写单个sheet
* @param filePath 文件路径
* @param input 文件输入流
*/
public static void write(String filePath, InputStream input){
try {
FileOutputStream output = new FileOutputStream(filePath);
ReadableByteChannel inputChannel = Channels.newChannel(input);
WritableByteChannel outputChannel = Channels.newChannel(output);
ByteBuffer buffer = ByteBuffer.allocateDirect(10240);
long size = 0;
while (inputChannel.read(buffer) != -1) {
buffer.flip();
size += outputChannel.write(buffer);
buffer.clear();
}
}catch (Exception e){
log.error("file:{},write error:", filePath, e);
}
}
/**
* 写多个sheet
*
* @param filePath 文件路径
......@@ -198,52 +221,15 @@ public class EasyExcelUtil {
}
/**
* 将excel文件保存至指定路径
* @param filePath
* @param fileName
* @param sheetName
* @param clazz
* @param datas
* @param <T>
*/
public static <T> String saveExcelWithPath(String filePath, String fileName, String sheetName, Class<T> clazz, List<T> datas){
try {
formatExcelExports(clazz, datas);
String fileAddress = filePath + fileName + ".xlsx";
FileOutputStream out = new FileOutputStream(fileAddress);
EasyExcel.write(out, clazz).sheet(sheetName).doWrite(datas);
return fileAddress;
}catch (Exception e){
log.error("file:{},saveExcelWithPath error:", fileName, e);
return null;
}
}
/**
* InputStream转换excel文件保存至指定路径
* @param filePath
* @param fileName
* @param input
* 生成excel路径
* @param filePath 文件保存路径
* @param projectName 项目名
* @param nickName 昵称
* @param fileName 文件名
* @return
*/
public static String saveExcelWithPath(String filePath, String fileName, InputStream input){
try {
String fileAddress = filePath + fileName + ".xlsx";
FileOutputStream output = new FileOutputStream(fileAddress);
ReadableByteChannel inputChannel = Channels.newChannel(input);
WritableByteChannel outputChannel = Channels.newChannel(output);
ByteBuffer buffer = ByteBuffer.allocateDirect(10240);
long size = 0;
while (inputChannel.read(buffer) != -1) {
buffer.flip();
size += outputChannel.write(buffer);
buffer.clear();
}
return fileAddress;
}catch (Exception e){
log.error("file:{},saveExcelWithPath error:", fileName, e);
return null;
}
public static String generateExcelFilePath(String filePath, String projectName, String nickName, String fileName){
return filePath + Tools.concat(projectName, nickName, System.currentTimeMillis(), fileName) + ".xlsx";
}
private static <T> void formatExcelExports(Class<T> clazz, List<T> datas){
......
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