From 95cdeea70bfee905c8601a8fc11cbba7aa31b85c Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期三, 26 四月 2023 17:16:49 +0800
Subject: [PATCH] 对账
---
src/main/java/com/boying/job/ReadFileScheduled2.java | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 113 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/boying/job/ReadFileScheduled2.java b/src/main/java/com/boying/job/ReadFileScheduled2.java
new file mode 100644
index 0000000..f4e134a
--- /dev/null
+++ b/src/main/java/com/boying/job/ReadFileScheduled2.java
@@ -0,0 +1,113 @@
+package com.boying.job;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.boying.entity.ErrorLog;
+import com.boying.entity.OrderRecord;
+import com.boying.service.ErrorLogService;
+import com.boying.service.OrderRecordService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * @author kdq
+ * @version 1.0.0
+ * @ClassName ReadFileScheduled.java
+ * @Description TODO
+ * @createTime 2023骞�04鏈�24鏃� 09:07:00
+ */
+@Slf4j
+@Component
+public class ReadFileScheduled2 {
+
+ @Autowired
+ private OrderRecordService orderRecordService;
+ @Autowired
+ private ErrorLogService errorLogService;
+
+ //@Scheduled(cron = "0 30 14 * * ?")
+ public void execute() throws Exception {
+ Path path = Paths.get("E:\\ycCheckBill\\Bank_PSBC_20230422.txt");
+
+ DateTime start = DateUtil.parse( "2023-04-21 22:30:00");
+ DateTime end = DateUtil.parse("2023-04-22 22:29:59");
+
+ QueryWrapper<OrderRecord> wrapper = new QueryWrapper<>();
+ wrapper.lambda()
+ .isNotNull(OrderRecord::getUpdateTime)
+ .between(OrderRecord::getUpdateTime,start,end)
+ .isNotNull(OrderRecord::getMoney)
+ .eq(OrderRecord::getStatus,1)
+ .eq(OrderRecord::getType,1);
+ List<OrderRecord> list = orderRecordService.list(wrapper);
+
+ try {
+ List<String> lines = Files.readAllLines(path);
+ String s = lines.get(0);
+ String[] split = s.split("\\|");
+ int count = Integer.parseInt(split[0]);
+ //鍒ゆ柇count鏁伴噺鏄惁澶т簬0
+ if(count == 0){
+ if(list.size() >0){
+ //閭偍娌℃湁鏀跺埌閲戦锛岃鍗曡〃閲屾湁璁板綍
+ for (OrderRecord orderRecord : list) {
+ ErrorLog errorLog = new ErrorLog();
+ errorLog.setMoney(orderRecord.getMoney());
+ errorLog.setQueryId(orderRecord.getId());
+ errorLog.setRemark("缂存澶辫触");
+ errorLogService.save(errorLog);
+ }
+ }
+ }else {
+ List<OrderRecord> lineList = new ArrayList<>();
+ for (int i = 1; i < lines.size(); i++) {
+ String s1 = lines.get(i);
+ String[] split1 = s.split("\\|");
+ int id = Integer.parseInt(split[1]);
+ OrderRecord byId = orderRecordService.getById(id);
+ lineList.add(byId);
+ }
+
+ //list 涓湁鐨勶紝浣嗘槸lineList娌℃湁鐨�
+ Map<OrderRecord, OrderRecord> tempMap = lineList.parallelStream().collect(Collectors.toMap(Function.identity(), Function.identity(), (oldData, newData) -> newData));
+ List<OrderRecord> collect = list.parallelStream().filter(str -> {
+ return !tempMap.containsKey(str);
+ }).collect(Collectors.toList());
+
+ for (OrderRecord orderRecord : collect) {
+ ErrorLog errorLog = new ErrorLog();
+ errorLog.setMoney(orderRecord.getMoney());
+ errorLog.setQueryId(orderRecord.getId());
+ errorLog.setRemark("缂存澶辫触");
+ errorLogService.save(errorLog);
+ }
+ //lineList 涓湁鐨勶紝浣嗘槸List娌℃湁鐨�
+ Map<OrderRecord, OrderRecord> tempMap1 = list.parallelStream().collect(Collectors.toMap(Function.identity(), Function.identity(), (oldData, newData) -> newData));
+ List<OrderRecord> collect1 = lineList.parallelStream().filter(str -> {
+ return !tempMap1.containsKey(str);
+ }).collect(Collectors.toList());
+
+ for (OrderRecord orderRecord : collect1) {
+ ErrorLog errorLog = new ErrorLog();
+ errorLog.setMoney(orderRecord.getMoney());
+ errorLog.setQueryId(orderRecord.getId());
+ errorLog.setRemark("缂存鎴愬姛");
+ errorLogService.save(errorLog);
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
--
Gitblit v1.9.1