|
@@ -32,6 +32,7 @@ import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
|
|
|
import com.pj.project.tb_order.TbOrder;
|
|
|
import com.pj.project.tb_order.TbOrderService;
|
|
|
import com.pj.project4sp.global.BusinessException;
|
|
|
+import com.pj.utils.sg.AjaxError;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -68,28 +69,19 @@ public class InvoiceApplyService {
|
|
|
InvoiceConfig invoiceConfig;
|
|
|
|
|
|
|
|
|
- private static final String appid = "5644763";
|
|
|
- private static final String appsecret = "F382196D16B98BC6F4A461Ced7505953";
|
|
|
- private static final String applyUrl = "http://117.141.148.233:8765/monolithic/uni/invoice/invoiceBillPush";
|
|
|
- private static final String applyAction = "billPus";
|
|
|
- private static final String businessTaxRateCode = "3040408000000000000";
|
|
|
- private static final String carTaxRateCode = "3040502020200000000";
|
|
|
- private static final String sellerTaxpayerId = "915003006188392540";
|
|
|
- private static final String sellerName = "金蝶软件(中国)有限公司";
|
|
|
-
|
|
|
- public String applyInvoice(String infoId){
|
|
|
+ public String applyInvoice(String infoId) {
|
|
|
String code = this.preApply(infoId);
|
|
|
- if(!StrUtil.equals("200", code)) {
|
|
|
+ if (!StrUtil.equals("200", code)) {
|
|
|
throw new BusinessException("开票申请推送失败!");
|
|
|
}
|
|
|
return code;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public String preApply(String infoId){
|
|
|
+ public String preApply(String infoId) {
|
|
|
Date now = new Date();
|
|
|
Map<String, String> param = new HashMap<>();
|
|
|
- param.put("action",invoiceConfig.getApplyAction());
|
|
|
+ param.put("action", invoiceConfig.getApplyAction());
|
|
|
param.put("appid", invoiceConfig.getAppId());
|
|
|
param.put("timestamp", InvoiceUtils.date2StrByInt(now, "yyyyMMddHHmmssFFF"));
|
|
|
param.put("transid", InvoiceUtils.genTransId());
|
|
@@ -104,7 +96,7 @@ public class InvoiceApplyService {
|
|
|
|
|
|
//开始组装接口参数
|
|
|
InvoiceApply invoiceApply = new InvoiceApply();
|
|
|
- invoiceApply.setRequestId(now.getTime()+"")
|
|
|
+ invoiceApply.setRequestId(now.getTime() + "")
|
|
|
.setBusinessSystemCode("SW_TEST")
|
|
|
.setInterfaceCode("BILL.PUSH");
|
|
|
List<InvoiceApplySub> applys = new ArrayList<>();
|
|
@@ -118,7 +110,7 @@ public class InvoiceApplyService {
|
|
|
.setBuyerName(info.getEntityName()).setBuyerTaxpayerId(info.getTaxIdNo())
|
|
|
.setBuyerRecipientMail(info.getEmail())
|
|
|
.setBuyerProperty(0)
|
|
|
- .setBuyerBankAndAccount(info.getBank()+info.getBankNo())
|
|
|
+ .setBuyerBankAndAccount(info.getBank() + info.getBankNo())
|
|
|
.setTextField1(info.getCustomerName())
|
|
|
.setSellerName(invoiceConfig.getSellerName())
|
|
|
.setSellerTaxpayerId(invoiceConfig.getSellerTaxpayerId())
|
|
@@ -133,7 +125,7 @@ public class InvoiceApplyService {
|
|
|
List<InvoiceApplySubDetail> applyDetails = new ArrayList<>();
|
|
|
Snowflake snowflake = IdUtil.getSnowflake(1, 1);
|
|
|
for (FeeDeatilsGroup group : feeDetailsGroupList) {
|
|
|
- String detailId = snowflake.nextIdStr();
|
|
|
+ String detailId = snowflake.nextIdStr();
|
|
|
InvoiceApplySubDetail applyDetail = new InvoiceApplySubDetail();
|
|
|
applyDetail.setAmount(group.getItemPrice())
|
|
|
.setDetailId(detailId)
|
|
@@ -142,9 +134,9 @@ public class InvoiceApplyService {
|
|
|
.setQuantity(group.getNum())
|
|
|
.setPrice(group.getUnitPrice())
|
|
|
.setTaxRate(group.getTaxRate().toString());
|
|
|
- if(StrUtil.equals("0.09", applyDetail.getTaxRate())){
|
|
|
+ if (StrUtil.equals("0.09", applyDetail.getTaxRate())) {
|
|
|
applyDetail.setRevenueCode(invoiceConfig.getCarTaxRateCode());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
applyDetail.setRevenueCode(invoiceConfig.getBusinessTaxRateCode());
|
|
|
}
|
|
|
applyDetails.add(applyDetail);
|
|
@@ -167,17 +159,17 @@ public class InvoiceApplyService {
|
|
|
String result = HttpUtil.createPost(url).header("Content-Type", "application/json").body(paramStr).execute().body();
|
|
|
log.info("invoice apply result:" + result);
|
|
|
JSONObject jsonResult = JSONUtil.parseObj(result);
|
|
|
- if( StrUtil.equals("0", jsonResult.getStr("code"))){
|
|
|
- info.setApplyAble(1);
|
|
|
+ if (StrUtil.equals("0", jsonResult.getStr("code"))) {
|
|
|
+ info.setApplyAble(1).setStatus(2);
|
|
|
tbInvoiceInfoService.updateById(info);
|
|
|
return "200";
|
|
|
- }else {
|
|
|
- return "500";
|
|
|
+ } else {
|
|
|
+ throw new AjaxError("开票失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<FeeDeatilsGroup> grouping(List<TbInvoiceOrder> invoiceOrderList){
|
|
|
+ private List<FeeDeatilsGroup> grouping(List<TbInvoiceOrder> invoiceOrderList) {
|
|
|
List<TbFeeDetails> feeDetailsList = new ArrayList<>();
|
|
|
for (TbInvoiceOrder invoiceOrder : invoiceOrderList) {
|
|
|
List<TbFeeDetails> detailsList = tbFeeDetailsService.findByTransactionId(invoiceOrder.getTransactionId());
|
|
@@ -186,11 +178,11 @@ public class InvoiceApplyService {
|
|
|
List<FeeDeatilsGroup> list = new ArrayList<>();
|
|
|
for (TbFeeDetails detail : feeDetailsList) {
|
|
|
FeeDeatilsGroup group = new FeeDeatilsGroup();
|
|
|
- BeanUtil.copyProperties(detail, group);
|
|
|
- String hash = (detail.getItemTypeName() + detail.getUnitPrice()).hashCode() + "";
|
|
|
- group.setGroupHash(hash);
|
|
|
- list.add(group);
|
|
|
- }
|
|
|
+ BeanUtil.copyProperties(detail, group);
|
|
|
+ String hash = (detail.getItemTypeName() + detail.getUnitPrice()).hashCode() + "";
|
|
|
+ group.setGroupHash(hash);
|
|
|
+ list.add(group);
|
|
|
+ }
|
|
|
Map<String, List<FeeDeatilsGroup>> collect = list.stream()
|
|
|
.collect(Collectors.groupingBy(FeeDeatilsGroup::getGroupHash));
|
|
|
List<FeeDeatilsGroup> completeGroups = new ArrayList<>();
|
|
@@ -212,7 +204,7 @@ public class InvoiceApplyService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public synchronized Map<String, Object> callBack(String sub) {
|
|
|
+ public synchronized Map<String, Object> callBack(String sub) {
|
|
|
log.info("进入开票回调:");
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
|
@@ -220,17 +212,18 @@ public class InvoiceApplyService {
|
|
|
InvoiceApplyCallBackSub callBackSub = JSONUtil.toBean(jsonObject, InvoiceApplyCallBackSub.class);
|
|
|
|
|
|
TbInvoiceDetails invoiceDetail = tbInvoiceDetailsService.getById(callBackSub.getBillNo());
|
|
|
- if(invoiceDetail == null){
|
|
|
+ if (invoiceDetail == null) {
|
|
|
log.info("开票信息子记录{}不存在:", callBackSub.getBillNo());
|
|
|
map.put("code", 500);
|
|
|
map.put("message", "失败,开票信息数据异常");
|
|
|
return map;
|
|
|
}
|
|
|
- if(invoiceDetail.getIsApply() == 2){
|
|
|
+ if (invoiceDetail.getIsApply() == 2) {
|
|
|
log.info("重复回调,开票信息子记录{}已开票成功:", callBackSub.getBillNo());
|
|
|
- }else{
|
|
|
- invoiceDetail.setIsApply(2).setInvoiceNo(callBackSub.getInvoiceNum()).setInvoiceCode(callBackSub.getInvoiceCode())
|
|
|
- .setFileUrl(callBackSub.getInvoiceFileUrl()).setImageUrl(callBackSub.getInvoiceImageUrl());
|
|
|
+ } else {
|
|
|
+ invoiceDetail.setIsApply(2).setInvoiceNo(callBackSub.getInvoiceNum())
|
|
|
+ .setInvoiceCode(callBackSub.getInvoiceCode())
|
|
|
+ .setFileUrl(callBackSub.getInvoiceFileUrl()).setImageUrl(callBackSub.getInvoiceImageUrl());
|
|
|
tbInvoiceDetailsService.updateById(invoiceDetail);
|
|
|
TbInvoiceInfo info = tbInvoiceInfoService.getById(invoiceDetail.getInfoId());
|
|
|
// List<TbInvoiceDetails> infoAllDetails = tbInvoiceDetailsService.findByInfoId(info.getId());
|
|
@@ -239,11 +232,18 @@ public class InvoiceApplyService {
|
|
|
// newInvoiceNo = StrUtil.isEmpty(newInvoiceNo) ?
|
|
|
// detail.getInvoiceNo() : newInvoiceNo+","+detail.getInvoiceNo();
|
|
|
// }
|
|
|
- info.setIsApply(2);
|
|
|
+ String status = callBackSub.getInvoiceStatus();
|
|
|
+ if ("0".equals(status)) {
|
|
|
+ //开票成功
|
|
|
+ info.setStatus(1);
|
|
|
+ info.setIsApply(2);
|
|
|
+ } else {
|
|
|
+ info.setStatus(Integer.parseInt(status));
|
|
|
+ }
|
|
|
tbInvoiceInfoService.updateById(info);
|
|
|
String oldInvoiceNo = info.getInvoiceNo();
|
|
|
String newInvoiceNo = StrUtil.isEmpty(oldInvoiceNo) ?
|
|
|
- callBackSub.getInvoiceNum() : oldInvoiceNo+","+callBackSub.getInvoiceNum();
|
|
|
+ callBackSub.getInvoiceNum() : oldInvoiceNo + "," + callBackSub.getInvoiceNum();
|
|
|
|
|
|
SoMap so = new SoMap();
|
|
|
so.put("id", info.getId());
|