Browse Source

招行发票

master
zhaoyiran 4 months ago
parent
commit
a22e848f01
  1. 201
      src/main/java/com/win/bank/domain/BasicInvoiceDO.java
  2. 22
      src/main/java/com/win/bank/enums/CmbInvoiceQueryTypeEnum.java
  3. 9
      src/main/java/com/win/bank/mapper/BasicInvoiceMapper.java
  4. 3
      src/main/java/com/win/bank/service/BaseBankService.java
  5. 10
      src/main/java/com/win/bank/service/MainService.java
  6. 5
      src/main/java/com/win/bank/service/bocom/BocomServiceImpl.java
  7. 110
      src/main/java/com/win/bank/service/cmb/CmbServiceImpl.java
  8. 60
      src/main/java/com/win/bank/service/cmb/entity/FinancialInvoice.java
  9. 119
      src/main/java/com/win/bank/service/cmb/entity/SaleInvoice.java
  10. 121
      src/main/java/com/win/bank/service/cmb/entity/TicketInvoice.java
  11. 32
      src/main/java/com/win/bank/service/invoice/BasicInvoiceService.java

201
src/main/java/com/win/bank/domain/BasicInvoiceDO.java

@ -0,0 +1,201 @@
package com.win.bank.domain;
import java.math.BigDecimal;
import java.time.LocalDate;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("basic_invoice")
@Data
public class BasicInvoiceDO {
// 发票ID
private String invoiceId;
// 系统创建时间
private LocalDate systemCreateTime;
// 发票代码
private String invoiceCode;
// 发票号码
private String invoiceNo;
// 校验码
private String checkCode;
// 开票日期
private String invoiceDate;
// 发票类型
private String invoiceType;
// 发票类型名称
private String invoiceTypeName;
// 购方名称
private String buyerName;
// 购方税号
private String buyerTaxNo;
// 购方银行帐号
private String buyerBankNo;
// 购方地址电话
private String buyerAddTel;
// 销方名称
private String sellerName;
// 销方税号
private String sellerTaxNo;
// 销方银行帐号
private String sellerBankNo;
// 销方地址电话
private String sellerAddTel;
// 开票人
private String makeInvoicePerson;
// 复核人
private String reCheckPerson;
// 收款人
private String gatheringPerson;
// 合计金额
private BigDecimal totalAmount;
// 合计税额
private BigDecimal totalTax;
// 价税合计
private BigDecimal amountTax;
// 发票查验结果标记
private Integer checkState;
// 作废标记
private String cancelFlag;
// 备注
private String comments;
// 是否蓝票
private String blueInvoiceFlag;
// 蓝票发票代码
private String blueInvoiceCode;
// 蓝票发票号码
private String blueInvoiceNo;
// 企业税号
private String taxNo;
// 用户编号
private String userId;
// 用户名称
private String userName;
// 录入方式
private String source;
// 创建时间
private String createTime;
// 更新时间
private String updateTime;
// 使用标记
private String useTag;
// 备注
private String remark;
// 发票类别
private String ticketClass;
// 姓名
private String passenger;
// 车次
private String trafficNum;
// 出发点
private String startAddr;
// 目的地
private String endAddr;
// 座位类型编号
private String seatClass;
// 座位类型名称
private String seatClassName;
// 附加费
private BigDecimal additionAmount;
// 附加费2
private BigDecimal addition2Amount;
// 上车时间
private String startTime;
// 下车时间
private String endTime;
// 票据所在地
private String TicketAddr;
// 车型
private String vehicleType;
// 车重
private String vehicleWeight;
// 消费类型
private String consumerType;
// 发票文件类型
private String fileType;
// 发票下载链接
private String dmzUrl;
// 下载链接(内网)
private String bizUrl;
// 是否退票费
private String refundFlag;
// 保险费
private BigDecimal insurance;
// 其它税费
private BigDecimal otherTax;
// 交款人
private String payerPartyName;
// 详情信息
private String message;
// 状态
private String status;
// 分行号
private String bbkNum;
// 用户推送的备注
private String userRemark;
// 财政票据类型
private String finInvoiceType;
}

