parent
cc98960c7e
commit
f7ac586fb3
@ -0,0 +1,108 @@ |
||||
package com.jianshui.invoice.domain; |
||||
|
||||
import com.jianshui.common.annotation.Excel; |
||||
import com.jianshui.common.core.domain.BaseEntity; |
||||
import net.logstash.logback.encoder.org.apache.commons.lang3.builder.ToStringBuilder; |
||||
import net.logstash.logback.encoder.org.apache.commons.lang3.builder.ToStringStyle; |
||||
|
||||
/** |
||||
* 开票接口回调对象 invoice_back |
||||
* |
||||
* @author jianshui |
||||
* @date 2023-10-26 |
||||
*/ |
||||
public class InvoiceBack extends BaseEntity |
||||
{ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** $column.columnComment */ |
||||
private String id; |
||||
|
||||
/** 系统订单号 */ |
||||
@Excel(name = "系统订单号") |
||||
private String systemOrderno; |
||||
|
||||
/** 回调状态0未回调 1回调成功 2回调失败 3回调多次失败,不再回调 */ |
||||
@Excel(name = "回调状态0未回调 1回调成功 2回调失败 3回调多次失败,不再回调") |
||||
private String status; |
||||
|
||||
/** 回调地址 */ |
||||
@Excel(name = "回调地址") |
||||
private String backUrl; |
||||
|
||||
/** $column.columnComment */ |
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |
||||
private String identity; |
||||
|
||||
/** 回调信息 */ |
||||
@Excel(name = "回调信息") |
||||
private String backMsg; |
||||
|
||||
public void setId(String id) |
||||
{ |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getId() |
||||
{ |
||||
return id; |
||||
} |
||||
public void setSystemOrderno(String systemOrderno) |
||||
{ |
||||
this.systemOrderno = systemOrderno; |
||||
} |
||||
|
||||
public String getSystemOrderno() |
||||
{ |
||||
return systemOrderno; |
||||
} |
||||
public void setStatus(String status) |
||||
{ |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getStatus() |
||||
{ |
||||
return status; |
||||
} |
||||
public void setBackUrl(String backUrl) |
||||
{ |
||||
this.backUrl = backUrl; |
||||
} |
||||
|
||||
public String getBackUrl() |
||||
{ |
||||
return backUrl; |
||||
} |
||||
public void setIdentity(String identity) |
||||
{ |
||||
this.identity = identity; |
||||
} |
||||
|
||||
public String getIdentity() |
||||
{ |
||||
return identity; |
||||
} |
||||
public void setBackMsg(String backMsg) |
||||
{ |
||||
this.backMsg = backMsg; |
||||
} |
||||
|
||||
public String getBackMsg() |
||||
{ |
||||
return backMsg; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) |
||||
.append("id", getId()) |
||||
.append("systemOrderno", getSystemOrderno()) |
||||
.append("status", getStatus()) |
||||
.append("backUrl", getBackUrl()) |
||||
.append("identity", getIdentity()) |
||||
.append("createTime", getCreateTime()) |
||||
.append("backMsg", getBackMsg()) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.jianshui.invoice.mapper; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.jianshui.invoice.domain.InvoiceBack; |
||||
|
||||
/** |
||||
* 开票接口回调Mapper接口 |
||||
* |
||||
* @author jianshui |
||||
* @date 2023-10-26 |
||||
*/ |
||||
public interface InvoiceBackMapper extends BaseMapper<InvoiceBack> |
||||
{ |
||||
/** |
||||
* 查询开票接口回调 |
||||
* |
||||
* @param id 开票接口回调主键 |
||||
* @return 开票接口回调 |
||||
*/ |
||||
public InvoiceBack selectInvoiceBackById(String id); |
||||
|
||||
/** |
||||
* 查询开票接口回调列表 |
||||
* |
||||
* @param invoiceBack 开票接口回调 |
||||
* @return 开票接口回调集合 |
||||
*/ |
||||
public List<InvoiceBack> selectInvoiceBackList(InvoiceBack invoiceBack); |
||||
|
||||
/** |
||||
* 新增开票接口回调 |
||||
* |
||||
* @param invoiceBack 开票接口回调 |
||||
* @return 结果 |
||||
*/ |
||||
public int insertInvoiceBack(InvoiceBack invoiceBack); |
||||
|
||||
/** |
||||
* 修改开票接口回调 |
||||
* |
||||
* @param invoiceBack 开票接口回调 |
||||
* @return 结果 |
||||
*/ |
||||
public int updateInvoiceBack(InvoiceBack invoiceBack); |
||||
|
||||
/** |
||||
* 删除开票接口回调 |
||||
* |
||||
* @param id 开票接口回调主键 |
||||
* @return 结果 |
||||
*/ |
||||
public int deleteInvoiceBackById(String id); |
||||
|
||||
/** |
||||
* 批量删除开票接口回调 |
||||
* |
||||
* @param ids 需要删除的数据主键集合 |
||||
* @return 结果 |
||||
*/ |
||||
public int deleteInvoiceBackByIds(String[] ids); |
||||
} |
@ -0,0 +1,144 @@ |
||||
package com.jianshui.invoice.task; |
||||
|
||||
import cn.hutool.http.HttpUtil; |
||||
import cn.hutool.json.JSONObject; |
||||
import cn.hutool.json.JSONUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.jianshui.common.utils.StringUtils; |
||||
import com.jianshui.common.utils.spring.SpringUtils; |
||||
import com.jianshui.invoice.domain.Invoice; |
||||
import com.jianshui.invoice.domain.InvoiceBack; |
||||
import com.jianshui.invoice.domain.Redinfo; |
||||
import com.jianshui.invoice.mapper.InvoiceBackMapper; |
||||
import com.jianshui.invoice.mapper.InvoiceMapper; |
||||
import com.jianshui.system.domain.CompanyserviceProp; |
||||
import com.jianshui.system.service.ICompanyservicePropService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 定时任务-发票推送 |
||||
* |
||||
* @author 简税平台 |
||||
*/ |
||||
@Component("invoiceBackTask") |
||||
@Slf4j |
||||
public class InvoiceBackTask |
||||
{ |
||||
|
||||
@Autowired |
||||
private InvoiceBackMapper invoiceBackMapper; |
||||
|
||||
@Autowired |
||||
private InvoiceMapper invoiceMapper; |
||||
|
||||
|
||||
public void bkParams(String params) |
||||
{ |
||||
// 默认10次
|
||||
int j = params == null ? 10: Integer.parseInt(params) ; |
||||
|
||||
log.info("[重汽回调定时任务开始执行]---{}次",params); |
||||
|
||||
QueryWrapper<InvoiceBack> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("status", "0").eq("status","2"); |
||||
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectList(queryWrapper); |
||||
|
||||
for (InvoiceBack invoiceBack : invoiceBackList) { |
||||
|
||||
int i = 0; |
||||
|
||||
while (i < j){ |
||||
|
||||
String id = invoiceBack.getSystemOrderno(); |
||||
String identity = invoiceBack.getIdentity(); |
||||
|
||||
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("未配置回调地址"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
break; |
||||
} |
||||
|
||||
String callBackUrl = secretIdProp.getValue(); |
||||
log.info("【控制台】发票回调,回调地址{}",callBackUrl); |
||||
|
||||
if (id == null) { |
||||
log.info("【控制台】发票回调,id为空"); |
||||
invoiceBack.setStatus("3"); |
||||
invoiceBack.setBackMsg("id为空"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
break; |
||||
} |
||||
|
||||
Invoice invoice = invoiceMapper.selectBySystemOrderNo(null,id); |
||||
if (invoice == null) { |
||||
log.info("【控制台】发票信息未查询到,id={}", id); |
||||
invoiceBack.setStatus("3"); |
||||
invoiceBack.setBackMsg("发票信息未查询到"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
break; |
||||
} |
||||
|
||||
try { |
||||
log.info("【控制台】发票回调接口,发送数据开始,id={}", id); |
||||
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("发票信息未查询到"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
}else if("9999".equals(status)){ |
||||
invoiceBack.setStatus("3"); |
||||
invoiceBack.setBackMsg(message); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
}else { |
||||
invoiceBack.setStatus("3"); |
||||
invoiceBack.setBackMsg(status+message); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
} |
||||
break; |
||||
} |
||||
} catch (Exception e) { |
||||
log.info("【控制台】发票回调接口,发送数据异常,id={}", id); |
||||
invoiceBack.setStatus("2"); |
||||
invoiceBack.setBackMsg("发送数据异常"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
} |
||||
i++; |
||||
|
||||
} |
||||
|
||||
// 一直没结果
|
||||
if(i == j){ |
||||
invoiceBack.setStatus("3"); |
||||
invoiceBack.setBackMsg("调用次数上限一直失败!"); |
||||
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
||||
} |
||||
|
||||
} |
||||
log.info("[重汽回调定时任务执行结束]---"); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -1,87 +0,0 @@ |
||||
package com.jianshui.invoice.task; |
||||
|
||||
import cn.hutool.http.HttpUtil; |
||||
import cn.hutool.json.JSONUtil; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.jianshui.common.core.domain.entity.Companyservice; |
||||
import com.jianshui.common.core.redis.RedisCache; |
||||
import com.jianshui.common.utils.StringUtils; |
||||
import com.jianshui.common.utils.spring.SpringUtils; |
||||
import com.jianshui.framework.manager.AsyncManager; |
||||
import com.jianshui.invoice.domain.BillInfo; |
||||
import com.jianshui.invoice.domain.Invoice; |
||||
import com.jianshui.invoice.domain.dto.QueryBillInfoDTO; |
||||
import com.jianshui.invoice.mapper.InvoiceMapper; |
||||
import com.jianshui.invoice.service.IInvoiceApiService; |
||||
import com.jianshui.queue.utils.RedisQueueUtil; |
||||
import lombok.SneakyThrows; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.TimerTask; |
||||
|
||||
/** |
||||
* @Description 重汽开票回调 |
||||
**/ |
||||
@Slf4j |
||||
public class QueryBackZhongQiTask extends TimerTask { |
||||
|
||||
private String callBackUrl; |
||||
private Long id; |
||||
|
||||
|
||||
public QueryBackZhongQiTask(String callBackUrl, Long id) { |
||||
this.callBackUrl = callBackUrl; |
||||
this.id = id; |
||||
} |
||||
|
||||
@SneakyThrows |
||||
@Override |
||||
public void run() { |
||||
RedisCache redisCache = SpringUtils.getBean(RedisCache.class); |
||||
|
||||
|
||||
InvoiceMapper invoiceMapper = SpringUtils.getBean(InvoiceMapper.class); |
||||
Invoice invoice = invoiceMapper.selectInvoiceById(id); |
||||
if (invoice == null) { |
||||
log.info("【控制台】发票信息未查询到,id={}", id); |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
log.info("【控制台】发票回调接口,发送数据开始,id={}", id); |
||||
String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); |
||||
|
||||
log.info("【控制台】发票回调接口,发送数据结束,id={},接口返回信息={}", id, JSONUtil.toJsonStr(invoice)); |
||||
} catch (Exception e) { |
||||
log.info("【控制台】发票回调接口,发送数据异常,id={}", id); |
||||
return; |
||||
} |
||||
|
||||
// TODO: 2023/10/25 回调队列看一下怎么处理
|
||||
|
||||
|
||||
/* if (invoice == null || StringUtils.equalsAny(Integer.toString(invoice.getState()), "0", "20")) { |
||||
// 查询下失败队列,是否有次数
|
||||
String keys = "invoice_query_times_" + this.companyservice.getCompanyid() + "_" + this.finalBillInfo.getSystemOrderno(); |
||||
Integer queryTimes = redisCache.getCacheObject(keys); |
||||
// 查询重试次数超过20次,就不查了
|
||||
if (queryTimes != null && queryTimes > 20) { |
||||
log.error("【定时任务】【发票查询】发票信息始终不存在,不再进行查询:{}", JSONObject.toJSONString(this.finalBillInfo)); |
||||
redisCache.deleteObject(keys); |
||||
return; |
||||
} |
||||
if (queryTimes == null) { |
||||
queryTimes = 0; |
||||
} |
||||
queryTimes += 1; |
||||
redisCache.setCacheObject(keys, queryTimes); |
||||
log.error("【定时任务】【发票查询】发票信息不存在或还在开票中,再次进入查询:{}", JSONObject.toJSONString(this.finalBillInfo)); |
||||
AsyncManager.me().execute(new QueryBackZhongQiTask(this.finalBillInfo, companyservice, this.invoiceApiService)); |
||||
} |
||||
|
||||
RedisQueueUtil.build().setData(invoice).onQueue("invoice_add_callback_consumer").retry(0).dispatch();*/ |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,82 @@ |
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper |
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.jianshui.invoice.mapper.InvoiceBackMapper"> |
||||
|
||||
<resultMap type="com.jianshui.invoice.domain.InvoiceBack" id="InvoiceBackResult"> |
||||
<result property="id" column="id" /> |
||||
<result property="systemOrderno" column="system_orderno" /> |
||||
<result property="status" column="status" /> |
||||
<result property="backUrl" column="back_url" /> |
||||
<result property="identity" column="identity" /> |
||||
<result property="createTime" column="create_time" /> |
||||
<result property="backMsg" column="back_msg" /> |
||||
</resultMap> |
||||
|
||||
<sql id="selectInvoiceBackVo"> |
||||
select id, system_orderno, status, back_url, identity, create_time, back_msg from invoice_back |
||||
</sql> |
||||
|
||||
<select id="selectInvoiceBackList" parameterType="com.jianshui.invoice.domain.InvoiceBack" resultMap="InvoiceBackResult"> |
||||
<include refid="selectInvoiceBackVo"/> |
||||
<where> |
||||
<if test="systemOrderno != null and systemOrderno != ''"> and system_orderno = #{systemOrderno}</if> |
||||
<if test="status != null and status != ''"> and status = #{status}</if> |
||||
<if test="backUrl != null and backUrl != ''"> and back_url = #{backUrl}</if> |
||||
<if test="identity != null and identity != ''"> and identity = #{identity}</if> |
||||
<if test="backMsg != null and backMsg != ''"> and back_msg = #{backMsg}</if> |
||||
</where> |
||||
</select> |
||||
|
||||
<select id="selectInvoiceBackById" parameterType="String" resultMap="InvoiceBackResult"> |
||||
<include refid="selectInvoiceBackVo"/> |
||||
where id = #{id} |
||||
</select> |
||||
|
||||
<insert id="insertInvoiceBack" parameterType="com.jianshui.invoice.domain.InvoiceBack"> |
||||
insert into invoice_back |
||||
<trim prefix="(" suffix=")" suffixOverrides=","> |
||||
<if test="id != null">id,</if> |
||||
<if test="systemOrderno != null">system_orderno,</if> |
||||
<if test="status != null">status,</if> |
||||
<if test="backUrl != null">back_url,</if> |
||||
<if test="identity != null">identity,</if> |
||||
<if test="createTime != null">create_time,</if> |
||||
<if test="backMsg != null">back_msg,</if> |
||||
</trim> |
||||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
||||
<if test="id != null">#{id},</if> |
||||
<if test="systemOrderno != null">#{systemOrderno},</if> |
||||
<if test="status != null">#{status},</if> |
||||
<if test="backUrl != null">#{backUrl},</if> |
||||
<if test="identity != null">#{identity},</if> |
||||
<if test="createTime != null">#{createTime},</if> |
||||
<if test="backMsg != null">#{backMsg},</if> |
||||
</trim> |
||||
</insert> |
||||
|
||||
<update id="updateInvoiceBack" parameterType="com.jianshui.invoice.domain.InvoiceBack"> |
||||
update invoice_back |
||||
<trim prefix="SET" suffixOverrides=","> |
||||
<if test="systemOrderno != null">system_orderno = #{systemOrderno},</if> |
||||
<if test="status != null">status = #{status},</if> |
||||
<if test="backUrl != null">back_url = #{backUrl},</if> |
||||
<if test="identity != null">identity = #{identity},</if> |
||||
<if test="createTime != null">create_time = #{createTime},</if> |
||||
<if test="backMsg != null">back_msg = #{backMsg},</if> |
||||
</trim> |
||||
where id = #{id} |
||||
</update> |
||||
|
||||
<delete id="deleteInvoiceBackById" parameterType="String"> |
||||
delete from invoice_back where id = #{id} |
||||
</delete> |
||||
|
||||
<delete id="deleteInvoiceBackByIds" parameterType="String"> |
||||
delete from invoice_back where id in |
||||
<foreach item="id" collection="array" open="(" separator="," close=")"> |
||||
#{id} |
||||
</foreach> |
||||
</delete> |
||||
</mapper> |
@ -0,0 +1,34 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace=".dao.InvoiceBackDao"> |
||||
|
||||
<resultMap type=".entity.InvoiceBack" id="InvoiceBackMap"> |
||||
<result property="id" column="id" jdbcType="VARCHAR"/> |
||||
<result property="systemOrderno" column="system_orderno" jdbcType="VARCHAR"/> |
||||
<result property="status" column="status" jdbcType="VARCHAR"/> |
||||
<result property="backUrl" column="back_url" jdbcType="VARCHAR"/> |
||||
<result property="identity" column="identity" jdbcType="VARCHAR"/> |
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> |
||||
<result property="backMsg" column="back_msg" jdbcType="VARCHAR"/> |
||||
</resultMap> |
||||
|
||||
<!-- 批量插入 --> |
||||
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> |
||||
insert into jianshui_dev.invoice_back(system_ordernostatusback_urlidentitycreate_timeback_msg) |
||||
values |
||||
<foreach collection="entities" item="entity" separator=","> |
||||
(#{entity.systemOrderno}#{entity.status}#{entity.backUrl}#{entity.identity}#{entity.createTime}#{entity.backMsg}) |
||||
</foreach> |
||||
</insert> |
||||
<!-- 批量插入或按主键更新 --> |
||||
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true"> |
||||
insert into jianshui_dev.invoice_back(system_ordernostatusback_urlidentitycreate_timeback_msg) |
||||
values |
||||
<foreach collection="entities" item="entity" separator=","> |
||||
(#{entity.systemOrderno}#{entity.status}#{entity.backUrl}#{entity.identity}#{entity.createTime}#{entity.backMsg}) |
||||
</foreach> |
||||
on duplicate key update |
||||
system_orderno = values(system_orderno) status = values(status) back_url = values(back_url) identity = values(identity) create_time = values(create_time) back_msg = values(back_msg) </insert> |
||||
|
||||
</mapper> |
||||
|
Loading…
Reference in new issue