|
|
@@ -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)
|