Veronique hai 7 meses
pai
achega
7eeb7a97dd

+ 38 - 0
conf/esTemplate/payrequestrecord.json

@@ -0,0 +1,38 @@
+{
+  "info": {
+    "properties": {
+      "appId": {
+        "type": "text",
+        "index": "not_analyzed"
+      },
+      "billKey": {
+        "type": "text",
+        "index": "not_analyzed"
+      },
+      "payDate": {
+        "type": "text",
+        "index": "not_analyzed"
+      },
+      "bankBillNo": {
+        "type": "text",
+        "index": "not_analyzed"
+      },
+      "payAmount": {
+        "type": "text",
+        "index": "not_analyzed"
+      },
+      "createBy": {
+        "type": "long"
+      },
+      "createTimeLong": {
+        "type": "long"
+      },
+      "updateBy": {
+        "type": "long"
+      },
+      "updateTimeLong": {
+        "type": "long"
+      }
+    }
+  }
+}

+ 3 - 0
conf/eskeys.properties

@@ -73,3 +73,6 @@ es.orderstep.index = yjheating_orderstep_
 #订单退款申请
 es.refundorderrequest.index = yjheating_refundorderrequest_
 
+#请求销账记录
+es.payrequest.record.index = yjheating_payrequest_record_
+

+ 29 - 0
conf/script/1000/callThird/BE_Call_RequestPay.groovy

@@ -1,19 +1,24 @@
+import com.dySweetFishPlugin.elasticsearch.ESClient
 import com.sweetfish.convert.json.JsonConvert
 import com.sweetfish.service.RetResult
 import com.yinjie.heating.common.api.BusinessExecutor
+import com.yinjie.heating.common.api.NoSqlKeysService
 import com.yinjie.heating.common.datas.ERPModule
+import com.yinjie.heating.common.datas.ESKeys
 import com.yinjie.heating.common.datas.HeatingAppInvokerCode
 import com.yinjie.heating.common.entity.base.ProcessMapItem
 import com.yinjie.heating.common.entity.callthird.BaseResponse
 import com.yinjie.heating.common.entity.callthird.QueryFeeResponse
 import com.yinjie.heating.common.entity.heating.HeatingApp
 import com.yinjie.heating.common.entity.heating.HeatingAppInvoker
+import com.yinjie.heating.common.entity.heating.PayRequestRecord
 import com.yinjie.heating.common.http.HttpTools
 import com.yinjie.heating.common.tool.CommonUtils
 import com.yinjie.heating.common.tool.PaySignatureUtil
 import org.apache.commons.lang3.StringUtils
 import org.apache.logging.log4j.LogManager
 import org.apache.logging.log4j.Logger
+import org.elasticsearch.common.xcontent.XContentType
 import org.rex.RMap
 
 import javax.annotation.Resource
@@ -28,6 +33,12 @@ class BE_Call_RequestPay implements BusinessExecutor<ProcessMapItem, BaseRespons
     @Resource
     private JsonConvert jsonConvert
 
+    @Resource
+    private ESClient esClient
+
+    @Resource
+    private NoSqlKeysService keysService
+
     @Override
     String scriptName() {
         return "调用外部热力服务商接口-请求销账"
@@ -61,6 +72,24 @@ class BE_Call_RequestPay implements BusinessExecutor<ProcessMapItem, BaseRespons
 
         }
 
+        //此处需要将请求记录下来
+        PayRequestRecord requestRecord = new PayRequestRecord()
+        requestRecord.with {
+            it.appId = app.appId
+            it.billKey = billKey
+            it.bankBillNo = bankBillNo
+            it.payDate = payDate
+            it.payAmount = payAmount
+        }
+        PayRequestRecord.create(requestRecord, 999L)
+
+        //暂时写入es,由定时线程统一将前一天的记录存成文件,并删除缓存
+        esClient.getClient()
+                .prepareIndex(keysService.getESKey(ESKeys.ES_ERP_PAY_REQUEST_RECORD_INDEX, supplierCode), ESKeys.ES_ERP_PAY_REQUEST_RECORD_TYPE)
+                .setSource(jsonConvert.convertTo(requestRecord), XContentType.JSON)
+                .get()
+
+
         Map<String, String> header = new HashMap<>()
         header.put("Content-Type", "application/json")
 

+ 15 - 0
conf/script/1000/init/Init_21_PayRequestRecord.groovy

@@ -0,0 +1,15 @@
+import com.yinjie.heating.common.api.NoSqlKeysService
+import com.yinjie.heating.common.datas.ESKeys
+import com.dySweetFishPlugin.elasticsearch.ESClient
+import com.sweetfish.util.Utility
+
+static def createRunnable(ESClient esClient, NoSqlKeysService keysService, long supplierCode) {
+    return {
+        //region 站内通知和短信
+        esClient.checkIndexEx(keysService.getESKey(ESKeys.ES_ERP_PAY_REQUEST_RECORD_INDEX, supplierCode), ESKeys.INDEX_CONFIG,
+                Utility.ofMap(ESKeys.ESERPDEFAULT_TYPE, "payrequestrecord.json"))
+    } as Runnable
+}
+
+//groovy最后一个表达式的值为返回
+createRunnable(esClient, keysService, supplierCode)

+ 67 - 0
conf/script/1000/init/Time_3_D_0_1_0_0_SavePayRequestRecord.groovy

