package com.ruoyi.zhushi.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.zhushi.entity.*;
import com.ruoyi.zhushi.mapper.DkRecordMapper;
import com.ruoyi.zhushi.service.DkRecordService;
import com.ruoyi.zhushi.util.Constans;
import com.ruoyi.zhushi.util.TimeUtils;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class DkRecordServiceImpl implements DkRecordService {
    @Autowired
    private DkRecordMapper dkMapper;

    public String getTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = new Date();
        return sdf.format(currentDate);
    }

    @Override
    public TableDataInfo<DkCheckInRecordDTO> queryPageList(DkCheckInRecordDTO dkCheckInRecordDTO, PageQuery pageQuery) {
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null);
        Page<DkCheckInRecordDTO> result = dkMapper.selectVoPage(pageQuery.build(), queryWrapper);
        return TableDataInfo.build(result);
    }

    private LambdaQueryWrapper<DkCheckInRecord> buildQueryWrapper(DkCheckInRecordDTO dkCheckInRecordDTO, String flag) {
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = Wrappers.lambdaQuery();

        queryWrapper.eq(null != dkCheckInRecordDTO.getSysUserId() ,DkCheckInRecord::getSysUserId, dkCheckInRecordDTO.getSysUserId());
        queryWrapper.eq(null != dkCheckInRecordDTO.getSysUserName() ,DkCheckInRecord::getSysUserName, dkCheckInRecordDTO.getSysUserName());
        queryWrapper.eq(null != dkCheckInRecordDTO.getCheckInTime(), DkCheckInRecord::getCheckInTime, dkCheckInRecordDTO.getCheckInTime());
        queryWrapper.eq(null != dkCheckInRecordDTO.getCheckInStatus(), DkCheckInRecord::getCheckInStatus, dkCheckInRecordDTO.getCheckInStatus());
//        queryWrapper.eq(null != dkCheckInRecordDTO.getExportRange(), DkCheckInRecord::getExportRange, dkCheckInRecordDTO.getExportRange());
        if(dkCheckInRecordDTO.getStrDay() != null){
            queryWrapper.between(DkCheckInRecord::getCheckInTime, TimeUtils.getStartTime(dkCheckInRecordDTO.getStrDay()),
                TimeUtils.getEndTime(dkCheckInRecordDTO.getStrDay()));
        }
        if(dkCheckInRecordDTO.getStrMonth() != null){
            queryWrapper.between(DkCheckInRecord::getCheckInTime, TimeUtils.getFirstDayOfMonth(dkCheckInRecordDTO.getStrMonth()),
                TimeUtils.getLastDayOfMonth(dkCheckInRecordDTO.getStrMonth()));
        }
        if(flag != null){
            queryWrapper.groupBy(DkCheckInRecord::getSysUserName);
        }

        queryWrapper.orderByDesc(DkCheckInRecord::getSysUserName).orderByDesc(DkCheckInRecord::getCheckInTime);
        return queryWrapper;
    }

    public LocalDateTime  getStartTime() {
        LocalDate today = LocalDate .now();
        // 定义一天的开始和结束时间
        LocalTime startTime = LocalTime.of(0, 0, 0); // 00:00:00
        LocalDateTime startOfDay = today.atTime(startTime);
        return startOfDay;
    }

    public LocalDateTime  getEndTime() {
        LocalDate today = LocalDate .now();
        // 定义一天的开始和结束时间
        LocalTime endTime = LocalTime.of(23, 59, 59); // 23:59:59
        LocalDateTime endOfDay = today.atTime(endTime);
        return endOfDay;
    }

    /**
     * 查询预警结果列表
     */
    @Override
    public List<DkCheckInRecordDTO> queryList(DkCheckInRecordDTO dkCheckInRecordDTO) {
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null);
        List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
        dkCheckInRecordDTOS.forEach(dk -> {
            if("0".equals(dk.getCheckInStatus())){
                dk.setCheckInStatus("正常");
            }
            if("1".equals(dk.getCheckInStatus())){
                dk.setCheckInStatus("迟到");
            }
            if("2".equals(dk.getCheckInStatus())){
                dk.setCheckInStatus("缺卡");
            }
        });
        return dkCheckInRecordDTOS;
    }

    @Override
    public void exportNew(DkCheckInRecordDTO dkCheckInRecordDTO, HttpServletResponse response) {
        // 获取所有人员
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, "export");

        // 查询出所有人员
        List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
        if(dkCheckInRecordDTOS.size() == 0){
            return;
        }
        try {
            FileInputStream templateFile = null;
            InputStream inputStream = null;
            Workbook workbook;
            // 加载模板文件
            if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){
                templateFile = new FileInputStream("template-guonei.xlsx");
//                DkRecordServiceImpl.class.getClassLoader().getResourceAsStream("template/template-guonei.xlsx");
                ClassPathResource resource = new ClassPathResource("template/template-guonei.xlsx");
                inputStream = resource.getInputStream();
            }
            if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){
                templateFile = new FileInputStream("template-riben.xlsx");
                ClassPathResource resource = new ClassPathResource("template/template-riben.xlsx");
                inputStream = resource.getInputStream();
            }
            workbook = WorkbookFactory.create(inputStream);
            Sheet templateSheet = workbook.getSheetAt(0);

            // 遍历所有人员
            for (int i = 0; i < dkCheckInRecordDTOS.size(); i++){
                DkCheckInRecordDTO dk = dkCheckInRecordDTOS.get(i);

                // 获取每个人员的打卡记录并生成excel
                // 自动检测文件格式并创建对应的 Workbook
//                workbook = WorkbookFactory.create(templateFile);

//                Workbook workbook = new XSSFWorkbook(templateFile);
//                workbook.setSheetName(i, dk.getSysUserName());
//                Sheet sheet = workbook.getSheetAt(i); // 获取第一个工作表

//                Sheet sheet = getOrCreateSheet(workbook, i, dk.getSysUserName());
                // 创建新Sheet，使用原始模板Sheet的名称加上序号
                String sheetName = templateSheet.getSheetName() + "_" + (i + 1);
                int newSheetIndex = workbook.getNumberOfSheets();
                workbook.cloneSheet(0);
                workbook.setSheetName(newSheetIndex, dk.getSysUserName());
                // 获取新创建的Sheet
                Sheet newSheet = workbook.getSheetAt(newSheetIndex);

                // 准备数据
                dkCheckInRecordDTO.setSysUserId(dk.getSysUserId());
                dkCheckInRecordDTO.setSysUserName(dk.getSysUserName());
                // 国内模版
                if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){
                    // 构造导出数据
                    EmployeeAttendance attendanceData = prepareSampleData(dkCheckInRecordDTO);
                    // 填充数据到模板
                    if (attendanceData.getDayRecords().size() == 0){
                        return;
                    }
                    fillTemplate(newSheet, attendanceData);
                }
                // 日本模版
                if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){
                    // 构造导出数据
                    EmployeeAttendance attendanceData = prepareSampleDataRiBen(dkCheckInRecordDTO);
                    // 填充数据到模板
                    if (attendanceData.getDayRecords().size() == 0){
                        return;
                    }
                    fillTemplateRiBen(newSheet, attendanceData);
                }

            }
            // 保存为新文件
