You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1152 lines
52 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. package com.inscloudtech.bankStatementAnalysis.helper;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.io.FileUtil;
  5. import cn.hutool.core.util.IdUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.alibaba.excel.EasyExcel;
  8. import com.alibaba.excel.ExcelReader;
  9. import com.alibaba.excel.context.AnalysisContext;
  10. import com.alibaba.excel.exception.ExcelAnalysisStopException;
  11. import com.alibaba.excel.read.listener.ReadListener;
  12. import com.alibaba.excel.read.metadata.ReadSheet;
  13. import com.alibaba.excel.util.ListUtils;
  14. import com.aspose.cells.Cell;
  15. import com.aspose.cells.Cells;
  16. import com.aspose.cells.Workbook;
  17. import com.aspose.cells.Worksheet;
  18. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  19. import com.inscloudtech.bankStatementAnalysis.excel.CellsWrapper;
  20. import com.inscloudtech.bankStatementAnalysis.helper.HelperUtil;
  21. import com.inscloudtech.bankStatementAnalysis.mapper.*;
  22. import com.inscloudtech.bankStatementAnalysis.service.ImportService;
  23. import com.inscloudtech.common.constant.BankStatementConstants;
  24. import com.inscloudtech.common.constant.Constants;
  25. import com.inscloudtech.common.exception.dc.AnalyzeDataFailedException;
  26. import com.inscloudtech.common.exception.dc.ImportDataFailedException;
  27. import com.inscloudtech.common.exception.dc.TemplateNotFindException;
  28. import com.inscloudtech.common.utils.bean.BeanUtils;
  29. import com.inscloudtech.common.utils.file.FileUtils;
  30. import com.inscloudtech.datacenter.domain.PlateNumberInfo;
  31. import com.inscloudtech.datacenter.mapper.es.*;
  32. import com.inscloudtech.datacenter.service.ImportResultService;
  33. import com.inscloudtech.datacenter.domain.BankStatement;
  34. import com.inscloudtech.datacenter.domain.OpeningAccountInfo;
  35. import com.inscloudtech.bankStatementAnalysis.domain.entity.ABCCompanyInfoEntity;
  36. import com.inscloudtech.bankStatementAnalysis.domain.entity.ABCCompanyStatementEntity;
  37. import com.inscloudtech.bankStatementAnalysis.domain.entity.ABCCustomerInfoEntity;
  38. import com.inscloudtech.bankStatementAnalysis.domain.entity.ABCCustomerStatementEntity;
  39. import com.inscloudtech.bankStatementAnalysis.util.AsposeUtil;
  40. import lombok.RequiredArgsConstructor;
  41. import lombok.extern.slf4j.Slf4j;
  42. import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
  43. import org.springframework.stereotype.Component;
  44. import java.io.File;
  45. import java.util.*;
  46. import java.util.regex.Pattern;
  47. import java.util.stream.Collectors;
  48. /**
  49. * 农业银行数据分析
  50. */
  51. @Slf4j
  52. @RequiredArgsConstructor
  53. @Component
  54. public class ABCDataAnalysisHelper {
  55. private final ImportResultService importResultService;
  56. private final ImportService importService;
  57. private final EsABCCustomerStatementMapper esABCCustomerStatementMapper;
  58. private final EsABCCompanyStatementMapper esABCCompanyStatementMapper;
  59. private final EsABCCustomerInfoMapper esABCCustomerInfoMapper;
  60. private final EsABCCompanyInfoMapper esABCCompanyInfoMapper;
  61. private final ESOpeningAccountInfoMapper esOpeningAccountInfoMapper;
  62. private final static String BANK_NAME = "农业银行";
  63. private final static String IGNORE_SHEET_NAME = "金融资产列表,首页,子账户列表,冻结历史列表,共有权列表";
  64. public void importData(File file, String caseId) {
  65. List<File> fileList = FileUtil.loopFiles(file);
  66. // 筛选文件
  67. List<File> excelFileList = HelperUtil.getExcelFile(fileList);
  68. //农行数据大致分为两类:
  69. // 1. 开户信息和流水在同一个工作簿
  70. // 2. 开户信息和流水分开工作簿
  71. //农行的数据文件分两类:1、无法读取;2、可以读取
  72. for (File excelFile : excelFileList) {
  73. try {
  74. String excelFileName = excelFile.getAbsolutePath();
  75. String sourceFile = HelperUtil.getSourceFileName(excelFileName, BANK_NAME);
  76. Workbook wb = new Workbook(excelFileName);
  77. List<ABCCompanyInfoEntity> companyOAIList = new ArrayList<>();
  78. boolean bsHasNotCard = false;
  79. int count = wb.getWorksheets().getCount();
  80. for (int sheetNo = 0; sheetNo < count; sheetNo++) {
  81. try {
  82. boolean templateIsExist = false;
  83. Worksheet worksheet = wb.getWorksheets().get(sheetNo);
  84. Cells cells = worksheet.getCells();
  85. String sheetName = worksheet.getName();
  86. String nameWithSheetName = sourceFile + BankStatementConstants.NAME_WITH_SHEET_NAME + sheetName;
  87. Cell oaiCell1 = AsposeUtil.getCell(cells, "开户日期");
  88. if (oaiCell1 != null) {//个人开户信息
  89. if (excelFileName.endsWith(".xlsx")) {
  90. personOai(oaiCell1, excelFileName, sheetNo, cells);
  91. }
  92. if (excelFileName.endsWith(".xls")) {
  93. Cell tradeDateCell = AsposeUtil.getCell(cells, "发生额");
  94. if (tradeDateCell != null) {//20240428新模板 个人,开户流水在一个模板里
  95. readBsAndOai(excelFileName, cells, sheetNo, nameWithSheetName);
  96. } else {
  97. readOAI(cells);
  98. }
  99. }
  100. templateIsExist = true;
  101. }
  102. if (!templateIsExist) {
  103. Cell oaiCell2 = AsposeUtil.getCell(cells, "账户启用日期");
  104. Cell oaiCell3 = AsposeUtil.getCell(cells, "合约建立日期");
  105. if (oaiCell2 != null || oaiCell3 != null) {//公司开户信息
  106. Cell tradeDateCell = AsposeUtil.getCell(cells, "交易日期");
  107. if (tradeDateCell != null) {//20240416新模板 对公开户,流水在一个模板里
  108. readBsAndOai(excelFileName, cells, sheetNo, nameWithSheetName);
  109. templateIsExist = true;
  110. } else {
  111. Cell tempCell = oaiCell3;
  112. if (oaiCell2 != null) {
  113. tempCell = oaiCell2;
  114. bsHasNotCard = true;//这种模板 开户+流水,但是流水里没有卡号,开户表里只能有一行
  115. }
  116. if (excelFileName.endsWith(".xls")) {
  117. companyOAIList = readCompanyOAIByXls(cells);
  118. } else {
  119. companyOai(tempCell, excelFileName, sheetNo, companyOAIList);
  120. }
  121. templateIsExist = true;
  122. }
  123. }
  124. }
  125. if (!templateIsExist && bsHasNotCard) {
  126. Cell bsCell1 = AsposeUtil.getCell(cells, "交易行省市代码");
  127. if (bsCell1 != null) {//这种模板 开户+流水,但是流水里没有卡号
  128. //2023081615505557832-账号:24055401040001038
  129. if (excelFileName.endsWith(".xls")) {
  130. readCompanyBSByXls(excelFileName, cells, companyOAIList.get(0));
  131. } else {
  132. companyBs(bsCell1, excelFileName, sheetNo, companyOAIList.get(0));//这个表的时间长度较长
  133. }
  134. templateIsExist = true;
  135. }
  136. }
  137. if (!templateIsExist) {
  138. Cell bsCell2 = AsposeUtil.getCell(cells, "合约账户余额");
  139. if (bsCell2 != null) {
  140. companyBs(bsCell2, excelFileName, sheetNo, null);
  141. templateIsExist = true;
  142. }
  143. }
  144. if (!templateIsExist) {
  145. Cell bsCell3 = AsposeUtil.getCell(cells, "子账号序号");
  146. if (bsCell3 != null) {
  147. Cell temp = AsposeUtil.getCell(cells, "交易日期");
  148. if (temp != null) {
  149. personBs(bsCell3, excelFileName, sheetNo,nameWithSheetName);
  150. templateIsExist = true;
  151. }
  152. }
  153. }
  154. if (!templateIsExist) {
  155. Cell bsCell4 = AsposeUtil.getCell(cells, "身份证号码");
  156. if (bsCell4 != null) {
  157. if (excelFileName.endsWith(".xlsx")) {
  158. personBs(bsCell4, excelFileName, sheetNo,nameWithSheetName);
  159. }
  160. if (excelFileName.endsWith(".xls")) {
  161. readABCCustomerBS(excelFileName, cells, null);
  162. }
  163. templateIsExist = true;
  164. }
  165. }
  166. if (!templateIsExist) {
  167. Cell flagCell = AsposeUtil.getCell(cells, "中国农业银行司法查询控制系统");
  168. if (flagCell != null) {
  169. Cell temp = AsposeUtil.getCell(cells, "交易日期");
  170. if (temp != null) {
  171. personBs(temp, excelFileName, sheetNo,nameWithSheetName);
  172. templateIsExist = true;
  173. }
  174. }
  175. }
  176. if (!templateIsExist && (!IGNORE_SHEET_NAME.contains(sheetName))) {
  177. throw new TemplateNotFindException(sourceFile + BankStatementConstants.NAME_WITH_SHEET_NAME + sheetName);
  178. }
  179. } catch (Exception e) {
  180. importResultService.record(caseId, BANK_NAME, e);
  181. }
  182. }
  183. } catch (Exception e) {
  184. importResultService.record(caseId, BANK_NAME, e);
  185. }
  186. }
  187. }
  188. private void readBsAndOai(String excelFileName, Cells cells,int sheetNo,String nameWithSheetName) {
  189. Cell cardCell = AsposeUtil.getCell(cells, "产品号/账号/客户号");
  190. if (cardCell == null) {
  191. cardCell = AsposeUtil.getCell(cells, "卡号");
  192. if(cardCell == null){
  193. throw new TemplateNotFindException(nameWithSheetName);
  194. }
  195. }
  196. String cardNumber = getCardNumber(cardCell,cells,nameWithSheetName);
  197. String cardHolderName = getCardHolderName(cells,nameWithSheetName);
  198. List<ABCCompanyInfoEntity> oaiList = new ArrayList<>();
  199. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  200. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  201. .headRowNumber(cardCell.getRow()+1)
  202. .head(ABCCompanyInfoEntity.class)
  203. .registerReadListener(companyOAIReadListener(oaiList))
  204. .build();
  205. reader.read(sheet);
  206. } catch (Exception e) {
  207. throw new ImportDataFailedException(e.getMessage(), nameWithSheetName);
  208. }
  209. Cell tradeDateCell = AsposeUtil.getCell(cells, "交易日期");
  210. if (tradeDateCell == null) {
  211. tradeDateCell = AsposeUtil.getCell(cells, "发生额");//20240428
  212. if(tradeDateCell == null){
  213. throw new TemplateNotFindException(nameWithSheetName);
  214. }
  215. }
  216. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  217. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  218. .headRowNumber(tradeDateCell.getRow() + 1)
  219. .head(ABCCompanyStatementEntity.class)
  220. .registerReadListener(companyBsListenerFor20240416(cardNumber,cardHolderName,nameWithSheetName))
  221. .build();
  222. reader.read(sheet);
  223. } catch (Exception e) {
  224. throw new ImportDataFailedException(e.getMessage(), nameWithSheetName);
  225. }
  226. }
  227. private String getCardNumber(Cell cardCell,Cells cells,String sourceFile) {
  228. int startRow = cardCell.getRow();
  229. int startCol = cardCell.getColumn();
  230. Cell cardNumberCell = cells.get(startRow + 1, startCol);
  231. if(null == cardNumberCell || StrUtil.isEmpty(cardNumberCell.getStringValue())){
  232. throw new ImportDataFailedException("读取卡号信息异常", sourceFile);
  233. }
  234. String cardNumber = cardNumberCell.getStringValue().trim();
  235. if(cardNumber.contains("/")){
  236. cardNumber = cardNumber.split("/")[0];
  237. }
  238. return cardNumber;
  239. }
  240. private String getCardHolderName(Cells cells,String sourceFile) {
  241. Cell cardCell = AsposeUtil.getCell(cells, "户名");
  242. if (cardCell == null) {
  243. throw new ImportDataFailedException("无法读取表头信息.", sourceFile);
  244. }
  245. int startRow = cardCell.getRow();
  246. int startCol = cardCell.getColumn();
  247. Cell cardNumberCell = cells.get(startRow + 1, startCol);
  248. if(null == cardNumberCell || StrUtil.isEmpty(cardNumberCell.getStringValue())){
  249. throw new ImportDataFailedException("读取户名信息异常", sourceFile);
  250. }
  251. String cardNumber = cardNumberCell.getStringValue().trim();
  252. if(cardNumber.contains("/")){
  253. cardNumber = cardNumber.split("/")[0];
  254. }
  255. return cardNumber;
  256. }
  257. void personBs(Cell bsCell, String excelFileName, int sheetNo,String nameWithSheetName){
  258. int headRowNum = bsCell.getRow() + 1;
  259. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  260. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  261. .headRowNumber(headRowNum)
  262. .head(ABCCustomerStatementEntity.class)
  263. .registerReadListener(personBSReadListener(nameWithSheetName))
  264. .build();
  265. reader.read(sheet);
  266. } catch (Exception e) {
  267. throw new ImportDataFailedException(e.getMessage(), excelFileName);
  268. }
  269. }
  270. private void companyBs(Cell tempCell, String excelFileName, int sheetNo,ABCCompanyInfoEntity oai) {
  271. String sourceFile = HelperUtil.getSourceFileName(excelFileName,BANK_NAME);
  272. int headRowNum = tempCell.getRow() + 1;
  273. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  274. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  275. .headRowNumber(headRowNum)
  276. .head(ABCCompanyStatementEntity.class)
  277. .registerReadListener(companyBSReadListener(oai,sourceFile))
  278. .build();
  279. reader.read(sheet);
  280. } catch (Exception e) {
  281. throw new ImportDataFailedException(e.getMessage(), excelFileName);
  282. }
  283. }
  284. private void companyOai(Cell tempCell, String excelFileName, int sheetNo,List<ABCCompanyInfoEntity> oaiList) {
  285. int headRowNum = tempCell.getRow() + 1;
  286. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  287. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  288. .headRowNumber(headRowNum)
  289. .head(ABCCompanyInfoEntity.class)
  290. .registerReadListener(companyOAIReadListener(oaiList))
  291. .build();
  292. reader.read(sheet);
  293. } catch (Exception e) {
  294. throw new ImportDataFailedException(e.getMessage(), excelFileName);
  295. }
  296. }
  297. private void personOai(Cell oaiCell1, String excelFileName,int sheetNo,Cells cells) {
  298. int headRowNum = oaiCell1.getRow() + 1;
  299. try (ExcelReader reader = EasyExcel.read(excelFileName).build()) {
  300. ReadSheet sheet = EasyExcel.readSheet(sheetNo)
  301. .headRowNumber(headRowNum)
  302. .head(ABCCustomerInfoEntity.class)
  303. .registerReadListener(personOAIReadListener())
  304. .build();
  305. reader.read(sheet);
  306. } catch (Exception e) {
  307. if(e instanceof OLE2NotOfficeXmlFileException){
  308. String sourceFile = HelperUtil.getSourceFileName(excelFileName,BANK_NAME);
  309. log.error("xlsx是手动改的后缀 而不是通过另存为的方式-"+sourceFile);
  310. try {
  311. CellsWrapper<ABCCustomerInfoEntity> wrapper = new CellsWrapper<>(cells, ABCCustomerInfoEntity.class, false);
  312. wrapper.doRead(-1);
  313. List<ABCCustomerInfoEntity> entryList = wrapper.getEntryList();
  314. esABCCustomerInfoMapper.insertBatch(entryList);
  315. } catch (Exception ex) {
  316. throw new ImportDataFailedException(ex.getMessage(), sourceFile);
  317. }
  318. }else {
  319. throw new AnalyzeDataFailedException(e.getMessage(),e);
  320. // HelperUtil.recordErrorImportResult(e.getMessage(), sourceFile,sheetName,caseId,BANK_NAME);
  321. }
  322. }
  323. }
  324. public ReadListener<ABCCompanyStatementEntity> companyBsListenerFor20240416(String cardNumber,String cardHolderName,String sourceFile) {
  325. return new ReadListener<ABCCompanyStatementEntity>() {
  326. List<ABCCompanyStatementEntity> cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  327. @Override
  328. public void invoke(ABCCompanyStatementEntity entity, AnalysisContext context) {
  329. // 4 交易日期
  330. String transDate = entity.getTransactionDate();
  331. try {
  332. if (StrUtil.isNotEmpty(transDate)) { // 20211006
  333. String transTime = entity.getTransactionTime();
  334. if (StrUtil.isNotEmpty(transTime)) { // 14:15:07
  335. if (transTime.length() > Constants.DATE_TIME_FULL_FORMAT_LENGTH) {
  336. // 20131001145718000
  337. transTime = transTime.substring(8, 14);
  338. DateUtil.parse(transTime, "HHmmss");
  339. entity.setTransactionTime(transTime);
  340. } else { // 20081222 030411
  341. if (transTime.contains(":")) {
  342. DateUtil.parse(transDate + " " + transTime, "yyyyMMdd HH:mm:ss");
  343. } else {
  344. DateUtil.parse(transDate + transTime, "yyyyMMddHHmmss");
  345. }
  346. }
  347. } else {
  348. DateUtil.parse(transDate, "yyyyMMdd");
  349. }
  350. }
  351. } catch (Exception e) {
  352. log.error(sourceFile+"解析交易日期异常", e);
  353. Integer currentRowNum = context.getCurrentRowNum() + 1;
  354. throw new AnalyzeDataFailedException("第"+ currentRowNum +"行解析交易日期异常", e, sourceFile);
  355. }
  356. entity.setId(IdUtil.objectId());
  357. entity.setCardNumber(cardNumber);
  358. entity.setCardHolderName(cardHolderName);
  359. entity.setSourceFile(sourceFile);
  360. cacheList.add(entity);
  361. if (cacheList.size() >= Constants.BATCH_SIZE) {
  362. save();
  363. }
  364. }
  365. @Override
  366. public void doAfterAllAnalysed(AnalysisContext context) {
  367. if (!cacheList.isEmpty()) {
  368. save();
  369. }
  370. }
  371. private void save() {
  372. esABCCompanyStatementMapper.insertBatch(cacheList);
  373. cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  374. }
  375. };
  376. }
  377. public ReadListener<ABCCustomerInfoEntity> personOAIReadListener() {
  378. return new ReadListener<ABCCustomerInfoEntity>() {
  379. List<ABCCustomerInfoEntity> cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  380. @Override
  381. public void invoke(ABCCustomerInfoEntity entity, AnalysisContext context) {
  382. entity.setId(IdUtil.objectId());
  383. cacheList.add(entity);
  384. if (cacheList.size() >= Constants.BATCH_SIZE) {
  385. save();
  386. }
  387. }
  388. @Override
  389. public void doAfterAllAnalysed(AnalysisContext context) {
  390. if (!cacheList.isEmpty()) {
  391. save();
  392. }
  393. }
  394. private void save() {
  395. esABCCustomerInfoMapper.insertBatch(cacheList);
  396. cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  397. }
  398. };
  399. }
  400. public ReadListener<ABCCompanyInfoEntity> companyOAIReadListener(List<ABCCompanyInfoEntity> oaiList) {
  401. return new ReadListener<ABCCompanyInfoEntity>() {
  402. List<ABCCompanyInfoEntity> cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  403. @Override
  404. public void invoke(ABCCompanyInfoEntity entity, AnalysisContext context) {
  405. String cardNumber = entity.getCardNumber();
  406. if(StrUtil.isEmpty(cardNumber)){
  407. return;
  408. }
  409. if (HelperUtil.isContainsChinese(cardNumber)){
  410. return;
  411. }
  412. cardNumber = entity.getCardNumber().trim();
  413. if(cardNumber.contains("/")){
  414. cardNumber = cardNumber.split("/")[0];
  415. }
  416. if(StrUtil.isEmpty(entity.getIdCardNo())){
  417. entity.setIdCardNo("");//做统计值是null不会被统计,空字符串可以
  418. }
  419. entity.setCardNumber(cardNumber);
  420. entity.setId(IdUtil.objectId());
  421. cacheList.add(entity);
  422. oaiList.add(entity);
  423. if (cacheList.size() >= Constants.BATCH_SIZE) {
  424. save();
  425. }
  426. }
  427. @Override
  428. public void doAfterAllAnalysed(AnalysisContext context) {
  429. if (!cacheList.isEmpty()) {
  430. save();
  431. }
  432. }
  433. private void save() {
  434. esABCCompanyInfoMapper.insertBatch(cacheList);
  435. cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  436. }
  437. };
  438. }
  439. public ReadListener<ABCCompanyStatementEntity> companyBSReadListener(ABCCompanyInfoEntity oai,String sourceFile) {
  440. return new ReadListener<ABCCompanyStatementEntity>() {
  441. List<ABCCompanyStatementEntity> cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  442. @Override
  443. public void invoke(ABCCompanyStatementEntity entity, AnalysisContext context) {
  444. entity.setId(IdUtil.objectId());
  445. entity.setSourceFile(sourceFile);
  446. if(null != oai && StrUtil.isEmpty(entity.getCardNumber())){
  447. entity.setCardNumber(oai.getCardNumber2());
  448. entity.setCardHolderName(oai.getCardHolderName());
  449. }
  450. cacheList.add(entity);
  451. if (cacheList.size() >= Constants.BATCH_SIZE) {
  452. save();
  453. }
  454. }
  455. @Override
  456. public void doAfterAllAnalysed(AnalysisContext context) {
  457. if (!cacheList.isEmpty()) {
  458. save();
  459. }
  460. }
  461. private void save() {
  462. esABCCompanyStatementMapper.insertBatch(cacheList);
  463. cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  464. }
  465. };
  466. }
  467. public ReadListener<ABCCustomerStatementEntity> personBSReadListener(String sourceFile) {
  468. return new ReadListener<ABCCustomerStatementEntity>() {
  469. List<ABCCustomerStatementEntity> cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  470. @Override
  471. public void invoke(ABCCustomerStatementEntity entity, AnalysisContext context) {
  472. entity.setId(IdUtil.objectId());
  473. entity.setSourceFile(sourceFile);
  474. cacheList.add(entity);
  475. if (cacheList.size() >= Constants.BATCH_SIZE) {
  476. save();
  477. }
  478. }
  479. @Override
  480. public void doAfterAllAnalysed(AnalysisContext context) {
  481. if (!cacheList.isEmpty()) {
  482. save();
  483. }
  484. }
  485. private void save() {
  486. esABCCustomerStatementMapper.insertBatch(cacheList);
  487. cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  488. }
  489. };
  490. }
  491. public void analyzeData(String caseId) {
  492. // 开户信息
  493. analyzeOAI(caseId);
  494. // 流水信息
  495. analyzeBS(caseId);
  496. }
  497. private void analyzeOAI(String caseId) {
  498. // 先分析公司数据
  499. analyzeCompanyOAI(caseId);
  500. analyzeCustomerOAI(caseId);
  501. }
  502. private void analyzeCustomerOAI(String caseId) {
  503. List<OpeningAccountInfo> oaiList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  504. List<ABCCustomerInfoEntity> entityList =
  505. HelperUtil.getEntityList(esABCCustomerInfoMapper, ABCCustomerInfoEntity.class);
  506. Set<String> uniqueKeySet = new HashSet();
  507. for (ABCCustomerInfoEntity entity : entityList) {
  508. OpeningAccountInfo oai = getOpeningAccountInfo( entity);
  509. String md5Id = HelperUtil.generateMD5Id4OAI(oai,caseId);
  510. //未导入数据内部去重
  511. if(HelperUtil.deduplication(md5Id,uniqueKeySet)){
  512. continue;
  513. }
  514. oai.setId(md5Id);
  515. oai.setCaseId(caseId);
  516. oaiList.add(oai);
  517. if (oaiList.size() >= Constants.BATCH_SIZE) {
  518. List<OpeningAccountInfo> dest = HelperUtil.getDest(oaiList);
  519. HelperUtil.batchSaveOAI2Es(dest, caseId);
  520. oaiList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  521. }
  522. }
  523. uniqueKeySet.clear();
  524. if (!oaiList.isEmpty()) {
  525. List<OpeningAccountInfo> dest = HelperUtil.getDest(oaiList);
  526. HelperUtil.batchSaveOAI2Es(dest, caseId);
  527. }
  528. }
  529. private static OpeningAccountInfo getOpeningAccountInfo(ABCCustomerInfoEntity entity) {
  530. OpeningAccountInfo oai = new OpeningAccountInfo();
  531. oai.setBankName(BANK_NAME);
  532. String cardNumber = entity.getCardNumber();
  533. oai.setAccountNumber(cardNumber);
  534. oai.setIdNo(entity.getIdCardNo());
  535. oai.setName(entity.getCardHolderName());
  536. oai.setPhone(entity.getPhone());
  537. oai.setAddress(entity.getAddress());
  538. oai.setOpeningAccountDate(entity.getOpeningAccountDate());
  539. oai.setClosingDate(entity.getCloseDate());
  540. oai.setStatus(entity.getStatus());
  541. oai.setAccountOpeningInstitution(entity.getAccountOpeningInstitution());
  542. oai.setBalance(entity.getBalance());
  543. return oai;
  544. }
  545. private void analyzeCompanyOAI(String caseId) {
  546. List<OpeningAccountInfo> oaiList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  547. List<ABCCompanyInfoEntity> entityList =
  548. HelperUtil.getEntityList(esABCCompanyInfoMapper, ABCCompanyInfoEntity.class);
  549. Set<String> uniqueKeySet = new HashSet();
  550. for (ABCCompanyInfoEntity entity : entityList) {
  551. OpeningAccountInfo oai = getOpeningAccountInfo(entity);
  552. String md5Id = HelperUtil.generateMD5Id4OAI(oai,caseId);
  553. //未导入数据内部去重
  554. if(HelperUtil.deduplication(md5Id,uniqueKeySet)){
  555. continue;
  556. }
  557. oai.setId(md5Id);
  558. oai.setCaseId(caseId);
  559. oaiList.add(oai);
  560. if (oaiList.size() >= Constants.BATCH_SIZE) {
  561. List<OpeningAccountInfo> dest = HelperUtil.getDest(oaiList);
  562. HelperUtil.batchSaveOAI2Es(dest, caseId);
  563. oaiList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  564. }
  565. }
  566. if (!oaiList.isEmpty()) {
  567. List<OpeningAccountInfo> dest = HelperUtil.getDest(oaiList);
  568. HelperUtil.batchSaveOAI2Es(dest, caseId);
  569. }
  570. }
  571. private static OpeningAccountInfo getOpeningAccountInfo(ABCCompanyInfoEntity entity) {
  572. OpeningAccountInfo oai = new OpeningAccountInfo();
  573. oai.setName(entity.getCardHolderName());
  574. oai.setBankName(BANK_NAME);
  575. oai.setAccountNumber(entity.getCardNumber());
  576. oai.setPhone(entity.getPhone());
  577. oai.setAddress(entity.getAddress());
  578. oai.setOpeningAccountDate(entity.getOpeningAccountDate());
  579. oai.setClosingDate(entity.getCloseDate());
  580. oai.setStatus(entity.getStatus());
  581. oai.setAccountOpeningInstitution(entity.getAccountOpeningInstitution());
  582. return oai;
  583. }
  584. private void analyzeBS(String caseId) {
  585. // 异步进行
  586. analyzeBSForCompany(caseId);
  587. analyzeBSForCustomer(caseId);
  588. }
  589. private void analyzeBSForCustomer(String caseId) {
  590. //去重
  591. Set<String> uniqueKeySet = new HashSet();
  592. List<PlateNumberInfo> plateNumberInfoList = new ArrayList<>();
  593. List<BankStatement> bsList = new ArrayList<>();
  594. Map<String, ABCCustomerInfoEntity> cache = new HashMap<>();
  595. List<OpeningAccountInfo> oaiList = HelperUtil.getEntityListV2(esOpeningAccountInfoMapper, OpeningAccountInfo.class, caseId);
  596. List<ABCCustomerInfoEntity> customerInfoList =
  597. HelperUtil.getEntityList(esABCCustomerInfoMapper, ABCCustomerInfoEntity.class);
  598. for (ABCCustomerInfoEntity info : customerInfoList) {
  599. cache.put(info.getIdCardNo(), info);
  600. }
  601. Map<String, List<ABCCustomerInfoEntity>> groupByCardNumber = customerInfoList.stream().filter(item ->StrUtil.isNotEmpty(item.getCardNumber()))
  602. .collect(Collectors.groupingBy(ABCCustomerInfoEntity::getCardNumber));
  603. Map<String, List<ABCCustomerInfoEntity>> groupByAccountNo = customerInfoList.stream().filter(item ->StrUtil.isNotEmpty(item.getAccountNo()))
  604. .collect(Collectors.groupingBy(ABCCustomerInfoEntity::getAccountNo));
  605. // 处理个人流水
  606. List<ABCCustomerStatementEntity> entityList =
  607. HelperUtil.getEntityList(esABCCustomerStatementMapper, ABCCustomerStatementEntity.class);
  608. entityList.stream().filter(item ->StrUtil.isNotEmpty(item.getAccountNo()))
  609. .collect(Collectors.groupingBy(ABCCustomerStatementEntity::getAccountNo));
  610. // 主要其实就是流水数据
  611. for (ABCCustomerStatementEntity entity : entityList) {
  612. String sourceFile = entity.getSourceFile();
  613. try {
  614. // 流水
  615. BankStatement bs = new BankStatement();
  616. bs.setBankName(BANK_NAME);
  617. String cardNumber = entity.getCardNumber();
  618. String accountNo = entity.getAccountNo();
  619. bs.setIdCardNo(entity.getIdCardNo());
  620. bs.setCardHolderName(entity.getCardHolderName());
  621. bs.setCardNumber(cardNumber);
  622. if (StrUtil.isEmpty(bs.getIdCardNo()) || StrUtil.isEmpty(bs.getCardHolderName())) {
  623. if (groupByCardNumber.containsKey(cardNumber)) {
  624. List<ABCCustomerInfoEntity> abcCustomerInfoEntities = groupByCardNumber.get(cardNumber);
  625. ABCCustomerInfoEntity oai = abcCustomerInfoEntities.get(0);
  626. bs.setIdCardNo(oai.getIdCardNo());
  627. bs.setCardHolderName(oai.getCardHolderName());
  628. bs.setCardNumber(StringUtils.isEmpty(oai.getCardNumber())?oai.getCardNumber2():oai.getCardNumber());
  629. }
  630. if(StrUtil.isEmpty(bs.getCardHolderName()) && StrUtil.isEmpty(entity.getCardHolderName()) && StrUtil.isNotEmpty(accountNo) ){
  631. for (String oaiAccountNo : groupByAccountNo.keySet()) {
  632. if(oaiAccountNo.contains(accountNo)){
  633. List<ABCCustomerInfoEntity> abcCustomerInfoEntities = groupByAccountNo.get(oaiAccountNo);
  634. ABCCustomerInfoEntity oai = abcCustomerInfoEntities.get(0);
  635. bs.setIdCardNo(oai.getIdCardNo());
  636. bs.setCardHolderName(oai.getCardHolderName());
  637. bs.setCardNumber(StringUtils.isEmpty(oai.getCardNumber())?oai.getCardNumber2():oai.getCardNumber());
  638. break;
  639. }
  640. }
  641. }
  642. }
  643. ABCCustomerInfoEntity info = cache.getOrDefault(bs.getIdCardNo(), null);
  644. if (info != null) {
  645. bs.setPhone(info.getPhone());
  646. if (StringUtils.isEmpty(bs.getCardHolderName())) {
  647. bs.setCardHolderName(info.getCardHolderName());
  648. if (StringUtils.isEmpty(bs.getCardHolderName())) {
  649. Optional<ABCCustomerInfoEntity> first = cache.values().stream().filter(item -> StrUtil.isNotEmpty(item.getCardNumber())).filter(cs -> cs.getCardNumber().equalsIgnoreCase(bs.getCardNumber())).findFirst();
  650. first.ifPresent(abcCustomerInfoEntity -> bs.setCardHolderName(abcCustomerInfoEntity.getCardHolderName()));
  651. first.ifPresent(abcCustomerInfoEntity -> bs.setIdCardNo(abcCustomerInfoEntity.getIdCardNo()));
  652. }
  653. }
  654. if (StringUtils.isEmpty(bs.getCardNumber())) {
  655. bs.setCardNumber(info.getCardNumber());
  656. if (StringUtils.isEmpty(bs.getCardNumber())) {
  657. Optional<ABCCustomerInfoEntity> first = cache.values().stream().filter(item -> StrUtil.isNotEmpty(item.getCardNumber())).filter(cs -> cs.getIdCardNo().equalsIgnoreCase(bs.getIdCardNo())).findFirst();
  658. first.ifPresent(abcCustomerInfoEntity -> bs.setCardNumber(abcCustomerInfoEntity.getCardNumber()));
  659. }
  660. }
  661. cache.put(info.getIdCardNo(), info);
  662. }
  663. if (StringUtils.isEmpty(bs.getIdCardNo()) && StringUtils.isNotEmpty(bs.getCardNumber())) {
  664. Optional<OpeningAccountInfo> first = oaiList.stream().filter(cs -> StrUtil.isNotEmpty(cs.getAccountNumber())).filter(cs -> cs.getAccountNumber().equalsIgnoreCase(bs.getCardNumber())).findFirst();
  665. first.ifPresent(abcCustomerInfoEntity -> bs.setIdCardNo(abcCustomerInfoEntity.getIdNo()));
  666. }
  667. // 1 货币类型
  668. // 人民币
  669. bs.setTransCurrencyType(Constants.CURRENCY_TYPE_CHINA);
  670. // 2 交易金额 可能是double或者int类型
  671. bs.setTransactionAmount(entity.getTransactionAmount());
  672. // 3 余额
  673. bs.setBalance(entity.getBalance());
  674. // 4 交易时间
  675. String transactionDate = entity.getTransactionDate();
  676. String transTime = entity.getTransactionTime();
  677. if (StrUtil.isNotEmpty(transactionDate)) {
  678. if (StringUtils.isEmpty(transTime)) {
  679. transTime = "000000";
  680. }
  681. if(!isInteger(transTime)){
  682. transTime = "000000";
  683. }
  684. String transactionTime = transactionDate + transTime;
  685. String format = "yyyyMMddHHmmss";
  686. try {
  687. if (transactionTime.length() > format.length()) {
  688. transactionTime = transactionTime.substring(0, format.length());
  689. }
  690. bs.setTransactionTime(DateUtil.parse(transactionTime, format));
  691. } catch (Exception e) {
  692. String filename = entity.getSourceFile();
  693. log.error("解析交易时间异常: {}{}", e.getMessage(), e,filename);
  694. throw new AnalyzeDataFailedException(String.format("解析交易时间错误,无法将【%s】格式化为【%s】", transactionTime, format), e, sourceFile);
  695. }
  696. }
  697. String counterpartyName = entity.getCounterpartyName();
  698. String counterpartyIdCardNo = entity.getCounterpartyIdCardNo();
  699. bs.setCounterpartIdCardNo(counterpartyIdCardNo);
  700. if (StrUtil.isNotEmpty(counterpartyName) && StrUtil.isEmpty(counterpartyIdCardNo)) {
  701. List<ABCCustomerInfoEntity> rstList = cache.values().stream()
  702. .filter(cs -> cs.getCardHolderName().equalsIgnoreCase(counterpartyName))
  703. .collect(Collectors.toList());
  704. if (!rstList.isEmpty()) {
  705. ABCCustomerInfoEntity cs = rstList.get(0);
  706. bs.setCounterpartIdCardNo(cs.getIdCardNo());
  707. }
  708. }
  709. bs.setCounterpartyName(counterpartyName);
  710. bs.setCounterpartyBankName(entity.getCounterpartyBankName());
  711. bs.setCounterpartyAccount(entity.getCounterpartyAccount());
  712. bs.setTransactionInstitutions(entity.getTransactionInstitutions());
  713. bs.setSummary(entity.getSummary());
  714. bs.setTransRemark(entity.getTransRemark());
  715. bs.setTransChannel(entity.getTransChannel());
  716. String md5Id = HelperUtil.generateMD5Id(bs,caseId);
  717. //未导入数据内部去重
  718. if(HelperUtil.deduplication(md5Id,uniqueKeySet)){
  719. continue;
  720. }
  721. bs.setSourceFile(entity.getSourceFile());
  722. bs.setId(md5Id);
  723. bs.setCaseId(caseId);
  724. try {
  725. BeanUtils.beanAttributeValueTrim(bs);
  726. } catch (Exception e) {
  727. e.printStackTrace();
  728. }
  729. bsList.add(bs);
  730. HelperUtil.extractPlateNumber(bs,plateNumberInfoList);
  731. if (bsList.size() >= Constants.BATCH_SIZE) {
  732. List<BankStatement> dest = HelperUtil.getDest(bsList);
  733. HelperUtil.batchInsert2Es(dest, caseId);
  734. bsList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  735. }
  736. } catch (Exception e) {
  737. importResultService.record(caseId, BANK_NAME, e, sourceFile);
  738. }
  739. }
  740. uniqueKeySet.clear();
  741. HelperUtil.batchInsertPlateNumber(plateNumberInfoList);
  742. // 保存数据库
  743. if (!bsList.isEmpty()) {
  744. List<BankStatement> dest = HelperUtil.getDest(bsList);
  745. HelperUtil.batchInsert2Es(dest, caseId);
  746. }
  747. }
  748. private void analyzeBSForCompany(String caseId) {
  749. List<BankStatement> bsList = new ArrayList<>();
  750. List<ABCCompanyStatementEntity> entityList =
  751. HelperUtil.getEntityList(esABCCompanyStatementMapper, ABCCompanyStatementEntity.class);
  752. List<ABCCompanyInfoEntity> companyInfoList =
  753. HelperUtil.getEntityList(esABCCompanyInfoMapper, ABCCompanyInfoEntity.class);
  754. Map<String, ABCCompanyInfoEntity> nameCompanyInfoMap = new HashMap<>();
  755. for (ABCCompanyInfoEntity entity : companyInfoList) {
  756. nameCompanyInfoMap.put(entity.getCardHolderName(), entity);
  757. }
  758. Map<String, List<ABCCompanyInfoEntity>> groupByContractNo = companyInfoList.stream()
  759. .filter(item ->StrUtil.isNotEmpty(item.getContractNo()))
  760. .collect(Collectors.groupingBy(ABCCompanyInfoEntity::getContractNo));
  761. Set<String> uniqueKeySet = new HashSet();
  762. List<PlateNumberInfo> plateNumberInfoList = new ArrayList<>();
  763. for (ABCCompanyStatementEntity entity : entityList) {
  764. String sourceFile = entity.getSourceFile();
  765. try {
  766. // 流水
  767. BankStatement bs = new BankStatement();
  768. bs.setBankName(BANK_NAME);
  769. String cardHolderName = entity.getCardHolderName();
  770. bs.setCardHolderName(cardHolderName);
  771. bs.setCardNumber(entity.getCardNumber());
  772. if (StrUtil.isEmpty(bs.getCardHolderName())) {
  773. if (groupByContractNo.containsKey(entity.getContractNo())) {
  774. List<ABCCompanyInfoEntity> abcCompanyInfoEntities = groupByContractNo.get(entity.getContractNo());
  775. ABCCompanyInfoEntity companyInfo = abcCompanyInfoEntities.get(0);
  776. bs.setCardHolderName(companyInfo.getCardHolderName());
  777. String cardNumber = companyInfo.getCardNumber();
  778. cardNumber = StrUtil.isEmpty(cardNumber) ? companyInfo.getCardNumber2() : cardNumber;
  779. bs.setCardNumber(StrUtil.isEmpty(cardNumber) ? companyInfo.getContractNo() : cardNumber);
  780. bs.setIdCardNo(companyInfo.getIdCardNo());
  781. }
  782. }
  783. if (StrUtil.isEmpty(bs.getIdCardNo())) {
  784. bs.setIdCardNo("");
  785. }
  786. ABCCompanyInfoEntity ci = nameCompanyInfoMap.getOrDefault(cardHolderName, null);
  787. if (ci != null) {
  788. if (StrUtil.isEmpty(bs.getCardNumber())) {
  789. bs.setCardNumber(ci.getCardNumber());
  790. }
  791. bs.setPhone(ci.getPhone());
  792. }
  793. // 1 货币类型
  794. // 人民币
  795. bs.setTransCurrencyType(Constants.CURRENCY_TYPE_CHINA);
  796. // 2 交易金额 可能是double或者int类型
  797. bs.setTransactionAmount(entity.getTransactionAmount());
  798. // 3 余额
  799. bs.setBalance(entity.getBalance());
  800. // 4 交易日期 20170314143047165086
  801. String transactionDate = entity.getTransactionDate();
  802. if (StrUtil.isNotEmpty(transactionDate)) {
  803. // 如果包含-,则用yyyy-MM-dd来解析
  804. String format;
  805. if (transactionDate.contains("-")) {
  806. format = "yyyy-MM-dd";
  807. } else if (transactionDate.contains("/")) {
  808. format = "yyyy/MM/dd";
  809. } else {
  810. format = "yyyyMMdd";
  811. }
  812. String transactionTime = entity.getTransactionTime();
  813. // 如果不为空,则组合
  814. if (StrUtil.isNotEmpty(transactionTime)) {
  815. if (!isInteger(transactionTime)) {
  816. transactionTime = "00:00:00";
  817. }
  818. // 还需要分情况考虑,一种是交易时间的长度超过了14位,另一种是交易时间的长度小于14位
  819. if (transactionTime.length() > Constants.DATE_TIME_FULL_FORMAT_LENGTH) {
  820. transactionTime = transactionTime.substring(
  821. Constants.DATE_FULL_FORMAT_LENGTH, Constants.DATE_TIME_FULL_FORMAT_LENGTH);
  822. }
  823. transactionDate += " " + transactionTime;
  824. // 如果包含:,则用HH:mm:ss来解析
  825. if (transactionTime.contains(":")) {
  826. format = format + " HH:mm:ss";
  827. } else {
  828. format += " HHmmss";
  829. }
  830. try {
  831. bs.setTransactionTime(DateUtil.parse(transactionDate, format));
  832. } catch (Exception e) {
  833. log.error("解析交易日期异常:{},{}", e.getMessage() + entity.getSourceFile(), e);
  834. throw new AnalyzeDataFailedException(
  835. "解析交易日期失败,无法将【" + transactionDate + transactionTime + "】以格式【" + format + "】解析", e, entity.getSourceFile());
  836. }
  837. }
  838. } else {
  839. // 一般情况下,交易日期不为空
  840. // 若是为空,则交易日期和时间同时包含在交易时间内哦
  841. String transactionTime = entity.getTransactionTime();
  842. if (transactionTime != null) {
  843. String format = "yyyyMMddHHmmss";
  844. try {
  845. // 需要截断 20170314 143047
  846. int len = format.length();
  847. if (transactionTime.length() > len) {
  848. transactionTime = transactionTime.substring(0, len);
  849. }
  850. bs.setTransactionTime(DateUtil.parse(transactionTime, format));
  851. } catch (Exception e) {
  852. log.error("解析交易日期异常:{}", e.getMessage(), e);
  853. throw new AnalyzeDataFailedException(
  854. "解析交易日期失败,无法将【" + transactionTime + "】以格式【" + format + "】解析", e, sourceFile);
  855. }
  856. }
  857. }
  858. String counterpartyName = entity.getCounterpartyName();
  859. bs.setCounterpartyName(counterpartyName);
  860. bs.setCounterpartyAccount(entity.getCounterpartyAccount());
  861. bs.setCounterpartyBankName(entity.getCounterpartyBankName());
  862. bs.setTransChannel(entity.getTransChannel());
  863. bs.setSummary(entity.getSummary());
  864. bs.setTransactionInstitutions(entity.getTransactionInstitutions());
  865. String md5Id = HelperUtil.generateMD5Id(bs, caseId);
  866. //未导入数据内部去重
  867. if (HelperUtil.deduplication(md5Id, uniqueKeySet)) {
  868. continue;
  869. }
  870. bs.setSourceFile(entity.getSourceFile());
  871. bs.setId(md5Id);
  872. bs.setCaseId(caseId);
  873. try {
  874. BeanUtils.beanAttributeValueTrim(bs);
  875. } catch (Exception e) {
  876. e.printStackTrace();
  877. }
  878. bsList.add(bs);
  879. HelperUtil.extractPlateNumber(bs,plateNumberInfoList);
  880. if (bsList.size() >= Constants.BATCH_SIZE) {
  881. List<BankStatement> dest = HelperUtil.getDest(bsList);
  882. HelperUtil.batchInsert2Es(dest, caseId);
  883. bsList.clear();
  884. bsList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE);
  885. }
  886. } catch (Exception e) {
  887. importResultService.record(caseId, BANK_NAME, e, sourceFile);
  888. }
  889. }
  890. uniqueKeySet.clear();
  891. HelperUtil.batchInsertPlateNumber(plateNumberInfoList);
  892. // 保存数据库
  893. if (!bsList.isEmpty()) {
  894. List<BankStatement> dest = HelperUtil.getDest(bsList);
  895. HelperUtil.batchInsert2Es(dest, caseId);
  896. }
  897. }
  898. public static boolean isInteger(String str) {
  899. Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
  900. return pattern.matcher(str).matches();
  901. }
  902. private List<ABCCustomerInfoEntity> readOAI( Cells cells) throws Exception {
  903. CellsWrapper<ABCCustomerInfoEntity> wrapper = new CellsWrapper<>(cells, ABCCustomerInfoEntity.class, false);
  904. wrapper.doRead(-1);
  905. List<ABCCustomerInfoEntity> entryList = wrapper.getEntryList();
  906. esABCCustomerInfoMapper.insertBatch(entryList);
  907. return entryList;
  908. }
  909. private List<ABCCompanyInfoEntity> readCompanyOAIByXls(Cells cells) throws Exception {
  910. CellsWrapper<ABCCompanyInfoEntity> wrapper = new CellsWrapper<>(cells, ABCCompanyInfoEntity.class, false);
  911. wrapper.doRead(-1);
  912. List<ABCCompanyInfoEntity> entryList = wrapper.getEntryList();
  913. esABCCompanyInfoMapper.insertBatch(entryList);
  914. return entryList;
  915. }
  916. private void readABCCustomerBS(String excelFileName, Cells cells, List<ABCCustomerInfoEntity> oaiList) throws Exception {
  917. String sourceFile = HelperUtil.getSourceFileName(excelFileName,BANK_NAME);
  918. // 读个人流水
  919. try {
  920. CellsWrapper<ABCCustomerStatementEntity> wrapper = new CellsWrapper<>(cells, ABCCustomerStatementEntity.class, true);
  921. wrapper.doRead(-1);
  922. List<ABCCustomerStatementEntity> entryList = wrapper.getEntryList();
  923. Map<String, List<ABCCustomerInfoEntity>> groupByAccountNo = new HashMap<>();
  924. if(CollectionUtil.isNotEmpty(oaiList)){
  925. groupByAccountNo = oaiList.stream().collect(Collectors.groupingBy(ABCCustomerInfoEntity::getAccountNo));
  926. }
  927. for (ABCCustomerStatementEntity bs : entryList) {
  928. bs.setId(IdUtil.objectId());
  929. bs.setSourceFile(sourceFile);
  930. String accountNo = bs.getAccountNo();
  931. if(StrUtil.isNotEmpty(accountNo)){
  932. if (groupByAccountNo.containsKey(accountNo)) {
  933. List<ABCCustomerInfoEntity> tempList = groupByAccountNo.get(accountNo);
  934. ABCCustomerInfoEntity oai = tempList.get(0);
  935. bs.setCardHolderName(oai.getCardHolderName());
  936. bs.setCardNumber(oai.getCardNumber());
  937. }
  938. }
  939. }
  940. //save to es
  941. esABCCustomerStatementMapper.insertBatch(entryList);
  942. } catch (Exception e) {
  943. if (e instanceof ExcelAnalysisStopException) {
  944. return;
  945. }
  946. log.error("readABCCustomerBS:读取文件异常:{}", e.getMessage(), e);
  947. throw new ImportDataFailedException(e.getMessage(), excelFileName);
  948. }
  949. }
  950. private void readCompanyBSByXls(String excelFileName, Cells cells,ABCCompanyInfoEntity oai) throws Exception {
  951. String sourceFile = HelperUtil.getSourceFileName(excelFileName,BANK_NAME);
  952. try {
  953. CellsWrapper<ABCCompanyStatementEntity> wrapper = new CellsWrapper<>(cells, ABCCompanyStatementEntity.class, true);
  954. wrapper.doRead(-1);
  955. String cardHolderName = oai.getCardHolderName();
  956. String cardNumber = oai.getCardNumber();
  957. if(StrUtil.isEmpty(cardNumber)){
  958. cardNumber = oai.getCardNumber2();
  959. }else {
  960. if(cardNumber.length() > 17){
  961. cardNumber = oai.getCardNumber2();
  962. }
  963. }
  964. List<ABCCompanyStatementEntity> entryList = wrapper.getEntryList();
  965. //加ID
  966. for (ABCCompanyStatementEntity bs : entryList) {
  967. bs.setId(IdUtil.objectId());
  968. bs.setSourceFile(sourceFile);
  969. bs.setCardNumber(cardNumber);
  970. bs.setCardHolderName(cardHolderName);
  971. }
  972. //save to es
  973. esABCCompanyStatementMapper.insertBatch(entryList);
  974. } catch (Exception e) {
  975. log.error("readABCCompanyBS:读取文件异常:{}", e.getMessage(), e);
  976. throw new ImportDataFailedException(e.getMessage(), excelFileName);
  977. }
  978. }
  979. }