| | |
| | | package cn.lili.modules.lmk.service.impl; |
| | | |
| | | import cn.lili.common.utils.StringUtils; |
| | | import cn.lili.modules.lmk.domain.query.PrizeGrantRecordQuery; |
| | | import cn.lili.modules.lmk.domain.query.PrizeRecordTimeQuery; |
| | | import cn.lili.modules.lmk.domain.vo.PrizeRecordTimeVO; |
| | | import cn.lili.modules.lmk.enums.general.PrizeDistributeStatusEnum; |
| | | import cn.lili.modules.lmk.enums.general.PrizeGrantStatusEnums; |
| | | import cn.lili.modules.lmk.enums.general.PrizeStatusEnum; |
| | | import cn.lili.modules.order.order.entity.dto.PrizeRecordExportDetailDTO; |
| | | import cn.lili.utils.COSUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import cn.lili.modules.lmk.domain.entity.PrizeRecord; |
| | | import cn.lili.modules.lmk.mapper.PrizeRecordMapper; |
| | |
| | | import cn.lili.modules.lmk.domain.form.PrizeRecordForm; |
| | | import cn.lili.modules.lmk.domain.vo.PrizeRecordVO; |
| | | import cn.lili.modules.lmk.domain.query.PrizeRecordQuery; |
| | | 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; |
| | | |
| | | /** |
| | | * 用户抽奖记录表 服务实现类 |
| | | * 用户抽奖记录 服务实现类 |
| | | * |
| | | * @author peng |
| | | * @since 2025-08-14 |
| | |
| | | |
| | | private final PrizeRecordMapper prizeRecordMapper; |
| | | |
| | | private final COSUtil cosUtil; |
| | | |
| | | @Override |
| | | public void queryExportStock(HttpServletResponse response, PrizeRecordQuery query){ |
| | | List<PrizeRecordVO> 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(); |
| | | } |
| | | } |
| | | } |
| | | public XSSFWorkbook initExportData(List<PrizeRecordVO> list){ |
| | | List<PrizeRecordExportDetailDTO> exportDetailDTOS = new ArrayList<>(); |
| | | for (PrizeRecordVO vo : list){ |
| | | PrizeRecordExportDetailDTO detailDtO = new PrizeRecordExportDetailDTO(); |
| | | 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++){ |
| | | PrizeRecordExportDetailDTO dto = exportDetailDTOS.get(i); |
| | | Row row = sheet.createRow(i+1); |
| | | row.createCell(0).setCellValue(dto.getNickName()); |
| | | row.createCell(1).setCellValue(dto.getPrizeActivityName()); |
| | | if (PrizeStatusEnum.WIN.name().equals(dto.getPrizeStatus())){ |
| | | row.createCell(2).setCellValue(PrizeStatusEnum.WIN.getDescription()); |
| | | }else{ |
| | | row.createCell(2).setCellValue(PrizeStatusEnum.NOT_WIN.getDescription()); |
| | | } |
| | | |
| | | row.createCell(3).setCellValue(dto.getPrizeContent()); |
| | | if (PrizeDistributeStatusEnum.SUCCESS.name().equals(dto.getDistributeStatus())){ |
| | | row.createCell(4).setCellValue(PrizeGrantStatusEnums.SUCCESS.getDescription()); |
| | | }else if(PrizeDistributeStatusEnum.FAILED.name().equals(dto.getDistributeStatus())){ |
| | | row.createCell(4).setCellValue(PrizeDistributeStatusEnum.FAILED.getDescription()); |
| | | }else if(PrizeDistributeStatusEnum.NOT_WAIT.name().equals(dto.getDistributeStatus())){ |
| | | row.createCell(4).setCellValue(PrizeDistributeStatusEnum.NOT_WAIT.getDescription()); |
| | | |
| | | }else { |
| | | row.createCell(4).setCellValue(PrizeDistributeStatusEnum.WAIT.getDescription()); |
| | | } |
| | | |
| | | } |
| | | |
| | | return workbook; |
| | | |
| | | } |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | |
| | | public Result page(PrizeRecordQuery query) { |
| | | IPage<PrizeRecordVO> page = PageUtil.getPage(query, PrizeRecordVO.class); |
| | | baseMapper.getPage(page, query); |
| | | for (PrizeRecordVO vo :page.getRecords()){ |
| | | if (StringUtils.isNotBlank(vo.getPrizeActivityCover())){ |
| | | vo.setPrizeActivityCoverUrl(cosUtil.getPreviewUrl(vo.getPrizeActivityCover())); |
| | | } |
| | | if (StringUtils.isNotBlank(vo.getPrizeImg())){ |
| | | vo.setPrizeImgUrl(cosUtil.getPreviewUrl(vo.getPrizeImg())); |
| | | } |
| | | } |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public List<PrizeRecordTimeVO> getPrizeRecordListByTime(PrizeRecordTimeQuery query) { |
| | | return baseMapper.getPrizeRecordListByTime(query); |
| | | } |
| | | } |