22
src/main/java/com/win/bank/enums/CmbInvoiceQueryTypeEnum.java

@ -0,0 +1,22 @@
package com.win.bank.enums;
public enum CmbInvoiceQueryTypeEnum {
A("A", "增值税发票"), I("I", "财政电子票"), T("T", "费用发票");
private final String code;
private final String description;
CmbInvoiceQueryTypeEnum(String code, String description) {
this.code = code;
this.description = description;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
}

9
src/main/java/com/win/bank/mapper/BasicInvoiceMapper.java

@ -0,0 +1,9 @@
package com.win.bank.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.win.bank.domain.BasicInvoiceDO;
@Mapper
public interface BasicInvoiceMapper extends BaseMapper<BasicInvoiceDO> {}

3
src/main/java/com/win/bank/service/BaseBankService.java

@ -18,4 +18,7 @@ public interface BaseBankService {
* @return * @return
*/ */
BankDO queryPaymentResult(BankDO bankDO); BankDO queryPaymentResult(BankDO bankDO);
void getInvoice();
} }

10
src/main/java/com/win/bank/service/MainService.java

@ -18,7 +18,7 @@ public class MainService {
@Resource @Resource
private BankService bankService; private BankService bankService;
@Scheduled(cron = "0 0/1 * * * ? ") // @Scheduled(cron = "0 0/1 * * * ? ")
public void payTask() { public void payTask() {
List<BankDO> bankDOList = bankService.listByStatus(PaymentStatusEnum.UNPROCESSED.getCode()); List<BankDO> bankDOList = bankService.listByStatus(PaymentStatusEnum.UNPROCESSED.getCode());
for (BankDO bankDO : bankDOList) { for (BankDO bankDO : bankDOList) {
@ -28,7 +28,7 @@ public class MainService {
} }
} }
@Scheduled(cron = "30 0/1 * * * ? ") // @Scheduled(cron = "30 0/1 * * * ? ")
public void queryPaymentResult() { public void queryPaymentResult() {
List<BankDO> bankDOList = bankService.listByStatus(PaymentStatusEnum.PAYING.getCode()); List<BankDO> bankDOList = bankService.listByStatus(PaymentStatusEnum.PAYING.getCode());
for (BankDO bankDO : bankDOList) { for (BankDO bankDO : bankDOList) {
@ -39,4 +39,10 @@ public class MainService {
} }
} }
} }
@Scheduled(cron = "0 0/1 * * * ? ")
public void getInvoice() {
BaseBankService baseBankService = BaseBankServiceUtil.get("cmb".toUpperCase());
baseBankService.getInvoice();
}
} }

5
src/main/java/com/win/bank/service/bocom/BocomServiceImpl.java

