1.数据库

1.1字段添加与初始化

  1. #电商
  2. ALTER TABLE mall_trade.invoice_apply_record ADD apply_result CHAR(1) NULL
  3. COMMENT '申请结果:1:等待中 2:申请失败 3:申请成功';
  4. #全员营销
  5. ALTER TABLE im.invoice_apply_record ADD apply_result CHAR(1) NULL
  6. COMMENT '申请结果:1:等待中 2:申请失败 3:申请成功';
  1. #所有已开票和已邮寄的发票申请 均是申请成功
  2. update im.invoice_apply_record
  3. set apply_result = '3'
  4. where `status` in ('2','3');
  5. #所有纸质(专用)发票申请未开票的 均是等待中
  6. update im.invoice_apply_record
  7. set apply_result ='1'
  8. where `status` = '1' and invoice_type = '2';
  9. #所有电票申请 未开票的 均为开票失败
  10. update im.invoice_apply_record
  11. set apply_result = '2'
  12. where `status`='1' and invoice_type='1';

1.2yurun_common数据库新增数据表

  1. use yurun_common;
  2. CREATE TABLE invoice_record(
  3. id INT NOT NULL AUTO_INCREMENT COMMENT 'id' ,
  4. invoice_from VARCHAR(32) COMMENT '开票来源 1-电商2-全员营销3-X6' ,
  5. invoice_type CHAR(1) COMMENT '发票类型 1-电子普票2-纸质普票' ,
  6. apply_id INT COMMENT '开票申请id' ,
  7. order_id VARCHAR(32) COMMENT '开票订单id' ,
  8. invoice_serial_no VARCHAR(32) COMMENT '发票流水号' ,
  9. invoice_no VARCHAR(32) COMMENT '发票号码' ,
  10. invoice_code VARCHAR(128) COMMENT '发票代码' ,
  11. total_amount_tax DECIMAL(10,2) COMMENT '价税合计金额' ,
  12. total_amount_notax DECIMAL(10,2) COMMENT '合计不含税金额' ,
  13. total_tax DECIMAL(10,2) COMMENT '合计税额' ,
  14. original_invoice_no VARCHAR(128) COMMENT '原发票票号' ,
  15. original_invoice_code VARCHAR(128) COMMENT '原发票代码' ,
  16. invoice_url VARCHAR(1024) COMMENT '发票url' ,
  17. invoice_status CHAR(1) COMMENT '发票状态 1-未开票2-已开票3-已下载4-已红冲' ,
  18. is_red CHAR(1) COMMENT '是否红冲 0-否1-是' ,
  19. invoice_config_id INT COMMENT '发票配置编号' ,
  20. invoice_time DATETIME COMMENT '开票日期' ,
  21. PRIMARY KEY (id)
  22. ) COMMENT = '发票信息表 ';
  23. CREATE TABLE invoice_detail(
  24. id INT NOT NULL AUTO_INCREMENT COMMENT 'id' ,
  25. invoice_id INT COMMENT '发票id' ,
  26. price DECIMAL(10,2) COMMENT '价格' ,
  27. num INT COMMENT '数量' ,
  28. amount DECIMAL(10,2) COMMENT '合计' ,
  29. tax_amount DECIMAL(10,2) COMMENT '合计税额' ,
  30. tax_rate DECIMAL(10,2) COMMENT '合计税率' ,
  31. order_detail_id INT COMMENT '订单明细编号' ,
  32. PRIMARY KEY (id)
  33. ) COMMENT = '发票明细表 ';
  34. CREATE TABLE invoice_config(
  35. id INT NOT NULL AUTO_INCREMENT COMMENT 'id' ,
  36. user_name VARCHAR(64) COMMENT '平台用户名' ,
  37. password VARCHAR(64) COMMENT '平台密码' ,
  38. taxpayer_id VARCHAR(64) COMMENT '纳税人识别号' ,
  39. authorization_code VARCHAR(32) COMMENT '接入系统平台授权码' ,
  40. qymc VARCHAR(128) COMMENT '开票方名称' ,
  41. nsrdzdah VARCHAR(32) COMMENT '开票方电子档案号' ,
  42. swjg_dm VARCHAR(32) COMMENT '税务机构代码' ,
  43. bmb_bbh VARCHAR(32) COMMENT '编码表版本号' ,
  44. xhf_dz VARCHAR(128) COMMENT '销货方地址' ,
  45. xhf_dh VARCHAR(32) COMMENT '销货方电话' ,
  46. xhf_yhzh VARCHAR(128) COMMENT '销货方银行账号' ,
  47. version VARCHAR(32) COMMENT '接口版本号' ,
  48. max_bill_amount DECIMAL(10,2) COMMENT '开票面额' ,
  49. issuer_name VARCHAR(32) COMMENT '开票人姓名' ,
  50. payee_name VARCHAR(32) COMMENT '收款人姓名' ,
  51. reviewer_name VARCHAR(32) COMMENT '复核人姓名' ,
  52. PRIMARY KEY (id)
  53. ) COMMENT = '发票主体配置表 ';
  54. CREATE TABLE tax_classification_code(
  55. id INT NOT NULL AUTO_INCREMENT COMMENT 'id' ,
  56. code VARCHAR(32) COMMENT '编码' ,
  57. classification_code VARCHAR(32) COMMENT '分类编码' ,
  58. name VARCHAR(128) COMMENT '分类名称' ,
  59. abbreviation VARCHAR(32) COMMENT '分类简称' ,
  60. tax_rate VARCHAR(32) COMMENT '税率' ,
  61. special_management VARCHAR(32) COMMENT '增值税特殊管理' ,
  62. PRIMARY KEY (id)
  63. ) COMMENT = '税收分类编码表';

