|
@@ -2,7 +2,6 @@ package ieven.server.webapp.domain.data;
|
|
|
|
|
|
import com.mongodb.client.MongoCursor;
|
|
|
import ieven.server.webapp.domain.FileIdInput;
|
|
|
-import ieven.server.webapp.domain.IdInput;
|
|
|
import ieven.server.webapp.domain.exporter.Exporter;
|
|
|
import ieven.server.webapp.domain.file.LogicalFile;
|
|
|
import ieven.server.webapp.infrastructure.wrapper.Mapped;
|
|
@@ -11,7 +10,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.bson.Document;
|
|
|
-import org.bson.types.ObjectId;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -22,7 +20,10 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.Future;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -30,261 +31,271 @@ import java.util.regex.Pattern;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DataService {
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
- @Autowired
|
|
|
- @Lazy
|
|
|
- private DataService dataService;
|
|
|
+ @Autowired private MongoTemplate mongoTemplate;
|
|
|
+ @Autowired @Lazy private DataService dataService;
|
|
|
|
|
|
- public Mapped viewDataByFileId(ViewInput viewInput) {
|
|
|
- String fileId = viewInput.getFileId();
|
|
|
- int page = viewInput.getPage();
|
|
|
- int pageSize = viewInput.getPageSize();
|
|
|
- if (StringUtils.isBlank(fileId)) {
|
|
|
- return Mapped.ERROR("没有选择文件");
|
|
|
- } else {
|
|
|
- Future<Long> totalFuture = dataService.countTotal(fileId);
|
|
|
- Future<LinkedHashMap<String, String>> headerFuture = dataService.viewHeaders(fileId);
|
|
|
- int skip = (page - 1) * pageSize;
|
|
|
- Query queryList = new Query(Criteria.where("fileId").is(fileId));
|
|
|
- List<DataMap> resultList = mongoTemplate.find(
|
|
|
- queryList.skip(skip).limit(pageSize),
|
|
|
- DataMap.class);
|
|
|
- for (DataMap dataMap : resultList) {
|
|
|
- dataMap.formId();
|
|
|
- }
|
|
|
- Long total = null;
|
|
|
- LinkedHashMap<String, String> headers = null;
|
|
|
- try {
|
|
|
- total = totalFuture.get();
|
|
|
- headers = headerFuture.get();
|
|
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return Mapped.ERROR("系统查询出错");
|
|
|
- }
|
|
|
- Mapped mapped = Mapped.OK();
|
|
|
- mapped.put("result", resultList);
|
|
|
- mapped.put("header", headers);
|
|
|
- mapped.put("code", 200);
|
|
|
- mapped.put("page", page);
|
|
|
- mapped.put("total", total);
|
|
|
- mapped.put("pageSize", pageSize);
|
|
|
- return mapped;
|
|
|
- }
|
|
|
+ public Mapped viewDataByFileId(ViewInput viewInput) {
|
|
|
+ String fileId = viewInput.getFileId();
|
|
|
+ int page = viewInput.getPage();
|
|
|
+ int pageSize = viewInput.getPageSize();
|
|
|
+ if (StringUtils.isBlank(fileId)) {
|
|
|
+ return Mapped.ERROR("没有选择文件");
|
|
|
+ } else {
|
|
|
+ Future<Long> totalFuture = dataService.countTotal(fileId);
|
|
|
+ Future<LinkedHashMap<String, String>> headerFuture = dataService.viewHeaders(fileId);
|
|
|
+ int skip = (page - 1) * pageSize;
|
|
|
+ Query queryList = new Query(Criteria.where("fileId").is(fileId));
|
|
|
+ List<DataMap> resultList =
|
|
|
+ mongoTemplate.find(queryList.skip(skip).limit(pageSize), DataMap.class);
|
|
|
+ for (DataMap dataMap : resultList) {
|
|
|
+ dataMap.formId();
|
|
|
+ }
|
|
|
+ Long total = null;
|
|
|
+ LinkedHashMap<String, String> headers = null;
|
|
|
+ try {
|
|
|
+ total = totalFuture.get();
|
|
|
+ headers = headerFuture.get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Mapped.ERROR("系统查询出错");
|
|
|
+ }
|
|
|
+ Mapped mapped = Mapped.OK();
|
|
|
+ mapped.put("result", resultList);
|
|
|
+ mapped.put("header", headers);
|
|
|
+ mapped.put("code", 200);
|
|
|
+ mapped.put("page", page);
|
|
|
+ mapped.put("total", total);
|
|
|
+ mapped.put("pageSize", pageSize);
|
|
|
+ return mapped;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public Mapped viewDataByQueryParam(QueryParam param) {
|
|
|
- String fileId = param.getFileId();
|
|
|
- int page = param.getPage();
|
|
|
- int pageSize = param.getPageSize();
|
|
|
- int skip = (page - 1) * pageSize;
|
|
|
- String mode = param.getMode();
|
|
|
- Criteria criteria = Criteria.where("fileId").is(fileId);
|
|
|
- List<QueryParam.Param1> param1List = param.getValues();
|
|
|
- if (CollectionUtils.isNotEmpty(param1List)) {
|
|
|
- List<Criteria> criList = new ArrayList<>();
|
|
|
- for (QueryParam.Param1 param1 : param1List) {
|
|
|
- String fieldAlias = param1.getFieldAlias();
|
|
|
- String value = param1.getValue();
|
|
|
- if (StringUtils.isBlank(fieldAlias)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String mode1 = param1.getMode();
|
|
|
- if ("is".equals(mode1)) {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
- String[] sp = filtered.split(";");
|
|
|
- if (sp.length > 1) {
|
|
|
- newCri.in(Arrays.asList(sp));
|
|
|
- } else {
|
|
|
- newCri.is(value.trim());
|
|
|
- }
|
|
|
- criList.add(newCri);
|
|
|
- } else {
|
|
|
- String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
- String[] sp = filtered.split(";");
|
|
|
- if (sp.length > 1) {
|
|
|
- for (String sped : sp) {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String regex = "^.*" + sped.trim() + ".*$";
|
|
|
- Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
- newCri.regex(pattern);
|
|
|
- criList.add(newCri);
|
|
|
- }
|
|
|
- } else {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String regex = "^.*" + value.trim() + ".*$";
|
|
|
- Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
- newCri.regex(pattern);
|
|
|
- criList.add(newCri);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Criteria cri = new Criteria();
|
|
|
- if ("and".equals(mode)) {
|
|
|
- cri.andOperator(criList);
|
|
|
- } else {
|
|
|
- cri.orOperator(criList);
|
|
|
- }
|
|
|
- criteria.andOperator(cri);
|
|
|
+ public Mapped viewDataByQueryParam(QueryParam param) {
|
|
|
+ String fileId = param.getFileId();
|
|
|
+ int page = param.getPage();
|
|
|
+ int pageSize = param.getPageSize();
|
|
|
+ int skip = (page - 1) * pageSize;
|
|
|
+ String mode = param.getMode();
|
|
|
+ Criteria criteria = Criteria.where("fileId").is(fileId);
|
|
|
+ List<QueryParam.Param1> param1List = param.getValues();
|
|
|
+ if (CollectionUtils.isNotEmpty(param1List)) {
|
|
|
+ List<Criteria> criList = new ArrayList<>();
|
|
|
+ for (QueryParam.Param1 param1 : param1List) {
|
|
|
+ String fieldAlias = param1.getFieldAlias();
|
|
|
+ String value = param1.getValue();
|
|
|
+ if (StringUtils.isBlank(fieldAlias)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- Future<Long> totalFuture = dataService.countTotalByQuery(new Query(criteria));
|
|
|
- Future<LinkedHashMap<String, String>> headerFuture = dataService.viewHeaders(fileId);
|
|
|
- Query dataQuery = new Query(criteria);
|
|
|
- if (CollectionUtils.isNotEmpty(param.getOrders())) {
|
|
|
- for (QueryParam.Param2 param2 : param.getOrders()) {
|
|
|
- String alias = param2.getFieldAlias();
|
|
|
- String orderBy = param2.getMode();
|
|
|
- if ("asc".equals(orderBy)) {
|
|
|
- dataQuery.with(Sort.by(Sort.Order.asc(alias)));
|
|
|
- } else if ("desc".equals(orderBy)) {
|
|
|
- dataQuery.with(Sort.by(Sort.Order.desc(alias)));
|
|
|
- }
|
|
|
+ String mode1 = param1.getMode();
|
|
|
+ if ("is".equals(mode1)) {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
+ String[] sp = filtered.split(";");
|
|
|
+ if (sp.length > 1) {
|
|
|
+ newCri.in(Arrays.asList(sp));
|
|
|
+ } else {
|
|
|
+ newCri.is(value.trim());
|
|
|
+ }
|
|
|
+ criList.add(newCri);
|
|
|
+ } else {
|
|
|
+ String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
+ String[] sp = filtered.split(";");
|
|
|
+ if (sp.length > 1) {
|
|
|
+ for (String sped : sp) {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String regex = "^.*" + sped.trim() + ".*$";
|
|
|
+ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
+ newCri.regex(pattern);
|
|
|
+ criList.add(newCri);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String regex = "^.*" + value.trim() + ".*$";
|
|
|
+ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
+ newCri.regex(pattern);
|
|
|
+ criList.add(newCri);
|
|
|
+ }
|
|
|
}
|
|
|
- //分页
|
|
|
- dataQuery.skip(skip).limit(pageSize);
|
|
|
- List<DataMap> resultList = mongoTemplate.find(
|
|
|
- dataQuery,
|
|
|
- DataMap.class);
|
|
|
- for (DataMap dataMap : resultList) {
|
|
|
- dataMap.formId();
|
|
|
- }
|
|
|
- Long total = null;
|
|
|
- LinkedHashMap<String, String> headers = null;
|
|
|
- try {
|
|
|
- total = totalFuture.get();
|
|
|
- headers = headerFuture.get();
|
|
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return Mapped.ERROR("系统查询出错");
|
|
|
+ }
|
|
|
+ Criteria cri = new Criteria();
|
|
|
+ if ("and".equals(mode)) {
|
|
|
+ cri.andOperator(criList);
|
|
|
+ } else {
|
|
|
+ cri.orOperator(criList);
|
|
|
+ }
|
|
|
+ criteria.andOperator(cri);
|
|
|
+ }
|
|
|
+ Future<Long> totalFuture = dataService.countTotalByQuery(new Query(criteria));
|
|
|
+ Future<LinkedHashMap<String, String>> headerFuture = dataService.viewHeaders(fileId);
|
|
|
+ Query dataQuery = new Query(criteria);
|
|
|
+ if (CollectionUtils.isNotEmpty(param.getOrders())) {
|
|
|
+ for (QueryParam.Param2 param2 : param.getOrders()) {
|
|
|
+ String alias = param2.getFieldAlias();
|
|
|
+ String orderBy = param2.getMode();
|
|
|
+ if ("asc".equals(orderBy)) {
|
|
|
+ dataQuery.with(Sort.by(Sort.Order.asc(alias)));
|
|
|
+ } else if ("desc".equals(orderBy)) {
|
|
|
+ dataQuery.with(Sort.by(Sort.Order.desc(alias)));
|
|
|
}
|
|
|
- Mapped mapped = Mapped.OK();
|
|
|
- mapped.put("result", resultList);
|
|
|
- mapped.put("header", headers);
|
|
|
- mapped.put("code", 200);
|
|
|
- mapped.put("page", page);
|
|
|
- mapped.put("total", total);
|
|
|
- mapped.put("pageSize", pageSize);
|
|
|
- return mapped;
|
|
|
+ }
|
|
|
}
|
|
|
+ // 分页
|
|
|
+ dataQuery.skip(skip).limit(pageSize);
|
|
|
+ List<DataMap> resultList = mongoTemplate.find(dataQuery, DataMap.class);
|
|
|
+ for (DataMap dataMap : resultList) {
|
|
|
+ dataMap.formId();
|
|
|
+ }
|
|
|
+ Long total = null;
|
|
|
+ LinkedHashMap<String, String> headers = null;
|
|
|
+ try {
|
|
|
+ total = totalFuture.get();
|
|
|
+ headers = headerFuture.get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Mapped.ERROR("系统查询出错");
|
|
|
+ }
|
|
|
+ Mapped mapped = Mapped.OK();
|
|
|
+ mapped.put("result", resultList);
|
|
|
+ mapped.put("header", headers);
|
|
|
+ mapped.put("code", 200);
|
|
|
+ mapped.put("page", page);
|
|
|
+ mapped.put("total", total);
|
|
|
+ mapped.put("pageSize", pageSize);
|
|
|
+ return mapped;
|
|
|
+ }
|
|
|
|
|
|
- public Mapped viewHeaders(FileIdInput fileIdInput) {
|
|
|
- String fileId = fileIdInput.getFileId();
|
|
|
- LogicalFile logicalFile = mongoTemplate.findOne(new Query(Criteria.where("id").is(fileId)), LogicalFile.class);
|
|
|
- Fields fields = mongoTemplate.findOne(new Query(Criteria.where("fileId").is(fileId)), Fields.class);
|
|
|
- if (logicalFile != null && fields != null) {
|
|
|
- String filename = logicalFile.getFilename();
|
|
|
- if (Properties.MAIN_PROPS.containsKey(filename)) {
|
|
|
- fields.setMainProps(Properties.MAIN_PROPS.get(filename));
|
|
|
- }
|
|
|
- if (Properties.DETAILS_EXPORTABLE.containsKey(filename)) {
|
|
|
- fields.setDetailsExportable(Properties.DETAILS_EXPORTABLE.get(filename));
|
|
|
- }
|
|
|
- }
|
|
|
- Mapped mapped = Mapped.OK();
|
|
|
- mapped.put("result", fields);
|
|
|
- return mapped;
|
|
|
+ public Mapped viewHeaders(FileIdInput fileIdInput) {
|
|
|
+ String fileId = fileIdInput.getFileId();
|
|
|
+ LogicalFile logicalFile =
|
|
|
+ mongoTemplate.findOne(new Query(Criteria.where("id").is(fileId)), LogicalFile.class);
|
|
|
+ Fields fields =
|
|
|
+ mongoTemplate.findOne(new Query(Criteria.where("fileId").is(fileId)), Fields.class);
|
|
|
+ if (logicalFile != null && fields != null) {
|
|
|
+ String filename = logicalFile.getFilename();
|
|
|
+ if (Properties.MAIN_PROPS.containsKey(filename)) {
|
|
|
+ fields.setMainProps(Properties.MAIN_PROPS.get(filename));
|
|
|
+ }
|
|
|
+ if (Properties.DETAILS_EXPORTABLE.containsKey(filename)) {
|
|
|
+ fields.setDetailsExportable(Properties.DETAILS_EXPORTABLE.get(filename));
|
|
|
+ }
|
|
|
}
|
|
|
+ Mapped mapped = Mapped.OK();
|
|
|
+ mapped.put("result", fields);
|
|
|
+ return mapped;
|
|
|
+ }
|
|
|
|
|
|
- public Mapped exportDataByQueryParam(QueryParam param) {
|
|
|
- String fileId = param.getFileId();
|
|
|
- String mode = param.getMode();
|
|
|
- Criteria criteria = Criteria.where("fileId").is(fileId);
|
|
|
- List<QueryParam.Param1> param1List = param.getValues();
|
|
|
- if (CollectionUtils.isNotEmpty(param1List)) {
|
|
|
- List<Criteria> criList = new ArrayList<>();
|
|
|
- for (QueryParam.Param1 param1 : param1List) {
|
|
|
- String fieldAlias = param1.getFieldAlias();
|
|
|
- String value = param1.getValue();
|
|
|
- if (StringUtils.isBlank(fieldAlias)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String mode1 = param1.getMode();
|
|
|
- if ("is".equals(mode1)) {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
- String[] sp = filtered.split(";");
|
|
|
- if (sp.length > 1) {
|
|
|
- newCri.in(Arrays.asList(sp));
|
|
|
- } else {
|
|
|
- newCri.is(value.trim());
|
|
|
- }
|
|
|
- criList.add(newCri);
|
|
|
- } else {
|
|
|
- String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
- String[] sp = filtered.split(";");
|
|
|
- if (sp.length > 1) {
|
|
|
- for (String sped : sp) {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String regex = "^.*" + sped.trim() + ".*$";
|
|
|
- Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
- newCri.regex(pattern);
|
|
|
- criList.add(newCri);
|
|
|
- }
|
|
|
- } else {
|
|
|
- Criteria newCri = new Criteria(fieldAlias);
|
|
|
- String regex = "^.*" + value.trim() + ".*$";
|
|
|
- Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
- newCri.regex(pattern);
|
|
|
- criList.add(newCri);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Criteria cri = new Criteria();
|
|
|
- if ("and".equals(mode)) {
|
|
|
- cri.andOperator(criList);
|
|
|
- } else {
|
|
|
- cri.orOperator(criList);
|
|
|
- }
|
|
|
- criteria.andOperator(cri);
|
|
|
+ /**
|
|
|
+ * 导出
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public Query dataQueryByParam(QueryParam param) {
|
|
|
+ String fileId = param.getFileId();
|
|
|
+ String mode = param.getMode();
|
|
|
+ if (!param.getFileIds().contains(fileId)) {
|
|
|
+ param.getFileIds().add(fileId);
|
|
|
+ }
|
|
|
+ Criteria criteria = Criteria.where("fileId").in(param.getFileIds());
|
|
|
+ List<QueryParam.Param1> param1List = param.getValues();
|
|
|
+ if (CollectionUtils.isNotEmpty(param1List)) {
|
|
|
+ List<Criteria> criList = new ArrayList<>();
|
|
|
+ for (QueryParam.Param1 param1 : param1List) {
|
|
|
+ String fieldAlias = param1.getFieldAlias();
|
|
|
+ String value = param1.getValue();
|
|
|
+ if (StringUtils.isBlank(fieldAlias)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- Query dataQuery = new Query(criteria);
|
|
|
- if (CollectionUtils.isNotEmpty(param.getOrders())) {
|
|
|
- for (QueryParam.Param2 param2 : param.getOrders()) {
|
|
|
- String alias = param2.getFieldAlias();
|
|
|
- String orderBy = param2.getMode();
|
|
|
- if ("asc".equals(orderBy)) {
|
|
|
- dataQuery.with(Sort.by(Sort.Order.asc(alias)));
|
|
|
- } else if ("desc".equals(orderBy)) {
|
|
|
- dataQuery.with(Sort.by(Sort.Order.desc(alias)));
|
|
|
- }
|
|
|
+ String mode1 = param1.getMode();
|
|
|
+ if ("is".equals(mode1)) {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
+ String[] sp = filtered.split(";");
|
|
|
+ if (sp.length > 1) {
|
|
|
+ newCri.in(Arrays.asList(sp));
|
|
|
+ } else {
|
|
|
+ newCri.is(value.trim());
|
|
|
+ }
|
|
|
+ criList.add(newCri);
|
|
|
+ } else {
|
|
|
+ String filtered = value.replaceAll(" ", ";").replaceAll("\t", ";").replaceAll(";", ";");
|
|
|
+ String[] sp = filtered.split(";");
|
|
|
+ if (sp.length > 1) {
|
|
|
+ for (String sped : sp) {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String regex = "^.*" + sped.trim() + ".*$";
|
|
|
+ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
+ newCri.regex(pattern);
|
|
|
+ criList.add(newCri);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ Criteria newCri = new Criteria(fieldAlias);
|
|
|
+ String regex = "^.*" + value.trim() + ".*$";
|
|
|
+ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
+ newCri.regex(pattern);
|
|
|
+ criList.add(newCri);
|
|
|
+ }
|
|
|
}
|
|
|
- //查询游标
|
|
|
- MongoCursor<Document> cursor = mongoTemplate.getCollection("data")
|
|
|
- .find(dataQuery.getQueryObject())
|
|
|
- .batchSize(1000)
|
|
|
- .noCursorTimeout(true)
|
|
|
- .cursor();
|
|
|
- Exporter exporter = new Exporter();
|
|
|
- String exportFileId = exporter.export(cursor, fileId);
|
|
|
- Mapped mapped = Mapped.OK();
|
|
|
- mapped.put("result", exportFileId);
|
|
|
- return mapped;
|
|
|
+ }
|
|
|
+ Criteria cri = new Criteria();
|
|
|
+ if ("and".equals(mode)) {
|
|
|
+ cri.andOperator(criList);
|
|
|
+ } else {
|
|
|
+ cri.orOperator(criList);
|
|
|
+ }
|
|
|
+ criteria.andOperator(cri);
|
|
|
}
|
|
|
-
|
|
|
- @Async
|
|
|
- Future<Long> countTotal(String fileId) {
|
|
|
- Long total = mongoTemplate.count(new Query(Criteria.where("fileId").is(fileId)), DataMap.class);
|
|
|
- return new AsyncResult<>(total);
|
|
|
+ Query dataQuery = new Query(criteria);
|
|
|
+ if (CollectionUtils.isNotEmpty(param.getOrders())) {
|
|
|
+ for (QueryParam.Param2 param2 : param.getOrders()) {
|
|
|
+ String alias = param2.getFieldAlias();
|
|
|
+ String orderBy = param2.getMode();
|
|
|
+ if ("asc".equals(orderBy)) {
|
|
|
+ dataQuery.with(Sort.by(Sort.Order.asc(alias)));
|
|
|
+ } else if ("desc".equals(orderBy)) {
|
|
|
+ dataQuery.with(Sort.by(Sort.Order.desc(alias)));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return dataQuery;
|
|
|
+ }
|
|
|
|
|
|
- @Async
|
|
|
- public Future<Long> countTotalByQuery(Query query) {
|
|
|
- Long total = mongoTemplate.count(query, DataMap.class);
|
|
|
- return new AsyncResult<>(total);
|
|
|
- }
|
|
|
+ public Mapped exportDataByQueryParam(QueryParam param) {
|
|
|
+ Query dataQuery = this.dataQueryByParam(param);
|
|
|
+ // 查询游标
|
|
|
+ MongoCursor<Document> cursor =
|
|
|
+ mongoTemplate
|
|
|
+ .getCollection("data")
|
|
|
+ .find(dataQuery.getQueryObject())
|
|
|
+ .batchSize(1000)
|
|
|
+ .noCursorTimeout(true)
|
|
|
+ .cursor();
|
|
|
+ Exporter exporter = new Exporter();
|
|
|
+ String exportFileId = exporter.export(cursor, param.getFileId(), param.getModelId());
|
|
|
+ Mapped mapped = Mapped.OK();
|
|
|
+ mapped.put("result", exportFileId);
|
|
|
+ return mapped;
|
|
|
+ }
|
|
|
|
|
|
- @Async
|
|
|
- Future<LinkedHashMap<String, String>> viewHeaders(String fileId) {
|
|
|
- Query query = new Query(Criteria.where("fileId").is(fileId));
|
|
|
- Fields fields = mongoTemplate.findOne(query, Fields.class);
|
|
|
- if (fields != null) {
|
|
|
- return new AsyncResult<>(fields.getFields());
|
|
|
- } else {
|
|
|
- return new AsyncResult<>(new LinkedHashMap<>());
|
|
|
- }
|
|
|
+ @Async
|
|
|
+ Future<Long> countTotal(String fileId) {
|
|
|
+ Long total = mongoTemplate.count(new Query(Criteria.where("fileId").is(fileId)), DataMap.class);
|
|
|
+ return new AsyncResult<>(total);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public Future<Long> countTotalByQuery(Query query) {
|
|
|
+ Long total = mongoTemplate.count(query, DataMap.class);
|
|
|
+ return new AsyncResult<>(total);
|
|
|
+ }
|
|
|
|
|
|
+ @Async
|
|
|
+ Future<LinkedHashMap<String, String>> viewHeaders(String fileId) {
|
|
|
+ Query query = new Query(Criteria.where("fileId").is(fileId));
|
|
|
+ Fields fields = mongoTemplate.findOne(query, Fields.class);
|
|
|
+ if (fields != null) {
|
|
|
+ return new AsyncResult<>(fields.getFields());
|
|
|
+ } else {
|
|
|
+ return new AsyncResult<>(new LinkedHashMap<>());
|
|
|
}
|
|
|
+ }
|
|
|
}
|