|
@@ -0,0 +1,66 @@
|
|
|
+package com.jkcredit.info.query.task;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.jkcredit.info.query.util.QueryCountUtil;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xusonglin
|
|
|
+ * @version V1.0
|
|
|
+ **/
|
|
|
+@Component
|
|
|
+public class QueryCountTask {
|
|
|
+ @Scheduled(cron = "59 59 23 ? * *", zone = "Asia/Shanghai")
|
|
|
+// @Scheduled(cron = "0 0/2 * * * ?", zone = "Asia/Shanghai")
|
|
|
+ public void count() {
|
|
|
+ String fileName = DateUtil.format(new Date(), "yyyyMM") + ".txt";
|
|
|
+ String filePath = "C:\\Users\\Administrator\\Desktop\\work\\count\\" + fileName;
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ ioe.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> stringList = FileUtil.readLines(file, Charset.defaultCharset());
|
|
|
+ List<String> countList = new ArrayList<>();
|
|
|
+
|
|
|
+ int listTotalCount = 0;
|
|
|
+ int detailTotalCount = 0;
|
|
|
+ for (String str : stringList) {
|
|
|
+ if (str.contains("total")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] countArray = str.split(",");
|
|
|
+ listTotalCount += Integer.parseInt(countArray[1]);
|
|
|
+ detailTotalCount += Integer.parseInt(countArray[2]);
|
|
|
+ countList.add(str);
|
|
|
+ }
|
|
|
+ String countStr = DateUtil.today() + "," + QueryCountUtil.getQueryInfoListCount() + "," + QueryCountUtil.getQueryDetailCount();
|
|
|
+ countList.add(countStr);
|
|
|
+
|
|
|
+ listTotalCount += QueryCountUtil.getQueryInfoListCount();
|
|
|
+ detailTotalCount += QueryCountUtil.getQueryDetailCount();
|
|
|
+ int totalCount = listTotalCount + detailTotalCount;
|
|
|
+ countList.add("total:" + totalCount);
|
|
|
+
|
|
|
+ FileUtil.writeLines(countList, file, Charset.defaultCharset());
|
|
|
+ QueryCountUtil.clearQueryInfoListCount();
|
|
|
+ QueryCountUtil.clearQueryDetailCount();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println(DateUtil.format(new Date(), "yyyyMM"));
|
|
|
+ }
|
|
|
+}
|