McInvoiceDto.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.malk.xzkj.model;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.malk.base.BaseDto;
  4. import com.malk.server.common.McException;
  5. import com.malk.server.common.McREnum;
  6. import com.malk.utils.UtilMap;
  7. import lombok.AllArgsConstructor;
  8. import lombok.Builder;
  9. import lombok.Data;
  10. import lombok.NoArgsConstructor;
  11. import org.apache.commons.lang3.StringUtils;
  12. import java.math.BigDecimal;
  13. import java.util.Map;
  14. /**
  15. * ppExt: 新版本官方返回数据已结构化, 以官方为准
  16. *
  17. * @apiNote https://cloud.tencent.com/document/api/866/33527#AirTransport 数据结构
  18. */
  19. @Data
  20. @Builder
  21. @AllArgsConstructor
  22. @NoArgsConstructor
  23. public class McInvoiceDto extends BaseDto {
  24. /**************** 发票 ****************/
  25. /**
  26. * 发票名称 [类型全称]
  27. */
  28. private String name;
  29. /**
  30. * 发票用途 [供应商、报销]
  31. */
  32. private String type;
  33. // 兼容: 不为空
  34. public String getName() {
  35. if (StringUtils.isBlank(name)) {
  36. return kindName;
  37. }
  38. return name;
  39. }
  40. /**
  41. * 发票类型 [类型简称]
  42. * -
  43. * ppExt: 全电票, 新版本识别接口, 返回名称为: 电子发票(普通发票) 不包含全电标识, 发类型为: 全电发票. 注意取值
  44. */
  45. private String kindName;
  46. /**
  47. * 发票类型 [编码]
  48. */
  49. private int kind;
  50. /**
  51. * 发票代码
  52. */
  53. private String code;
  54. /**
  55. * 发票号码
  56. */
  57. private String serial;
  58. /**
  59. * 开票日期 [yyyy-MM-dd]
  60. */
  61. private String date;
  62. /**
  63. * 校验码
  64. */
  65. private String checkCode;
  66. /**
  67. * 价税合计
  68. */
  69. private BigDecimal amount;
  70. /**
  71. * 不含税金额
  72. */
  73. private BigDecimal excludingTax;
  74. /// 没有税额时, 税额可能没传递 [因此前提是不含税为空],不含税金额等于价税合计
  75. public BigDecimal getExcludingTax() {
  76. if (ObjectUtil.isNull((excludingTax)) && (ObjectUtil.isNull(tax) || BigDecimal.ZERO.compareTo(tax) == 0)) {
  77. return amount;
  78. }
  79. return excludingTax;
  80. }
  81. /**
  82. * 不含税金额
  83. */
  84. private BigDecimal tax;
  85. /// 取值为null, 合计会异常
  86. public BigDecimal getTax() {
  87. if (ObjectUtil.isNull(tax)) {
  88. return BigDecimal.ZERO;
  89. }
  90. return tax;
  91. }
  92. /**
  93. * 购买方名称
  94. */
  95. private String buyerName;
  96. /**
  97. * 购买方税号
  98. */
  99. private String buyerTaxId;
  100. /**
  101. * 销售方名称
  102. */
  103. private String sellerName;
  104. /**
  105. * 销售方税号
  106. */
  107. private String sellerTaxId;
  108. /**
  109. * 备注
  110. */
  111. private String remark;
  112. /**************** 交通 ****************/
  113. /**
  114. * 乘客姓名
  115. */
  116. private String passengerName;
  117. /**
  118. * 座位类型
  119. */
  120. private String seatType;
  121. /**
  122. * 出发地
  123. */
  124. private String departurePort;
  125. /**
  126. * 到达地
  127. */
  128. private String arrivePort;
  129. /**
  130. * 出发时间 [yyyy-MM-dd HH:mm]
  131. */
  132. private String departureTime;
  133. /**
  134. * 车次编号/航班号
  135. */
  136. private String trainNo;
  137. /**
  138. * 保险费
  139. */
  140. private BigDecimal insuranceCosts;
  141. /**
  142. * 燃油附加费
  143. */
  144. private BigDecimal fuelCosts;
  145. /**
  146. * 民航发展基金
  147. */
  148. private BigDecimal constructionCosts;
  149. /**************** 格式化 ****************/
  150. /**
  151. * 实例Map, 服务宜搭组件映射 [明细组件获取表头, 通过名称转换字段]
  152. *
  153. * @implSpec const headers = this.$("tableField_liv5f4d2").props.children[0].props.children.map(({ props: { label, fieldId } }) => ({ label, compId: fieldId }))
  154. */
  155. public static Map formatDtoLabelAndProp() {
  156. Map data = UtilMap.map("发票名称, 发票类型, 发票代码, 发票号码, 开票日期, 校验码, 价税合计, 不含税金额, 税额", "name, kindName, code, serial, date, checkCode, amount, excludingTax, tax");
  157. data.putAll(UtilMap.map("购买方名称, 购买方税号, 销售方名称, 销售方税号", "buyerName, buyerTaxId, sellerName, sellerTaxId"));
  158. data.putAll(UtilMap.map("乘客姓名, 座位类型, 出发地, 到达地, 出发时间, 车次编号/航班号, 保险费, 燃油附加费, 民航发展基金", "passengerName, seatType, departurePort, arrivePort, departureTime, trainNo, insuranceCosts, fuelCosts, constructionCosts"));
  159. return data;
  160. }
  161. /**
  162. * 格式化返回
  163. */
  164. public static Map formatResponse(Object result) {
  165. return UtilMap.map("result, dto", result, formatDtoLabelAndProp());
  166. }
  167. /**************** 返回值 ****************/
  168. // 成功状态标记
  169. private final static String SUC_CODE = "OK";
  170. /**
  171. * 断言错误信息
  172. */
  173. public static void assertSuccess(Map result, String kind) {
  174. String code = UtilMap.getString(result, "Code");
  175. McException.assertException(!SUC_CODE.equals(code), McREnum.VENDOR_ERROR.getCode(), kind, "tencent");
  176. }
  177. }