@@ -0,0 +1,67 @@
+import com.dySweetFishPlugin.elasticsearch.ESClient
+import com.sweetfish.convert.json.JsonConvert
+import com.sweetfish.source.PageFlipper
+import com.yinjie.heating.common.api.NoSqlKeysService
+import com.yinjie.heating.common.datas.ESKeys
+import com.yinjie.heating.common.entity.heating.PayRequestRecord
+import com.yinjie.heating.common.tool.ERPUtils
+import org.apache.logging.log4j.Logger
+import org.elasticsearch.index.query.QueryBuilders
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
+import java.nio.file.StandardOpenOption
+import java.time.LocalDate
+import java.time.ZoneId
+
+static def createRunnable(String appHome, ESClient esClient, NoSqlKeysService keysService, JsonConvert jsonConvert, Logger logger, String dataSourceId, long supplierCode) {
+    return {
+        logger.info("写入请求销账记录开始...")
+
+        def zone = ZoneId.of("GMT+8")
+        def yesterday = LocalDate.now(zone).minusDays(1).toString()
+
+        String fileName = appHome + File.separator +
+                "savedPayRequest" + File.separator +
+                supplierCode + File.separator + yesterday + ".txt"
+
+        Path filePath = Paths.get(fileName)
+        Files.createDirectories(filePath.getParent())
+
+        Ignore_ExecPageFlipper.execute(1000, { PageFlipper p ->
+            List<PayRequestRecord> payRequestRecordList = ESList.<PayRequestRecord> getESList()
+                    .esClient(esClient)
+                    .jsonConvert(jsonConvert)
+                    .clazz(PayRequestRecord.class)
+                    .queryBuilder({
+                        return QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_ERP_PAY_REQUEST_RECORD_TYPE))
+                                .must(QueryBuilders.rangeQuery("createTimeLong").lt(ERPUtils.dayStartTimeMilliseconds))
+
+                    })
+                    .index(keysService.getESKey(ESKeys.ES_ERP_PAY_REQUEST_RECORD_INDEX, supplierCode))
+                    .executePage(p)
+
+            String saveContent = ""
+            payRequestRecordList.each {
+                saveContent += it.convertToSaveFormat() + "\r\n"
+            }
+
+
+            Files.write(filePath,
+                    Collections.singleton(new StringBuilder(saveContent)),
+                    StandardCharsets.UTF_8,
+                    StandardOpenOption.CREATE,
+                    StandardOpenOption.WRITE,
+                    StandardOpenOption.APPEND)
+        })
+
+        sleep(1000) //无论如何,让脚本执行时间超过1s,防止1s内执行完毕导致多次执行
+        logger.info("写入请求销账记录完成")
+
+    } as Runnable
+}
+
+//groovy最后一个表达式的值为返回
+createRunnable(appHome, esClient, keysService, jsonConvert, logger, dataSourceId, supplierCode)

+ 3 - 5
yjCommon/src/main/java/com/yinjie/heating/common/datas/ESKeys.java

@@ -86,11 +86,9 @@ public class ESKeys {
     //endregion
 
 
-    //region 门店品牌档案
-
-    public static final String ES_DELIVER_STORE_BRAND_INDEX = "es.storebrand.index";
-    public static final String ES_DELIVER_STORE_BRAND_TYPE = "info";
-
+    //region 银行请求销账记录
+    public static final String ES_ERP_PAY_REQUEST_RECORD_INDEX = "es.payrequest.record.index";
+    public static final String ES_ERP_PAY_REQUEST_RECORD_TYPE = "info";
     //endregion
 
     //region 门店档案

+ 69 - 0
yjCommon/src/main/java/com/yinjie/heating/common/entity/heating/PayRequestRecord.java

@@ -0,0 +1,69 @@
+package com.yinjie.heating.common.entity.heating;
+
+import com.sweetfish.util.Comment;
+import com.yinjie.heating.common.entity.base.BaseEntity;
+
+/**
+ * 银行传过来的请求销账记录,记录对账用
+ * 此表每天形成一个txt,不存库
+ */
+public class PayRequestRecord extends BaseEntity {
+    @Comment("")
+    private String appId;
+
+    @Comment("户号")
+    private String billKey;
+
+    @Comment("支付日期")
+    private String payDate;
+
+    @Comment("银行流水")
+    private String bankBillNo;
+
+    @Comment("金额")
+    private String payAmount;
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getBillKey() {
+        return billKey;
+    }
+
+    public void setBillKey(String billKey) {
+        this.billKey = billKey;
+    }
+
+    public String getPayDate() {
+        return payDate;
+    }
+
+    public void setPayDate(String payDate) {
+        this.payDate = payDate;
+    }
+
+    public String getBankBillNo() {
+        return bankBillNo;
+    }
+
+    public void setBankBillNo(String bankBillNo) {
+        this.bankBillNo = bankBillNo;
+    }
+
+    public String getPayAmount() {
+        return payAmount;
+    }
+
+    public void setPayAmount(String payAmount) {
+        this.payAmount = payAmount;
+    }
+
+    public String convertToSaveFormat() {
+        return this.appId + "-" + this.billKey + "-" + this.payDate + "-" + this.bankBillNo + "-" + this.payAmount;
+    }
+}