This commit is contained in:
linfso 2024-08-02 17:11:38 +08:00
parent a46a631310
commit 59b216b430
6 changed files with 71 additions and 41 deletions

View File

@ -80,9 +80,13 @@ public class EmisCommonController extends EmisBaseController
@Autowired
private IEmisPrintTplService emisPrintTplService;
@Autowired
private IEmisSettleInvoiceChRecordService emisSettleInvoiceChRecordService;
@Autowired
RedissonService redissonService;
/**
* 获取中心可用简单数
* @param prefix
@ -478,7 +482,7 @@ public class EmisCommonController extends EmisBaseController
// 加锁查询
redissonService.lock(lockKey,300);
try{
emisBaseService.autoDoSmsSend();
emisSettleInvoiceChRecordService.autoDoQueryOpenBillStatus();
}catch(Exception ex){
ex.printStackTrace();
log.error("autoQueryInvoiceStatusTrigger exception:"+ex.getMessage());
@ -486,7 +490,7 @@ public class EmisCommonController extends EmisBaseController
log.error("autoQueryInvoiceStatusTrigger end");
redissonService.unlock(lockKey);
return AjaxResult.success("发送成功");
return AjaxResult.success("成功");
}

View File

@ -50,6 +50,8 @@ public class EmisSettleInvoiceChRecordController extends BaseController
@Autowired
private IEmisSettleInvoiceChRecordService emisSettleInvoiceChRecordService;
/**
* 查询渠道开票记录表列表
*/

View File