1.3表数据初始化

发票相关表

  1. INSERT INTO `yurun_common`.`invoice_config`(`id`, `user_name`, `password`, `taxpayer_id`, `authorization_code`, `qymc`, `nsrdzdah`, `swjg_dm`, `bmb_bbh`, `xhf_dz`, `xhf_dh`, `xhf_yhzh`, `version`, `max_bill_amount`, `issuer_name`, `payee_name`, `reviewer_name`) VALUES (1, 'xaJ8DlpY', '3201000130NDgxYjE4N2RiODA4Yjk3MQ==', '91320105067086195W', 'XFYE6BJ24H', '南京雨润连锁经营管理有限公司', NULL, NULL, '18.0', '江苏南京浦口区桥林紫峰路19号', '025-66200131', '中国农业银行南京汉中西路支行 10107001040219131', '2.0', 100000.00, '熊钰馨', '吕小娣', '孔祥晨');
  1. insert into yurun_common.invoice_record
  2. (id,apply_id,invoice_from,invoice_type,order_id,invoice_serial_no,invoice_no,invoice_code,
  3. total_amount_tax,total_amount_notax,total_tax,invoice_url,invoice_status,invoice_time,is_red,
  4. original_invoice_no,original_invoice_code,invoice_config_id)
  5. select
  6. id,apply_id,'2',IF(invoice_type = '2','1','2') ,order_id,invoice_serial_no,invoice_no,invoice_code,total_amount_tax,total_amount_notax,
  7. total_tax,invoice_url, IF(invoice_status = '4','3',invoice_status),create_time,is_red,original_invoice_no,original_invoice_code,1
  8. from
  9. im.invoice_no_record;
  1. insert into
  2. yurun_common.invoice_detail
  3. (id,invoice_id,price,num,amount,tax_amount,tax_rate,order_detail_id)
  4. select
  5. id,invoice_id,price,num,amount,tax_amount,tax_rate,order_detail_id
  6. from im.invoice_item_detail;

税收分类编码表
见初始化文件

2.Nacos配置文件

2.1新增服务配置文件(invoice-service.yaml)

  1. # 数据源配置
  2. spring:
  3. datasource:
  4. url: xxxxxxxx
  5. username: xxxx
  6. password: xxxx
  7. invoice:
  8. url: "http://open.jsaisino.com/dianzifapiaoService/slqzconsole.do"
  9. rocketmq:
  10. nameServer: xxxxx
  11. producer:
  12. #超时时间
  13. sendMessageTimeout: 30000
  14. #发送组
  15. group: publicInvoiceGroup
  16. topic:
  17. invoiceApply: invoiceApply_pro
  18. invoiceDownload: invoiceDownload_pro
  19. invoiceResult: invoiceResult_pro
  20. invoiceApplyRed: invoiceApplyRed_pro
  21. invoiceResultRed: invoiceResultRed_pro
  22. consumerGroup:
  23. invoiceApply: invoiceApply_pro
  24. invoiceDownload: invoiceDownload_pro
  25. invoiceApplyRed: invoiceApplyRed_pro

2.2全员营销配置项(im-service.yaml)

在原有配置基础上添加如下配置

  1. #添加队列相关配置
  2. rocketmq:
  3. nameServer: xxxxxx
  4. producer:
  5. #超时时间
  6. sendMessageTimeout: 30000
  7. #发送组
  8. group: biGroup
  9. topic:
  10. invoiceApply: invoiceApply_pro
  11. invoiceResult: invoiceResult_pro
  12. consumerGroup:
  13. invoiceResult: invoiceResult_im_pro

2.3电商配置项(mall-trade-service.yaml)

在原有的队列配置中添加几个topic和消费者组

  1. # 队列配置
  2. rocketmq:
  3. nameServer: xxxxxxxxx
  4. producer:
  5. #超时时间
  6. sendMessageTimeout: 30000
  7. #发送组
  8. group: mallGroup
  9. topic:
  10. autoCancel: mall_autoCancel
  11. autoComplete: mall_autoComplete
  12. autoCloseReturn: mall_autoCloseReturn
  13. invoiceApply: invoiceApply_pro
  14. invoiceResult: invoiceResult_pro
  15. invoiceResultRed: invoiceResultRed_pro
  16. invoiceApplyRed: invoiceApplyRed_pro
  17. consumerGroup:
  18. autoCancel: mall_autoCancel
  19. autoComplete: mall_autoComplete
  20. autoCloseReturn: mall_autoCloseReturn
  21. invoiceResult: invoiceResult_trade_pro
  22. invoiceResultRed: invoiceResultRed_trade_pro

2.4文档中心和网关的路由配置项

  1. - id: invoice-service
  2. uri: lb://invoice-service
  3. predicates:
  4. - Path=/invoice/**
  5. filters:
  6. - StripPrefix=1

3.生产RocketMQ创建话题

队列作用 生产
正票开具申请队列 invoiceApply_pro
红票开具申请队列 invoiceApplyRed_pro
正票结果队列 invoiceResult_pro
红票结果队列 invoiceResultRed_pro
下载队列 invoiceDownload_pro