| | |
| | | package cn.lili.modules.lmk.service.impl; |
| | | |
| | | import cn.lili.modules.lmk.enums.general.PrizeGrantStatusEnums; |
| | | import cn.lili.modules.order.order.entity.dto.PrizeGrantRecordExportDetailDtO; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import cn.lili.modules.lmk.domain.entity.PrizeGrantRecord; |
| | | import cn.lili.modules.lmk.mapper.PrizeGrantRecordMapper; |
| | |
| | | import cn.lili.modules.lmk.domain.form.PrizeGrantRecordForm; |
| | | import cn.lili.modules.lmk.domain.vo.PrizeGrantRecordVO; |
| | | import cn.lili.modules.lmk.domain.query.PrizeGrantRecordQuery; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import cn.lili.utils.PageUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | private final PrizeGrantRecordMapper prizeGrantRecordMapper; |
| | | |
| | | @Override |
| | | public void queryExportStock(HttpServletResponse response, PrizeGrantRecordQuery query){ |
| | | List<PrizeGrantRecordVO> list = baseMapper.getExportData(query); |
| | | XSSFWorkbook workbook = initExportData(list); |
| | | try { |
| | | // 设置响应头 |
| | | String fileName = URLEncoder.encode("奖品发放记录", "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | ServletOutputStream out = response.getOutputStream(); |
| | | workbook.write(out); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | workbook.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | private XSSFWorkbook initExportData(List<PrizeGrantRecordVO> list){ |
| | | List<PrizeGrantRecordExportDetailDtO> exportDetailDtOS = new ArrayList<>(); |
| | | for (PrizeGrantRecordVO vo : list){ |
| | | PrizeGrantRecordExportDetailDtO detailDtO = new PrizeGrantRecordExportDetailDtO(); |
| | | BeanUtils.copyProperties(vo,detailDtO); |
| | | exportDetailDtOS.add(detailDtO); |
| | | } |
| | | |
| | | XSSFWorkbook workbook = new XSSFWorkbook(); |
| | | |
| | | Sheet sheet = workbook.createSheet("奖品发放记录"); |
| | | // 创建表头 |
| | | Row header = sheet.createRow(0); |
| | | String[] headers = { |
| | | "用户昵称", "活动名","商品名", |
| | | "商品内容","发放状态" |
| | | ,"描述" |
| | | }; |
| | | for(int i= 0 ;i< headers.length;i++){ |
| | | Cell cell = header.createCell(i); |
| | | cell.setCellValue(headers[i]); |
| | | } |
| | | for (int i=0;i< exportDetailDtOS.size();i++){ |
| | | PrizeGrantRecordExportDetailDtO dto = exportDetailDtOS.get(i); |
| | | Row row = sheet.createRow(i+1); |
| | | row.createCell(0).setCellValue(dto.getNickName()); |
| | | row.createCell(1).setCellValue(dto.getActivityName()); |
| | | row.createCell(2).setCellValue(dto.getPrizeName()); |
| | | row.createCell(3).setCellValue(dto.getPrizeContent()); |
| | | if (PrizeGrantStatusEnums.SUCCESS.name().equals(dto.getGrantStatus())){ |
| | | row.createCell(4).setCellValue(PrizeGrantStatusEnums.SUCCESS.getDescription()); |
| | | }else { |
| | | row.createCell(4).setCellValue(PrizeGrantStatusEnums.FAILED.getDescription()); |
| | | |
| | | } |
| | | |
| | | row.createCell(5).setCellValue(dto.getDes()); |
| | | } |
| | | |
| | | return workbook; |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |