|
@@ -2,6 +2,7 @@ package ieven.server.webapp.domain.alipay;
|
|
|
|
|
|
import com.mongodb.client.MongoCursor;
|
|
|
import ieven.server.webapp.domain.ModelIdInput;
|
|
|
+import ieven.server.webapp.domain.data.DataMap;
|
|
|
import ieven.server.webapp.domain.data.Fields;
|
|
|
import ieven.server.webapp.domain.data.FieldsService;
|
|
|
import ieven.server.webapp.domain.file.FileStatus;
|
|
@@ -10,19 +11,18 @@ import ieven.server.webapp.infrastructure.wrapper.Mapped;
|
|
|
import ieven.server.webapp.util.DataUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.bson.Document;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -31,6 +31,9 @@ public class AlipayService {
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
@Autowired
|
|
|
private FieldsService fieldsService;
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private AlipayService alipayService;
|
|
|
private final static String FNAME_PERSONINFO = "提取的人员信息表";
|
|
|
private final static String FIELDNAME_BANKCARD = "绑定银行卡";
|
|
|
private final static String EXTRACT_BANKCARDTYPE = "提取银行卡类型";
|
|
@@ -63,10 +66,15 @@ public class AlipayService {
|
|
|
Fields fields = fieldsService.createHeaderAndSave(PERSONINFO_HEADERNAMES, fileId);
|
|
|
//根据模型id查询所有的文件
|
|
|
String key1 = "fieldsReverse." + FIELDNAME_BANKCARD;
|
|
|
- Query queryExist = new Query(Criteria.where(key1).exists(true));
|
|
|
+ Query queryExist = new Query(Criteria.where(key1).exists(true).and(""));
|
|
|
List<Fields> fieldsList = mongoTemplate.find(queryExist, Fields.class);
|
|
|
for (Fields fields1 : fieldsList) {
|
|
|
- extractPersonInfoByFileId(fields1);
|
|
|
+ //再次过滤出是原始非修改过的文件的
|
|
|
+ Query queryIsGenerated = new Query(Criteria.where("id").is(fields1.getFileId()).and("generated").is(Boolean.FALSE));
|
|
|
+ LogicalFile checked = mongoTemplate.findOne(queryIsGenerated, LogicalFile.class);
|
|
|
+ if (checked != null && checked.getId() != null && checked.getId().equals(fields1.getFileId())) {
|
|
|
+ alipayService.extractPersonInfoByFileId(fields1, fields);
|
|
|
+ }
|
|
|
}
|
|
|
Mapped mapped = Mapped.OK();
|
|
|
mapped.put("result", logicalFile);
|
|
@@ -75,11 +83,17 @@ public class AlipayService {
|
|
|
|
|
|
//遍历文件里面的所有内容
|
|
|
@Async
|
|
|
- public void extractPersonInfoByFileId(Fields fields) {
|
|
|
- LinkedHashMap<String, String> headerReversed = fields.getFieldsReverse();
|
|
|
- String fField1 = headerReversed.get(FIELDNAME_BANKCARD);
|
|
|
- String fileId = fields.getFileId();
|
|
|
- Query query = new Query(Criteria.where("fileId").is(fileId));
|
|
|
+ public void extractPersonInfoByFileId(Fields input, Fields output) {
|
|
|
+ LinkedHashMap<String, String> inputReversed = input.getFieldsReverse();
|
|
|
+ LinkedHashMap<String, String> outputReversed = output.getFieldsReverse();
|
|
|
+ String inputFileId = input.getFileId();
|
|
|
+ String outputFileId = output.getFileId();
|
|
|
+ String in1 = inputReversed.get("绑定银行卡");
|
|
|
+ String out1 = inputReversed.get("绑定银行卡");
|
|
|
+ String out2 = outputReversed.get("提取银行卡类型");
|
|
|
+ String out3 = outputReversed.get("提取银行卡开户行");
|
|
|
+ String out4 = outputReversed.get("提取银行卡号");
|
|
|
+ Query query = new Query(Criteria.where("fileId").is(inputFileId));
|
|
|
query.fields().include();
|
|
|
MongoCursor<Document> cursor = mongoTemplate.getCollection("data")
|
|
|
.find(query.getQueryObject())
|
|
@@ -87,22 +101,33 @@ public class AlipayService {
|
|
|
.noCursorTimeout(true)
|
|
|
.cursor();
|
|
|
Document doc;
|
|
|
- List<Document> needToSave = new ArrayList<>(1000);
|
|
|
+ List<DataMap> needToSave = new ArrayList<>(1000);
|
|
|
while (cursor.hasNext()) {
|
|
|
//写法1(建议)
|
|
|
doc = cursor.next();
|
|
|
- //绑定银行卡
|
|
|
- String value1 = doc.getString(fField1);
|
|
|
+ DataMap newDoc = new DataMap();
|
|
|
+ newDoc.put("fileId", outputFileId);
|
|
|
+ //其他字段
|
|
|
+ for (String headerName : PERSONINFO_HEADERNAMES) {
|
|
|
+ String inputAlias = inputReversed.get(headerName);
|
|
|
+ if (StringUtils.isNotBlank(inputAlias)) {
|
|
|
+ String outputAlias = outputReversed.get(headerName);
|
|
|
+ if (StringUtils.isNotBlank(outputAlias)) {
|
|
|
+ newDoc.put(outputAlias, doc.get(inputAlias));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //绑定银行卡字段
|
|
|
+ String value1 = doc.getString(in1);
|
|
|
String[] splited1 = value1.split(";");
|
|
|
for (String s1 : splited1) {
|
|
|
if (StringUtils.isNotBlank(s1)) {
|
|
|
String[] splited2 = s1.split(":");
|
|
|
if (splited2.length == 3) {
|
|
|
- doc.put(EXTRACT_BANKCARDTYPE, splited2[0]);
|
|
|
- doc.put(EXTRACT_BANKCARDCODE, splited2[1]);
|
|
|
- doc.put(EXTRACT_BANKCARD, splited2[2]);
|
|
|
- doc.remove("_id");
|
|
|
- needToSave.add(doc);
|
|
|
+ newDoc.put(out2, splited2[0]);
|
|
|
+ newDoc.put(out3, splited2[1]);
|
|
|
+ newDoc.put(out4, splited2[2]);
|
|
|
+ needToSave.add(newDoc);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -112,6 +137,7 @@ public class AlipayService {
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(needToSave)) {
|
|
|
+// saveLines(new ArrayList<>(needToSave));
|
|
|
saveLines(needToSave);
|
|
|
}
|
|
|
}
|
|
@@ -126,11 +152,13 @@ public class AlipayService {
|
|
|
String current = DataUtils.currentDate();
|
|
|
logicalFile.setUploadDate(current);
|
|
|
logicalFile.setModelId(modelId);
|
|
|
+ logicalFile.setGenerated(Boolean.TRUE);
|
|
|
return mongoTemplate.insert(logicalFile);
|
|
|
}
|
|
|
|
|
|
@Async
|
|
|
- public void saveLines(List<Document> documentList) {
|
|
|
- mongoTemplate.insert(documentList, "data1");
|
|
|
+ public void saveLines(List<DataMap> documentList) {
|
|
|
+ mongoTemplate.insert(documentList,DataMap.class);
|
|
|
}
|
|
|
+
|
|
|
}
|