|
|
|
@ -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; |
|
|
|
@ -36,8 +37,7 @@ import java.util.*; |
|
|
|
|
*/ |
|
|
|
|
@Component("invoiceBackTask") |
|
|
|
|
@Slf4j |
|
|
|
|
public class InvoiceBackTask |
|
|
|
|
{ |
|
|
|
|
public class InvoiceBackTask { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private InvoiceBackMapper invoiceBackMapper; |
|
|
|
@ -56,11 +56,9 @@ public class InvoiceBackTask |
|
|
|
|
* @author kk |
|
|
|
|
* @date 9:03 |
|
|
|
|
* @param: [params] |
|
|
|
|
* @return: |
|
|
|
|
* 开票回调 |
|
|
|
|
* @return: 开票回调 |
|
|
|
|
*/ |
|
|
|
|
public void bkParams(String params) |
|
|
|
|
{ |
|
|
|
|
public void bkParams(String params) { |
|
|
|
|
// TODO: 2023/11/9 回调次数处理
|
|
|
|
|
// 默认1次 定时任务控制,补偿机制
|
|
|
|
|
int j = params == null ? 1 : Integer.parseInt(params); |
|
|
|
@ -168,8 +166,7 @@ public class InvoiceBackTask |
|
|
|
|
* @author kk |
|
|
|
|
* @date 2023/11/14 9:03 |
|
|
|
|
* @param: [] |
|
|
|
|
* @return: |
|
|
|
|
* 机动车加密导出-定时任务 |
|
|
|
|
* @return: 机动车加密导出-定时任务 |
|
|
|
|
*/ |
|
|
|
|
public void exportVehicleInvoice() { |
|
|
|
|
// 查询配置的nginx地址
|
|
|
|
@ -213,29 +210,92 @@ public class InvoiceBackTask |
|
|
|
|
|
|
|
|
|
// 发票回调补偿机制。
|
|
|
|
|
|
|
|
|
|
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("[重汽回调定时任务执行结束]---"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|