//            FileOutputStream outputFile = new FileOutputStream("output.xlsx");
//            workbook.write(outputFile);
//            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//            response.setHeader("Content-disposition", "attachment;filename=用户数据_模板.xlsx");
//             删除原始模板Sheet（如果不需要）
            workbook.removeSheetAt(0);
            workbook.write(response.getOutputStream());
            // 关闭资源
//            outputFile.close();
            workbook.close();
            templateFile.close();

            System.out.println("Excel 导出成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 获取或创建工作表的工具方法
    private Sheet getOrCreateSheet(Workbook workbook, int sheetIndex, String sheetName) {
        Sheet sheet;
        if (workbook.getNumberOfSheets() > sheetIndex) {
            // 工作表已存在，获取它
            sheet = workbook.getSheetAt(sheetIndex);
            // 可选：如果需要，重命名现有工作表
            workbook.setSheetName(sheetIndex, sheetName);
        } else {
            // 工作表不存在，创建它
            sheet = workbook.createSheet(sheetName);
        }
        return sheet;
    }

    private EmployeeAttendance prepareSampleData(DkCheckInRecordDTO dkCheckInRecordDTO) {

        // 定义员工类对象
        EmployeeAttendance data = new EmployeeAttendance();
        // 设置员工的名字
        data.setEmployeeName(dkCheckInRecordDTO.getSysUserName());

        // 判断月日是否为空
        if(dkCheckInRecordDTO.getStrMonth() != null){
            data.setDateTime(dkCheckInRecordDTO.getStrMonth());
        }
        if(dkCheckInRecordDTO.getStrDay() != null){
            data.setDateTime(dkCheckInRecordDTO.getStrDay());
        }

        //根据userId获取打卡配置信息
        DkAttendanceGroup dkAttendanceGroup = dkMapper.queryConfigByUserId(dkCheckInRecordDTO.getSysUserId());


        // 是否允许迟到
        Boolean allowLate = dkAttendanceGroup.getAllowLate();
        // 允许迟到的时长
        Integer lateRange = dkAttendanceGroup.getLateRange();
        // 是否允许早退
        Boolean allowEarly = dkAttendanceGroup.getAllowEarly();
        // 允许早退的时长
        Integer earlyRange = dkAttendanceGroup.getEarlyRange();

        // 定义集合，用于存储每天打卡记录
        List<DayRecord> dayRecords = new ArrayList<>();
        // 根据用户的ID查询该用户所有的打卡记录
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null);
        List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
        if (dkCheckInRecordDTOS == null && dkCheckInRecordDTOS.isEmpty()){
            return data;
        }
        // 构造excel数据
        for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){
            // 根据打卡时间获取日期
            LocalDate localDate = dk.getCheckInTime() != null ? dk.getCheckInTime().toLocalDate() : LocalDate.now();
            // 构造当天开始打卡时间
            String workStartTime = dkAttendanceGroup.getWorkStartTime();
            LocalDateTime workStartTime1 = LocalDateTime.of(localDate, LocalTime.parse(workStartTime));
            // 构造当天结束打卡时间
            String workEndTime = dkAttendanceGroup.getWorkEndTime();
            LocalDateTime workEndTime1 = LocalDateTime.of(localDate, LocalTime.parse(workEndTime));

            // 构造DayRecord
            DayRecord dayRecord = new DayRecord();
            dayRecord.setDay(localDate.toString());
            // 获取星期几（返回 DayOfWeek 枚举）
            DayOfWeek dayOfWeek = localDate.getDayOfWeek();
            int week = dayOfWeek.getValue();
            dayRecord.setWeekday(String.valueOf(week));
            dayRecord.setStartTime(null != dk.getClockIn() ? dk.getClockIn().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
            dayRecord.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
            // 打卡异常判断
            if(dk.getClockIn() != null && dk.getClockOut() != null){
                if(dk.getClockIn().isAfter(workStartTime1)){
                    dayRecord.setChidao("*");
                    dayRecord.setRemark("迟到1次");
                }
            }

            if(dk.getClockIn() != null && dk.getClockOut() == null){
                dayRecord.setYichang("*");
                dayRecord.setRemark("异常打卡");
            }

            // 判断是否为工作日加班
            if(dk.getClockOut() != null){
                if(dk.getClockOut().isAfter(workEndTime1)){
                    // 计算时间差
                    Duration duration = Duration.between(workEndTime1, dk.getClockOut());
                    // 获取小时差（注意：此方法会舍去分钟和秒部分）
                    long hours1 = duration.toMinutes();  // 结果：6 小时（15:45 - 09:30 = 6小时15分钟）

                    if(hours1 >= 30){
                        BigDecimal a = new BigDecimal(hours1);
                        BigDecimal b = new BigDecimal("60");
                        // 执行除法，指定精度和舍入模式
                        BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP);
                        dayRecord.setGongzuori("*");
                        dayRecord.setRemark("加班1次:" + result + "小时");
                    }
                }
            }
            // 判断是否为休假日加班
            if(Constans.ZHOULIU.equals(dk.getWeek()) || Constans.ZHOURI.equals(dk.getWeek())){
                dayRecord.setXiuxiri("*");
                dayRecord.setRemark("加班1次");
            }
            // 判断是否为法定节假日加班
//            // 获取法定节假日时间
//            List<LocalDate> holidays = getHolidays(LocalDate.now().getYear());
//            // 获取打卡日期
//            int day = dk.getDay();



            dayRecords.add(dayRecord);
        }

