package org.jeecg.modules.clockinlog.controller;

import java.io.*;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils2;
import org.jeecg.modules.clockInproject.entity.ClockInProject;
import org.jeecg.modules.clockInproject.service.IClockInProjectService;
import org.jeecg.modules.clockinauth.entity.ClockinAuth;
import org.jeecg.modules.clockinauth.service.IClockinAuthService;
import org.jeecg.modules.clockinlog.entity.ClockinLog;
import org.jeecg.modules.clockinlog.mapper.ClockinLogMapper;
import org.jeecg.modules.clockinlog.ressp.ClockInLogExportResp;
import org.jeecg.modules.clockinlog.ressp.ClockInLogExportResp2;
import org.jeecg.modules.clockinlog.ressp.ClockInLogResp;
import org.jeecg.modules.clockinlog.service.IClockinLogService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.clockinteamlog.entity.ClockinTeamLog;
import org.jeecg.modules.clockinteamlog.service.IClockinTeamLogService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.view.JeecgMapExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import reactor.core.publisher.Flux;

/**
 * @Description: clockin_log
 * @Author: jeecg-boot
 * @Date:   2024-10-24
 * @Version: V1.0
 */
@Api(tags="clockin_log")
@RestController
@RequestMapping("/clockinlog/clockinLog")
@Slf4j
public class ClockinLogController extends JeecgController<ClockinLog, IClockinLogService> {
	@Autowired
	private IClockinLogService clockinLogService;
	 @Value("${jeecg.path.upload}")
	 private String upLoadPath;
	 @Resource
	 private ClockinLogMapper clockinLogMapper;
	 @Resource
	 private IClockinTeamLogService clockinTeamLogService;
	 @Resource
	 private IClockinAuthService clockinAuthService;
	 @Resource
	 private IClockInProjectService clockInProjectService;
	/**
	 * 分页列表查询
	 *
	 * @param clockinLog
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "clockin_log-分页列表查询")
	@ApiOperation(value="clockin_log-分页列表查询", notes="clockin_log-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ClockinLog>> queryPageList(ClockinLog clockinLog,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<ClockinLog> queryWrapper = QueryGenerator.initQueryWrapper(clockinLog, req.getParameterMap());
		Page<ClockinLog> page = new Page<ClockinLog>(pageNo, pageSize);
		IPage<ClockinLog> pageList = clockinLogService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param clockinLog
	 * @return
	 */
	@AutoLog(value = "clockin_log-添加")
	@ApiOperation(value="clockin_log-添加", notes="clockin_log-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ClockinLog clockinLog) {
		clockinLogService.save(clockinLog);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param clockinLog
	 * @return
	 */
	@AutoLog(value = "clockin_log-编辑")
	@ApiOperation(value="clockin_log-编辑", notes="clockin_log-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ClockinLog clockinLog) {
		clockinLogService.updateById(clockinLog);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "clockin_log-通过id删除")
	@ApiOperation(value="clockin_log-通过id删除", notes="clockin_log-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		clockinLogService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "clockin_log-批量删除")
	@ApiOperation(value="clockin_log-批量删除", notes="clockin_log-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.clockinLogService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "clockin_log-通过id查询")
	@ApiOperation(value="clockin_log-通过id查询", notes="clockin_log-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ClockinLog> queryById(@RequestParam(name="id",required=true) String id) {
		ClockinLog clockinLog = clockinLogService.getById(id);
		if(clockinLog==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(clockinLog);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param clockinLog
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ClockinLog clockinLog) {
        return super.exportXls(request, clockinLog, ClockinLog.class, "clockin_log");
    }


	@RequestMapping(value = "/exportXls2")
	public Object exportXls3(HttpServletRequest request, ClockinLog clockinLog) throws IOException {
		return this.exportXls3(request,ClockInLogExportResp.class, "打卡");
	}

//	@RequestMapping(value = "/exportXls2")
	 protected ModelAndView exportXls2(HttpServletRequest request, Class<ClockInLogExportResp> clazz, String title) {
		 // Step.1 组装查询条件
		 Map<String, String[]> parameterMap = request.getParameterMap();
		 String[] clockStartTimes = parameterMap.get("clockStartTime");
		 String[] userIds = parameterMap.get("userId");
		 String[] projectIds = parameterMap.get("projectId");

//		 QueryWrapper<ClockinLog> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 LambdaQueryChainWrapper<ClockinTeamLog> queryChainWrapper = clockinTeamLogService.lambdaQuery()
				 .eq(ClockinTeamLog::getDelFlag, 0);

//		 List<ClockinTeamLog> clockinTeamLogs = clockinTeamLogService.lambdaQuery()
//				 .eq(ClockinTeamLog::getDelFlag, 0)
//				 .list();

		 if(userIds!=null && userIds.length!=0 && StringUtils.isNotBlank(userIds[0])){
			 queryChainWrapper.eq(ClockinTeamLog::getUserId,userIds[0]);
		 }
		 List<ClockinTeamLog> clockinTeamLogs = queryChainWrapper.list();
		 if(projectIds!=null && projectIds.length!=0 && StringUtils.isNotBlank(projectIds[0])){
			 ClockInProject clockInProject = clockInProjectService.lambdaQuery()
					 .eq(ClockInProject::getDelFlag, 0)
					 .eq(ClockInProject::getId,projectIds[0])
					 .one();
			 if(clockInProject == null){
			 	throw new JeecgBootException("项目错误");
			 }
			 try {
				 clockinTeamLogs = clockinTeamLogService.lambdaQuery()
						 .eq(ClockinTeamLog::getDelFlag, 0)
						 .eq(ClockinTeamLog::getTeamId, clockInProject.getTeamId())
						 .list();
//				 clockinTeamLogs.add(clockinTeamLog);
			 }catch (Exception e){
			 	throw new JeecgBootException("该项目可能存在两个团队绑定，请检查项目管理");
			 }


		 }



//		 int day = Integer.parseInt(DateUtils2.getNowMonthMaxDay());
		 String nowYearMonth = DateUtils2.getNowYearMonth();

		 if(clockStartTimes!=null && clockStartTimes.length!=0 && StringUtils.isNotBlank(clockStartTimes[0])){
			 nowYearMonth = clockStartTimes[0];
		 }
		 YearMonth yearMonth = YearMonth.parse(nowYearMonth);
		 int day = yearMonth.lengthOfMonth();


		 String yearMonthDay = "";

		 // Step.2 获取导出数据
//		 List<ClockinLog> pageList = service.list(queryWrapper);
//		 List<ClockinLog> exportList = null;
		 List<Map<String, Object>> list = new ArrayList<>();
		List<String> strings = null;
		 List<ClockInLogExportResp> exportList = new ArrayList<>();
		 for (ClockinTeamLog clockinTeamLog:clockinTeamLogs){
			 ClockInProject clockInProject = clockInProjectService.lambdaQuery()
					 .eq(ClockInProject::getDelFlag, 0)
					 .eq(ClockInProject::getTeamId, clockinTeamLog.getTeamId())
					 .one();

			 if(clockInProject == null){
			 	continue;
			 }
			 ClockinAuth clockinAuth = clockinAuthService.lambdaQuery()
					 .eq(ClockinAuth::getDelFlag, 0)
					 .eq(ClockinAuth::getUserId, clockinTeamLog.getUserId())
					 .one();
			 if(clockinAuth == null){
			 	continue;
			 }
			 List<ClockInLogExportResp2> clockInLogExportResp2s = new ArrayList<>();
			 ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp();
			 clockInLogExportResp.setName(clockinAuth.getName());
			 clockInLogExportResp.setDate(nowYearMonth);
			 for (int n= 1;n<=day;n++){
				 ClockInLogExportResp2 clockInLogExportResp2 = new ClockInLogExportResp2();


				 clockInLogExportResp2.setDay(n+"");
				 yearMonthDay = nowYearMonth+"-"+n;
				 if(n < 10){
					 yearMonthDay = nowYearMonth+"-0"+n;
				 }

				 Date date = DateUtils2.getDate(yearMonthDay + " 23:59:59");
				 LocalDateTime localDateTime = DateUtils2.dateToDateTime(date);
				 Integer type = 0;
				 if(DayOfWeek.SATURDAY.equals(localDateTime.getDayOfWeek()) || DayOfWeek.SUNDAY.equals(localDateTime.getDayOfWeek())){
					 type = 1;
				 }

				 List<ClockInLogResp> clockInLogExpeort = clockinLogMapper.getClockInLogExpeort(yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type);
				 String clockInTime = "";
				 for (ClockInLogResp clockInLogResp:clockInLogExpeort) {

					 if(StringUtils.isBlank(clockInLogResp.getTime())){
					 	clockInLogResp.setClockStartTime("缺卡");
					 }
					 clockInTime = clockInTime+"\n"+clockInLogResp.getClockStartTime();
//					 strings.add(clockInLogResp.getClockStartTime());
				 }
				 clockInLogExportResp2.setClockInTime(clockInTime);
				 clockInLogExportResp2s.add(clockInLogExportResp2);

			 }
			 clockInLogExportResp.setClockInLogExportResp2s(clockInLogExportResp2s);
			 exportList.add(clockInLogExportResp);
		 }


		 // 过滤选中数据
//		 String selections = request.getParameter("selections");
//		 if (oConvertUtils.isNotEmpty(selections)) {
//			 List<String> selectionList = Arrays.asList(selections.split(","));
//			 exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
//		 } else {
//			 exportList = pageList;
//		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, title);
		 mv.addObject(NormalExcelConstants.CLASS, clazz);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams  exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);

//		 exportParams.setType(ExcelType.XSSF);
		 exportParams.setImageBasePath(upLoadPath);

		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
	 }



	protected Object exportXls3(HttpServletRequest request, Class<ClockInLogExportResp> clazz, String title) throws IOException {

		// Step.1 组装查询条件
		Map<String, String[]> parameterMap = request.getParameterMap();
		String[] clockStartTimes = parameterMap.get("clockStartTime");
		String[] userIds = parameterMap.get("userId");
		String[] projectIds = parameterMap.get("projectId");

//		 QueryWrapper<ClockinLog> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		LambdaQueryChainWrapper<ClockinTeamLog> queryChainWrapper = clockinTeamLogService.lambdaQuery()
				.eq(ClockinTeamLog::getDelFlag, 0);

//		 List<ClockinTeamLog> clockinTeamLogs = clockinTeamLogService.lambdaQuery()
//				 .eq(ClockinTeamLog::getDelFlag, 0)
//				 .list();

		if(userIds!=null && userIds.length!=0 && StringUtils.isNotBlank(userIds[0])){
			queryChainWrapper.eq(ClockinTeamLog::getUserId,userIds[0]);
		}
		List<ClockinTeamLog> clockinTeamLogs = queryChainWrapper.list();
		if(projectIds!=null && projectIds.length!=0 && StringUtils.isNotBlank(projectIds[0])){
			ClockInProject clockInProject = clockInProjectService.lambdaQuery()
					.eq(ClockInProject::getDelFlag, 0)
					.eq(ClockInProject::getId,projectIds[0])
					.one();
			if(clockInProject == null){
				throw new JeecgBootException("项目错误");
			}
			try {
				clockinTeamLogs = clockinTeamLogService.lambdaQuery()
						.eq(ClockinTeamLog::getDelFlag, 0)
						.eq(ClockinTeamLog::getTeamId, clockInProject.getTeamId())
						.list();
//				 clockinTeamLogs.add(clockinTeamLog);
			}catch (Exception e){
				throw new JeecgBootException("该项目可能存在两个团队绑定，请检查项目管理");
			}


		}
		// 创建工作簿
		Workbook workbook =  new XSSFWorkbook();
		// 创建工作表
		Sheet sheet = workbook.createSheet("考勤");



//		Row headerRow2 = sheet.createRow(2);
//
//
//		headerRow2.createCell(0).setCellValue("日期");
//		headerRow2.createCell(1).setCellValue("打卡时间");

		List<Map<String, Object>> maps = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
//		XSSFWorkbook workbook = new XSSFWorkbook();
//		XSSFSheet sheet = workbook.createSheet("打卡数据");
//		XSSFRow headRow = sheet.createRow(0);
//		headRow.createCell(0).setCellValue("姓名");
//		headRow.createCell(1).setCellValue("性别");
//		headRow.createCell(2).setCellValue("数据");
		List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
		ExcelExportEntity excelExportEntity = new ExcelExportEntity("姓名", "name");
		excelExportEntity.setNeedMerge(true);

		ExcelExportEntity excelExportEntity1 = new ExcelExportEntity("性别", "sex");
		excelExportEntity1.setNeedMerge(true);

		ExcelExportEntity excelExportEntity2 = new ExcelExportEntity("数据", "list");
		excelExportEntity2.setNeedMerge(true);

		entity.add(excelExportEntity);
		entity.add(excelExportEntity1);
		entity.add(excelExportEntity2);

//		 int day = Integer.parseInt(DateUtils2.getNowMonthMaxDay());
		String nowYearMonth = DateUtils2.getNowYearMonth();

		if(clockStartTimes!=null && clockStartTimes.length!=0 && StringUtils.isNotBlank(clockStartTimes[0])){
			nowYearMonth = clockStartTimes[0];
		}
		YearMonth yearMonth = YearMonth.parse(nowYearMonth);
		int day = yearMonth.lengthOfMonth();


		String yearMonthDay = "";

		// Step.2 获取导出数据
//		 List<ClockinLog> pageList = service.list(queryWrapper);
//		 List<ClockinLog> exportList = null;
		List<Map<String, Object>> list = new ArrayList<>();
		List<String> strings = null;
		List<ClockInLogExportResp> exportList = new ArrayList<>();
		CellStyle wrapStyle = workbook.createCellStyle();
		wrapStyle.setAlignment(HorizontalAlignment.CENTER);
		wrapStyle.setBorderTop(BorderStyle.THIN); // 顶部边框
		wrapStyle.setBorderBottom(BorderStyle.THIN); // 底部边框
		wrapStyle.setBorderLeft(BorderStyle.THIN); // 左边边框
		wrapStyle.setBorderRight(BorderStyle.THIN); // 右边边框

		int headerRowNum = 0;
		for (ClockinTeamLog clockinTeamLog:clockinTeamLogs){
			ClockInProject clockInProject = clockInProjectService.lambdaQuery()
					.eq(ClockInProject::getDelFlag, 0)
					.eq(ClockInProject::getTeamId, clockinTeamLog.getTeamId())
					.one();

			if(clockInProject == null){
				continue;
			}
			ClockinAuth clockinAuth = clockinAuthService.lambdaQuery()
					.eq(ClockinAuth::getDelFlag, 0)
					.eq(ClockinAuth::getUserId, clockinTeamLog.getUserId())
					.one();
			if(clockinAuth == null){
				continue;
			}
			List<ClockInLogExportResp2> clockInLogExportResp2s = new ArrayList<>();
			ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp();
			clockInLogExportResp.setName(clockinAuth.getName());
			clockInLogExportResp.setDate(nowYearMonth);


			// 创建表头行
			Row headerRow = sheet.createRow(headerRowNum);
			Cell cell1 = headerRow.createCell(0);
			cell1.setCellStyle(wrapStyle);
			cell1.setCellValue("姓名："+clockinAuth.getName()+"     日期："+nowYearMonth);
			sheet.addMergedRegion(new CellRangeAddress(headerRowNum,headerRowNum,0,day-1));
//			Row row1 = sheet.createRow(1);
//			row1.createCell(0).setCellValue(clockinAuth.getName());
			sheet.setColumnWidth(0,256*10);
			sheet.setColumnWidth(1,256*10);
			map.put("name",clockinAuth.getName());
			map.put("sex",nowYearMonth);
			List<Map<String, Object>> maps1 = new ArrayList<>();
			Row row = sheet.createRow(1+headerRowNum);
			Row row2 = sheet.createRow(2+headerRowNum);
			headerRowNum = headerRowNum + 3;

			int num = 3;
			for (int n= 1;n<=day;n++){
				ClockInLogExportResp2 clockInLogExportResp2 = new ClockInLogExportResp2();


				clockInLogExportResp2.setDay(n+"");
				yearMonthDay = nowYearMonth+"-"+n;
				if(n < 10){
					yearMonthDay = nowYearMonth+"-0"+n;
				}

				Date date = DateUtils2.getDate(yearMonthDay + " 23:59:59");
				LocalDateTime localDateTime = DateUtils2.dateToDateTime(date);
				Integer type = 0;
				if(DayOfWeek.SATURDAY.equals(localDateTime.getDayOfWeek()) || DayOfWeek.SUNDAY.equals(localDateTime.getDayOfWeek())){
					type = 1;
				}

				Cell cell2 = row.createCell(n - 1);
				cell2.setCellValue(n);
				cell2.setCellStyle(wrapStyle);

				List<ClockInLogResp> clockInLogExpeort = clockinLogMapper.getClockInLogExpeort(yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type);
				String clockInTime = "";
				for (ClockInLogResp clockInLogResp:clockInLogExpeort) {
					if(StringUtils.isBlank(clockInLogResp.getTime())&&clockInLogResp.getType() == 2){
						continue;
					}

					if(StringUtils.isBlank(clockInLogResp.getTime())){
						clockInLogResp.setClockStartTime("缺卡");
					}
					clockInTime = clockInTime+"\n"+clockInLogResp.getClockStartTime();
//					 strings.add(clockInLogResp.getClockStartTime());
				}
				// 创建一个单元格样式，用于自动换行

				wrapStyle.setWrapText(true);
				Cell cell = row2.createCell(n-1);
				cell.setCellValue(clockInTime);
				cell.setCellStyle(wrapStyle);
				Map<String, Object> map1 = new HashMap<>();
				map1.put(n+"",clockInTime);
				maps1.add(map1);
				clockInLogExportResp2.setClockInTime(clockInTime);
				clockInLogExportResp2s.add(clockInLogExportResp2);

			}
			map.put("list",maps1);
			maps.add(map);
			clockInLogExportResp.setClockInLogExportResp2s(clockInLogExportResp2s);
			exportList.add(clockInLogExportResp);
		}

		// 调整列宽以适应内容
		sheet.autoSizeColumn(0);
		sheet.autoSizeColumn(1);

		// 将工作簿写入字节数组输出流
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		workbook.write(bos);
		byte[] bytes = bos.toByteArray();

		// 构建响应头
		org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
		headers.setContentDispositionFormData("attachment", "attendance_data.xlsx");

		// 返回响应实体
		return ResponseEntity.ok()
				.headers(headers)
				.body(bytes);

		// 过滤选中数据
//		 String selections = request.getParameter("selections");
//		 if (oConvertUtils.isNotEmpty(selections)) {
//			 List<String> selectionList = Arrays.asList(selections.split(","));
//			 exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
//		 } else {
//			 exportList = pageList;
//		 }

		// Step.3 AutoPoi 导出Excel
//		ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//		//此处设置的filename无效 ,前端会重更新设置一下
//
//		mv.addObject(NormalExcelConstants.FILE_NAME, title);
//		mv.addObject(NormalExcelConstants.CLASS, entity.getClass());
//		//update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
//		ExportParams  exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
//
////		exportParams.setType(ExcelType.XSSF);
//		exportParams.setImageBasePath(upLoadPath);
//
//		//update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
//		mv.addObject(NormalExcelConstants.PARAMS,exportParams);
//		mv.addObject(NormalExcelConstants.DATA_LIST, maps);
//		return mv;
	}




	private String getId(ClockinLog item) {
		 try {
			 return PropertyUtils.getProperty(item, "id").toString();
		 } catch (Exception e) {
			 e.printStackTrace();
			 return null;
		 }
	 }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ClockinLog.class);
    }


}
