//package com.huimv.receive.timer;
//
//
//import cn.hutool.core.date.DateUtil;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
//import com.huimv.receive.common.token.TokenSign;
//import com.huimv.receive.entity.*;
//import com.huimv.receive.service.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.time.LocalDateTime;
//import java.time.ZoneId;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
//@Configuration
//@EnableScheduling
//public class SafeTimer {
//
//
//    @Autowired
//    private IBillPcrService pcrService;
//    @Autowired
//    private IBillIsolateService isolateService;
//    @Autowired
//    private IConfigurationService configurationService;
//
//    @Autowired
//    private ISysUserService sysUserService;
//    @Autowired
//    private IBaseProcessService processService;
//    @Autowired
//    private IBaseLocationService locationService;
//    @Autowired
//    private IBillCleanService cleanService;
//
//
//    @Scheduled(cron = "0 0/1 * * * ? ")
//    private void getShenChan() throws Exception {
//        QueryWrapper<BillIsolate> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("bill_status", 1);
//        List<BillIsolate> isolates = isolateService.list(queryWrapper);
//        Date date = new Date();
//        for (BillIsolate billIsolate : isolates) {
//            if (billIsolate.getIsolateEndDate().getTime() <= date.getTime()) {
//                billIsolate.setIsolateRealEndDate(date);
//                billIsolate.setIsolateRealDayNum(billIsolate.getIsolateDayNum());
//                billIsolate.setBillStatus(2);
//                billIsolate.setPassUserName("自然解除隔离");
//                billIsolate.setPassDate(date);
//                BaseProcess baseProcess = processService.getById(billIsolate.getProcessId());
//                QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
//                locationQueryWrapper.eq("id", billIsolate.getIsolateLocationId());
//                BaseLocation baseLocation = locationService.getOne(locationQueryWrapper);//当前隔离所在的位置
//
//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                String end = sdf.format(billIsolate.getIsolateEndDate());
//                String start = sdf.format(billIsolate.getIsolateStartDate());
//                String now = sdf.format(new Date());
//                if (baseProcess.getDestId().equals(billIsolate.getIsolateLocationId()) || baseProcess.getDestId() >= 13) {
//                    //目的地就是当前隔离地点
//                    baseProcess.setProcessType(1);
//                    baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
//                    baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
//                } else {
//                    baseProcess.setProcessType(0);
//                    baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getNextLocation());
//                    baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getNextId());
//                }
//                if (billIsolate.getIsolateLocationId() == 3 && baseProcess.getDestId() >= 4) {
//                    //通过生成洗消记录
//                    BillClean billClean = new BillClean();
//                    billClean.setVistitType(billIsolate.getVistitType());
//                    billClean.setDestName(billIsolate.getDestName());
//                    billClean.setDestId(billIsolate.getDestId());
//                    billClean.setAdmissionUserName(billIsolate.getAdmissionUserName());
//                    billClean.setAdmissionUserId(billIsolate.getAdmissionUserId());
//                    billClean.setVistitDate(billIsolate.getVistitDate());
//                    billClean.setSubDate(LocalDateTime.now());
//                    billClean.setFarmId(billIsolate.getFarmId());
//                    billClean.setPassUserName(billIsolate.getPassUserName());
//                    billClean.setPassDate(billIsolate.getPassDate());
//                    billClean.setPassUserId(billIsolate.getPassUserId());
//                    billClean.setProcessId(billIsolate.getProcessId());
//                    billClean.setTestLocation("场内");
//                    billClean.setTestLocationId(4);
//                    billClean.setPhone(billIsolate.getPhone());
//                    cleanService.save(billClean);
//
//                    String status = baseProcess.getAllLocationStatus();
//                    String[] split = status.split(",");
//                    split[0] = "2";
//                    split[1] = "2";
//                    split[2] = "2";
//                    split[3] = "2";
//                    split[4] = "1";
//                    baseProcess.setAllLocationStatus(split[0] + "," + split[1] + "," + split[2] + "," + split[3]+"," +split[4]+ status.substring(9));
//                }
//
//                billIsolate.setIsolateRealEndDate(new Date());
//                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
//                Calendar cal1 = Calendar.getInstance();
//                Calendar cal2 = Calendar.getInstance();
//                Date startDate = sdf1.parse(start);
//                Date endDate = sdf1.parse(now);
//                cal1.setTime(startDate);
//                cal2.setTime(endDate);
//                long days = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / (1000 * 3600 * 24);
//                billIsolate.setIsolateRealDayNum(Long.toString(days));
//                billIsolate.setBillStatus(2);
//
//                baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + now);
//
//                String status = baseProcess.getCurrentStatus();
//                String substring = status.substring(0, status.length() - 1);
//                baseProcess.setCurrentStatus(substring + "1," + 0);
//
//                if (billIsolate.getIsolateLocationId() == 5) {
//                    baseProcess.setAllLocationStatus("2,2,2,2,2,2");
//                }
//                if (billIsolate.getIsolateLocationId() == 3) {
//                    String status1 = baseProcess.getAllLocationStatus();
//                    String[] split = status1.split(",");
//                    split[0] = "2";
//                    split[1] = "2";
//                    split[2] = "2";
//                    split[3] = "2";
//                    baseProcess.setAllLocationStatus(split[0] + "," + split[1] + "," + split[2] + "," + split[3]  + status1.substring(7));
//                }
//
//                isolateService.updateById(billIsolate);
//                processService.updateById(baseProcess);
//            }
//        }
//    }
//
//    @Scheduled(cron = "0 0/1 * * * ? ")
//    private void pcr() throws Exception {
//        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("bill_status", 1);
//        List<BillPcr> pcrs = pcrService.list(queryWrapper);
//        Date date = new Date();
//        for (BillPcr pcr : pcrs) {
//            Date subDate = pcr.getCheckDate();
//            // 将LocalDateTime转换为Date
//
//            if ((subDate.getTime() + pcr.getQualifiedDate() * 60 * 60 * 1000) <= date.getTime()) {
//                pcr.setBillStatus(3);
//                pcrService.updateById(pcr);
//            }
//        }
//    }
//
//    //计算年龄
//    @Scheduled(cron = "0 0 0 * * ? ")
//    private void getAge()   {
//        System.out.println("开始");
//        List<SysUser> sysUsers = sysUserService.list();
//        for (SysUser sysUser : sysUsers) {
//            int i = DateUtil.ageOfNow(sysUser.getBirthday());
//            if (i !=sysUser.getAge() ){
//                sysUser.setAge(i);
//                sysUserService.updateById(sysUser);
//            }
//        }
//    }
//
//}
