这个是用Java的内置类实现的导入excel:
public ResponseData pup2PubTransfer(@RequestParam MultipartFile file, HttpServletResponse response) throws Exception {
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setSheetNum(2);
params.setNeedVerfiy(true);
ExcelImportResult<OmsPubBankFlowExcelEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
OmsPubBankFlowExcelEntity.class, params);
//List<OmsPubBankFlowExcelEntity> list= ExcelImportUtil.importExcel(file.getInputStream(), OmsPubBankFlowExcelEntity.class,params);
//校验 客户名称,金额,交易时间不能为空,如果有一条不满足则返回,没有则存储
if (result.getFailList().size() > 0) {
OutputStream fos = response.getOutputStream();
result.getWorkbook().write(fos);
fos.close();
} else { ...
导入并校验:
@ApiOperation("公对公转账银行流水记录导入")
@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseData pup2PubTransfer(@RequestParam MultipartFile file, HttpServletResponse response) throws Exception {
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setSheetNum(2);
params.setNeedVerfiy(true);
ExcelImportResult<OmsPubBankFlowExcelEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
OmsPubBankFlowExcelEntity.class, params);
//List<OmsPubBankFlowExcelEntity> list= ExcelImportUtil.importExcel(file.getInputStream(), OmsPubBankFlowExcelEntity.class,params);
//校验 客户名称,金额,交易时间不能为空,如果有一条不满足则返回,没有则存储
if (result.getFailList().size() > 0) {
OutputStream fos = response.getOutputStream();
result.getWorkbook().write(fos);
fos.close();
} else {
List<OmsPubBankFlowExcelEntity> omsPubBankFlowExcelEntitys = result.getList();
//先做单,对公
List<OmsOrder> pubOmsOrders = omsOrderService.queryVerifyOrder(BizConstants.CWDZ_DG_XZD.getCode());
//后做单,已预收,预收款做单
List<OmsOrder> advanceOmsOrders=omsOrderService.queryVerifyOrder(BizConstants.CWDZ_DG_YSK_YZD.getCode());
pubOmsOrders.addAll(advanceOmsOrders);
List handOrder=new ArrayList();
List exceptionOrder=new ArrayList();
Iterator<OmsPubBankFlowExcelEntity> iterator = omsPubBankFlowExcelEntitys.iterator();
while (iterator.hasNext()){
OmsPubBankFlowExcelEntity entity=iterator.next();
for(OmsOrder omsOrder:pubOmsOrders){
String amount=entity.getAmount();
BigDecimal bankAmount=new BigDecimal(amount);
BigDecimal orderAmount=omsOrder.getTotalAmount();
String orderTime = DateUtil.format(omsOrder.getCreateTime(), "yyyy-MM");
String bankTime=DateUtil.format(entity.getTransferTime(), "yyyy-MM");
if(entity.getAccName().equals(omsOrder.getKhmc())
&& (orderAmount.compareTo(bankAmount)==0) && orderTime.equals(bankTime)){
omsOrder.setPayStatus(BizConstants.ZFZT_YZF.getCode());
if(!handOrder.contains(omsOrder)){
handOrder.add(omsOrder);
}else{
omsOrder.setPayStatus(BizConstants.ZFZT_WZF.getCode());
exceptionOrder.add(omsOrder);
}
iterator.remove();
}
}
}
}
return null;
}