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);
|
}
|
}
|
}
|