Commit 79975002 by 陈健智

上传任务调整

parent 07da5aee
package com.zhiwei.brandkbs2.aop; package com.zhiwei.brandkbs2.aop;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.exception.ExceptionCast; import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
...@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component; ...@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Objects;
/** /**
* @author cjz * @author cjz
...@@ -34,7 +36,7 @@ public class AopDownloadTask { ...@@ -34,7 +36,7 @@ public class AopDownloadTask {
@Resource(name = "downloadTaskServiceImpl") @Resource(name = "downloadTaskServiceImpl")
DownloadTaskService downloadTaskService; 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{ public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
Signature signature = joinPoint.getSignature(); Signature signature = joinPoint.getSignature();
Method method = ((MethodSignature) signature).getMethod(); Method method = ((MethodSignature) signature).getMethod();
...@@ -53,7 +55,11 @@ public class AopDownloadTask { ...@@ -53,7 +55,11 @@ public class AopDownloadTask {
ExceptionCast.cast(CommonCodeEnum.FAIL, "下载异常", e); 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(); fileAddress = ((ResponseResult) proceed).getData().toString();
}
downloadTaskService.updateDownloadTask(taskId, 100, DownloadTask.Status.FINISH.getName(), fileAddress); downloadTaskService.updateDownloadTask(taskId, 100, DownloadTask.Status.FINISH.getName(), fileAddress);
return proceed; return proceed;
} }
......
...@@ -8,6 +8,7 @@ import com.alibaba.excel.read.metadata.ReadSheet; ...@@ -8,6 +8,7 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO; import com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO;
import com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO; import com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO;
import com.zhiwei.brandkbs2.util.Tools;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.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;
...@@ -113,6 +114,28 @@ public class EasyExcelUtil { ...@@ -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 * 写多个sheet
* *
* @param filePath 文件路径 * @param filePath 文件路径
...@@ -198,52 +221,15 @@ public class EasyExcelUtil { ...@@ -198,52 +221,15 @@ public class EasyExcelUtil {
} }
/** /**
* 将excel文件保存至指定路径 * 生成excel路径
* @param filePath * @param filePath 文件保存路径
* @param fileName * @param projectName 项目名
* @param sheetName * @param nickName 昵称
* @param clazz * @param fileName 文件名
* @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
* @return * @return
*/ */
public static String saveExcelWithPath(String filePath, String fileName, InputStream input){ public static String generateExcelFilePath(String filePath, String projectName, String nickName, String fileName){
try { return filePath + Tools.concat(projectName, nickName, System.currentTimeMillis(), fileName) + ".xlsx";
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;
}
} }
private static <T> void formatExcelExports(Class<T> clazz, List<T> datas){ 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