This commit is contained in:
linfso 2024-07-25 08:44:39 +08:00
parent 3f382e52fb
commit 4b9379378c
9 changed files with 200 additions and 2 deletions

View File

@ -15,6 +15,8 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.emis.domain.EmisSettleInvoiceChRecord;
import com.xdadan.erp.emis.domain.EmisSettleInvoiceRecord;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.service.IEmisSettleInvoiceChRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@ -110,6 +112,27 @@ public class EmisSettleInvoiceChRecordController extends BaseController
return toAjax(emisSettleInvoiceChRecordService.insertEmisSettleInvoiceChRecord(emisSettleInvoiceChRecord));
}
@Log(title = "发送航信开票", businessType = BusinessType.UPDATE)
@PostMapping("/sendHXToOpen")
public AjaxResult sendHXToOpen(@RequestBody EmisSettleInvoiceRecord emisSettleInvoiceRecord)
{
try {
return toAjax(emisSettleInvoiceChRecordService.sendHXToOpen(emisSettleInvoiceRecord.getId()));
}
catch (Exception ex){
ex.printStackTrace();
// 返回子定义异常
if(ex instanceof EmisBizError){
return AjaxResult.error(ex.getMessage(),((EmisBizError)ex).getErrorCode());
}
return AjaxResult.error("服务器异常,联系客服");
}
}
/**
* 修改渠道开票记录表
*/

View File

@ -13,7 +13,10 @@ package com.xdadan.erp.web.emis;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -107,9 +110,29 @@ public class EmisSettleInvoiceRecordController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody EmisSettleInvoiceRecord emisSettleInvoiceRecord)
{
return toAjax(emisSettleInvoiceRecordService.insertEmisSettleInvoiceRecord(emisSettleInvoiceRecord));
try {
return toAjax(emisSettleInvoiceRecordService.insertEmisSettleInvoiceRecord(emisSettleInvoiceRecord));
}
catch (DuplicateKeyException e) {
e.printStackTrace();
return AjaxResult.error("开票流水号重复!");
}
catch (Exception ex){
ex.printStackTrace();
// 返回子定义异常
if(ex instanceof EmisBizError){
return AjaxResult.error(ex.getMessage(),((EmisBizError)ex).getErrorCode());
}
return AjaxResult.error("服务器异常,联系客服");
}
}
/**
* 修改开票记录表
*/

View File

@ -28,6 +28,8 @@ public interface EmisBaseInvoiceChInfoMapper extends BaseMapper<EmisBaseInvoiceC
*/
public EmisBaseInvoiceChInfo selectEmisBaseInvoiceChInfoById(Long id);
public EmisBaseInvoiceChInfo selectEmisBaseInvoiceChInfoByTaxNo(String taxNo);
/**
* 查询列表
*

View File

@ -11,8 +11,9 @@ package com.xdadan.erp.emis.service;
import java.util.List;
import com.xdadan.erp.emis.domain.EmisSettleInvoiceChRecord;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
/**
/**
* @ClassName EmisSettleInvoiceChRecordService
* @Description 渠道开票记录表
* @author linfso
@ -75,4 +76,6 @@ public interface IEmisSettleInvoiceChRecordService
* @return 结果
*/
public int deleteEmisSettleInvoiceChRecordById(Long id);
public int sendHXToOpen(Long id) throws EmisBizError;
}

View File

@ -76,4 +76,7 @@ public interface IEmisSettleInvoiceRecordService
* @return 结果
*/
public int deleteEmisSettleInvoiceRecordById(Long id);
}

View File

