BE_Call_ViewBillFile.groovy 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import com.dySweetFishPlugin.tool.lang.Holder
  2. import com.sweetfish.convert.json.JsonConvert
  3. import com.sweetfish.service.RetResult
  4. import com.yinjie.heating.common.api.BusinessExecutor
  5. import com.yinjie.heating.common.datas.ERPModule
  6. import com.yinjie.heating.common.entity.base.ProcessMapItem
  7. import com.yinjie.heating.common.entity.callthird.ViewBillResponse
  8. import com.yinjie.heating.common.entity.heating.BankBill
  9. import com.yinjie.heating.common.entity.heating.HeatingApp
  10. import org.apache.commons.lang3.StringUtils
  11. import org.apache.logging.log4j.LogManager
  12. import org.apache.logging.log4j.Logger
  13. import org.rex.RMap
  14. import javax.annotation.Resource
  15. import java.nio.charset.StandardCharsets
  16. import java.nio.file.Files
  17. import java.nio.file.Path
  18. import java.nio.file.Paths
  19. import java.util.stream.Stream
  20. class BE_Call_ViewBillFile implements BusinessExecutor<ProcessMapItem, ViewBillResponse> {
  21. private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  22. @Resource
  23. private JsonConvert jsonConvert
  24. @Resource(name = "property.downloadBillRoot")
  25. private String downloadBillRoot
  26. @Override
  27. String scriptName() {
  28. return "后台页面调用-查看账单"
  29. }
  30. @Override
  31. ERPModule module() {
  32. return ERPModule.CALL_THIRD
  33. }
  34. static List<BankBill> readBillFile(Path scriptFile, boolean trimed, Logger logger) {
  35. final List<BankBill> billList = new ArrayList<>()
  36. try {
  37. Integer iIndex = 0
  38. Holder<Integer> prefix = Holder.of(iIndex)
  39. try (Stream<String> lines = Files.lines(scriptFile, StandardCharsets.UTF_8)) {
  40. lines.each { line ->
  41. line = (trimed) ? line.trim() : line
  42. if (!line.isEmpty()) {
  43. if (prefix.get() == 0) {
  44. //第一行不要,因为是统计行
  45. // buf.append((trimed) ? line.trim() : line)
  46. } else {
  47. //解析单行数据
  48. String[] billParams = line.split("\\|")
  49. //交易日期|银行交易流水号|平台交易号|机表号|交易金额|合同号(同机表号)|手续费|扣除手续费之后的金额
  50. BankBill bankBill = new BankBill()
  51. bankBill.paymentDate = billParams[0]
  52. bankBill.bankBillNO = billParams[1]
  53. bankBill.plateBillNO = billParams[2]
  54. bankBill.paymentClientCode = billParams[3]
  55. bankBill.paymentAmount = new BigDecimal(billParams[4])
  56. bankBill.serviceFee = new BigDecimal(billParams[6])
  57. bankBill.settlementFee = new BigDecimal(billParams[7])
  58. billList.add(bankBill)
  59. }
  60. prefix.set(1)
  61. }
  62. }
  63. }
  64. } catch (IOException e) {
  65. logger.error(e.getMessage(), e)
  66. }
  67. return billList
  68. }
  69. RetResult<ViewBillResponse> execute(ProcessMapItem source) {
  70. RMap params = source.itemData
  71. String dataSourceId = source.dataSourceId
  72. long supplierCode = source.supplierCode
  73. String payDate = params.getString("payDate")
  74. HeatingApp app = params.get("app") as HeatingApp
  75. params.remove("app")//避免影响下面验签
  76. //接口均返回正确,错误放在result里
  77. if (app == null) {
  78. logger.error("下载对账单传入app为空")
  79. return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
  80. .respCode("DEF0010")
  81. .respMsg("用户不存在")
  82. .timeStamp((new Date()).time as String)
  83. .build())
  84. }
  85. if (StringUtils.isBlank(payDate)) {
  86. logger.error("下载对账单传入参数不正确")
  87. return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
  88. .respCode("DEF0006")
  89. .respMsg("系统错误")
  90. .timeStamp((new Date()).time as String)
  91. .build())
  92. }
  93. //查找对应日期的文件夹是否存在
  94. Path dirPath = Paths.get(downloadBillRoot + File.separator + payDate)
  95. if (Files.exists(dirPath) && (Files.isDirectory(dirPath))) {
  96. Path filePath = Paths.get(downloadBillRoot + File.separator + payDate + File.separator + "GD_" + payDate + "_" + app.upperChannelAppId + ".txt")
  97. if (Files.exists(filePath)) {
  98. //读取文件内容
  99. List<BankBill> billList = readBillFile(filePath, true, logger)
  100. return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
  101. .respCode("00000")
  102. .respMsg("success")
  103. .appId(app.appId)
  104. .billList(billList)
  105. .timeStamp((new Date()).time as String)
  106. .build())
  107. } else {
  108. logger.error("找不到对账单" + filePath.toString())
  109. return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
  110. .respCode("DEF0020")
  111. .respMsg("该日期账单文件暂未生成")
  112. .timeStamp((new Date()).time as String)
  113. .build())
  114. }
  115. } else {
  116. logger.error("找不到对账单日期" + payDate + "的目录")
  117. return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
  118. .respCode("DEF0020")
  119. .respMsg("该日期账单文件暂未生成")
  120. .timeStamp((new Date()).time as String)
  121. .build())
  122. }
  123. }
  124. }