|
|
@ -1,6 +1,8 @@ |
|
|
|
package com.inscloudtech.bankStatementAnalysis.helper; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
@ -17,6 +19,8 @@ import com.alibaba.excel.util.ListUtils; |
|
|
|
import com.aspose.cells.*; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
|
|
|
|
import com.inscloudtech.bankStatementAnalysis.domain.ImportCommonStatement; |
|
|
|
import com.inscloudtech.bankStatementAnalysis.domain.entity.PSBCStatementEntity; |
|
|
|
import com.inscloudtech.bankStatementAnalysis.helper.HelperUtil; |
|
|
|
import com.inscloudtech.bankStatementAnalysis.service.ImportService; |
|
|
|
import com.inscloudtech.common.constant.BankStatementConstants; |
|
|
@ -104,7 +108,8 @@ public class CIBDataAnalysisHelper { |
|
|
|
throw new TemplateNotFindException(sourceFileWithSheetName); |
|
|
|
}else { |
|
|
|
Cell c = AsposeUtil.getCell(cells, "信用卡历史账单"); |
|
|
|
if (tradeCell != null && c == null) { |
|
|
|
Cell creditCardFlag = AsposeUtil.getCell(cells, "名下的交易明细"); |
|
|
|
if (tradeCell != null && c == null && creditCardFlag == null) { |
|
|
|
ExcelReader reader = EasyExcel.read(excelFile).build(); |
|
|
|
Class<CIBStatementEntity> clazz = CIBStatementEntity.class; |
|
|
|
ReadSheet sheet = EasyExcel.readSheet(sheetNo) |
|
|
@ -115,6 +120,8 @@ public class CIBDataAnalysisHelper { |
|
|
|
reader.read(sheet); |
|
|
|
}else if(c != null){ |
|
|
|
readCreditCardBS(cells,sourceFileWithSheetName,caseId,sheetNo,excelFile); |
|
|
|
}else if(creditCardFlag != null){ |
|
|
|
readCreditCardBS20240913(cells,sourceFileWithSheetName,caseId,sheetNo,excelFile,creditCardFlag); |
|
|
|
}else { |
|
|
|
throw new TemplateNotFindException(sourceFileWithSheetName); |
|
|
|
} |
|
|
@ -129,6 +136,74 @@ public class CIBDataAnalysisHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void readCreditCardBS20240913(Cells cells, String sourceFileWithSheetName, String caseId, int sheetNo, File excelFile, Cell creditCardFlag) { |
|
|
|
|
|
|
|
String value = creditCardFlag.getStringValue(); // 尊敬的xxx先生/女士: |
|
|
|
String[] split = value.split("名下的交易明细"); |
|
|
|
// 客户名称 |
|
|
|
String cardHolderName = split[0]; |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(cardHolderName)) { |
|
|
|
throw new ImportDataFailedException("无法获取客户名称.",sourceFileWithSheetName); |
|
|
|
} |
|
|
|
|
|
|
|
Cell tr = AsposeUtil.getCell(cells, "交易日期"); |
|
|
|
|
|
|
|
try (ExcelReader r = EasyExcel.read(excelFile).build()) { |
|
|
|
String finalCardHolderName = cardHolderName; |
|
|
|
ReadSheet readSheet = EasyExcel.readSheet(sheetNo) |
|
|
|
.headRowNumber(tr.getRow() + 1) |
|
|
|
.head(ImportCommonStatement.class) |
|
|
|
.registerReadListener(new ReadListener<ImportCommonStatement>() { |
|
|
|
private static final int BATCH_SIZE = Constants.BATCH_SIZE; |
|
|
|
private List<CIBCreditCardBSEntity> cacheList = |
|
|
|
ListUtils.newArrayListWithExpectedSize(BATCH_SIZE); |
|
|
|
|
|
|
|
@Override |
|
|
|
public void invoke(ImportCommonStatement importData, AnalysisContext context) { |
|
|
|
CIBCreditCardBSEntity entry = new CIBCreditCardBSEntity(); |
|
|
|
BeanUtil.copyProperties(importData,entry); |
|
|
|
|
|
|
|
String id = IdUtil.objectId(); |
|
|
|
entry.setId(id); |
|
|
|
|
|
|
|
entry.setCardHolderName(finalCardHolderName); |
|
|
|
entry.setSourceFile(sourceFileWithSheetName); |
|
|
|
String transactionTime1 = importData.getTransactionTime(); |
|
|
|
if(transactionTime1.length() == 8){ |
|
|
|
transactionTime1 = transactionTime1.substring(0,6); |
|
|
|
} |
|
|
|
String transactionTime = importData.getTransactionDate() + transactionTime1; |
|
|
|
entry.setTransactionTime(DateUtil.parse(transactionTime, DatePattern.PURE_DATETIME_FORMAT)); |
|
|
|
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() { |
|
|
|
esCIBCreditCardBankStatementMapper.insertBatch(cacheList); |
|
|
|
cacheList = ListUtils.newArrayListWithExpectedSize(BATCH_SIZE); |
|
|
|
} |
|
|
|
}) |
|
|
|
.build(); |
|
|
|
r.read(readSheet); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getMessage(), e); |
|
|
|
throw new ImportDataFailedException(e.getMessage(), sourceFileWithSheetName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void readBSWithLikeCSV(Cells cells, String caseId,String sourceFile,int headRow) { |
|
|
|
try { |
|
|
|
Cell cardHolderNameCell = cells.get(0, 0); |
|
|
@ -277,7 +352,9 @@ public class CIBDataAnalysisHelper { |
|
|
|
String cardHolderName = entity.getCardHolderName(); |
|
|
|
bs.setCardHolderName(cardHolderName); |
|
|
|
importService.setIdCardAndCardNumberByCardHolderName(oaiMap,cardHolderName,bs); |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(bs.getCardNumber())){ |
|
|
|
bs.setCardNumber(entity.getCardNumber()); |
|
|
|
} |
|
|
|
bs.setSummary(entity.getSummary()); |
|
|
|
bs.setTransCurrencyType(Constants.CURRENCY_TYPE_CHINA); |
|
|
|
bs.setTransactionAmount(BigDecimal.valueOf(Double.parseDouble(entity.getTransactionAmount()))); |
|
|
|