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