//        dayRecords.add(new DayRecord(1, "金", "09:05", "18:23", "迟到", "", 0.5, "会议"));
//        dayRecords.add(new DayRecord(2, "土", "08:55", "18:30", "正常", "", 1.0, ""));
//        dayRecords.add(new DayRecord(3, "日", "", "", "休息", "年假", 0, ""));
        // 添加更多日期记录...

        data.setDayRecords(dayRecords);
        return data;
    }

    public static List<LocalDate> getHolidays(int year) {
        List<LocalDate> holidays = new ArrayList<>();
        // 元旦
        holidays.add(LocalDate.of(year, 1, 1));
        // 春节（这里简单示例，实际需考虑农历计算，可使用第三方农历库）
        holidays.add(LocalDate.of(year, 1, 22));
        holidays.add(LocalDate.of(year, 1, 23));
        holidays.add(LocalDate.of(year, 1, 24));
        // 清明节
        holidays.add(LocalDate.of(year, 4, 4));
        // 劳动节
        holidays.add(LocalDate.of(year, 5, 1));
        // 端午节
        holidays.add(LocalDate.of(year, 6, 22));
        // 中秋节
        holidays.add(LocalDate.of(year, 9, 29));
        // 国庆节
        holidays.add(LocalDate.of(year, 10, 1));
        holidays.add(LocalDate.of(year, 10, 2));
        holidays.add(LocalDate.of(year, 10, 3));
        return holidays;
    }

    private JSONObject getJjr() {
        String url = "http://timor.tech/api/holiday/year/";
        OkHttpClient client = new OkHttpClient();
        Response response;
        //解密数据
        String rsa = null;
        Request request = new Request.Builder()
            .url(url)
            .get()
            .addHeader("Content-Type", "application/x-www-form-urlencoded")
            .build();
        try {
            response = client.newCall(request).execute();
            rsa = response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return JSONObject.parseObject(rsa);
    }

    private void fillTemplate(Sheet sheet, EmployeeAttendance data) {
        // 填充标题区域
        setCellValue(sheet, 6, 10, data.getEmployeeName());
        setCellValue(sheet, 3, 1, data.getDateTime());
//        setCellValue(sheet, 2, 0, data.getYear() + "年" + data.getMonth() + "月考勤记录");

        // 填充数据表格
        int rowIndex = 10; // 数据起始行（根据模板调整）
        for (DayRecord record : data.getDayRecords()) {
            setCellValue(sheet, rowIndex, 1, record.getDay());
            setCellValue(sheet, rowIndex, 2, record.getWeekday());
            setCellValue(sheet, rowIndex, 3, record.getStartTime());
            setCellValue(sheet, rowIndex, 4, record.getEndTime());
            setCellValue(sheet, rowIndex, 5, record.getChidao());
//            setCellValue(sheet, rowIndex, 6, record.getEndTime());
            setCellValue(sheet, rowIndex, 7, record.getYichang());
            setCellValue(sheet, rowIndex, 8, record.getGongzuori());
            setCellValue(sheet, rowIndex, 9, record.getXiuxiri());
            setCellValue(sheet, rowIndex, 10, record.getFadingjiari());
            setCellValue(sheet, rowIndex, 11, record.getXiuxi());
            setCellValue(sheet, rowIndex, 12, record.getQingjia());
            setCellValue(sheet, rowIndex, 13, record.getRemark());

            rowIndex++;
        }
    }

    private void setCellValue(Sheet sheet, int rowIndex, int colIndex, Object value) {
        Row row = sheet.getRow(rowIndex);
        if (row == null) {
            row = sheet.createRow(rowIndex);
        }

        Cell cell = row.getCell(colIndex);
        if (cell == null) {
            cell = row.createCell(colIndex);
        }

        if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Integer) {
            cell.setCellValue((Integer) value);
        } else if (value instanceof Double) {
            cell.setCellValue((Double) value);
        } else if (value != null) {
            cell.setCellValue(value.toString());
        }
    }

    private EmployeeAttendance prepareSampleDataRiBen(DkCheckInRecordDTO dkCheckInRecordDTO) {

        // 定义员工类对象
        EmployeeAttendance data = new EmployeeAttendance();
        // 设置员工的名字
        data.setEmployeeName(dkCheckInRecordDTO.getSysUserName());

        // 判断月日是否为空
        if(dkCheckInRecordDTO.getStrMonth() != null){
            data.setDateTime(dkCheckInRecordDTO.getStrMonth());
        }
        if(dkCheckInRecordDTO.getStrDay() != null){
            data.setDateTime(dkCheckInRecordDTO.getStrDay());
        }

        //根据userId获取打卡配置信息
        DkAttendanceGroup dkAttendanceGroup = dkMapper.queryConfigByUserId(dkCheckInRecordDTO.getSysUserId());


        // 是否允许迟到
        Boolean allowLate = dkAttendanceGroup.getAllowLate();
        // 允许迟到的时长
        Integer lateRange = dkAttendanceGroup.getLateRange();
        // 是否允许早退
        Boolean allowEarly = dkAttendanceGroup.getAllowEarly();
        // 允许早退的时长
        Integer earlyRange = dkAttendanceGroup.getEarlyRange();

        // 定义集合，用于存储每天打卡记录
        List<DayRecord> dayRecords = new ArrayList<>();
        // 根据用户的ID查询该用户所有的打卡记录
        LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null);
        List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
        // 构造excel数据
        for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){
            // 根据打卡时间获取日期
            LocalDate localDate = dk.getCheckInTime().toLocalDate();
            // 构造当天开始打卡时间
            String workStartTime = dkAttendanceGroup.getWorkStartTime();
            LocalDateTime workStartTime1 = LocalDateTime.of(localDate, LocalTime.parse(workStartTime));
            // 构造当天结束打卡时间
            String workEndTime = dkAttendanceGroup.getWorkEndTime();
            LocalDateTime workEndTime1 = LocalDateTime.of(localDate, LocalTime.parse(workEndTime));

            // 构造DayRecord
            DayRecord dayRecord = new DayRecord();
            dayRecord.setDay(localDate.toString());
            dayRecord.setWeekday(dk.getWeek());
            dayRecord.setStartTime(null != dk.getClockIn() ? dk.getClockIn().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
            dayRecord.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
            // 打卡异常判断
            if(dk.getClockIn() != null && dk.getClockOut() != null){
                if(dk.getClockIn().isAfter(workStartTime1)){
                    dayRecord.setChidao("*");
                    dayRecord.setRemark("迟到1次");
                }
            }

            if(dk.getClockIn() != null && dk.getClockOut() == null){
                dayRecord.setYichang("*");
                dayRecord.setRemark("异常打卡");
            }

            // 判断是否为工作日加班
            if(dk.getClockOut() != null){
                if(dk.getClockOut().isAfter(workEndTime1)){
                    // 计算时间差
                    Duration duration = Duration.between(workEndTime1, dk.getClockOut());
                    // 获取小时差（注意：此方法会舍去分钟和秒部分）
                    long hours1 = duration.toMinutes();  // 结果：6 小时（15:45 - 09:30 = 6小时15分钟）

                    if(hours1 >= 30){
                        BigDecimal a = new BigDecimal(hours1);
                        BigDecimal b = new BigDecimal("60");
                        // 执行除法，指定精度和舍入模式
                        BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP);
                        dayRecord.setGongzuori("*");
                        dayRecord.setRemark("加班1次:" + result + "小时");
                    }
                }
            }
            // 判断是否为休假日加班
            if(Constans.ZHOULIU.equals(dk.getWeek()) || Constans.ZHOURI.equals(dk.getWeek())){
                dayRecord.setXiuxiri("*");
                dayRecord.setRemark("加班1次");
            }
            // 判断是否为法定节假日加班
//            // 获取法定节假日时间
//            List<LocalDate> holidays = getHolidays(LocalDate.now().getYear());
//            // 获取打卡日期
//            int day = dk.getDay();



            dayRecords.add(dayRecord);
        }

