增加对账功能异常捕获和处理

This commit is contained in:
panshuling321 2022-04-22 11:34:49 +08:00
parent 5f5a4c377e
commit e0aaee803e
6 changed files with 294 additions and 251 deletions

View File

@ -1,6 +1,8 @@
package com.xhpc.activity.controller;
import com.xhpc.activity.domain.XhpcTradebillUploadRecordDomain;
import com.xhpc.activity.service.CommonService;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
@ -8,8 +10,6 @@ import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.common.util.LogUserUtils;
import com.xhpc.system.api.model.LoginUser;
import com.xhpc.activity.domain.XhpcTradebillUploadRecordDomain;
import com.xhpc.activity.service.CommonService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -21,7 +21,7 @@ import java.util.Map;
@RestController
@RequestMapping("/common")
public class CommonController extends BaseController {
public class XhpcTradebillCommonController extends BaseController {
@Resource
CommonService commonService;

View File

@ -1,13 +1,13 @@
package com.xhpc.activity.controller;
import com.xhpc.activity.domain.XhpcTradebillInternetCheckRecordDomain;
import com.xhpc.activity.service.InternetBillService;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.activity.domain.XhpcTradebillInternetCheckRecordDomain;
import com.xhpc.activity.service.InternetBillService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -17,7 +17,7 @@ import java.util.Map;
@RestController
@RequestMapping("/internet")
public class InternetBillController extends BaseController {
public class XhpcTradebillInternetBillController extends BaseController {
@Resource

View File

@ -1,13 +1,13 @@
package com.xhpc.activity.controller;
import com.xhpc.activity.domain.XhpcTradebillPaymentCheckRecordDomain;
import com.xhpc.activity.service.PaymentBillService;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.activity.domain.XhpcTradebillPaymentCheckRecordDomain;
import com.xhpc.activity.service.PaymentBillService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -17,7 +17,7 @@ import java.util.Map;
@RestController
@RequestMapping("/payment")
public class PaymentBillController extends BaseController {
public class XhpcTradebillPaymentBillController extends BaseController {
@Resource
PaymentBillService paymentBillService;

View File

@ -1,6 +1,7 @@
package com.xhpc.activity.service.impl;
import com.aliyun.oss.OSSClient;
import com.xhpc.common.core.exception.CustomException;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.activity.config.AliOSSProperties;
import com.xhpc.activity.domain.XhpcTradebillInternetCheckRecordDomain;
@ -19,6 +20,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@ -59,6 +61,7 @@ public class CommonServiceImpl implements CommonService {
Map<String, Integer> totalMap = new HashMap<>();
int insertCount = 0;
resDomain.setStatus(2);
try {
switch (domain.getType()) {
case 1:
case 2:
@ -113,6 +116,11 @@ public class CommonServiceImpl implements CommonService {
resDomain.setUncheckCount(totalMap.get("uncheckCount"));
uploadRecordMapper.updateByPrimaryKey(resDomain);
return resDomain;
} catch (Exception exception){
exception.printStackTrace();
throw new CustomException("内部错误");
}
}
@ -121,9 +129,10 @@ public class CommonServiceImpl implements CommonService {
XhpcTradebillUploadRecordDomain domain = new XhpcTradebillUploadRecordDomain();
// 创建OSSClient实例
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
String suffix = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf(".") + 1);
File dataFile = File.createTempFile("temp_", suffix);
try{
file.transferTo(dataFile);
String ossPath = "bill/" + file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) + "_" + System.currentTimeMillis() + "." + suffix;
@ -138,8 +147,10 @@ public class CommonServiceImpl implements CommonService {
domain.setEndTime(endTime);
domain.setType(type);
domain.setTenantId(tenantId);
return ossUpload(domain);
} catch (Exception exception){
throw new CustomException("服务错误");
}
}
@Override

View File

@ -7,6 +7,7 @@ import cn.hutool.core.text.csv.CsvReader;
import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.xhpc.common.core.exception.CustomException;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.utils.poi.ExcelUtil;
import com.xhpc.activity.domain.XhpcHistoryOrderDomain;
@ -182,6 +183,7 @@ public class InternetBillServiceImpl implements InternetBillService {
List<HDTradebillVo> hdTradebillVoList = new ArrayList<>();
List<String> serialNumberList = new ArrayList<>();
try {
switch (suffix.toUpperCase()) {
case "XLS":
case "XLSX":
@ -196,6 +198,10 @@ public class InternetBillServiceImpl implements InternetBillService {
default:
break;
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
for (HDTradebillVo vo : hdTradebillVoList) {
XhpcTradebillInternetCheckRecordDomain domain = new XhpcTradebillInternetCheckRecordDomain();
@ -245,6 +251,7 @@ public class InternetBillServiceImpl implements InternetBillService {
List<XJTradeBillVo> xjTradeBillVoList = new ArrayList<>();
List<String> serialNumberList = new ArrayList<>();
try {
switch (suffix.toUpperCase()) {
case "XLS":
case "XLSX":
@ -259,6 +266,10 @@ public class InternetBillServiceImpl implements InternetBillService {
default:
break;
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
for (XJTradeBillVo vo : xjTradeBillVoList) {
XhpcTradebillInternetCheckRecordDomain domain = new XhpcTradebillInternetCheckRecordDomain();
@ -312,6 +323,7 @@ public class InternetBillServiceImpl implements InternetBillService {
List<XDTTradebillVo> xdtTradebillVoList = new ArrayList<>();
List<String> serialNumberList = new ArrayList<>();
try {
switch (suffix.toUpperCase()) {
case "XLS":
case "XLSX":
@ -326,6 +338,10 @@ public class InternetBillServiceImpl implements InternetBillService {
default:
break;
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
for (XDTTradebillVo vo : xdtTradebillVoList) {
XhpcTradebillInternetCheckRecordDomain domain = new XhpcTradebillInternetCheckRecordDomain();
@ -374,6 +390,7 @@ public class InternetBillServiceImpl implements InternetBillService {
List<Map<String, Object>> dataList = new ArrayList<>();
List<String> serialNumberList = new ArrayList<>();
try {
switch (suffix.toUpperCase()) {
case "XLS":
case "XLSX":
@ -384,7 +401,10 @@ public class InternetBillServiceImpl implements InternetBillService {
default:
break;
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
for (KDTradebillVo vo : kdTradebillVoList) {
if (vo.getOrderNo().equals("交易订单号") || StrUtil.hasBlank(vo.getOrderNo())) {

View File

@ -9,6 +9,7 @@ import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.xhpc.common.core.exception.CustomException;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.activity.domain.XhpcTradebillPaymentCheckRecordDomain;
import com.xhpc.activity.mapper.XhpcRechargeOrderMapper;
@ -139,6 +140,7 @@ public class PaymentBillServiceImpl implements PaymentBillService {
List<XhpcTradebillPaymentCheckRecordDomain> paymentCheckRecordDomainList = new ArrayList<>();
String suffix = dataFile.getName().substring(dataFile.getName().lastIndexOf(".") + 1);
System.out.println(dataFile.getAbsolutePath());
try {
switch (suffix.toUpperCase()) {
case "CSV":
CsvReader csvReader = CsvUtil.getReader();
@ -222,6 +224,10 @@ public class PaymentBillServiceImpl implements PaymentBillService {
default:
throw new Exception("暂不支持的文件格式");
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
paymentCheckRecordDomainList.sort(Comparator.comparing(XhpcTradebillPaymentCheckRecordDomain::getStatus));
return paymentCheckRecordDomainList;
@ -252,6 +258,7 @@ public class PaymentBillServiceImpl implements PaymentBillService {
List<XhpcTradebillPaymentCheckRecordDomain> paymentCheckRecordDomainList = new ArrayList<>();
String suffix = dataFile.getName().substring(dataFile.getName().lastIndexOf(".") + 1);
try {
if ("CSV".equalsIgnoreCase(suffix)) {// 微信充值订单格式
CsvReader csvReader = CsvUtil.getReader();
CsvData data = csvReader.read(dataFile);
@ -314,6 +321,11 @@ public class PaymentBillServiceImpl implements PaymentBillService {
} else {
throw new Exception("暂不支持的文件格式");
}
} catch (Exception e){
e.printStackTrace();
throw new CustomException("文件数据不合规,请检查");
}
paymentCheckRecordDomainList.sort(Comparator.comparing(XhpcTradebillPaymentCheckRecordDomain::getStatus));
return paymentCheckRecordDomainList;
}