|
@@ -1,22 +1,20 @@
|
|
|
package com.boman.file.service;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
import com.boman.common.core.utils.SecurityUtils;
|
|
|
-import com.boman.common.core.utils.ServletUtils;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.utils.poi.ExcelUtil;
|
|
|
import com.boman.common.redis.RedisKey;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
-import com.boman.domain.*;
|
|
|
+import com.boman.domain.GenTable;
|
|
|
+import com.boman.domain.GenTableColumn;
|
|
|
+import com.boman.domain.SysDept;
|
|
|
+import com.boman.domain.VaccineInfoOperation;
|
|
|
import com.boman.domain.constant.CacheConstants;
|
|
|
-import com.boman.domain.constant.MaskConstant;
|
|
|
import com.boman.domain.dto.AjaxResult;
|
|
|
import com.boman.domain.dto.ExportExcelDto;
|
|
|
import com.boman.domain.dto.FormDataDto;
|
|
|
import com.boman.domain.dto.ImportExcelDto;
|
|
|
-import com.boman.domain.utils.CamelLowerUnderScore;
|
|
|
import com.boman.domain.utils.ThreadPoolService;
|
|
|
import com.boman.file.utils.FileUploadUtils;
|
|
|
import com.boman.system.api.RemoteDeptService;
|
|
@@ -24,29 +22,26 @@ import com.boman.system.api.model.LoginUser;
|
|
|
import com.boman.web.core.api.RemoteAttendanceService;
|
|
|
import com.boman.web.core.api.RemoteObjService;
|
|
|
import com.boman.web.core.api.RemoteVaccineInfoService;
|
|
|
-import com.google.common.base.CaseFormat;
|
|
|
-import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
-import org.apache.http.impl.client.HttpClients;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
+import static com.boman.common.core.utils.poi.ExcelUtil.filterData;
|
|
|
+import static com.boman.domain.constant.MaskConstant.LIST_VISIBLE;
|
|
|
|
|
|
/**
|
|
|
* 本地文件存储
|
|
@@ -174,7 +169,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
- columns = ExcelUtil.filterData(columns, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
+ columns = filterData(columns, 4, LIST_VISIBLE::equals);
|
|
|
ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
|
List<Map<String, Object>> list;
|
|
|
if (BooleanUtils.isTrue(empty)) {
|
|
@@ -210,7 +205,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
|
List<GenTableColumn> allColumn = genTable.getColumns();
|
|
|
- List<GenTableColumn> columns = ExcelUtil.filterData(allColumn, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
+ List<GenTableColumn> columns = filterData(allColumn, 4, LIST_VISIBLE::equals);
|
|
|
|
|
|
String filename = UUID.randomUUID() + ".xlsx";
|
|
|
String fileAbsPath = localFilePath + "/" + filename;
|
|
@@ -262,10 +257,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
// }
|
|
|
|
|
|
String key = RedisKey.ASYNC_DOWNLOAD_YMJZ + username;
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("fileStaticPath", fileStaticPath);
|
|
|
- jsonObject.put("fileAbsPath", fileAbsPath);
|
|
|
- redisService.setCacheObject(key, jsonObject);
|
|
|
+ saveIntoRedis(fileAbsPath, fileStaticPath, key);
|
|
|
} catch (IOException e) {
|
|
|
LOGGER.error("导出失败", e);
|
|
|
e.printStackTrace();
|
|
@@ -287,26 +279,29 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
@Override
|
|
|
public AjaxResult asyncExportYmjzExcel(HttpServletResponse response, VaccineInfoOperation info) throws IOException {
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + "vaccine_info");
|
|
|
- List<GenTableColumn> allColumn = genTable.getColumns();
|
|
|
- List<GenTableColumn> columns = ExcelUtil.filterData(allColumn, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
+ List<GenTableColumn> columns = filterData(genTable.getColumns(), 4, LIST_VISIBLE::equals);
|
|
|
|
|
|
String filename = UUID.randomUUID() + ".xlsx";
|
|
|
String fileAbsPath = localFilePath + "/" + filename;
|
|
|
String fileStaticPath = domain + localFilePrefix + "/" + filename;
|
|
|
- File file = new File(fileAbsPath);
|
|
|
|
|
|
- ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
|
- String username = SecurityUtils.getUsername();
|
|
|
+ asyncHandle(info, columns, fileAbsPath, fileStaticPath);
|
|
|
+ return AjaxResult.success("成功", fileStaticPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void asyncHandle(VaccineInfoOperation info, List<GenTableColumn> columns, String fileAbsPath, String fileStaticPath) {
|
|
|
+ final String username = SecurityUtils.getUsername();
|
|
|
+ final ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
|
+ final File file = new File(fileAbsPath);
|
|
|
|
|
|
ThreadPoolService.execute(() -> {
|
|
|
List<Map<String, Object>> list;
|
|
|
LOGGER.info("开始查询, 线程名称: {}", Thread.currentThread().getName());
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
+
|
|
|
String key = RedisKey.ASYNC_DOWNLOAD_YMJZ + username;
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("fileStaticPath", fileStaticPath);
|
|
|
- jsonObject.put("fileAbsPath", fileAbsPath);
|
|
|
- redisService.setCacheObject(key, jsonObject);
|
|
|
+ saveIntoRedis(fileAbsPath, fileStaticPath, key);
|
|
|
+
|
|
|
list = listYmjz(info, columns);
|
|
|
boolean empty = isEmpty(list);
|
|
|
int size = BooleanUtils.isFalse(empty) ? 0 : list.size();
|
|
@@ -314,20 +309,19 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
|
|
|
try {
|
|
|
util.asyncExportExcelCommon(new FileOutputStream(file), list, "sheet1", columns, empty, false);
|
|
|
- long timeout = 2L;
|
|
|
- if (size > 100000 && size < 500000) {
|
|
|
- timeout = 5L;
|
|
|
- } else if (size > 500000) {
|
|
|
- timeout = 10L;
|
|
|
- }
|
|
|
} catch (IOException e) {
|
|
|
LOGGER.error("导出失败", e);
|
|
|
+ redisService.deleteObject(key);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- return AjaxResult.success("成功", fileStaticPath);
|
|
|
+ private void saveIntoRedis(String fileAbsPath, String fileStaticPath, String key) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("fileStaticPath", fileStaticPath);
|
|
|
+ jsonObject.put("fileAbsPath", fileAbsPath);
|
|
|
+ redisService.setCacheObject(key, jsonObject);
|
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> getData(ExportExcelDto dto, String tableName, List<GenTableColumn> columns) {
|