//        dayRecords.add(new DayRecord(1, "金", "09:05", "18:23", "迟到", "", 0.5, "会议"));
//        dayRecords.add(new DayRecord(2, "土", "08:55", "18:30", "正常", "", 1.0, ""));
//        dayRecords.add(new DayRecord(3, "日", "", "", "休息", "年假", 0, ""));
        // 添加更多日期记录...

        data.setDayRecords(dayRecords);
        return data;
    }

    private void fillTemplateRiBen(Sheet sheet, EmployeeAttendance data) {
        // 填充标题区域
        setCellValue(sheet, 5, 13, data.getEmployeeName());
        setCellValue(sheet, 2, 1, data.getDateTime());
//        setCellValue(sheet, 2, 0, data.getYear() + "年" + data.getMonth() + "月考勤记录");

        // 填充数据表格
        int rowIndex = 9; // 数据起始行（根据模板调整）
        for (DayRecord record : data.getDayRecords()) {
            setCellValue(sheet, rowIndex, 0, record.getDay());
            setCellValue(sheet, rowIndex, 1, record.getWeekday());
//            setCellValue(sheet, rowIndex, 3, data.getDateTime());
            setCellValue(sheet, rowIndex, 2, record.getStartTime());
            setCellValue(sheet, rowIndex, 3, record.getEndTime());
//            setCellValue(sheet, rowIndex, 6, record.getEndTime());
            setCellValue(sheet, rowIndex, 4, record.getChidao());
            setCellValue(sheet, rowIndex, 5, record.getYichang());
            setCellValue(sheet, rowIndex, 6, record.getXiuxi());
            setCellValue(sheet, rowIndex, 7, record.getChuanxiu());
            setCellValue(sheet, rowIndex, 8, record.getZhiban());
            setCellValue(sheet, rowIndex, 9, record.getQingjia());
            setCellValue(sheet, rowIndex, 10, record.getNianjia());
            setCellValue(sheet, rowIndex, 11, record.getJiaban());
            setCellValue(sheet, rowIndex, 12, record.getHeji());
            setCellValue(sheet, rowIndex, 13, record.getRemark());
            rowIndex++;
        }
    }
}
