123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- package ieven.server.webapp.service.alipay;
- import ieven.server.webapp.domain.IdInput;
- import ieven.server.webapp.domain.alipay.HeaderProperties;
- import ieven.server.webapp.domain.alipay.TFromToFileIds;
- import ieven.server.webapp.domain.data.Fields;
- import ieven.server.webapp.domain.file.FileService;
- import ieven.server.webapp.domain.file.LogicalFile;
- import ieven.server.webapp.infrastructure.wrapper.Mapped;
- import ieven.server.webapp.service.FieldsService;
- import ieven.server.webapp.service.datastatic.*;
- import ieven.server.webapp.service.tenpay.*;
- import ieven.server.webapp.util.DataUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- 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.data.mongodb.core.query.Update;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.CountDownLatch;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- @Slf4j
- @Service
- public class AlipayService {
- @Autowired
- FieldsService fieldsService;
- @Autowired
- private MongoTemplate mongoTemplate;
- @Autowired
- private HeaderProperties headerProperties;
- @Autowired
- private FileService fileService;
- @Value("${spring.data.fileExportPath}")
- private String path;
- public Mapped extractAll(String modelId) throws InterruptedException {
- final List<Fields> originFields = queryAllFields(modelId);
- // 先校验文件结构如果有不符合结构的文件 则暂停执行 给于提示
- fieldsService.checkAllFields(originFields);
- List<LogicalFile> logicalFiles = this.queryAllLogicalFiles2(modelId);
- List<String> checkResultStrings = new ArrayList<>();
- for (LogicalFile logicalFile : logicalFiles) {
- if (StringUtils.isBlank(logicalFile.getMatchType())) {
- checkResultStrings.add(logicalFile.getFilename() + "未匹配到文件校验规则,请检查!");
- }
- }
- if (checkResultStrings.size() > 0) {
- return Mapped.ERROR(String.join(" ", checkResultStrings));
- }
- // 先删除所有原来生成的表
- clearAllGenerated(modelId);
- // 查询出modelId的所有原始表头
- if (CollectionUtils.isEmpty(originFields)) {
- return Mapped.ERROR("文件为空");
- }
- // 无限制大小的threadpool
- ExecutorService exec = Executors.newCachedThreadPool();
- log.info("latch");
- CountDownLatch latch = new CountDownLatch(10);
- // 五联单-注册信息
- exec.execute(new ALIPAY_ORIGIN_REGISTER(originFields, modelId, mongoTemplate, latch));
- exec.execute(new ALIPAY_ORIGIN_REGISTER_JZY(originFields, modelId, mongoTemplate, latch));
- // 五联单-登录日志
- exec.execute(new ALIPAY_GENERATED_LOGIN(originFields, modelId, mongoTemplate, latch));
- // 五联单-交易记录
- exec.execute(new ALIPAY_GENERATED_TRADE(originFields, modelId, mongoTemplate, latch));
- // 五联单-账户明细
- exec.execute(new ALIPAY_GENERATED_ACCOUNT(originFields, modelId, mongoTemplate, latch));
- //经侦云-账户明细
- exec.execute(new ALIPAY_GENERATED_ACCOUNT_JZY(headerProperties, originFields, modelId, mongoTemplate, fileService, latch));
- // 五联单-转账明细
- exec.execute(new ALIPAY_GENERATED_TRANSFER(originFields, modelId, mongoTemplate, latch));
- // 反诈平台订单数据
- exec.execute(
- new AntiCheat(headerProperties, originFields, modelId, mongoTemplate, fileService, latch));
- // 治安平台订单数据
- exec.execute(
- new SecurityOrder(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch));
- // 经侦数据-订单数据
- exec.execute(
- new EconomicOrder(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch));
- // 网黑数据-订单数据
- latch.await();
- CountDownLatch latch15 = new CountDownLatch(1);
- exec.execute(
- new BlackOrder(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch15));
- latch15.await();
- //反诈治安-订单明细2
- CountDownLatch latch16 = new CountDownLatch(1);
- exec.execute(
- new AntiCheatTwo(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch16));
- latch16.await();
- log.info("latch");
- log.info("latch2");
- CountDownLatch latch2 = new CountDownLatch(7);
- // 五联单-账户透视
- exec.execute(
- new ScaleAnalysis(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch2));
- // 转账分析
- exec.execute(
- new TransferAnalysis(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch2));
- // 对手分析
- exec.execute(
- new EndAnalysis(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch2));
- // 收货地址分析
- exec.execute(
- new DeliveryAnalysis(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch2));
- // IP分析
- exec.execute(
- new IpAnalysis(
- headerProperties, originFields, modelId, mongoTemplate, fileService, latch2));
- // 存储了账号-户名的的信息
- Map<String, String> accountToName = new ConcurrentHashMap<>();
- // 反诈治安交易数据明细-从反诈读取户名
- exec.execute(new AntiSecurityTrade1(modelId, mongoTemplate, accountToName, latch2));
- // 反诈治安交易数据明细-从治安读取户名
- exec.execute(new AntiSecurityTrade2(modelId, mongoTemplate, accountToName, latch2));
- latch2.await();
- log.info("latch2");
- log.info("latch3");
- CountDownLatch latch3 = new CountDownLatch(1);
- // 反诈治安交易数据明细-从反诈读取 反诈治安交易数据明细合并到这里
- exec.execute(
- new AntiSecurityTrade3(
- headerProperties, modelId, mongoTemplate, accountToName, fileService, latch3));
- latch3.await();
- /* CountDownLatch latch11 = new CountDownLatch(1);
- // 反诈治安交易数据明细-从反诈读取 反诈治安交易数据明细合并到这里
- exec.execute(
- new AntiSecurityTrade5(headerProperties,originFields, modelId, mongoTemplate, fileService, latch11));
- latch11.await();*/
- // 反诈治安交易数据明细-从治安读取
- /*CountDownLatch latch8 = new CountDownLatch(1);
- exec.execute(
- new AntiSecurityTrade4(
- headerProperties, modelId, mongoTemplate, accountToName, fileService, latch8));
- latch8.await();*/
- log.info("latch3");
- log.info("latch4");
- CountDownLatch latch4 = new CountDownLatch(2);
- // 反诈治安-账户透视
- exec.execute(
- new AntiSecurityTradeScaleAnalysis(
- headerProperties, modelId, mongoTemplate, fileService, latch4));
- // 反诈治安-对手分析
- exec.execute(
- new AntiSecurityTradeEndAnalysis(
- headerProperties, modelId, mongoTemplate, fileService, latch4));
- latch4.await();
- log.info("latch4");
- log.info("latch5");
- CountDownLatch latch5 = new CountDownLatch(1);
- // 财付通 开户信息
- exec.execute(
- new TenpayAccount(
- originFields, modelId, mongoTemplate, fileService, accountToName, latch5));
- latch5.await();
- log.info("latch5");
- log.info("latch6");
- CountDownLatch latch6 = new CountDownLatch(1);
- // 财付通-订单明细
- exec.execute(new TenpayOrders(originFields, modelId, mongoTemplate, fileService, latch6));
- latch6.await();
- log.info("latch6");
- log.info("latch8");
- CountDownLatch latch8 = new CountDownLatch(2);
- // 财付通-订单明细
- exec.execute(new TenpayOrders0422(originFields, modelId, mongoTemplate, fileService, latch8));
- exec.execute(new TenpayShopOrders(originFields, modelId, mongoTemplate, fileService, latch8));
- latch8.await();
- log.info("latch8");
- log.info("latch7");
- CountDownLatch latch9 = new CountDownLatch(1);
- // 财付通-交易明细
- exec.execute(new TenpayTrades(modelId, mongoTemplate, accountToName, fileService, latch9));
- latch9.await();
- CountDownLatch latch7 = new CountDownLatch(3);
- // 财付通-手机明细
- exec.execute(new TenpayMobile(originFields, modelId, mongoTemplate, fileService, latch7));
- // 财付通-对手透视
- exec.execute(
- new TenpayTradesEndAnalysis(headerProperties, modelId, mongoTemplate, fileService, latch7));
- // 财付通-账户透视
- exec.execute(
- new TenpayTradesScaleAnalysis(
- headerProperties, modelId, mongoTemplate, fileService, latch7));
- latch7.await();
- //主体账户信息
- CountDownLatch latch10 = new CountDownLatch(1);
- exec.execute(
- new DataStaticAnalysis(
- headerProperties, modelId, mongoTemplate, fileService, latch10));
- latch10.await();
- //主体账户信息
- CountDownLatch latch11 = new CountDownLatch(1);
- exec.execute(
- new DataStaticAnalysisTotal(
- headerProperties, modelId, mongoTemplate, fileService, latch11));
- latch11.await();
- //数据统计-账户透视
- CountDownLatch latch12 = new CountDownLatch(1);
- exec.execute(
- new DataStaticAnalysisMain(
- headerProperties, modelId, mongoTemplate, fileService, latch12));
- latch12.await();
- //数据统计-对手透视
- CountDownLatch latch13 = new CountDownLatch(1);
- exec.execute(
- new DataStaticAnalysisDs(
- headerProperties, modelId, mongoTemplate, fileService, latch13));
- latch13.await();
- //数据统计-生成资金excel
- CountDownLatch latch14 = new CountDownLatch(1);
- exec.execute(new DataStaticExportExcel(modelId, mongoTemplate, fileService, latch14, path));
- latch14.await();
- reorder(modelId);
- log.info("执行完毕");
- return Mapped.OK();
- }
- // 对文件重排序
- private void reorder(String modelId) {
- List<String> orderedNames = headerProperties.getOrderedNames();
- Query query =
- new Query(Criteria.where("modelId").is(modelId).and("generated").is(Boolean.TRUE));
- List<LogicalFile> generated = mongoTemplate.find(query, LogicalFile.class);
- // current
- Date current = new Date();
- long currentMills = current.getTime();
- for (int i = 0; i < orderedNames.size(); i++) {
- for (LogicalFile logicalFile : generated) {
- String filename = logicalFile.getFilename();
- if (orderedNames.get(i).equals(filename)) {
- // 减1秒,造成顺序递减
- current.setTime(currentMills - (long) i * 1000);
- Update update = new Update().set("uploadDate", DataUtils.getDate(current));
- String id = logicalFile.getId();
- mongoTemplate.updateFirst(
- new Query(Criteria.where("id").is(id)), update, LogicalFile.class);
- break;
- }
- }
- }
- }
- public List<LogicalFile> queryAllLogicalFiles(String modelId) {
- Query query =
- new Query(Criteria.where("modelId").is(modelId).and("generated").is(Boolean.TRUE));
- return mongoTemplate.find(query, LogicalFile.class);
- }
- public List<LogicalFile> queryAllLogicalFiles2(String modelId) {
- Query query =
- new Query(Criteria.where("modelId").is(modelId).and("generated").is(Boolean.FALSE));
- return mongoTemplate.find(query, LogicalFile.class);
- }
- private void clearAllGenerated(String modelId) {
- List<LogicalFile> logicalFiles = queryAllLogicalFiles(modelId);
- for (LogicalFile old : logicalFiles) {
- IdInput idInput = new IdInput();
- idInput.setId(old.getId());
- fileService.deleteById(idInput);
- }
- mongoTemplate.remove(new Query(Criteria.where("modelId").is(modelId)), TFromToFileIds.class);
- }
- private List<Fields> queryAllFields(String modelId) {
- Query query = new Query(Criteria.where("modelId").is(modelId).and("generated").is(Boolean.FALSE));
- List<LogicalFile> fileList = mongoTemplate.find(query, LogicalFile.class);
- List<String> fileIdList = new ArrayList<>();
- for (LogicalFile file : fileList) {
- String fileId = file.getId();
- fileIdList.add(fileId);
- }
- Query query1 = new Query(Criteria.where("fileId").in(fileIdList));
- return mongoTemplate.find(query1, Fields.class);
- }
- }
|