@ -40,6 +40,15 @@ public interface EmisSettleInvoiceChRecordMapper extends BaseMapper<EmisSettleIn
public List<EmisSettleInvoiceChRecord> selectEmisSettleInvoiceChRecordList(EmisSettleInvoiceChRecord emisSettleInvoiceChRecord);
/**
* 获取待查询状态的数据
* @return
*/
public List<EmisSettleInvoiceChRecord> selectWaitQueryStatusList();
/**
* 检查是否重复
*

View File

@ -78,4 +78,6 @@ public interface IEmisSettleInvoiceChRecordService
public int deleteEmisSettleInvoiceChRecordById(Long id);
public int sendHXToOpen(Long id) throws EmisBizError;
public void autoDoQueryOpenBillStatus();
}

View File

@ -108,22 +108,20 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
EmisSettleInvoiceChRecord old=selectEmisSettleInvoiceChRecordById(id);
// 0-未发送 1-开票中 2-开票成功 3-开票失败
if(
!"0".equals(old.getOpenChStatus())
&& !"3".equals(old.getOpenChStatus())
if(old==null){
throw new EmisBizError(EmisBizErrorType.FAIL,"航信开票记录不存在");
}
){
throw new EmisBizError(EmisBizErrorType.FAIL,"当前状态不允许发送");
// 0-未发送 1-开票中 2-开票成功 3-开票失败
if("1".equals(old.getOpenChStatus()) || "2".equals(old.getOpenChStatus()) ){
throw new EmisBizError(EmisBizErrorType.FAIL,"航信开票中或已开票状态不允许发送开票");
}
EmisBaseInvoiceChInfo emisBaseInvoiceChInfo=emisBaseInvoiceChInfoMapper.selectEmisBaseInvoiceChInfoByTaxNo(old.getSalerCompanyTaxNo());
HXOrderInfo order = new HXOrderInfo();
String token=HXSdk.getToken(emisBaseInvoiceChInfo.getAppKey(),emisBaseInvoiceChInfo.getAppSecret());
// 91320104MA258WWMX2 丝路卡航(江苏)物流服务有限公司 4000251756 南京市秦淮区正学路1号南京晨光1865创意产业园F3幢1527号 交通银行股份有限公司南京新街口支行 320899991013001239978 2024-07-24 11:19:25 2024-07-24 11:45:21
order.setOrderNo(old.getReqNo());
order.setBuyerTaxNum(old.getCompanyTaxNo());
order.setBuyerName(old.getCompanyName());
@ -137,7 +135,6 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
order.setWithTaxFlag( "1");
order.setShowBankAccountType("3");
// 蓝票
order.setInvoiceType("1");
/*
@ -205,10 +202,8 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
newRecord.setId(old.getId());
newRecord.setOpenChStatus("1");
emisSettleInvoiceChRecordMapper.updateEmisSettleInvoiceChRecord(newRecord);
// 更新状态
updateChOpenBillStatus(newRecord.getReqNo());
// 更新状态为已发送状态
updateEmisSettleInvoiceChRecord(newRecord);
}
else{
EmisSettleInvoiceChRecord newRecord=new EmisSettleInvoiceChRecord();
@ -220,32 +215,44 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
return 1;
}
private void updateChOpenBillStatus(String reqNo){
EmisSettleInvoiceChRecord old=emisSettleInvoiceChRecordMapper.selectEmisSettleInvoiceChRecordByReqNo(reqNo);
public void autoDoQueryOpenBillStatus(){
EmisBaseInvoiceChInfo emisBaseInvoiceChInfo=emisBaseInvoiceChInfoMapper.selectEmisBaseInvoiceChInfoByTaxNo(old.getSalerCompanyTaxNo());
List<EmisSettleInvoiceChRecord> listWaitQuery=emisSettleInvoiceChRecordMapper.selectWaitQueryStatusList();
for (EmisSettleInvoiceChRecord itemRecord:listWaitQuery) {
try {
doQueryAndUpdateChOpenBillStatus(itemRecord);
}catch (Exception ex){
ex.printStackTrace();
}
}
String token=HXSdk.getToken(emisBaseInvoiceChInfo.getAppKey(),emisBaseInvoiceChInfo.getAppSecret());
}
EmisSettleInvoiceChRecord updRecord = new EmisSettleInvoiceChRecord();
updRecord.setId(old.getId());
private void doQueryAndUpdateChOpenBillStatus(EmisSettleInvoiceChRecord itemRecord){
// 立即查询状态
JSONObject jQRst=HXSdk.queryInvoiceResult(reqNo,token);
if( "00000".equals(jQRst.getString("code")) ){
JSONObject data=jQRst.getJSONObject("data");
JSONArray jInvoiceInfos=data.getJSONArray("invoiceInfos");
if(!CollectionUtils.isEmpty(jInvoiceInfos)) {
EmisBaseInvoiceChInfo emisBaseInvoiceChInfo = emisBaseInvoiceChInfoMapper.selectEmisBaseInvoiceChInfoByTaxNo(itemRecord.getSalerCompanyTaxNo());
JSONObject item0 = jInvoiceInfos.getJSONObject(0);
if("00000".equals(item0.getString("returnStatus"))){
updRecord.setFilePath(item0.getString("pdfUrl"));
updRecord.setInvoiceNo(item0.getString("invoiceNo"));
String token = HXSdk.getToken(emisBaseInvoiceChInfo.getAppKey(), emisBaseInvoiceChInfo.getAppSecret());
EmisSettleInvoiceChRecord updRecord = new EmisSettleInvoiceChRecord();
updRecord.setId(itemRecord.getId());
// 立即查询状态
JSONObject jQRst = HXSdk.queryInvoiceResult(itemRecord.getReqNo(), token);
if ("00000".equals(jQRst.getString("code"))) {
JSONObject data = jQRst.getJSONObject("data");
JSONArray jInvoiceInfos = data.getJSONArray("invoiceInfos");
if (!CollectionUtils.isEmpty(jInvoiceInfos)) {
JSONObject item0 = jInvoiceInfos.getJSONObject(0);
if ("00000".equals(item0.getString("returnStatus"))) {
updRecord.setFilePath(item0.getString("pdfUrl"));
updRecord.setInvoiceNo(item0.getString("invoiceNo"));
// updRecord.setRemark(jQRst.toJSONString());
updRecord.setOpenChStatus(item0.getString("status"));
updRecord.setOpenChStatus(item0.getString("status"));
updRecord.setOpenChStatusDesc("已查询开票");
updRecord.setOpenChStatusDesc("已查询开票");
/*
status string Y 2 发票状态:
0:待开票;
@ -258,16 +265,16 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
*/
}else{
updRecord.setOpenChStatus("-1");
updRecord.setOpenChStatusDesc(item0.getString("returnStatusMsg"));
}
} else {
updRecord.setOpenChStatus("-1");
updRecord.setOpenChStatusDesc(item0.getString("returnStatusMsg"));
}
emisSettleInvoiceChRecordMapper.updateEmisSettleInvoiceChRecord(updRecord);
emisSettleInvoiceChRecordMapper.updateEmisSettleInvoiceChRecord(updRecord);
}
}
}
}

View File

@ -160,6 +160,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from emis_settle_invoice_ch_record a
where a.req_no = #{ReqNo}
</select>
<select id="selectWaitQueryStatusList" parameterType="String" resultMap="EmisSettleInvoiceChRecordResult">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_invoice_ch_record a
where a.del_flag='0' and a.open_ch_status = '1'
</select>
<insert id="insertEmisSettleInvoiceChRecord" parameterType="EmisSettleInvoiceChRecord" useGeneratedKeys="true" keyProperty="id">
insert into emis_settle_invoice_ch_record
@ -308,11 +314,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteEmisSettleInvoiceChRecordById" parameterType="Long">
delete from emis_settle_invoice_ch_record where id = #{id}
update emis_settle_invoice_ch_record set del_flag='0' where id = #{id}
</delete>
<delete id="deleteEmisSettleInvoiceChRecordByIds" parameterType="String">
delete from emis_settle_invoice_ch_record where id in
update emis_settle_invoice_ch_record set del_flag='0' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>