| | |
| | | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.util.DateUtils; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.promotion.controller.management.dto.MgtCouponDTO; |
| | |
| | | import com.ruoyi.system.api.validate.UpdateGroup; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | public class MgtCouponController { |
| | | |
| | | private final ICouponService couponService; |
| | | private final HttpServletResponse response; |
| | | |
| | | /** |
| | | * 获取优惠券列表的分页数据 |
| | |
| | | public void exportReceiveDetail(@RequestBody MgtCouponReceiveQuery query) { |
| | | List<CouponReceiveDetailVO> couponReceiveDetailVOList = couponService.getCouponReceiveDetailList( |
| | | query); |
| | | String fileName = |
| | | "优惠券领取明细" + DateUtils.format(new Date(), "yyyyMMddHHmmss") + ".xlsx"; |
| | | |
| | | try (ExcelWriter excelWriter = EasyExcel.write(fileName, CouponReceiveDetailVO.class) |
| | | .build()) { |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("优惠券领取详情").build(); |
| | | excelWriter.write(couponReceiveDetailVOList, writeSheet); |
| | | response.setContentType( |
| | | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | try { |
| | | String fileName = URLEncoder.encode( |
| | | "优惠券领取明细" + DateUtils.format(new Date(), "yyyyMMddHHmmss"), "UTF-8") |
| | | .replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), CouponReceiveDetailVO.class) |
| | | .sheet("优惠券领取明细") |
| | | .doWrite(couponReceiveDetailVOList); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |