|
|
@@ -0,0 +1,149 @@
|
|
|
+import com.dySweetFishPlugin.tool.lang.Holder
|
|
|
+import com.sweetfish.convert.json.JsonConvert
|
|
|
+import com.sweetfish.service.RetResult
|
|
|
+import com.yinjie.heating.common.api.BusinessExecutor
|
|
|
+import com.yinjie.heating.common.datas.ERPModule
|
|
|
+import com.yinjie.heating.common.entity.base.ProcessMapItem
|
|
|
+import com.yinjie.heating.common.entity.callthird.ViewBillResponse
|
|
|
+import com.yinjie.heating.common.entity.heating.BankBill
|
|
|
+import com.yinjie.heating.common.entity.heating.HeatingApp
|
|
|
+import org.apache.commons.lang3.StringUtils
|
|
|
+import org.apache.logging.log4j.LogManager
|
|
|
+import org.apache.logging.log4j.Logger
|
|
|
+import org.rex.RMap
|
|
|
+
|
|
|
+import javax.annotation.Resource
|
|
|
+import java.nio.charset.StandardCharsets
|
|
|
+import java.nio.file.Files
|
|
|
+import java.nio.file.Path
|
|
|
+import java.nio.file.Paths
|
|
|
+import java.util.stream.Stream
|
|
|
+
|
|
|
+class BE_Call_ViewBillFile implements BusinessExecutor<ProcessMapItem, ViewBillResponse> {
|
|
|
+ private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JsonConvert jsonConvert
|
|
|
+
|
|
|
+ @Resource(name = "property.downloadBillRoot")
|
|
|
+ private String downloadBillRoot
|
|
|
+
|
|
|
+ @Override
|
|
|
+ String scriptName() {
|
|
|
+ return "后台页面调用-查看账单"
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ ERPModule module() {
|
|
|
+ return ERPModule.CALL_THIRD
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<BankBill> readBillFile(Path scriptFile, boolean trimed, Logger logger) {
|
|
|
+ final List<BankBill> billList = new ArrayList<>()
|
|
|
+
|
|
|
+ try {
|
|
|
+ Integer iIndex = 0
|
|
|
+ Holder<Integer> prefix = Holder.of(iIndex)
|
|
|
+ try (Stream<String> lines = Files.lines(scriptFile, StandardCharsets.UTF_8)) {
|
|
|
+ lines.each { line ->
|
|
|
+ line = (trimed) ? line.trim() : line
|
|
|
+ if (!line.isEmpty()) {
|
|
|
+ if (prefix.get() == 0) {
|
|
|
+ //第一行不要,因为是统计行
|
|
|
+// buf.append((trimed) ? line.trim() : line)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //解析单行数据
|
|
|
+ String[] billParams = line.split("\\|")
|
|
|
+ //交易日期|银行交易流水号|平台交易号|机表号|交易金额|合同号(同机表号)|手续费|扣除手续费之后的金额
|
|
|
+
|
|
|
+ BankBill bankBill = new BankBill()
|
|
|
+ bankBill.paymentDate = billParams[0]
|
|
|
+ bankBill.bankBillNO = billParams[1]
|
|
|
+ bankBill.plateBillNO = billParams[2]
|
|
|
+ bankBill.paymentClientCode = billParams[3]
|
|
|
+ bankBill.paymentAmount = new BigDecimal(billParams[4])
|
|
|
+ bankBill.serviceFee = new BigDecimal(billParams[6])
|
|
|
+ bankBill.settlementFee = new BigDecimal(billParams[7])
|
|
|
+
|
|
|
+ billList.add(bankBill)
|
|
|
+ }
|
|
|
+
|
|
|
+ prefix.set(1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error(e.getMessage(), e)
|
|
|
+ }
|
|
|
+
|
|
|
+ return billList
|
|
|
+ }
|
|
|
+
|
|
|
+ RetResult<ViewBillResponse> execute(ProcessMapItem source) {
|
|
|
+ RMap params = source.itemData
|
|
|
+ String dataSourceId = source.dataSourceId
|
|
|
+ long supplierCode = source.supplierCode
|
|
|
+
|
|
|
+ String payDate = params.getString("payDate")
|
|
|
+ HeatingApp app = params.get("app") as HeatingApp
|
|
|
+
|
|
|
+ params.remove("app")//避免影响下面验签
|
|
|
+
|
|
|
+ //接口均返回正确,错误放在result里
|
|
|
+ if (app == null) {
|
|
|
+ logger.error("下载对账单传入app为空")
|
|
|
+ return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
|
|
|
+ .respCode("DEF0010")
|
|
|
+ .respMsg("用户不存在")
|
|
|
+ .timeStamp((new Date()).time as String)
|
|
|
+ .build())
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(payDate)) {
|
|
|
+ logger.error("下载对账单传入参数不正确")
|
|
|
+ return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
|
|
|
+ .respCode("DEF0006")
|
|
|
+ .respMsg("系统错误")
|
|
|
+ .timeStamp((new Date()).time as String)
|
|
|
+ .build())
|
|
|
+ }
|
|
|
+
|
|
|
+ //查找对应日期的文件夹是否存在
|
|
|
+
|
|
|
+ Path dirPath = Paths.get(downloadBillRoot + File.separator + payDate)
|
|
|
+ if (Files.exists(dirPath) && (Files.isDirectory(dirPath))) {
|
|
|
+ Path filePath = Paths.get(downloadBillRoot + File.separator + payDate + File.separator + "GD_" + payDate + "_" + app.upperChannelAppId + ".txt")
|
|
|
+ if (Files.exists(filePath)) {
|
|
|
+ //读取文件内容
|
|
|
+ List<BankBill> billList = readBillFile(filePath, true, logger)
|
|
|
+
|
|
|
+ return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
|
|
|
+ .respCode("00000")
|
|
|
+ .respMsg("success")
|
|
|
+ .appId(app.appId)
|
|
|
+ .billList(billList)
|
|
|
+ .timeStamp((new Date()).time as String)
|
|
|
+ .build())
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("找不到对账单" + filePath.toString())
|
|
|
+ return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
|
|
|
+ .respCode("DEF0020")
|
|
|
+ .respMsg("该日期账单文件暂未生成")
|
|
|
+ .timeStamp((new Date()).time as String)
|
|
|
+ .build())
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("找不到对账单日期" + payDate + "的目录")
|
|
|
+ return RetResult.<ViewBillResponse> successT().result(new ViewBillResponse.Builder()
|
|
|
+ .respCode("DEF0020")
|
|
|
+ .respMsg("该日期账单文件暂未生成")
|
|
|
+ .timeStamp((new Date()).time as String)
|
|
|
+ .build())
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|