Commit 665bae30 authored by hanfeng's avatar hanfeng

Merge branch 'master-invoice-modular' into dev

# Conflicts:
#	xx-order/xx-order-server/src/main/java/com/xxfc/platform/order/biz/OrderAccountBiz.java
parents 5d8b60fd 830dfa2d
...@@ -123,4 +123,9 @@ public class OrderInvoice { ...@@ -123,4 +123,9 @@ public class OrderInvoice {
* 发票PDF路径 * 发票PDF路径
*/ */
private String invoiceUrl; private String invoiceUrl;
/**
* 发票内容
*/
private String contentTitle;
} }
\ No newline at end of file
...@@ -24,6 +24,11 @@ public class OrderPageVO extends BaseOrder { ...@@ -24,6 +24,11 @@ public class OrderPageVO extends BaseOrder {
//更换还车公司记录 //更换还车公司记录
List<BookRecordUpdateLog> bookRecordUpdateLogs; List<BookRecordUpdateLog> bookRecordUpdateLogs;
/**
* 订单最终支付金额:扣除所有费用之后
*/
private BigDecimal orderRealAmount;
/** /**
* 用户名 * 用户名
*/ */
......
...@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.feign.UserFeign; import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.exception.BaseException; import com.github.wxiaoqi.security.common.exception.BaseException;
...@@ -29,7 +31,6 @@ import com.xxfc.platform.order.pojo.mq.OrderMQDTO; ...@@ -29,7 +31,6 @@ import com.xxfc.platform.order.pojo.mq.OrderMQDTO;
import com.xxfc.platform.order.pojo.order.VehicleItemDTO; import com.xxfc.platform.order.pojo.order.VehicleItemDTO;
import com.xxfc.platform.order.pojo.price.CancelStartedVO; import com.xxfc.platform.order.pojo.price.CancelStartedVO;
import com.xxfc.platform.order.pojo.price.CostDetailExtend; import com.xxfc.platform.order.pojo.price.CostDetailExtend;
import com.xxfc.platform.order.pojo.price.DelayAddPriceVO;
import com.xxfc.platform.universal.constant.DictionaryKey; import com.xxfc.platform.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.entity.Dictionary; import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign; import com.xxfc.platform.universal.feign.ThirdFeign;
...@@ -37,9 +38,11 @@ import com.xxfc.platform.universal.vo.OrderRefundVo; ...@@ -37,9 +38,11 @@ import com.xxfc.platform.universal.vo.OrderRefundVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.jexl2.MapContext; import org.apache.commons.jexl2.MapContext;
import org.apache.commons.lang3.StringUtils;
import org.mockito.internal.util.collections.Sets; import org.mockito.internal.util.collections.Sets;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
...@@ -790,4 +793,36 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> { ...@@ -790,4 +793,36 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
log.error(StrUtil.format("退款异常{},订单号为:{}", ex.getMessage(), baseOrder.getNo()), ex); log.error(StrUtil.format("退款异常{},订单号为:{}", ex.getMessage(), baseOrder.getNo()), ex);
} }
} }
public List<OrderAccount> getByOrderId(Integer orderId) {
Example example = new Example(OrderAccount.class);
example.createCriteria().andEqualTo("orderId", orderId).andGreaterThan("accountType", 200);
return mapper.selectByExample(example);
}
public BigDecimal getAllOrderCost(Integer orderId) {
List<OrderAccount> list = getByOrderId(orderId);
BigDecimal bigDecimal = new BigDecimal("0");
if (list != null && list.size() > 0) {
list.parallelStream().forEach(result -> {
if(StringUtils.isNotBlank(result.getAccountDetail())) {
JSONObject jsonObject = JSONObject.parseObject(result.getAccountDetail());
log.info("获取订单的费用金额:", jsonObject.toJSONString());
if (jsonObject != null) {
JSONArray jsonArray = jsonObject.getJSONArray("deductions");
if(jsonArray != null && jsonArray.size() > 0) {
for (int i =0; i<jsonArray.size(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
if (jsonObject1 != null) {
bigDecimal.add(new BigDecimal(jsonObject1.getString("amount")));
}
}
log.info("获取订单的费用金额: {}", bigDecimal);
}
}
}
});
}
return bigDecimal;
}
} }
\ No newline at end of file
...@@ -9,10 +9,15 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; ...@@ -9,10 +9,15 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query; import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum;
import com.xxfc.platform.order.entity.BaseOrder; import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderInvoice; import com.xxfc.platform.order.entity.OrderInvoice;
import com.xxfc.platform.order.mapper.OrderInvoiceMapper; import com.xxfc.platform.order.mapper.OrderInvoiceMapper;
import com.xxfc.platform.order.pojo.dto.OrderInvoiceDto; import com.xxfc.platform.order.pojo.dto.OrderInvoiceDto;
import com.xxfc.platform.universal.entity.OrderData;
import com.xxfc.platform.universal.entity.vo.InvoiceVo;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.vehicle.constant.ResCode.ResCode; import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -42,6 +47,10 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> { ...@@ -42,6 +47,10 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> {
@Autowired @Autowired
HttpServletRequest request; HttpServletRequest request;
@Autowired
ThirdFeign thirdFeign;
/** /**
* 添加发票记录 * 添加发票记录
* @return * @return
...@@ -56,6 +65,7 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> { ...@@ -56,6 +65,7 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> {
return ObjectRestResponse.paramIsEmpty(); return ObjectRestResponse.paramIsEmpty();
} }
String[] orderIdArray = orderInvoice.getOrderIds().split(","); String[] orderIdArray = orderInvoice.getOrderIds().split(",");
List<OrderData> list = Lists.newArrayList();
if (orderIdArray.length > 0) { if (orderIdArray.length > 0) {
for (int a = 0; a <= orderIdArray.length - 1; a ++) { for (int a = 0; a <= orderIdArray.length - 1; a ++) {
String orderId = StringUtils.isBlank(orderIdArray[a])? "0" : orderIdArray[a]; String orderId = StringUtils.isBlank(orderIdArray[a])? "0" : orderIdArray[a];
...@@ -66,26 +76,68 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> { ...@@ -66,26 +76,68 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> {
//查询是否已开票 //查询是否已开票
OrderInvoice oldValue = selectByUserIdAndOrderId(appUserDTO.getUserid(), Integer.parseInt(orderId)).getData(); OrderInvoice oldValue = selectByUserIdAndOrderId(appUserDTO.getUserid(), Integer.parseInt(orderId)).getData();
if (oldValue == null) { //不存在就添加 if (oldValue == null) { //不存在就添加
OrderData orderData = new OrderData();
if (baseOrder.getType() == OrderTypeEnum.RENT_VEHICLE.getCode()) {
orderData.setOrderName(OrderTypeEnum.RENT_VEHICLE.getDesc());
}
if (baseOrder.getType() == OrderTypeEnum.TOUR.getCode()) {
orderData.setOrderName(OrderTypeEnum.TOUR.getDesc());
}
if (baseOrder.getType() == OrderTypeEnum.MEMBER.getCode()) {
orderData.setOrderName(OrderTypeEnum.MEMBER.getDesc());
}
orderData.setPrice(baseOrder.getRealAmount());
list.add(orderData);
continue;
} else {//已开票
log.info("该订单已经开票, {}", orderId);
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "该订单已经开票: orderId = " + orderId);
}
}
orderInvoice.setUserId(appUserDTO.getUserid()); orderInvoice.setUserId(appUserDTO.getUserid());
insertSelectiveRe(orderInvoice); insertSelectiveRe(orderInvoice);
log.info("添加发票记录成功: {}", orderInvoice); log.info("添加发票记录成功: {}", orderInvoice);
OrderInvoice newValue = selectByUserIdAndOrderId(appUserDTO.getUserid(), Integer.parseInt(orderId)).getData(); List<OrderInvoice> invoiceList = selectByIds(orderInvoice.getOrderIds()).getData();
if(newValue != null) { if(invoiceList != null && invoiceList.size() > 0) {
OrderInvoice newValue = invoiceList.get(0);
//调用第三方开票接口
InvoiceVo invoiceVo = new InvoiceVo();
invoiceVo.setContent(newValue.getContentTitle());
invoiceVo.setOrderId(newValue.getOrderIds());
invoiceVo.setPurchaserAccountBank(newValue.getContentAccount());
invoiceVo.setPurchaserAddressPhone(newValue.getContentContact());
invoiceVo.setPurchaserEmail(newValue.getReceiveContent());
invoiceVo.setPurchaserName(newValue.getTitleName());
invoiceVo.setPurchaserTaxCode(newValue.getTaxCode());
invoiceVo.setRemark(newValue.getContentRemark());
invoiceVo.setOrderInvoiceId(newValue.getId());
invoiceVo.setOrders(list);
ObjectRestResponse objectRestResponse = thirdFeign.invoicing(invoiceVo);
if (!objectRestResponse.isRel()) {
mapper.delete(newValue);
return objectRestResponse;
}
//更新订单状态
for (int a = 0; a <= orderIdArray.length - 1; a ++) {
String orderId = StringUtils.isBlank(orderIdArray[a]) ? "0" : orderIdArray[a];
BaseOrder baseOrder = baseOrderBiz.selectById(Integer.parseInt(orderId));
if (baseOrder == null) {
return ObjectRestResponse.createFailedResult(ResCode.ORDER_IS_NOT_EXIST.getCode(), ResCode.ORDER_IS_NOT_EXIST.getDesc() + ", 订单Id = " + orderId);
}
baseOrder.setInvoiceStatus(1); baseOrder.setInvoiceStatus(1);
baseOrder.setInvoiceId(newValue.getId()); baseOrder.setInvoiceId(newValue.getId());
baseOrderBiz.updateBaseOrder(baseOrder); baseOrderBiz.updateBaseOrder(baseOrder);
}
} else { } else {
return ObjectRestResponse.createFailedResult(ResultCode.DB_OPERATION_FAIL_CODE, ResultCode.getMsg(ResultCode.DB_OPERATION_FAIL_CODE)); return ObjectRestResponse.createFailedResult(ResultCode.DB_OPERATION_FAIL_CODE, ResultCode.getMsg(ResultCode.DB_OPERATION_FAIL_CODE));
} }
} else {//已开票
log.info("该订单已经开票, {}", orderId);
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "该订单已经开票: orderId = " + orderId);
}
}
} }
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
/** /**
* 根据orderIds字符串查询对应的发票记录 * 根据orderIds字符串查询对应的发票记录
* @param orderIds * @param orderIds
...@@ -109,7 +161,9 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> { ...@@ -109,7 +161,9 @@ public class OrderInvoiceBiz extends BaseBiz<OrderInvoiceMapper, OrderInvoice> {
} }
} }
} }
return ObjectRestResponse.succ(set); List<OrderInvoice> list = Lists.newArrayList();
list.addAll(set);
return ObjectRestResponse.succ(list);
} }
/** /**
......
...@@ -171,7 +171,10 @@ public class BaseOrderController extends CommonBaseController implements UserRes ...@@ -171,7 +171,10 @@ public class BaseOrderController extends CommonBaseController implements UserRes
dto.setUserId(Integer.valueOf(BaseContextHandler.getUserID())); dto.setUserId(Integer.valueOf(BaseContextHandler.getUserID()));
Query query = new Query(dto); Query query = new Query(dto);
PageDataVO<OrderPageVO> pages = PageDataVO.pageInfo(query, () -> baseOrderBiz.pageByParm(query.getSuper())); PageDataVO<OrderPageVO> pages = PageDataVO.pageInfo(query, () -> baseOrderBiz.pageByParm(query.getSuper()));
pages.getData().parallelStream().forEach(data -> data.setQrcodeStr(qrcodePrefix)); pages.getData().parallelStream().forEach(data -> {
data.setQrcodeStr(qrcodePrefix);
data.setOrderRealAmount(orderAccountBiz.getAllOrderCost(data.getId()));
});
return new ObjectRestResponse<>().data(pages); return new ObjectRestResponse<>().data(pages);
} }
...@@ -487,4 +490,6 @@ public class BaseOrderController extends CommonBaseController implements UserRes ...@@ -487,4 +490,6 @@ public class BaseOrderController extends CommonBaseController implements UserRes
return baseOrderBiz.updateBaseOrder(baseOrder); return baseOrderBiz.updateBaseOrder(baseOrder);
} }
} }
...@@ -25,9 +25,11 @@ public class Invoice { ...@@ -25,9 +25,11 @@ public class Invoice {
private String orderId; private String orderId;
/** /**
* 公司代码 * 发票订单表id
*/ */
private String companyCode; private Integer orderInvoiceId;
/** /**
* 发票订单号 * 发票订单号
...@@ -35,11 +37,18 @@ public class Invoice { ...@@ -35,11 +37,18 @@ public class Invoice {
private String orderNo; private String orderNo;
/**
* 公司代码
*/
private String companyCode;
/** /**
* 机构代码 * 机构代码
*/ */
private String orgCode; private String orgCode;
/** /**
* 发票代码 * 发票代码
*/ */
......
...@@ -3,6 +3,8 @@ package com.xxfc.platform.universal.entity; ...@@ -3,6 +3,8 @@ package com.xxfc.platform.universal.entity;
import lombok.Data; import lombok.Data;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.Date; import java.util.Date;
...@@ -13,6 +15,9 @@ import java.util.Date; ...@@ -13,6 +15,9 @@ import java.util.Date;
@Data @Data
@Table(name = "invoice_query_error") @Table(name = "invoice_query_error")
public class InvoiceQueryError { public class InvoiceQueryError {
@Id
@GeneratedValue(generator ="JDBC" )
private Integer id; private Integer id;
private Integer invoiceId; private Integer invoiceId;
private String invoiceSerialNum; private String invoiceSerialNum;
......
...@@ -18,13 +18,17 @@ public class InvoiceVo { ...@@ -18,13 +18,17 @@ public class InvoiceVo {
* 发票分类:01 专票,02 货物运输业增值税专用发票,03 机动车销售统一发票, * 发票分类:01 专票,02 货物运输业增值税专用发票,03 机动车销售统一发票,
* 04 增值税普通发票,10 增值税普通发票(电子),11 增值税普通发票(卷票),14 增值税普通发票(卷票) * 04 增值税普通发票,10 增值税普通发票(电子),11 增值税普通发票(卷票),14 增值税普通发票(卷票)
*/ */
private Integer invoiceCategory=10; private Integer invoiceCategory = 10;
/** /**
* 订单id :多个以逗号隔开 * 订单id :多个以逗号隔开
*/ */
private String orderId; private String orderId;
/**
* 发票订单表id
*/
private Integer orderInvoiceId;
/** /**
* 备注 * 备注
...@@ -56,13 +60,13 @@ public class InvoiceVo { ...@@ -56,13 +60,13 @@ public class InvoiceVo {
* 开票内容 * 开票内容
*/ */
private String content; private String content;
/** /**
* 购方手机 * 购方手机
*/ */
private String purchaserPhone; private String purchaserPhone;
private List<OrderData> orders; private List<OrderData> orders;
......
...@@ -5,6 +5,7 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; ...@@ -5,6 +5,7 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.universal.dto.SmsTemplateDTO; import com.xxfc.platform.universal.dto.SmsTemplateDTO;
import com.xxfc.platform.universal.entity.Dictionary; import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.entity.IdInformation; import com.xxfc.platform.universal.entity.IdInformation;
import com.xxfc.platform.universal.entity.vo.InvoiceVo;
import com.xxfc.platform.universal.vo.*; import com.xxfc.platform.universal.vo.*;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -94,4 +95,9 @@ public interface ThirdFeign { ...@@ -94,4 +95,9 @@ public interface ThirdFeign {
@RequestMapping("/captcha/app/unauth/verify") @RequestMapping("/captcha/app/unauth/verify")
ObjectRestResponse<Boolean> verify(@RequestParam(value = "phone")String phone, @RequestParam(value = "pointList")String pointList); ObjectRestResponse<Boolean> verify(@RequestParam(value = "phone")String phone, @RequestParam(value = "pointList")String pointList);
/************************************发票*************************************/
@PostMapping("/invoice/invoicing")
public ObjectRestResponse invoicing(@RequestBody InvoiceVo invoiceVo);
} }
...@@ -82,7 +82,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -82,7 +82,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
* 推送方式:-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机 * 推送方式:-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
*/ */
@Value("${invoice.pushMode}") @Value("${invoice.pushMode}")
private Integer pushMode = 2; private Integer pushMode;
private static final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(8); private static final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(8);
/** /**
...@@ -113,6 +113,10 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -113,6 +113,10 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
* @throws Exception * @throws Exception
*/ */
public String Invoicing(InvoiceVo invoiceVo) throws Exception { public String Invoicing(InvoiceVo invoiceVo) throws Exception {
//没有填写邮箱不需要进行推送
if (StringUtils.isBlank(invoiceVo.getPurchaserEmail())) {
pushMode = -1;
}
Invoice invoice = new Invoice(); Invoice invoice = new Invoice();
long on = snowflakeIdWorker.nextId(); long on = snowflakeIdWorker.nextId();
...@@ -127,6 +131,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -127,6 +131,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
invoice.setReviewer(checker); invoice.setReviewer(checker);
invoice.setIssuer(clerk); invoice.setIssuer(clerk);
invoice.setPushMode(pushMode); invoice.setPushMode(pushMode);
Date invoiceDate = new Date(); Date invoiceDate = new Date();
invoice.setCreateTime(invoiceDate); invoice.setCreateTime(invoiceDate);
invoice.setInvoiceDate(invoiceDate); invoice.setInvoiceDate(invoiceDate);
...@@ -157,24 +162,24 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -157,24 +162,24 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
BigDecimal taxExcludedAmount = BigDecimal.ZERO; BigDecimal taxExcludedAmount = BigDecimal.ZERO;
BigDecimal taxIncludedAmount = BigDecimal.ZERO; BigDecimal taxIncludedAmount = BigDecimal.ZERO;
for (OrderData order : orders) { for (OrderData order : orders) {
if (order.getWithTaxFlag()==1) { if (order.getWithTaxFlag() == 1) {
//含价税合计 //含价税合计
BigDecimal taxIncluded = order.getPrice(); BigDecimal taxIncluded = order.getPrice();
//税率 //税率
BigDecimal taxRate = order.getTaxRate(); BigDecimal taxRate = order.getTaxRate();
//不含税单价 //不含税单价
BigDecimal TaxFree = taxIncluded.divide(taxRate.add(new BigDecimal(1)),2,BigDecimal.ROUND_HALF_UP); BigDecimal TaxFree = taxIncluded.divide(taxRate.add(new BigDecimal(1)), 2, BigDecimal.ROUND_HALF_UP);
taxExcludedAmount=taxExcludedAmount.add(TaxFree); taxExcludedAmount = taxExcludedAmount.add(TaxFree);
taxIncludedAmount=taxIncludedAmount.add(taxIncluded); taxIncludedAmount = taxIncludedAmount.add(taxIncluded);
}else { } else {
//不含税单价 //不含税单价
BigDecimal taxFree = order.getPrice(); BigDecimal taxFree = order.getPrice();
//税率 //税率
BigDecimal taxRate = order.getTaxRate(); BigDecimal taxRate = order.getTaxRate();
//含税单价 //含税单价
BigDecimal taxIncluded = taxFree.multiply(taxRate.add(new BigDecimal(1))); BigDecimal taxIncluded = taxFree.multiply(taxRate.add(new BigDecimal(1)));
taxExcludedAmount=taxExcludedAmount.add(taxFree); taxExcludedAmount = taxExcludedAmount.add(taxFree);
taxIncludedAmount=taxIncludedAmount.add(taxIncluded); taxIncludedAmount = taxIncludedAmount.add(taxIncluded);
} }
} }
invoice.setInvoiceAmount(taxExcludedAmount); invoice.setInvoiceAmount(taxExcludedAmount);
...@@ -186,21 +191,22 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -186,21 +191,22 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
mapper.insert(invoice); mapper.insert(invoice);
//异步查询开票结果 //异步查询开票结果
schedule(invoiceSerialNum, invoice.getId(),invoice.getOrderId(),null, 0, 5,TimeUnit.SECONDS); schedule(invoiceSerialNum, invoice.getId(), invoice.getOrderId(), null, 0, 5, TimeUnit.SECONDS);
} }
/** /**
* 或去查询结果 * 或去查询结果
*
* @param invoiceSerialNum 发票流水号 * @param invoiceSerialNum 发票流水号
* @param id 发票id * @param id 发票id
* @param orderId 订单id * @param orderId 订单id
* @param lastStatus 上一次产需到的开票状态 * @param lastStatus 上一次产需到的开票状态
* @param count 已经查询过的次数 * @param count 已经查询过的次数
*/ */
public void queryInvoiceResult(String invoiceSerialNum, Integer id,String orderId,Integer lastStatus,Integer count) { public void queryInvoiceResult(String invoiceSerialNum, Integer id, String orderId, Integer lastStatus, Integer count) {
if (count==2){ if (count == 2) {
InvoiceQueryError invoiceQueryError = new InvoiceQueryError(); InvoiceQueryError invoiceQueryError = new InvoiceQueryError();
invoiceQueryError.setInvoiceId(id); invoiceQueryError.setInvoiceId(id);
invoiceQueryError.setInvoiceSerialNum(invoiceSerialNum); invoiceQueryError.setInvoiceSerialNum(invoiceSerialNum);
...@@ -211,24 +217,24 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -211,24 +217,24 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
} }
List<Map<String, Object>> result = invoiceResult(invoiceSerialNum); List<Map<String, Object>> result = invoiceResult(invoiceSerialNum);
if (result==null){ if (result == null) {
schedule(invoiceSerialNum, id,orderId,null, ++count, 2,TimeUnit.HOURS); schedule(invoiceSerialNum, id, orderId, null, ++count, 2, TimeUnit.HOURS);
return; return;
} }
log.info("查询到的开票结果={}",result); log.info("查询到的开票结果={}", result);
Map<String, Object> data = result.get(0); Map<String, Object> data = result.get(0);
Integer status = (Integer) data.get("status"); Integer status = (Integer) data.get("status");
String invoiceFileUrl = (String) data.get("invoiceFileUrl"); String invoiceFileUrl = (String) data.get("invoiceFileUrl");
String invoiceCode = (String) data.get("invoiceCode"); String invoiceCode = (String) data.get("invoiceCode");
String invoiceNum = (String) data.get("invoiceNum"); String invoiceNum = (String) data.get("invoiceNum");
String taxIncludedAmountStr = String.valueOf(data.get("taxIncludedAmount")) ; String taxIncludedAmountStr = String.valueOf(data.get("taxIncludedAmount"));
String taxExcludedAmountStr = String.valueOf(data.get("taxExcludedAmount")) ; String taxExcludedAmountStr = String.valueOf(data.get("taxExcludedAmount"));
Invoice invoice = new Invoice(); Invoice invoice = new Invoice();
invoice.setId(id); invoice.setId(id);
invoice.setStatus(status); invoice.setStatus(status);
invoice.setUpdateTime(new Date()); invoice.setUpdateTime(new Date());
if (StringUtils.isNotBlank(taxExcludedAmountStr)&&StringUtils.isNotBlank(taxIncludedAmountStr)) { if (StringUtils.isNotBlank(taxExcludedAmountStr) && StringUtils.isNotBlank(taxIncludedAmountStr)) {
BigDecimal taxExcludedAmount = new BigDecimal(taxExcludedAmountStr); BigDecimal taxExcludedAmount = new BigDecimal(taxExcludedAmountStr);
BigDecimal taxIncludedAmount = new BigDecimal(taxIncludedAmountStr); BigDecimal taxIncludedAmount = new BigDecimal(taxIncludedAmountStr);
invoice.setInvoiceAmount(taxExcludedAmount); invoice.setInvoiceAmount(taxExcludedAmount);
...@@ -237,15 +243,15 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -237,15 +243,15 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
invoice.setInvoiceSummaryAmountText(NumberToCN.number2CNMontrayUnit(taxIncludedAmount)); invoice.setInvoiceSummaryAmountText(NumberToCN.number2CNMontrayUnit(taxIncludedAmount));
} }
if (InvoiceStatusEum.ONGOING.getCode().equals(status) || InvoiceStatusEum.UNBILLED.getCode().equals(status)) { if (InvoiceStatusEum.ONGOING.getCode().equals(status) || InvoiceStatusEum.UNBILLED.getCode().equals(status)) {
schedule(invoiceSerialNum, id,orderId,status, ++count, 2,TimeUnit.HOURS); schedule(invoiceSerialNum, id, orderId, status, ++count, 2, TimeUnit.HOURS);
}else if (InvoiceStatusEum.SUCCESS.getCode().equals(status)){ } else if (InvoiceStatusEum.SUCCESS.getCode().equals(status)) {
invoice.setInvoiceCode(invoiceCode); invoice.setInvoiceCode(invoiceCode);
invoice.setInvoiceNo(invoiceNum); invoice.setInvoiceNo(invoiceNum);
invoice.setPictureUrl(invoiceFileUrl); invoice.setPictureUrl(invoiceFileUrl);
setOrderInvoice(orderId, status, invoiceFileUrl); setOrderInvoice(orderId, status, invoiceFileUrl);
}else { } else {
setOrderInvoice(orderId, status,null); setOrderInvoice(orderId, status, null);
} }
mapper.updateByPrimaryKeySelective(invoice); mapper.updateByPrimaryKeySelective(invoice);
...@@ -253,6 +259,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -253,6 +259,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
/** /**
* 设置订单发票表 * 设置订单发票表
*
* @param orderId 订单id * @param orderId 订单id
* @param status 发票查询状态 * @param status 发票查询状态
* @param invoiceFileUrl 发票pdf地址 * @param invoiceFileUrl 发票pdf地址
...@@ -268,6 +275,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -268,6 +275,7 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
/** /**
* 再次查询开票结果 * 再次查询开票结果
*
* @param invoiceSerialNum * @param invoiceSerialNum
* @param id * @param id
* @param orderId * @param orderId
...@@ -276,9 +284,9 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> { ...@@ -276,9 +284,9 @@ public class InvoiceBiz extends BaseBiz<InvoiceMapper, Invoice> {
* @param time * @param time
* @param timeUnit * @param timeUnit
*/ */
public void schedule(String invoiceSerialNum, Integer id,String orderId,Integer lastStatus, int count, int time,TimeUnit timeUnit) { public void schedule(String invoiceSerialNum, Integer id, String orderId, Integer lastStatus, int count, int time, TimeUnit timeUnit) {
executorService.schedule(() -> { executorService.schedule(() -> {
queryInvoiceResult(invoiceSerialNum, id,orderId,lastStatus, count); queryInvoiceResult(invoiceSerialNum, id, orderId, lastStatus, count);
}, time, timeUnit); }, time, timeUnit);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment