feature: 重汽 发票回调补偿机制

jianshui-ui
dongxiaoke 1 year ago
parent 7df7d9dcff
commit 38388b9599
  1. 176
      jianshui-invoice/src/main/java/com/jianshui/invoice/task/InvoiceBackTask.java

@ -1,6 +1,7 @@
package com.jianshui.invoice.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@ -31,13 +32,12 @@ import java.util.*;
/**
* 定时任务-发票推送
*
*
* @author 简税平台
*/
@Component("invoiceBackTask")
@Slf4j
public class InvoiceBackTask
{
public class InvoiceBackTask {
@Autowired
private InvoiceBackMapper invoiceBackMapper;
@ -53,29 +53,27 @@ public class InvoiceBackTask
/**
* @author kk
* @date 9:03
* @param: [params]
* @return:
* 开票回调
*/
public void bkParams(String params)
{
* @author kk
* @date 9:03
* @param: [params]
* @return: 开票回调
*/
public void bkParams(String params) {
// TODO: 2023/11/9 回调次数处理
// 默认1次 定时任务控制,补偿机制
int j = params == null ? 1: Integer.parseInt(params) ;
int j = params == null ? 1 : Integer.parseInt(params);
log.info("[重汽回调定时任务开始执行]---{}次",params);
log.info("[重汽回调定时任务开始执行]---{}次", params);
QueryWrapper<InvoiceBack> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", "0").or().eq("status","2").or().eq("status","3");
queryWrapper.eq("status", "0").or().eq("status", "2").or().eq("status", "3");
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectList(queryWrapper);
for (InvoiceBack invoiceBack : invoiceBackList) {
int i = 0;
while (i < j){
while (i < j) {
String id = invoiceBack.getSystemOrderno();
String identity = invoiceBack.getIdentity();
@ -83,8 +81,8 @@ public class InvoiceBackTask
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url");
if(secretIdProp == null || secretIdProp.getValue()==null || "".equals(secretIdProp.getValue())){
log.info("【控制台】发票回调,未配置回调地址{}"+identity);
if (secretIdProp == null || secretIdProp.getValue() == null || "".equals(secretIdProp.getValue())) {
log.info("【控制台】发票回调,未配置回调地址{}" + identity);
invoiceBack.setStatus("3");
invoiceBack.setBackMsg("未配置回调地址");
invoiceBack.setUpdateTime(new Date());
@ -93,7 +91,7 @@ public class InvoiceBackTask
}
String callBackUrl = secretIdProp.getValue();
log.info("【控制台】发票回调,回调地址{}",callBackUrl);
log.info("【控制台】发票回调,回调地址{}", callBackUrl);
if (id == null) {
log.info("【控制台】发票回调,id为空");
@ -104,38 +102,38 @@ public class InvoiceBackTask
break;
}
Invoice invoice = invoiceMapper.selectByOutTradeOrderno(Long.valueOf(identity),id,"0");
Invoice invoice = invoiceMapper.selectByOutTradeOrderno(Long.valueOf(identity), id, "0");
if (invoice == null) {
log.info("【控制台】发票信息未查询到,id={}", id);
invoice = new Invoice();
invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno());
invoice.setState(22);
invoice.setMessage(invoiceBack.getResultMsg() != null ? invoiceBack.getResultMsg().substring(0,200):"");
invoice.setMessage(invoiceBack.getResultMsg() != null ? invoiceBack.getResultMsg().substring(0, 200) : "");
}
try {
log.info("【控制台】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id,invoice.getOutTradeOrderno(),callBackUrl,JSONUtil.toJsonStr(invoice));
log.info("【控制台】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id, invoice.getOutTradeOrderno(), callBackUrl, JSONUtil.toJsonStr(invoice));
String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice));
log.info("【控制台】发票回调接口,发送数据结束,id={},接口返回信息={}", id, result);
JSONObject jsonObject = JSONUtil.parseObj(result);
if(jsonObject != null){
String status = jsonObject.get("status") != null ? jsonObject.get("status").toString():"";
String message = jsonObject.get("message")!= null ? jsonObject.get("message").toString():"";
if (jsonObject != null) {
String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : "";
String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : "";
if("0000".equals(status)){
if ("0000".equals(status)) {
invoiceBack.setStatus("1");
invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
}else if("9999".equals(status)){
} else if ("9999".equals(status)) {
invoiceBack.setStatus("3");
invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
}else {
} else {
invoiceBack.setStatus("3");
invoiceBack.setBackMsg(status+message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
}
@ -153,7 +151,7 @@ public class InvoiceBackTask
}
// 一直没结果
if(i == j){
if (i == j) {
invoiceBack.setStatus("3");
invoiceBack.setBackMsg("调用次数上限一直失败!");
invoiceBackMapper.updateInvoiceBack(invoiceBack);
@ -165,19 +163,18 @@ public class InvoiceBackTask
/**
* @author kk
* @date 2023/11/14 9:03
* @param: []
* @return:
* 机动车加密导出-定时任务
*/
public void exportVehicleInvoice(){
* @author kk
* @date 2023/11/14 9:03
* @param: []
* @return: 机动车加密导出-定时任务
*/
public void exportVehicleInvoice() {
// 查询配置的nginx地址
log.info("[重汽机动车加密导出定时任务开始]---");
CompanyserviceProp companyservicePropQuery = new CompanyserviceProp();
companyservicePropQuery.setKey("aisino_nginx_url");
List<CompanyserviceProp> companyservicePropList = propService.selectCompanyservicePropList(companyservicePropQuery);
log.info("[重汽机动车加密导出定时任务]获取到待发送identity集合,{}",JSONUtil.toJsonStr(companyservicePropList));
log.info("[重汽机动车加密导出定时任务]获取到待发送identity集合,{}", JSONUtil.toJsonStr(companyservicePropList));
for (CompanyserviceProp companyserviceProp : companyservicePropList) {
// 参数组装
@ -191,8 +188,8 @@ public class InvoiceBackTask
try {
IInvoiceApiService iInvoiceApiService = new AisinoConsoleInvoiceApiZhongQiServiceImpl();
HXResponse hxResponse = iInvoiceApiService.exportVehicleInvoice(JSON.parseObject(JSONUtil.toJsonStr(exportVehicleDTO)),companyservice);
log.info("[重汽机动车加密导出定时任务]返回结果,hxResponse={},identity={}",hxResponse,companyserviceProp.getCompanyid());
HXResponse hxResponse = iInvoiceApiService.exportVehicleInvoice(JSON.parseObject(JSONUtil.toJsonStr(exportVehicleDTO)), companyservice);
log.info("[重汽机动车加密导出定时任务]返回结果,hxResponse={},identity={}", hxResponse, companyserviceProp.getCompanyid());
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -204,38 +201,101 @@ public class InvoiceBackTask
/**
* @author kk
* @date 2024/4/10 20:32
* @param: []
* @return: 重汽数电回推补偿机制
*/
public void sdBackInvoice(){
* @author kk
* @date 2024/4/10 20:32
* @param: []
* @return: 重汽数电回推补偿机制
*/
public void sdBackInvoice() {
// 发票回调补偿机制。
log.info("[重汽回调定时任务开始执行]");
QueryWrapper<InvoiceBack> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", "0").or().eq("status", "2").or().eq("status", "3");
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectList(queryWrapper);
log.info("【重汽回调】查询到{}条带回调订单", invoiceBackList.size());
for (InvoiceBack invoiceBack : invoiceBackList) {
String id = invoiceBack.getSystemOrderno();
String identity = invoiceBack.getIdentity();
}
if (StrUtil.isEmpty(id)) {
log.info("【控制台】发票回调,id为空");
invoiceBack.setStatus("3");
invoiceBack.setBackMsg("id为空");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
break;
}
log.info("【重汽回调】订单号{},开始回调", id);
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url");
if (secretIdProp == null || secretIdProp.getValue() == null || "".equals(secretIdProp.getValue())) {
log.info("【控制台】发票回调,未配置回调地址{}",identity);
invoiceBack.setStatus("3");
invoiceBack.setBackMsg("未配置回调地址");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
break;
}
String callBackUrl = secretIdProp.getValue();
log.info("【控制台】发票回调,订单号{},回调地址{}",id, callBackUrl);
Invoice invoice = invoiceMapper.selectByOutTradeOrderno(Long.valueOf(identity), id, "0");
if (invoice == null) {
log.info("【控制台】发票信息未查询到,id={}", id);
invoice = new Invoice();
invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno());
invoice.setState(22);
invoice.setMessage(invoiceBack.getResultMsg() != null ? invoiceBack.getResultMsg().substring(0, 200) : "");
break;
}
try {
log.info("【控制台】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id, invoice.getOutTradeOrderno(), callBackUrl, JSONUtil.toJsonStr(invoice));
String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice));
log.info("【控制台】发票回调接口,发送数据结束,id={},接口返回信息={}", id, result);
JSONObject jsonObject = JSONUtil.parseObj(result);
if (jsonObject != null) {
String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : "";
String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : "";
if ("0000".equals(status)) {
invoiceBack.setStatus("1");
invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
} else if ("9999".equals(status)) {
invoiceBack.setStatus("3");
invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
} else {
invoiceBack.setStatus("3");
invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
}
break;
}
} catch (Exception e) {
log.info("【控制台】发票回调接口,发送数据异常,id={}", id);
invoiceBack.setStatus("2");
invoiceBack.setBackMsg("发送数据异常");
invoiceBack.setUpdateTime(new Date());
invoiceBackMapper.updateInvoiceBack(invoiceBack);
}
}
log.info("[重汽回调定时任务执行结束]---");
}
}

Loading…
Cancel
Save