ReportService.java 24 KB
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
package com.ruoyi.service;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.ruoyi.common.SignStatusEnum;
import com.ruoyi.common.cache.NowSchedulingCache;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.global.Result;
import com.ruoyi.common.global.ResultCode;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.DriverScheduling;
import com.ruoyi.driver.domain.Driver;
import com.ruoyi.driver.mapper.DriverMapper;
import com.ruoyi.driver.mapper.DriverSchedulingMapper;
import com.ruoyi.eexception.mapper.EquipmentExceptionMapper;
import com.ruoyi.in.domain.SignIn;
import com.ruoyi.in.mapper.SignInMapper;
import com.ruoyi.pojo.request.ReportErrorRequestVo;
import com.ruoyi.pojo.request.ReportViewRequestVo;
import com.ruoyi.pojo.response.*;
import com.ruoyi.pojo.vo.PersonSignDataResponseVo;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.utils.ConstDateUtil;
import com.ruoyi.utils.ToolUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.ruoyi.common.ApiProperties.PERSONNEL_API_KEY;
import static com.ruoyi.common.ConstDriverProperties.BC_TYPE_OUT;
import static com.ruoyi.common.ConstDriverProperties.PERSONNEL_POSTS_DRIVER;
import static com.ruoyi.common.ConstSignInConstSignInProperties.*;
import static com.ruoyi.common.ReportProperties.*;
import static com.ruoyi.common.redispre.GlobalRedisPreName.REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW;

/**
 * @author 20412
 */
@Service
@Slf4j
public class ReportService {

    @Autowired
    private SignInMapper signInMapper;
    @Autowired
    private DriverMapper driverMapper;

    @Autowired
    private ISysNoticeService noticeService;

    @Autowired
    private EquipmentExceptionMapper exceptionMapper;

    @Resource
    private SchedulingService schedulingService;

    @Autowired
    private DriverSchedulingMapper schedulingMapper;


    @Autowired
    private RedisCache redisCache;
    @Autowired
    private NowSchedulingCache nowSchedulingCache;

    /**
     * 查询报表信息
     */
    public List<ReportViewResponseVo> getReportScrollViewTable(ReportViewRequestVo requestVo, HttpServletResponse response) {
        List<ReportViewResponseVo> reportScrollViewTable = schedulingService.queryReportTableResponseVo(requestVo, response);
        return reportScrollViewTable;
    }

    public List<ReportErrorResponseVo> getErrorReportList(ReportErrorRequestVo request) {
        List<EquipmentExceptionResponseVo> list = exceptionMapper.selectEquipmentExceptionListByVo(request);
        return list.stream().map(item -> {
            ReportErrorResponseVo vo = new ReportErrorResponseVo();
            vo.setRemark(item.getRemark());
            vo.setName(item.getPersonnelName());
            vo.setSiteName(item.getSiteName());
            vo.setJobCode(item.getJobCode());
            vo.setDeviceId(item.getDeviceId());
            vo.setExType(item.getExType());
            vo.setCreateTime(item.getCreateTime());
            vo.setTitle(item.getTitle());
            vo.setNbbm(item.getNbbm());
            vo.setFleetName(item.getFleetName());
            vo.setLineName(item.getLineName());
            vo.setPlanTime(item.getPlanTime());
            return vo;
        }).collect(Collectors.toList());
    }


    public void exportReportList(ReportViewRequestVo requestVo, HttpServletResponse response) {
        List<ExportReportViewResponseVo> list = null;
        //  处理天
        if (requestVo.getExportFlag().equals(DAY)) {
            list = getDayReportTableResponseVo(requestVo.getDate());
            // 查询无排班异常
            ReportErrorRequestVo errorVo = new ReportErrorRequestVo();
            errorVo.setDate(requestVo.getDate());
            errorVo.setExType(SIGN_NO_SCHEDULING_EX_NUM);
            List<EquipmentExceptionResponseVo> errorList = exceptionMapper.selectEquipmentExceptionListByVo(errorVo);
            ExcelWriter excelWriter = null;
            try (OutputStream os = response.getOutputStream()) {
                excelWriter = EasyExcel.write(os).build();
                WriteSheet writeSheet = EasyExcel.writerSheet(0, "签到报表").head(ExportReportViewResponseVo.class).build();
                excelWriter.write(list, writeSheet);
                // 无排班打卡表
                Map<String, List<EquipmentExceptionResponseVo>> map = new HashMap<>();
                transfromMap(errorList, map);
                List<List<String>> errorListHead = createErrorListHead(map);
                WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "无排班打卡表").head(errorListHead).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
                excelWriter.write(createErrorListData(errorListHead.size(), map), writeSheet1);
                excelWriter.finish();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            return;
        }
        // 处理月
        else if (requestVo.getExportFlag().equals(MONTH)) {
            list = getMonthReportTableResponseVo(requestVo);
        }
        // 处理导出任意时间段  后台追加限制条件 366 天为最长导出时间
        else if (requestVo.getExportFlag().equals(TIME_PERIOD)) {
            list = getTimePeriodReportTableResponseVo(requestVo);
        }
        if (!DAY.equals(requestVo.getExportFlag())) {
            // 不导出图片清空路径信息
            ExcelUtil<ExportReportViewResponseVo> util = new ExcelUtil<ExportReportViewResponseVo>(ExportReportViewResponseVo.class);
            util.exportEasyExcel(response, list, "签到报表");
        }
    }