@ -169,6 +169,11 @@ public class BocomServiceImpl implements BaseBankService {
return bankDO; return bankDO;
} }
@Override
public void getInvoice() {
}
private String generateHeadMessage(String trCode, String reqNo) { private String generateHeadMessage(String trCode, String reqNo) {
SimpleDateFormat sdfd = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdfd = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdft = new SimpleDateFormat("HHmmss"); SimpleDateFormat sdft = new SimpleDateFormat("HHmmss");

110
src/main/java/com/win/bank/service/cmb/CmbServiceImpl.java

@ -3,26 +3,33 @@ package com.win.bank.service.cmb;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.time.LocalDate;
import java.util.Collections; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.win.bank.domain.BankDO; import com.win.bank.domain.BankDO;
import com.win.bank.domain.BasicInvoiceDO;
import com.win.bank.enums.CmbInvoiceQueryTypeEnum;
import com.win.bank.enums.PaymentStatusEnum; import com.win.bank.enums.PaymentStatusEnum;
import com.win.bank.service.BaseBankService; import com.win.bank.service.BaseBankService;
import com.win.bank.service.bank.BankService; import com.win.bank.service.bank.BankService;
import com.win.bank.service.cmb.entity.FinancialInvoice;
import com.win.bank.service.cmb.entity.SaleInvoice;
import com.win.bank.service.cmb.entity.TicketInvoice;
import com.win.bank.service.invoice.BasicInvoiceService;
import com.win.bank.utils.HttpUtil; import com.win.bank.utils.HttpUtil;
import com.win.bank.utils.JsonUtil; import com.win.bank.utils.JsonUtil;
@ -54,6 +61,9 @@ public class CmbServiceImpl implements BaseBankService {
@Resource @Resource
private BankService bankService; private BankService bankService;
@Resource
private BasicInvoiceService basicInvoiceService;
@Override @Override
public BankDO payment(BankDO bankDO) { public BankDO payment(BankDO bankDO) {
String funCode = "BB1PAYOP"; String funCode = "BB1PAYOP";
@ -139,6 +149,98 @@ public class CmbServiceImpl implements BaseBankService {
return bankDO; return bankDO;
} }
@Override
public void getInvoice() {
String funCode = "EWLINV01";
int pageSize = 100;
int totalPage;
LocalDate currentDate = LocalDate.now();
// 获取当前日期前7天的日期
LocalDate previousDate = currentDate.minusDays(7);
Set<String> oldIds = basicInvoiceService.getInvoiceId(previousDate);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String previousDateStr = previousDate.format(formatter);
for (CmbInvoiceQueryTypeEnum type : CmbInvoiceQueryTypeEnum.values()) {
int pageNum = 0;
do {
pageNum++;
String data = "{\"request\":{\"head\":{\"bizcode\":\"FPY001\",\"funcode\":\"" + funCode + "\",\"userid\":\"" + uid + "\"},\"body\":{\"reqdat\":{\"pageNum\":" + pageNum
+ ",\"pageSize\":" + pageSize + ",\"queryType\":\"" + type.getCode() + "\",\"createTimeS\":\"" + previousDateStr + "\"}}}}";
totalPage = getInvoice(data, type, funCode, oldIds);
} while (pageNum < totalPage);
}
}
private int getInvoice(String data, CmbInvoiceQueryTypeEnum type, String funCode, Set<String> oldIds) {
int totalPage = 0;
LocalDate currentDate = LocalDate.now();
logger.info("发送给招商银行的数据" + JsonUtil.formatJson(data));
String response;
try {
response = sendRequest(data, funCode);
} catch (Exception e) {
throw new RuntimeException(e);
}
logger.info("收到招商银行的数据:" + JsonUtil.formatJson(response));
JsonObject responseJson = new Gson().fromJson(response, JsonObject.class);
JsonObject headJson = responseJson.getAsJsonObject("response").getAsJsonObject("head");
if (SUCCESS_CODE.equals(headJson.get("resultcode").getAsString())) {
String str = responseJson.getAsJsonObject("response").getAsJsonObject("body").get("resdat").toString();
String resdatJsonString = str.substring(1, str.length() - 1).replace("\\\"", "\"");;
JsonObject resdatJson = JsonParser.parseString(resdatJsonString).getAsJsonObject();
if (SUCCESS_CODE.equals(resdatJson.get("code").getAsString())) {
JsonObject dataJson = resdatJson.getAsJsonObject("data");
totalPage = dataJson.get("totalPage").getAsInt();
JsonArray listJson = dataJson.getAsJsonArray("list");
List<BasicInvoiceDO> invoiceDOList = new ArrayList<>();
switch (type) {
case A:
listJson.forEach(item -> {
SaleInvoice saleInvoice = new Gson().fromJson(item, SaleInvoice.class);
if (!oldIds.contains(saleInvoice.getInvoiceId())) {
BasicInvoiceDO basicInvoiceDO = new BasicInvoiceDO();
BeanUtils.copyProperties(saleInvoice, basicInvoiceDO);
basicInvoiceDO.setSystemCreateTime(currentDate);
invoiceDOList.add(basicInvoiceDO);
}
});
break;
case I:
listJson.forEach(item -> {
FinancialInvoice financialInvoice = new Gson().fromJson(item, FinancialInvoice.class);
if (!oldIds.contains(financialInvoice.getInvoiceId())) {
BasicInvoiceDO basicInvoiceDO = new BasicInvoiceDO();
BeanUtils.copyProperties(financialInvoice, basicInvoiceDO);
basicInvoiceDO.setSystemCreateTime(currentDate);
invoiceDOList.add(basicInvoiceDO);
}
});
break;
case T:
listJson.forEach(item -> {
TicketInvoice ticketInvoice = new Gson().fromJson(item, TicketInvoice.class);
if (!oldIds.contains(ticketInvoice.getTicketId())) {
BasicInvoiceDO basicInvoiceDO = new BasicInvoiceDO();
BeanUtils.copyProperties(ticketInvoice, basicInvoiceDO);
basicInvoiceDO.setSystemCreateTime(currentDate);
basicInvoiceDO.setInvoiceId(ticketInvoice.getTicketId());
basicInvoiceDO.setInvoiceType(ticketInvoice.getTicketType());
basicInvoiceDO.setInvoiceTypeName(ticketInvoice.getTicketTypeName());
basicInvoiceDO.setInvoiceDate(ticketInvoice.getTicketDate());
invoiceDOList.add(basicInvoiceDO);
}
});
break;
}
basicInvoiceService.saveBatch(invoiceDOList);
}
}
return totalPage;
}
public String sendRequest(String data, String funcode) throws Exception { public String sendRequest(String data, String funcode) throws Exception {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("UID", uid); map.put("UID", uid);

60
src/main/java/com/win/bank/service/cmb/entity/FinancialInvoice.java

@ -0,0 +1,60 @@
package com.win.bank.service.cmb.entity;
import java.math.BigDecimal;
import lombok.Data;
/**
* 财政电子票
*
* @author admin
*/
@Data
public class FinancialInvoice {
// 发票ID
private String invoiceId;
// 发票代码
private String invoiceCode;
// 发票号码
private String invoiceNo;
// 开票日期
private String invoiceDate;
// 校验码
private String checkCode;
// 合计金额
private BigDecimal totalAmount;
// 发票状态
private String cancelFlag;
// 交款人
private String payerPartyName;
// 详情信息
private String message;
// 发票类型
private String invoiceType;
// 发票查验结果标记
private String checkState;
// 录入方式
private String source;
// 企业税号
private String taxNo;
// 用户编号
private String userId;
// 用户名称
private String userName;
// 状态
private String status;
// 分行号
private String bbkNum;
// 用户推送的备注
private String userRemark;
// 备注
private String remark;
// 发票文件类型
private String fileType;
// 发票下载链接
private String dmzUrl;
// 下载链接(内网)
private String bizUrl;
// 财政票据类型
private String finInvoiceType;
}

119
src/main/java/com/win/bank/service/cmb/entity/SaleInvoice.java

@ -0,0 +1,119 @@
package com.win.bank.service.cmb.entity;
import java.math.BigDecimal;
import lombok.Data;
/**
* 增值税发票
*
* @author admin
*/
@Data
public class SaleInvoice {
// 发票ID
private String invoiceId;
// 发票代码
private String invoiceCode;
// 发票号码
private String invoiceNo;
// 校验码
private String checkCode;
// 开票日期
private String invoiceDate;
// 发票类型
private String invoiceType;
// 发票类型名称
private String invoiceTypeName;
// 购方名称
private String buyerName;
// 购方税号
private String buyerTaxNo;
// 购方银行帐号
private String buyerBankNo;
// 购方地址电话
private String buyerAddTel;
// 销方名称
private String sellerName;
// 销方税号
private String sellerTaxNo;
// 销方银行帐号
private String sellerBankNo;
// 销方地址电话
private String sellerAddTel;
// 开票人
private String makeInvoicePerson;
// 复核人
private String reCheckPerson;
// 收款人
private String gatheringPerson;
// 合计金额
private BigDecimal totalAmount;
// 合计税额
private BigDecimal totalTax;
// 价税合计
private BigDecimal amountTax;
// 发票查验结果标记
private Integer checkState;
// 作废标记
private String cancelFlag;
// 备注
private String comments;
// 是否蓝票
private String blueInvoiceFlag;
// 蓝票发票代码
private String blueInvoiceCode;
// 蓝票发票号码
private String blueInvoiceNo;
// 企业税号
private String taxNo;
// 用户编号
private String userId;
// 用户名称
private String userName;
// 录入方式
private String source;
// 创建时间
private String createTime;
// 更新时间
private String updateTime;
// 使用标记
private String useTag;
// 备注
private String remark;
}

121
src/main/java/com/win/bank/service/cmb/entity/TicketInvoice.java

@ -0,0 +1,121 @@
package com.win.bank.service.cmb.entity;
import java.math.BigDecimal;
import lombok.Data;
/**
* 费用发票
*
* @author admin
*/
@Data
public class TicketInvoice {
// 票据ID
private String ticketId;
// 用户ID
private String userId;
// 用户名称
private String userName;
// 录入方式
private String source;
// 创建时间
private String createTime;
// 发票类别
private String ticketClass;
// 发票类型
private String ticketType;
// 发票类型名称
private String ticketTypeName;
// 发票代码
private String invoiceCode;
// 发票号码
private String invoiceNo;
// 开票日期
private String ticketDate;
// 价税合计
private BigDecimal totalAmount;
// 姓名
private String passenger;
// 车次
private String trafficNum;
// 出发点
private String startAddr;
// 目的地
private String endAddr;
// 座位类型编号
private String seatClass;
// 座位类型名称
private String seatClassName;
// 附加费
private BigDecimal additionAmount;
// 附加费2
private BigDecimal addition2Amount;
// 上车时间
private String startTime;
// 下车时间
private String endTime;
// 票据所在地
private String TicketAddr;
// 车型
private String vehicleType;
// 车重
private String vehicleWeight;
// 消费类型
private String consumerType;
// 购方税号
private String buyerTaxNo;
// 购方名称
private String buyerName;
// 销方税号
private String sellerTaxNo;
// 销方名称
private String sellerName;
// 发票文件类型
private String fileType;
// 发票下载链接
private String dmzUrl;
// 下载链接(内网)
private String bizUrl;
// 是否退票费
private String refundFlag;
// 保险费
private BigDecimal insurance;
// 其它税费
private BigDecimal otherTax;
}

32
src/main/java/com/win/bank/service/invoice/BasicInvoiceService.java

@ -0,0 +1,32 @@
package com.win.bank.service.invoice;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.win.bank.domain.BasicInvoiceDO;
import com.win.bank.mapper.BasicInvoiceMapper;
/**
* @author admin
*/
@Service
public class BasicInvoiceService extends ServiceImpl<BasicInvoiceMapper, BasicInvoiceDO> implements IService<BasicInvoiceDO> {
public Set<String> getInvoiceId(LocalDate previousDate) {
Set<String> idSet = new HashSet<>();
QueryWrapper<BasicInvoiceDO> queryWrapper = new QueryWrapper<>();
queryWrapper.select("invoice_id");
queryWrapper.ge("system_create_time", previousDate);
List<BasicInvoiceDO> invoiceDOList = list(queryWrapper);
for (BasicInvoiceDO invoiceDO : invoiceDOList) {
idSet.add(invoiceDO.getInvoiceId());
}
return idSet;
}
}
Loading…
Cancel
Save