//package com.njcn.device.pq.job;
//
//import com.njcn.device.pq.constant.Param;
//import com.njcn.device.pq.pojo.po.Line;
//import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
//import com.njcn.device.pq.service.IPqsTerminalLogsService;
//import com.njcn.device.pq.service.TerminalBaseService;
//import com.njcn.message.constant.DeviceRebootType;
//import com.njcn.redis.utils.RedisUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
///**
// * Description:
// * Date: 2025/04/09  上午 10:11【需求编号】
// *定时扫描终端日志表是否需要通知前置重启
// * @author clam
// * @version V1.0.0
// */
////@Component
////@EnableScheduling
//public class ScheduledTasks {
//
//    @Autowired
//    private IPqsTerminalLogsService iPqsTerminalLogsService;
//
//    @Autowired
//    private TerminalBaseService terminalBaseService;
//
//    @Scheduled(fixedRate = 1000*60*10) // 每10分钟执行一次
//    public void reportCurrentTime() {
//        LocalDateTime now =LocalDateTime.now();
//        LocalDateTime tenMinutesAgo = now.minusMinutes(-10);
//        List<PqsTerminalLogs> list = iPqsTerminalLogsService.lambdaQuery()
//               // .between(PqsTerminalLogs::getCreateTime, tenMinutesAgo, now)
//                .eq(PqsTerminalLogs::getState, 1).eq(PqsTerminalLogs::getIsPush, 1).list();
//        if(!CollectionUtils.isEmpty(list)){
//            //一个是删除操作，其余都算终端设备更新操作
//            List<PqsTerminalLogs> delDevice = list.stream().filter(temp -> Objects.equals(temp.getOperateType(), Param.DEL) && Objects.equals(temp.getTerminalType(), 4)).distinct().collect(Collectors.toList());
//            List<String> delDevIds = new ArrayList<>();
//            if(!CollectionUtils.isEmpty(delDevice)){
//                delDevice.forEach(temp->{
//                    terminalBaseService.askRestartDevice(temp.getObjIndex(), DeviceRebootType.DELETE_TERMINAL);
//                    delDevIds.add(temp.getObjIndex());
//                  }
//                );
//            }
//            List<String> updateDevIds = new ArrayList<>();
//            List<String> lineIds = list.stream().filter(temp -> Objects.equals(temp.getTerminalType(), 6)).map(PqsTerminalLogs::getObjIndex).distinct().collect(Collectors.toList());
//            List<String> devIds = list.stream().filter(temp -> Objects.equals(temp.getTerminalType(), 4)).map(PqsTerminalLogs::getObjIndex).distinct().collect(Collectors.toList());
//
//            //更新的终端
//            List<Line> lineById = terminalBaseService.getLineById(lineIds);
//            List<String> devIdList = lineById.stream().map(temp -> {
//                return temp.getPids().split(",")[4];
//            }).distinct().collect(Collectors.toList());
//            updateDevIds.addAll(devIdList);
//            updateDevIds.addAll(devIds);
//            if(!CollectionUtils.isEmpty(delDevIds)){
//                updateDevIds.removeAll(delDevIds);
//            }
//            updateDevIds.stream().distinct().forEach(temp->{
//                        terminalBaseService.askRestartDevice(temp, DeviceRebootType.LEDGER_MODIFY);
//                    }
//            );
//
//        }
//
//    }
//
//    public static void main(String[] args) {
//        List<String> updateDevIds = new ArrayList<>();
//        List<String> list1 = new ArrayList<>();
//        List<String> list2 = new ArrayList<>();
//        List<String> list3 = new ArrayList<>();
//        list1.add("1");
//        list1.add("2");
//        list1.add("3");
//        list1.add("3");
//        list2.add("3");
//        list2.add("4");
//        list2.add("5");
//        list3.add("3");
//        updateDevIds.addAll(list1);
//        updateDevIds.addAll(list2);
//        updateDevIds.removeAll(list3);
//        System.out.println(updateDevIds);
//
//
//
//    }
//
//}