    private static void transfromMap(List<EquipmentExceptionResponseVo> errorList, Map<String, List<EquipmentExceptionResponseVo>> map) {
        // 以工号封装成map
        for (EquipmentExceptionResponseVo exceptionResponseVo : errorList) {
            List<EquipmentExceptionResponseVo> vos = map.get(exceptionResponseVo.getJobCode());
            if (CollectionUtil.isEmpty(vos)) {
                map.put(exceptionResponseVo.getJobCode(), new ArrayList<>(Arrays.asList(exceptionResponseVo)));
            } else {
                vos.add(exceptionResponseVo);
            }
        }
    }

    /**
     * 不确定数据列数
     *
     * @return
     */
    private List<List<String>> createErrorListData(int column, Map<String, List<EquipmentExceptionResponseVo>> map) {
        // 封装数据
        List<List<String>> result = new ArrayList<>();
        map.forEach((key, value) -> {
            List<String> data = new ArrayList<>();
            data.add(key);
            data.add(value.get(0).getPersonnelName());
            data.add(value.get(0).getFleetName());
            for (int i = 0; i < column; i++) {
                if (value.size() > i) {
                    EquipmentExceptionResponseVo vo = value.get(i);
                    data.add(ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", vo.getCreateTime()));
                    if (vo.getSignType() == null) {
                        data.add("");
                    } else {
                        data.add(vo.getSignType().equals(SIGN_IN) ? "签到" : "签退");
                    }
                } else {
                    data.add("");
                    data.add("");
                }
            }
            result.add(data);
        });
        return result;
    }

    private List<ExportReportViewResponseVo> getTimePeriodReportTableResponseVo(ReportViewRequestVo requestVo) {
        String startDate = requestVo.getStartDate();
        String endDate = requestVo.getEndDate();
        LocalDate startLocalDate = LocalDate.parse(startDate);
        LocalDate endLocalDate = LocalDate.parse(endDate);

        long days = ChronoUnit.DAYS.between(startLocalDate, endLocalDate);
        long timePeriod = 366;
        if (days > timePeriod) {
            throw new RuntimeException("时间段不能超过" + timePeriod + "天");
        }
        List<ExportReportViewResponseVo> voList = new ArrayList<>();
        // 分段查询
        spiteQueryResult(startLocalDate, endLocalDate, voList);

        return voList;
    }

    private void spiteQueryResult(LocalDate startLocalDate, LocalDate endLocalDate, List<ExportReportViewResponseVo> voList) {
        // 1 时间按月分段
        String split = "p";
        List<String> localDates = splitByMonth(startLocalDate, endLocalDate, split);
        // 2 按月创建多线程
        ExecutorService pool = Executors.newFixedThreadPool(localDates.size());
        // 3
        for (String date : localDates) {
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    String[] dateSplit = date.split(split);
                    List<DriverScheduling> vos = schedulingMapper.queryByMonth(dateSplit[0], dateSplit[1]);
                    Map<String, List<DriverScheduling>> resultMap = new HashMap<>();
                    handlerResultMap(resultMap, vos);
                    handleResultList(voList, resultMap);
                }
            });
        }
        pool.shutdown();
        try {
            // 等待所有任务执行完毕或超时
            pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException("导出失败,请尝试刷新页面重新导出或者联系管理员");
        }
    }

    private static List<String> splitByMonth(LocalDate startDate, LocalDate endDate, String split) {
        List<String> dates = new ArrayList<>();
        LocalDate currentMonthStart = startDate;
        LocalDate currentMonthEnd;
        while (currentMonthStart.isBefore(endDate) || currentMonthStart.isEqual(endDate)) {
            currentMonthEnd = currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth());
            if (currentMonthEnd.isAfter(endDate)) {
                currentMonthEnd = endDate;
            }
            dates.add(currentMonthStart + split + currentMonthEnd);
            currentMonthStart = currentMonthEnd.plusDays(1);
        }
        return dates;
    }

    private List<ExportReportViewResponseVo> getDayReportTableResponseVo(String date) {
        List<DriverScheduling> schedulingList = schedulingMapper.queryToDay(date, null, null, null);
        Map<String, List<DriverScheduling>> resultMap = new HashMap<>(800);
        List<ExportReportViewResponseVo> signVo = new ArrayList<>(800);
        handlerResultMap(date, resultMap, schedulingList);
        handleResultList(signVo, resultMap);
        return signVo;
    }

    private List<List<String>> createErrorListHead(Map<String, List<EquipmentExceptionResponseVo>> map) {
        List<List<String>> list = new ArrayList<>();
        list.add(Arrays.asList("工号"));
        list.add(Arrays.asList("姓名"));
        list.add(Arrays.asList("部门"));
        List<Integer> maxSignCount = Arrays.asList(0);
        map.forEach((key, value) -> {
            if (maxSignCount.get(0) < value.size()) {
                maxSignCount.set(0, value.size());
            }
        });
        for (int i = 0; i < maxSignCount.get(0) * 2; i = i + 2) {
            list.add(Arrays.asList("打卡时间"));
            list.add(Arrays.asList("打卡类型"));
        }
        return list;
    }

    private void handleResultList(List<ExportReportViewResponseVo> vo, Map<String, List<DriverScheduling>> resultMap) {
        for (String key : resultMap.keySet()) {
            resultMap.get(key).sort(Comparator.comparing(DriverScheduling::getFcsjT));
            vo.add(new ExportReportViewResponseVo(resultMap.get(key)));
        }
    }

    private void handlerResultMap(@NotBlank String date, Map<String, List<DriverScheduling>> resultMap, List<DriverScheduling> schedulingList) {
        for (DriverScheduling scheduling : schedulingList) {
            String key = date + scheduling.getJobCode();
            // TODO 特殊处理
            ToolUtils.updateReport(scheduling);
            if (Objects.isNull(resultMap.get(key))) {
                resultMap.put(key, new ArrayList<>(Arrays.asList(scheduling)));
            } else {
                resultMap.get(key).add(scheduling);
            }
        }
    }

    private void handlerResultMap(Map<String, List<DriverScheduling>> resultMap, List<DriverScheduling> schedulingList) {
        for (DriverScheduling scheduling : schedulingList) {
            String key = scheduling.getScheduleDate() + scheduling.getJobCode();
            ToolUtils.updateReport(scheduling);
            if (Objects.isNull(resultMap.get(key))) {
                resultMap.put(key, new ArrayList<>(Arrays.asList(scheduling)));
            } else {
                resultMap.get(key).add(scheduling);
            }
        }
    }

    private List<ExportReportViewResponseVo> getMonthReportTableResponseVo(ReportViewRequestVo requestVo) {
        List<ExportReportViewResponseVo> responseVos = new ArrayList<>(10000);
        List<String> days = getNowMonthAllDay(requestVo.getDate());
        for (String day : days) {
            List<ExportReportViewResponseVo> dayReportTableResponseVo = getDayReportTableResponseVo(day);
            // TODO 修改
            responseVos.addAll(dayReportTableResponseVo);
        }
        return responseVos;
    }

    private List<String> getNowMonthAllDay(@NotBlank String dateString) {
        // 获取当前年月
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate formatDate = LocalDate.parse(dateString, formatter);
        int month = formatDate.getMonthValue();
        int year = formatDate.getYear();
        YearMonth yearMonth = YearMonth.of(year, month);

        // 获取当前月份的第一天和最后一天日期
        LocalDate firstDay = yearMonth.atDay(1);
        LocalDate lastDay = yearMonth.atEndOfMonth();

        // 获取当前月份的所有日期集合
        List<String> datesInMonth = new ArrayList<>();
        LocalDate date = firstDay;
        while (!date.isAfter(lastDay)) {
            datesInMonth.add(date.toString());
            date = date.plusDays(1);
        }
        return datesInMonth;
    }

    public List<ReportDetailResponseVo> getReportDetail(ReportViewRequestVo vo, HttpServletResponse response) {
        List<ReportDetailResponseVo> responseVos = new ArrayList<>();
        List<DriverScheduling> toDay = schedulingMapper.queryToDay(vo.getDate(), vo.getName(), vo.getJobCode(), vo.getLineName());
        for (DriverScheduling scheduling : toDay) {
            ToolUtils.updateReport(scheduling);
            ReportDetailResponseVo reportDetailResponseVo = new ReportDetailResponseVo();
            handlerReportDetail(reportDetailResponseVo, scheduling);
            responseVos.add(reportDetailResponseVo);
        }
        responseVos.sort(Comparator.comparing(ReportDetailResponseVo::getPlanTime));
        return responseVos;
    }

    public Integer updateAlcoholExceptionCountById(Integer id, BigDecimal alcoholIntake) {
        DriverScheduling driverScheduling = schedulingMapper.querySelectColumnById(id);
        if (Objects.isNull(driverScheduling)) {
            log.warn("{}没有签到数据", id);
            return 1;
        }

        SignIn signIn = signInMapper.selectSignInById(driverScheduling.getSignInId());
        if (Objects.isNull(signIn)) {
            log.warn("{}没有查到签到数据", id);
            return 2;
        }

        if (!Objects.equals(3, driverScheduling.getExType())) {
            log.warn("{}不是酒驾数据,不能修改", id);
            return 3;
        }

        if (!Objects.equals(1, signIn.getType())) {
            log.warn("{}不是签到数据,不能修改", id);
            return 4;
        }

        Driver driver = driverMapper.getDriverInfoByJobCode(signIn.getJobCode());
        if (Objects.isNull(driver) || !Objects.equals(PERSONNEL_POSTS_DRIVER, driver.getPosts())) {
            log.warn("{}只能修改司机的数据", id);
            return 5;
        }


        schedulingMapper.updateRoster(driverScheduling, driverScheduling.getSignInId(), SignStatusEnum.SIGN_STATUS_ZONE_ENUM.getStatus(), driverScheduling.getSignTime(),
                SignStatusEnum.SIGN_STATUS_ZONE_ENUM.getDescription(), driverScheduling.getSignType(), driverScheduling.getAlcoholFlag(), alcoholIntake);

        nowSchedulingCache.refreshDriveScheDulingCacheByDateAndJobCode(driverScheduling, driverScheduling.getScheduleDate());


        String key = REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW + ConstDateUtil.FAST_YYYY_MM_DD.format(driverScheduling.getScheduleDate()) + ":" + signIn.getJobCode();
        redisCache.setCacheObject(key, 0, 1, TimeUnit.DAYS);

        return 0;
    }

    private void handlerReportDetail(ReportDetailResponseVo reportDetailResponseVo, DriverScheduling scheduling) {
        BeanUtils.copyProperties(scheduling, reportDetailResponseVo);
        reportDetailResponseVo.setPlanAction(scheduling.getBcType().equals(BC_TYPE_OUT) ? SIGN_IN_STRING : SIGN_IN_OUT_STRING);
        reportDetailResponseVo.setPlanTime(scheduling.getBcType().equals(BC_TYPE_OUT) ? new Date(scheduling.getFcsjT()) : new Date(scheduling.getZdsjT()));
        reportDetailResponseVo.setExString(SIGN_NO_EX_NUM.equals(scheduling.getExType()) ? NO_EX : HAVE_EX);

        // 设置操作 当前有操作的
        if (!Objects.isNull(scheduling.getSignInId())) {
            reportDetailResponseVo.setActualTime(scheduling.getSignTime());
            reportDetailResponseVo.setActualAction(scheduling.getSignType().equals(SIGN_IN) ? SIGN_IN_STRING : SIGN_IN_OUT_STRING);
            reportDetailResponseVo.setRemark(scheduling.getRemark());
            reportDetailResponseVo.setAlcoholString(ALCOHOL_FLAG_YES.equals(scheduling.getAlcoholFlag()) ? ALCOHOL_FLAG_YES_STRING : ALCOHOL_FLAG_NO_STRING);
        }
        // 当前无操作
        else {
            reportDetailResponseVo.setRemark(scheduling.getBcType().equals(BC_TYPE_OUT) ? "未签到" : "未签退");
            reportDetailResponseVo.setAlcoholString(ALCOHOL_FLAG_NO_STRING);
        }

    }

    public List<SignInResponseVo> getBigView(ReportViewRequestVo requestVo, HttpServletResponse response) {
        SignInResponseVo vo = new SignInResponseVo();
        vo.setDate(requestVo.getDate());
        vo.setJobCode(requestVo.getJobCode());
        List<SignInResponseVo> vos = signInMapper.selectSignInList(vo);
        return vos;
    }

    public SysNotice getAlarmNoticeByType(Integer type) {
        String username = SecurityUtils.getUsername();
        return noticeService.getAlarmNotice(username, type);
    }

    public Object sureNotice(SysNotice notice) {
        String username = SecurityUtils.getUsername();
        notice.setRemark(notice.getRemark() + "," + username);
        noticeService.updateNotice(notice);
        return null;
    }

    public Result<PersonSignDataResponseVo> listReportMonth(String month, HttpServletRequest request) {
        boolean validateDate = validateDate(month);
        String header = request.getHeader("X-TOKEN-AUTHORIZATION");
        if (!PERSONNEL_API_KEY.equals(header)) {
            return Result.ERROR(ResultCode.CODE_401, "X-TOKEN-AUTHORIZATION value error");
        }
        if (!validateDate) {
            return Result.ERROR(ResultCode.CODE_400, "Parameter format error");
        }
        ReportViewRequestVo vo = new ReportViewRequestVo();
        vo.setDate(month + "-01");
        List<ExportReportViewResponseVo> responseVoList = getMonthReportTableResponseVo(vo);
        PersonSignDataResponseVo responseVo = new PersonSignDataResponseVo();
        handleResponseByDay(responseVoList, responseVo, vo.getDate());
        return Result.OK(responseVo);
    }

    private void handleResponseByDay(List<ExportReportViewResponseVo> responseVoList, PersonSignDataResponseVo voList, @NotBlank String date) {
        List<PersonSignDataResponseVo.SignData> list = voList.getList();
        Map<String, List<ExportReportViewResponseVo>> map = new HashMap<>(30);
        for (ExportReportViewResponseVo vo : responseVoList) {
            String key = ConstDateUtil.formatDate("yyyy-MM-dd", vo.getScheduleDate());
            List<ExportReportViewResponseVo> vos = map.get(key);
            if (CollectionUtil.isEmpty(vos)) {
                map.put(key, new ArrayList<>(Arrays.asList(vo)));
            } else {
                map.get(key).add(vo);
            }
        }
        // 转换对象
        for (Map.Entry<String, List<ExportReportViewResponseVo>> entry : map.entrySet()) {
            PersonSignDataResponseVo.SignData signData = new PersonSignDataResponseVo.SignData();
            signData.setDate(entry.getKey());
            signData.setResponseVoList(entry.getValue());
            list.add(signData);
        }
    }

    /**
     * yyyy-MM 格式的正则表达式
     */
    public static boolean validateDate(String input) {
        String regex = "^(\\d{4})-(0[1-9]|1[0-2])$";

        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);

        return matcher.matches();
    }

    public Result<PersonSignDataResponseVo> listReportDay(String date, HttpServletRequest request) {
        boolean validateDayDate = validateDayDate(date);
        String header = request.getHeader("X-TOKEN-AUTHORIZATION");
        if (!PERSONNEL_API_KEY.equals(header)) {
            return Result.ERROR(ResultCode.CODE_401, "X-TOKEN-AUTHORIZATION value error");
        }
        if (!validateDayDate) {
            return Result.ERROR(ResultCode.CODE_400, "Date parameter format error");
        }
        ReportViewRequestVo vo = new ReportViewRequestVo();
        vo.setDate(date);
        List<ExportReportViewResponseVo> responseVos = new ArrayList<>(10000);
        List<ExportReportViewResponseVo> dayReportTableResponseVo = getDayReportTableResponseVo(date);
        responseVos.addAll(dayReportTableResponseVo);
        PersonSignDataResponseVo responseVo = new PersonSignDataResponseVo();
        handleResponseByDay(responseVos, responseVo, vo.getDate());
        return Result.OK(responseVo);
    }

    /**
     * yyyy-MM 格式的正则表达式
     */
    public static boolean validateDayDate(String input) {
        String datePattern1 = "\\d{4}-\\d{2}-\\d{2}";
        String datePattern2 = "^((\\d{2}(([02468][048])|([13579][26]))"
                + "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|"
                + "(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"
                + "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?("
                + "(((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?"
                + "((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
        if ((input != null)) {
            Pattern pattern = Pattern.compile(datePattern1);
            Matcher match = pattern.matcher(input);
            if (match.matches()) {
                pattern = Pattern.compile(datePattern2);
                match = pattern.matcher(input);
                return match.matches();
            } else {
                return false;
            }
        }
        return false;
    }
}