|
@@ -1,17 +1,19 @@
|
|
package com.boman.file.service;
|
|
package com.boman.file.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.boman.common.core.utils.SecurityUtils;
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.common.core.utils.poi.ExcelUtil;
|
|
import com.boman.common.core.utils.poi.ExcelUtil;
|
|
-import com.boman.domain.dto.AjaxResult;
|
|
|
|
import com.boman.common.redis.RedisKey;
|
|
import com.boman.common.redis.RedisKey;
|
|
import com.boman.common.redis.service.RedisService;
|
|
import com.boman.common.redis.service.RedisService;
|
|
import com.boman.domain.GenTable;
|
|
import com.boman.domain.GenTable;
|
|
import com.boman.domain.GenTableColumn;
|
|
import com.boman.domain.GenTableColumn;
|
|
import com.boman.domain.constant.MaskConstant;
|
|
import com.boman.domain.constant.MaskConstant;
|
|
|
|
+import com.boman.domain.dto.AjaxResult;
|
|
import com.boman.domain.dto.ExportExcelDto;
|
|
import com.boman.domain.dto.ExportExcelDto;
|
|
import com.boman.domain.dto.FormDataDto;
|
|
import com.boman.domain.dto.FormDataDto;
|
|
import com.boman.domain.dto.ImportExcelDto;
|
|
import com.boman.domain.dto.ImportExcelDto;
|
|
|
|
+import com.boman.domain.utils.ThreadPoolService;
|
|
import com.boman.file.utils.FileUploadUtils;
|
|
import com.boman.file.utils.FileUploadUtils;
|
|
import com.boman.web.core.api.RemoteAttendanceService;
|
|
import com.boman.web.core.api.RemoteAttendanceService;
|
|
import com.boman.web.core.api.RemoteObjService;
|
|
import com.boman.web.core.api.RemoteObjService;
|
|
@@ -26,8 +28,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.map;
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.map;
|
|
|
|
|
|
@@ -43,6 +48,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
{
|
|
{
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(LocalSysFileServiceImpl.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(LocalSysFileServiceImpl.class);
|
|
|
|
+ public static final String DOWNLOADING = "downloading";
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private RemoteObjService remoteObjService;
|
|
private RemoteObjService remoteObjService;
|
|
@@ -152,21 +158,13 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
-
|
|
|
|
|
|
+ columns = ExcelUtil.filterData(columns, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
- List<Map<String, Object>> list = null;
|
|
|
|
|
|
+ List<Map<String, Object>> list;
|
|
if (BooleanUtils.isTrue(empty)) {
|
|
if (BooleanUtils.isTrue(empty)) {
|
|
list = new ArrayList<>(0);
|
|
list = new ArrayList<>(0);
|
|
} else {
|
|
} else {
|
|
- FormDataDto condition = new FormDataDto();
|
|
|
|
- condition.setTable(tableName);
|
|
|
|
- condition.setFixedData(new JSONObject(dto.getCondition()));
|
|
|
|
- AjaxResult ajaxResult = remoteObjService.getByMap(condition);
|
|
|
|
- if (AjaxResult.checkSuccess(ajaxResult)) {
|
|
|
|
- list = ((List<Map<String, Object>>) ajaxResult.get(AjaxResult.DATA_TAG));
|
|
|
|
- columns = ExcelUtil.filterData(columns, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
|
- handleNullColumnValue(list, map(columns, GenTableColumn::getColumnName));
|
|
|
|
- }
|
|
|
|
|
|
+ list = getData(dto, tableName, columns);
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -177,6 +175,83 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 通用的导出接口
|
|
|
|
+ *
|
|
|
|
+ * @param response response
|
|
|
|
+ * @param dto tableName
|
|
|
|
+ * empty(true=>只带表头的excel,不含数据, false=>带数据的excel)
|
|
|
|
+ * condition 查询条件
|
|
|
|
+ * @return com.boman.domain.dto.AjaxResult
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult asyncExportExcelCommon(HttpServletResponse response, ExportExcelDto dto) throws IOException {
|
|
|
|
+ String tableName = dto.getTableName();
|
|
|
|
+ Boolean empty = dto.getEmpty();
|
|
|
|
+ ObjectUtils.requireNonNull(tableName, "exportExcelCommon tableName is empty");
|
|
|
|
+ ObjectUtils.requireNonNull(empty, "exportExcelCommon empty is empty");
|
|
|
|
+
|
|
|
|
+ GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
|
|
+ List<GenTableColumn> allColumn = genTable.getColumns();
|
|
|
|
+ List<GenTableColumn> columns = ExcelUtil.filterData(allColumn, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
|
+
|
|
|
|
+ String filename = UUID.randomUUID().toString() + ".xlsx";
|
|
|
|
+ String fileAbsPath = localFilePath + "/" + filename;
|
|
|
|
+ String fileStaticPath = domain + localFilePrefix + "/" + filename;
|
|
|
|
+ File file = new File(fileAbsPath);
|
|
|
|
+
|
|
|
|
+ ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
|
|
+
|
|
|
|
+ ThreadPoolService.execute(() -> {
|
|
|
|
+ List<Map<String, Object>> list;
|
|
|
|
+ int size = 0;
|
|
|
|
+ if (BooleanUtils.isTrue(empty)) {
|
|
|
|
+ list = new ArrayList<>(0);
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.info("开始查询, 线程名称: {}", Thread.currentThread().getName());
|
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
+ list = getData(dto, tableName, columns);
|
|
|
|
+ size = list.size();
|
|
|
|
+ LOGGER.info("查询到的数据长度为: {}, 查询耗时:{}秒", size, (System.currentTimeMillis() - currentTimeMillis) / 1000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ util.asyncExportExcelCommon(new FileOutputStream(file), list, "sheet1", columns, empty, false);
|
|
|
|
+ long timeout = 1L;
|
|
|
|
+ if (size > 100000 && size < 500000) {
|
|
|
|
+ timeout = 2L;
|
|
|
|
+ } else if(size > 500000){
|
|
|
|
+ timeout = 4L;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ redisService.setCacheObject(RedisKey.ASYNC_DOWNLOAD_SIGN + SecurityUtils.getUsername(), DOWNLOADING, timeout, TimeUnit.MINUTES);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ LOGGER.error("导出失败", e);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return AjaxResult.success("成功", fileStaticPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Map<String, Object>> getData(ExportExcelDto dto, String tableName, List<GenTableColumn> columns) {
|
|
|
|
+ List<Map<String, Object>> list = null;
|
|
|
|
+ FormDataDto condition = new FormDataDto();
|
|
|
|
+ condition.setTable(tableName);
|
|
|
|
+ condition.setFixedData(new JSONObject(dto.getCondition()));
|
|
|
|
+ condition.setPageSize(Integer.MAX_VALUE);
|
|
|
|
+ condition.setPageNo(1);
|
|
|
|
+ AjaxResult ajaxResult = remoteObjService.getByMap(condition);
|
|
|
|
+ if (AjaxResult.checkSuccess(ajaxResult)) {
|
|
|
|
+ list = ((List<Map<String, Object>>) ajaxResult.get(AjaxResult.DATA_TAG));
|
|
|
|
+ handleNullColumnValue(list, map(columns, GenTableColumn::getColumnName));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 功能描述: 导出数据,只是sql不一样,其余的都是通用接口的内容
|
|
* 功能描述: 导出数据,只是sql不一样,其余的都是通用接口的内容
|
|
*
|
|
*
|
|
@@ -257,4 +332,14 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 获取系统配置
|
|
|
|
+ *
|
|
|
|
+ * @return java.lang.String
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public String getConfigPath() {
|
|
|
|
+ return localFilePrefix + "_._" + domain + "_._" + localFilePath;
|
|
|
|
+ }
|
|
}
|
|
}
|