@ -10,7 +10,20 @@
package com.xdadan.erp.emis.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.emis.domain.EmisBaseInvoiceChInfo;
import com.xdadan.erp.emis.domain.EmisSettleBill;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.mapper.EmisBaseInvoiceChInfoMapper;
import com.xdadan.erp.emis.service.openbill.hx.HXOrderGoods;
import com.xdadan.erp.emis.service.openbill.hx.HXOrderInfo;
import com.xdadan.erp.emis.service.openbill.hx.HXSdk;
import com.xdadan.erp.emis.utils.WaybillHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xdadan.erp.emis.domain.EmisSettleInvoiceChRecord;
@ -29,6 +42,9 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
@Autowired
private EmisSettleInvoiceChRecordMapper emisSettleInvoiceChRecordMapper;
@Autowired
private EmisBaseInvoiceChInfoMapper emisBaseInvoiceChInfoMapper;
/**
* 查询渠道开票记录表
*
@ -75,9 +91,115 @@ public class EmisSettleInvoiceChRecordServiceImpl implements IEmisSettleInvoiceC
@Override
public int insertEmisSettleInvoiceChRecord(EmisSettleInvoiceChRecord emisSettleInvoiceChRecord)
{
// 判断对应账单是否存在
String reqNo= WaybillHelper.genOrderSn();
emisSettleInvoiceChRecord.setReqNo(reqNo);
return emisSettleInvoiceChRecordMapper.insertEmisSettleInvoiceChRecord(emisSettleInvoiceChRecord);
}
/**
* 发送到航信开票
* @param id
* @return
*/
@Override
public int sendHXToOpen(Long id) throws EmisBizError {
EmisSettleInvoiceChRecord old=selectEmisSettleInvoiceChRecordById(id);
// 0-未发送 1-开票中 2-开票成功 3-开票失败
if(
!"0".equals(old.getOpenChStatus())
&& !"3".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());
order.setBuyerAddress(old.getCompanyAddress());
order.setBuyerTel(old.getCompanyTel());
order.setBuyerBank(old.getBankName());
order.setBuyerBankAccount(old.getBankAccNo());
order.setSpecificFactor("0");
// order.setDeliverPhone("123213");
order.setDeliverEmail(old.getEmail());
order.setWithTaxFlag( "1");
// 蓝票
order.setInvoiceType("1");
/*
发票种类:
pc:普通发票(数电);
bs:专用发票(数电);
ec:数电普票(纸质);
es:数电专票(纸质);
p,普通发票(电票);
b,增值税电子专用发票;
c,普通发票(纸票);
s,专用发票;
r,普通发票(卷式);
j,机动车销售统一发票;
u,二手车销售统一发票;
e,收购发票(电票);
f,收购发票(纸质);
ret,铁路电子客票
eia,航空运输客票电子行程单
扫码开票仅支持数电普和数电专
*/
order.setInvoiceLine(old.getRealInvoiceType());
order.setSalerTaxNum(old.getSalerCompanyTaxNo());
order.setSalerName(old.getSalerCompanyName());
order.setSalerTel(old.getSalerCompanyTel());
order.setSalerAddress(old.getSalerCompanyAddress());
order.setSalerBank(old.getSalerBankName());
order.setSalerBankAccount(old.getSalerBankAccNo());
JSONArray jArrGoods = JSONArray.parseArray(old.getExtData());
List<HXOrderGoods> goodsList = new ArrayList<>();
for (int i=0;i<jArrGoods.size();i++) {
JSONObject item=jArrGoods.getJSONObject(i);
HXOrderGoods goodsItem = new HXOrderGoods();
goodsItem.setGoodsCode(item.getString("goodsCode"));
goodsItem.setGoodsName(item.getString("goodsName"));
goodsItem.setNum(item.getString("num"));
goodsItem.setUnit(item.getString("unit"));
goodsItem.setPrice(item.getString("price"));
goodsItem.setTaxRate(item.getString("taxRate"));
goodsItem.setSpecType(item.getString("specType"));
goodsList.add(goodsItem);
}
order.setDetailInfos(goodsList);
JSONObject jRst =HXSdk.asyncOpenBillReceive(order,token);
// 更新开票状态
if( "00000".equals(jRst.getString("code")) ){
EmisSettleInvoiceChRecord newRecord=new EmisSettleInvoiceChRecord();
newRecord.setId(old.getId());
newRecord.setOpenChStatus("1");
emisSettleInvoiceChRecordMapper.updateEmisSettleInvoiceChRecord(newRecord);
}
else{
EmisSettleInvoiceChRecord newRecord=new EmisSettleInvoiceChRecord();
newRecord.setId(old.getId());
newRecord.setOpenChStatus("3");
newRecord.setOpenChStatusDesc(jRst.getString("message"));
emisSettleInvoiceChRecordMapper.updateEmisSettleInvoiceChRecord(newRecord);
}
return 1;
}
/**
* 修改渠道开票记录表
*

View File

@ -18,6 +18,7 @@ import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.mapper.EmisSettleBillMapper;
import com.xdadan.erp.emis.service.EmisBaseService;
import com.xdadan.erp.emis.utils.WaybillHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xdadan.erp.emis.mapper.EmisSettleInvoiceRecordMapper;
@ -93,6 +94,10 @@ public class EmisSettleInvoiceRecordServiceImpl extends EmisBaseService implemen
throw new EmisBizError(EmisBizErrorType.FAIL,"业务账单未确认");
}
// 不重复的 id流水号
String applySeqNo= WaybillHelper.genApplySeqNo();
emisSettleInvoiceRecord.setApplySeqNo(applySeqNo);
// 插入发票记录
emisSettleInvoiceRecordMapper.insertEmisSettleInvoiceRecord(emisSettleInvoiceRecord);

View File

@ -69,6 +69,17 @@ public class WaybillHelper {
/**
* 生成申请流水号
* @return
*/
public static String genApplySeqNo(){
String billId = formatter.format(new Date());
billId += (int)((Math.random() * 9 + 1) * 1000);
return billId;
}

View File

@ -79,6 +79,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from emis_base_invoice_ch_info a
where a.id = #{id}
</select>
<select id="selectEmisBaseInvoiceChInfoByTaxNo" parameterType="String" resultMap="EmisBaseInvoiceChInfoResult">
select id, ch_id, ch_name, company_name, company_tax_no, ec_account, ec_name, app_key, app_secret, token, token_expire_time, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_base_invoice_ch_info a
where a.company_tax_no = #{taxNo}
</select>
<insert id="insertEmisBaseInvoiceChInfo" parameterType="EmisBaseInvoiceChInfo" useGeneratedKeys="true" keyProperty="id">
insert into emis_base_invoice_ch_info