From 679af1c3597191ffec4418bdeaead0e50980fb48 Mon Sep 17 00:00:00 2001 From: "583641232@qq.com" <583641232@qq.com> Date: Thu, 12 Sep 2024 16:22:18 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=E9=82=AE=E6=94=BF=E5=82=A8=E8=93=84=E9=93=B6=E8=A1=8C?= =?UTF-8?q?=E6=96=B0=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/BankStatementConstants.java | 2 + .../domain/ImportCommonStatement.java | 71 ++++++++++++ .../helper/HelperUtil.java | 15 +++ .../helper/PSBCDataAnalysisHelper.java | 106 ++++++++++++++---- 4 files changed, 173 insertions(+), 21 deletions(-) create mode 100644 cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/domain/ImportCommonStatement.java diff --git a/cas-common/src/main/java/com/inscloudtech/common/constant/BankStatementConstants.java b/cas-common/src/main/java/com/inscloudtech/common/constant/BankStatementConstants.java index a3543f8..c635fa9 100644 --- a/cas-common/src/main/java/com/inscloudtech/common/constant/BankStatementConstants.java +++ b/cas-common/src/main/java/com/inscloudtech/common/constant/BankStatementConstants.java @@ -18,6 +18,8 @@ public class BankStatementConstants { * 导入银行流水开户信息模板索引 */ public static final String IMPORT_TEMPLATE_OPENING_ACCOUNT = "import_template_opening_account"; + public static final String IMPORT_COMMON_STATEMENT = "import_common_statement"; + public static final String NAME_WITH_SHEET_NAME = "NAME_WITH_SHEET_NAME"; diff --git a/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/domain/ImportCommonStatement.java b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/domain/ImportCommonStatement.java new file mode 100644 index 0000000..01e3d38 --- /dev/null +++ b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/domain/ImportCommonStatement.java @@ -0,0 +1,71 @@ +package com.inscloudtech.bankStatementAnalysis.domain; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; +import org.dromara.easyes.annotation.IndexId; +import org.dromara.easyes.annotation.rely.IdType; + +/** + * 导入银行流水通用模板 + */ +@Data + +//@IndexName(BankStatementConstants.IMPORT_COMMON_STATEMENT) +public class ImportCommonStatement { + + @ExcelIgnore + @IndexId(type = IdType.CUSTOMIZE) + private String id; + + + @ExcelProperty("客户名称") + private String cardHolderName; + + @ExcelProperty({"客户账号"}) + private String cardNumber; + + @ExcelProperty({"交易日期"}) + private String transactionDate; + + @ExcelProperty({"交易时间"}) + private String transactionTime; + + + @ExcelProperty({"借贷标志","借贷标识"}) + private String loanFlag; + + // 收入金额 + @ExcelProperty("交易金额") + private String transactionAmount; + + // 交易后余额 + @ExcelProperty("账户余额") + private String balance; + + // 对方账号 + @ExcelProperty("对方账号") + private String counterpartyAccount; + + @ExcelProperty("对方户名") + private String counterpartyName; + + @ExcelProperty("对方行名") + private String counterpartyBankName; + + @ExcelProperty({"交易渠道","渠道名称"}) + private String transChannel; + + @ExcelProperty("交易摘要") + private String summary; + + @ExcelIgnore + private String caseId; + + @ExcelIgnore + private String bankName; + + + + +} diff --git a/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/HelperUtil.java b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/HelperUtil.java index 1bd7535..3bfc311 100644 --- a/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/HelperUtil.java +++ b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/HelperUtil.java @@ -1136,4 +1136,19 @@ public class HelperUtil { } EsMapperHolder.getPlateNumberInfoEsMapper().insertBatch(plateNumberInfoList); } + + public static String getStringValue(Cells cells, String key) { + Cell cell = AsposeUtil.getCell(cells, key); + if (cell == null) { + // 即便无法获取客户名称,也可以通过账号找到对应信息,无关紧要 + return ""; + } + + String rstValue = cells.get(cell.getRow(), cell.getColumn() + 1).getStringValue(); + if (StringUtils.isBlank(rstValue)) { + return ""; + } + + return rstValue; + } } diff --git a/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/PSBCDataAnalysisHelper.java b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/PSBCDataAnalysisHelper.java index 8390879..d78d84f 100644 --- a/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/PSBCDataAnalysisHelper.java +++ b/cas-system/src/main/java/com/inscloudtech/bankStatementAnalysis/helper/PSBCDataAnalysisHelper.java @@ -18,32 +18,26 @@ import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.holder.ReadHolder; import com.alibaba.excel.util.ListUtils; - import com.aspose.cells.Cell; import com.aspose.cells.Cells; import com.aspose.cells.Workbook; import com.aspose.cells.Worksheet; import com.baomidou.mybatisplus.core.toolkit.StringUtils; - -import com.inscloudtech.bankStatementAnalysis.helper.HelperUtil; +import com.inscloudtech.bankStatementAnalysis.domain.ImportCommonStatement; +import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCETStatementEntity; +import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCOpeningAccountInfoEntity; +import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCStatementEntity; +import com.inscloudtech.bankStatementAnalysis.mapper.EsPSBCOpeningAccountInfoMapper; +import com.inscloudtech.bankStatementAnalysis.mapper.EsPSBCStatementMapper; +import com.inscloudtech.bankStatementAnalysis.util.AsposeUtil; import com.inscloudtech.common.constant.Constants; import com.inscloudtech.common.exception.dc.AnalyzeDataFailedException; import com.inscloudtech.common.exception.dc.ImportDataFailedException; import com.inscloudtech.common.utils.bean.BeanUtils; -import com.inscloudtech.common.utils.file.FileUtils; -import com.inscloudtech.datacenter.domain.PlateNumberInfo; -import com.inscloudtech.bankStatementAnalysis.mapper.EsPSBCOpeningAccountInfoMapper; -import com.inscloudtech.bankStatementAnalysis.mapper.EsPSBCStatementMapper; -import com.inscloudtech.datacenter.service.ImportResultService; import com.inscloudtech.datacenter.domain.BankStatement; import com.inscloudtech.datacenter.domain.OpeningAccountInfo; - -import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCETStatementEntity; -import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCOpeningAccountInfoEntity; -import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCStatementEntity; - -import com.inscloudtech.bankStatementAnalysis.util.AsposeUtil; - +import com.inscloudtech.datacenter.domain.PlateNumberInfo; +import com.inscloudtech.datacenter.service.ImportResultService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -55,7 +49,6 @@ import java.util.*; import java.util.stream.Collectors; - /** * 中国邮政储蓄银行数据分析 */ @@ -429,7 +422,6 @@ public class PSBCDataAnalysisHelper { saveData(); } - log.info("读取邮政储蓄银行流水结束"); } @Override @@ -524,7 +516,7 @@ public class PSBCDataAnalysisHelper { return map; } /** - * 读取开户信息 + * */ private void readETData(File excelFile) { String excelFileName = excelFile.getAbsolutePath(); @@ -578,7 +570,6 @@ public class PSBCDataAnalysisHelper { saveData(); } - log.info("读取邮政储蓄银行流水结束"); } @Override @@ -606,6 +597,76 @@ public class PSBCDataAnalysisHelper { reader.read(sheet); } } + + void readBs20240912(File excelFile, Cells cells, int sheetNo,Cell qtlsh){ + + String cardHolderName = HelperUtil.getStringValue(cells, "客户名称:"); + String cardNumber = HelperUtil.getStringValue(cells, "客户账号:"); + + String sourceFile = HelperUtil.getSourceFileName(excelFile.getAbsolutePath(),BANK_NAME); + try (ExcelReader reader = EasyExcel.read(excelFile).build()) { + ReadSheet sheet = EasyExcel.readSheet(sheetNo) + .headRowNumber(qtlsh.getRow()+1) + .head(ImportCommonStatement.class) + .registerReadListener(new ReadListener() { + private static final int BATCH_SIZE = Constants.BATCH_SIZE; + private List cacheList = + ListUtils.newArrayListWithExpectedSize(BATCH_SIZE); + + @Override + public void invoke(ImportCommonStatement importData, AnalysisContext context) { + String balance = importData.getBalance(); + if (StringUtils.isEmpty(balance)) { // 过滤没有余额的数据 + return; + } + PSBCStatementEntity entry = new PSBCStatementEntity(); + BeanUtil.copyProperties(importData,entry); + + + String id = IdUtil.objectId(); + entry.setId(id); + entry.setCardNumber(cardNumber); + entry.setCardHolderName(cardHolderName); + entry.setSourceFile(sourceFile); + String transactionTime = importData.getTransactionDate() + " " + importData.getTransactionTime(); + entry.setTransactionTime(transactionTime); + String loanFlag = importData.getLoanFlag(); + String transactionAmount = importData.getTransactionAmount(); + BigDecimal bigDecimal = new BigDecimal(transactionAmount); + if (StrUtil.isNotEmpty(loanFlag) && loanFlag.contains("借")) {//transChannel + BigDecimal subtract = bigDecimal.negate(); + entry.setTransactionAmount(subtract.toString()); + } + cacheList.add(entry); + if (cacheList.size() >= BATCH_SIZE) { + saveData(); + cacheList = ListUtils.newArrayListWithExpectedSize(BATCH_SIZE); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 保存不够一百条数据的批次 + if (!cacheList.isEmpty()) { + saveData(); + } + + } + + private void saveData() { + statementMapper.insertBatch(cacheList); + cacheList = ListUtils.newArrayListWithExpectedSize(BATCH_SIZE); + } + }) + .build(); + reader.read(sheet); + } catch (Exception e) { + log.error("读取流水失败", e); + throw new ImportDataFailedException(e.getMessage(), sourceFile); + } + + } + private void readPSBCStatement(File excelFile, Cells cells, int sheetNo) throws Exception { Cell cell = AsposeUtil.getCell(cells, "交易日期"); @@ -617,7 +678,11 @@ public class PSBCDataAnalysisHelper { } Cell rstCell = AsposeUtil.getCell(excelFile, 0, "客户账号"); - if (rstCell != null) {//et模板 + + Cell qtlsh = AsposeUtil.getCell(excelFile, 0, "前台流水号"); + if(qtlsh != null && rstCell != null){ + readBs20240912(excelFile,cells,sheetNo,qtlsh); + }else if(rstCell != null) {//et模板 readETData(excelFile); }else { rstCell = AsposeUtil.getCell(excelFile, 0, "账号卡号"); @@ -723,7 +788,6 @@ public class PSBCDataAnalysisHelper { saveData(); } - log.info("读取邮政储蓄银行流水结束"); } @Override