|
@@ -1,22 +1,31 @@
|
|
|
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.GenTable;
|
|
|
-import com.boman.domain.GenTableColumn;
|
|
|
+import com.boman.domain.*;
|
|
|
+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;
|
|
|
+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;
|
|
@@ -25,15 +34,19 @@ 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.isEmpty;
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.map;
|
|
|
|
|
|
/**
|
|
@@ -56,6 +69,10 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
private RedisService redisService;
|
|
|
@Resource
|
|
|
private RemoteAttendanceService remoteAttendanceService;
|
|
|
+ @Resource
|
|
|
+ private RemoteVaccineInfoService remoteVaccineInfoService;
|
|
|
+ @Resource
|
|
|
+ private RemoteDeptService remoteDeptService;
|
|
|
|
|
|
/**
|
|
|
* 资源映射路径 前缀
|
|
@@ -186,7 +203,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
* @return com.boman.domain.dto.AjaxResult
|
|
|
*/
|
|
|
@Override
|
|
|
- public AjaxResult asyncExportExcelCommon(HttpServletResponse response, ExportExcelDto dto) throws IOException {
|
|
|
+ public AjaxResult asyncExportExcelCommon(HttpServletRequest request, HttpServletResponse response, ExportExcelDto dto) {
|
|
|
String tableName = dto.getTableName();
|
|
|
Boolean empty = dto.getEmpty();
|
|
|
ObjectUtils.requireNonNull(tableName, "exportExcelCommon tableName is empty");
|
|
@@ -196,36 +213,115 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
List<GenTableColumn> allColumn = genTable.getColumns();
|
|
|
List<GenTableColumn> columns = ExcelUtil.filterData(allColumn, 4, MaskConstant.LIST_VISIBLE::equals);
|
|
|
|
|
|
- String filename = UUID.randomUUID().toString() + ".xlsx";
|
|
|
+ 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();
|
|
|
+
|
|
|
+ String token = SecurityUtils.getToken(request);
|
|
|
+ LoginUser loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
|
|
+ Long deptId = loginUser.getSysUser().getDeptId();
|
|
|
+ List<SysDept> sysDepts = remoteDeptService.listChildrenDepts(deptId);
|
|
|
+ List<Long> deptIdList = new ArrayList<>();
|
|
|
+ if (sysDepts != null && sysDepts.size() > 0) {
|
|
|
+ for (SysDept sysDept : sysDepts) {
|
|
|
+ Long id = sysDept.getId();
|
|
|
+ deptIdList.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
ThreadPoolService.execute(() -> {
|
|
|
List<Map<String, Object>> list;
|
|
|
int size = 0;
|
|
|
- if (BooleanUtils.isTrue(empty)) {
|
|
|
+ Boolean emptyIn = empty;
|
|
|
+ if (BooleanUtils.isTrue(emptyIn)) {
|
|
|
list = new ArrayList<>(0);
|
|
|
} else {
|
|
|
LOGGER.info("开始查询, 线程名称: {}", Thread.currentThread().getName());
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
- list = getData(dto, tableName, columns);
|
|
|
- size = list.size();
|
|
|
+ list = getData1(dto, tableName, columns, deptIdList);
|
|
|
+ if (isEmpty(list)) {
|
|
|
+ size =0;
|
|
|
+ emptyIn = true;
|
|
|
+ } else {
|
|
|
+ size = list.size();
|
|
|
+ }
|
|
|
+
|
|
|
LOGGER.info("查询到的数据长度为: {}, 查询耗时:{}秒", size, (System.currentTimeMillis() - currentTimeMillis) / 1000);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- util.asyncExportExcelCommon(new FileOutputStream(file), list, "sheet1", columns, empty, false);
|
|
|
- long timeout = 1L;
|
|
|
+ util.asyncExportExcelCommon(new FileOutputStream(file), list, "sheet1", columns, emptyIn, false);
|
|
|
+ long timeout = 2L;
|
|
|
if (size > 100000 && size < 500000) {
|
|
|
- timeout = 2L;
|
|
|
+ timeout = 5L;
|
|
|
} else if(size > 500000){
|
|
|
- timeout = 4L;
|
|
|
+ timeout = 10L;
|
|
|
}
|
|
|
|
|
|
- redisService.setCacheObject(RedisKey.ASYNC_DOWNLOAD_SIGN + SecurityUtils.getUsername(), DOWNLOADING, timeout, TimeUnit.MINUTES);
|
|
|
+ String key = RedisKey.ASYNC_DOWNLOAD_YMJZ + username;
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("fileStaticPath", fileStaticPath);
|
|
|
+ jsonObject.put("fileAbsPath", fileAbsPath);
|
|
|
+ redisService.setCacheObject(key, jsonObject, timeout, TimeUnit.MINUTES);
|
|
|
+ } catch (IOException e) {
|
|
|
+ LOGGER.error("导出失败", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return AjaxResult.success("成功", fileStaticPath);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 通用的导出接口
|
|
|
+ *
|
|
|
+ * @param response response
|
|
|
+ * @param info 查询条件
|
|
|
+ * @return com.boman.domain.dto.AjaxResult
|
|
|
+ */
|
|
|
+ @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);
|
|
|
+
|
|
|
+ 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();
|
|
|
+
|
|
|
+ ThreadPoolService.execute(() -> {
|
|
|
+ List<Map<String, Object>> list;
|
|
|
+ LOGGER.info("开始查询, 线程名称: {}", Thread.currentThread().getName());
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
+ list = listYmjz(info, columns);
|
|
|
+ boolean empty = isEmpty(list);
|
|
|
+ int size = BooleanUtils.isFalse(empty) ? 0 : list.size();
|
|
|
+ LOGGER.info("查询到的数据长度为: {}, 查询耗时:{}秒", size, (System.currentTimeMillis() - currentTimeMillis) / 1000);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String key = RedisKey.ASYNC_DOWNLOAD_YMJZ + username;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("fileStaticPath", fileStaticPath);
|
|
|
+ jsonObject.put("fileAbsPath", fileAbsPath);
|
|
|
+ redisService.setCacheObject(key, jsonObject, timeout, TimeUnit.MINUTES);
|
|
|
} catch (IOException e) {
|
|
|
LOGGER.error("导出失败", e);
|
|
|
e.printStackTrace();
|
|
@@ -252,6 +348,52 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ private List<Map<String, Object>> getData1(ExportExcelDto dto, String tableName, List<GenTableColumn> columns, List<Long> deptIdList) {
|
|
|
+ List<Map<String, Object>> list = null;
|
|
|
+ FormDataDto condition = new FormDataDto();
|
|
|
+ condition.setTable(tableName);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("dept_id", deptIdList);
|
|
|
+ condition.setFixedData(jsonObject);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 单独去查疫苗接种信息的
|
|
|
+ *
|
|
|
+ * @param info info
|
|
|
+ * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> listYmjz(VaccineInfoOperation info, List<GenTableColumn> columns) {
|
|
|
+// TableDataInfo list = remoteObjService.list(info);
|
|
|
+// LOGGER.info("查询结果:{}", JSON.toJSONString(list));
|
|
|
+// List<?> rows = list.getRows();
|
|
|
+// return JSON.parseObject(JSON.toJSONString(rows), new TypeReference<List<Map<String, Object>>>() {
|
|
|
+// }.getType());
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = null;
|
|
|
+ FormDataDto condition = new FormDataDto();
|
|
|
+ condition.setTable("vaccine_info");
|
|
|
+ condition.setFixedData(new JSONObject());
|
|
|
+ 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不一样,其余的都是通用接口的内容
|
|
|
*
|