package com.ruoyi.personnel.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.personnel.dto.PersonRewardPunishmentRecordDto;
import com.ruoyi.personnel.excel.PersonRewardPunishmentRecordExcel;
import com.ruoyi.personnel.mapper.PersonRewardPunishmentRecordMapper;
import com.ruoyi.personnel.pojo.PersonRewardPunishmentRecord;
import com.ruoyi.personnel.service.PersonRewardPunishmentRecordService;
import com.ruoyi.personnel.vo.PersonRewardPunishmentRecordVO;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
*
* 奖惩记录 服务实现类
*
*
* @author
* @since 2024-10-08 11:25:02
*/
@Service
public class PersonRewardPunishmentRecordServiceImpl extends ServiceImpl implements PersonRewardPunishmentRecordService {
@Override
public IPage rewardPunishmentPage(Page page, PersonRewardPunishmentRecordDto punishmentRecordDto) {
return baseMapper.rewardPunishmentPage(page, punishmentRecordDto);
}
@Override
public List rewardPunishmentExport(PersonRewardPunishmentRecordDto punishmentRecordDto) {
return baseMapper.rewardPunishmentExport(punishmentRecordDto);
}
@Override
public void exportExcel(PersonRewardPunishmentRecordDto punishmentRecordDto, HttpServletResponse response) {
response.reset();
try{
List data = rewardPunishmentExport(punishmentRecordDto);
//导出
String fileName = "中天耐丝质量部奖惩记录"+ ExcelTypeEnum.XLSX;
fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
EasyExcel.write(response.getOutputStream())
.head(PersonRewardPunishmentRecordExcel.class)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽
.sheet()
.doWrite(data);
}catch (Exception e){
throw new RuntimeException("奖惩记录导出失败");
}
}
}