kongdeqiang
2023-09-22 4dfd3b17483445db01c894c253a1b692f01c0067
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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.scheduling.annotation.Scheduled;
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 40 18 * * ?")
    public void execute() throws Exception {
        Path path = Paths.get("E:\\ycCheckBill\\Bank_PSBC_20230421.txt");
 
        DateTime start = DateUtil.parse(  "2023-04-20 22:30:00");
        DateTime end = DateUtil.parse("2023-04-21 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);
        }
    }
}