| | |
| | | package cn.lili.modules.promotion.serviceimpl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.text.CharSequenceUtil; |
| | | import cn.lili.cache.Cache; |
| | | import cn.lili.common.enums.ResultCode; |
| | |
| | | import cn.lili.common.security.AuthUser; |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.common.vo.PageVO; |
| | | import cn.lili.modules.lmk.enums.general.AdminRoleEnum; |
| | | import cn.lili.modules.order.order.entity.dto.CouponExportDetailDTO; |
| | | import cn.lili.modules.order.order.entity.dto.OrderExportDTO; |
| | | import cn.lili.modules.order.order.entity.dto.OrderExportDetailDTO; |
| | | import cn.lili.modules.permission.service.AdminUserService; |
| | | import cn.lili.modules.promotion.entity.dos.Coupon; |
| | | import cn.lili.modules.promotion.entity.dos.MemberCoupon; |
| | | import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams; |
| | |
| | | import cn.lili.modules.promotion.service.MemberCouponService; |
| | | import cn.lili.modules.promotion.tools.PromotionTools; |
| | | import cn.lili.mybatis.util.PageUtil; |
| | | import cn.lili.utils.CommonUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private CouponService couponService; |
| | | |
| | | @Autowired |
| | | private AdminUserService adminUserService; |
| | | /** |
| | | * 缓存 |
| | | */ |
| | |
| | | this.update(updateWrapper); |
| | | } |
| | | |
| | | public List<MemberCouponVO> getMemberCouponsPageExport(MemberCouponSearchParams param){ |
| | | QueryWrapper<MemberCouponVO> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getMemberId()), "mc.member_id", param.getMemberId()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getStoreId()), "c.store_id", param.getStoreId()); |
| | | queryWrapper.like(CharSequenceUtil.isNotEmpty(param.getMemberName()), "mc.member_name", param.getMemberName()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getCouponId()), "mc.coupon_id", param.getCouponId()); |
| | | queryWrapper.like(CharSequenceUtil.isNotEmpty(param.getCouponName()), "c.coupon_name", param.getCouponName()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getGetType()), "mc.get_type", param.getGetType()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getScopeType()), "mc.scope_type", param.getPromotionStatus()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getCouponType()), "mc.coupon_type", param.getCouponType()); |
| | | queryWrapper.eq(CharSequenceUtil.isNotEmpty(param.getMemberCouponStatus()), "mc.member_coupon_status", param.getMemberCouponStatus()); |
| | | if (param.getStartTime() != null) { |
| | | queryWrapper.ge("mc.start_time", new Date(param.getStartTime())); |
| | | } |
| | | if (param.getEndTime() != null) { |
| | | queryWrapper.le("mc.end_time", new Date(param.getEndTime())); |
| | | } |
| | | return this.baseMapper.getMemberCouponsExport(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Page<MemberCouponVO> getMemberCouponsPage(Page<MemberCoupon> page, MemberCouponSearchParams param) { |
| | | QueryWrapper<MemberCouponVO> queryWrapper = new QueryWrapper<>(); |
| | |
| | | } |
| | | return this.baseMapper.getMemberCoupons(page, queryWrapper); |
| | | } |
| | | @Override |
| | | public void queryExportCoupon(HttpServletResponse response, MemberCouponSearchParams searchParams) { |
| | | |
| | | List<MemberCouponVO> records = this.getMemberCouponsPageExport(searchParams); |
| | | XSSFWorkbook workbook = initCouponExportData(records); |
| | | 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 initCouponExportData(List<MemberCouponVO> list){ |
| | | List<CouponExportDetailDTO> couponExportDetailDTOS = new ArrayList<>(); |
| | | for (MemberCoupon memberCoupon : list){ |
| | | CouponExportDetailDTO dto = new CouponExportDetailDTO(); |
| | | BeanUtil.copyProperties(memberCoupon, dto); |
| | | couponExportDetailDTOS.add(dto); |
| | | } |
| | | System.out.println("-----------------------"); |
| | | System.out.println(couponExportDetailDTOS); |
| | | 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< couponExportDetailDTOS.size();i++){ |
| | | CouponExportDetailDTO dto = couponExportDetailDTOS.get(i); |
| | | Row row = sheet.createRow(i+1); |
| | | row.createCell(0).setCellValue(dto.getMemberName()); |
| | | row.createCell(1).setCellValue(dto.getCouponName()); |
| | | if ("platform".equals(dto.getStoreName())){ |
| | | row.createCell(2).setCellValue("平台"); |
| | | }else { |
| | | row.createCell(2).setCellValue(dto.getStoreName()); |
| | | } |
| | | if (dto.getDiscount() != null){ |
| | | row.createCell(3).setCellValue(dto.getDiscount()+"折"); |
| | | } |
| | | if (dto.getPrice()!=null){ |
| | | row.createCell(3).setCellValue(dto.getPrice()+"¥"); |
| | | } |
| | | row.createCell(4).setCellValue(dto.getConsumeThreshold()); |
| | | if("FREE".equals(dto.getGetType())){ |
| | | row.createCell(5).setCellValue("免费获取"); |
| | | }else if("ACTIVITY".equals(dto.getGetType())){ |
| | | row.createCell(5).setCellValue("活动获取"); |
| | | }else if("lime".equals(dto.getGetType())){ |
| | | row.createCell(5).setCellValue("内购"); |
| | | }else if("purple".equals(dto.getGetType())){ |
| | | row.createCell(5).setCellValue("未知"); |
| | | } |
| | | |
| | | if("NEW".equals(dto.getMemberCouponStatus())){ |
| | | row.createCell(6).setCellValue("已领取"); |
| | | }else if("USED".equals(dto.getMemberCouponStatus())){ |
| | | row.createCell(6).setCellValue("已使用"); |
| | | }else if("EXPIRE".equals(dto.getMemberCouponStatus())){ |
| | | row.createCell(6).setCellValue("已过期"); |
| | | }else if("CLOSED".equals(dto.getMemberCouponStatus())){ |
| | | row.createCell(6).setCellValue("已作废"); |
| | | } |
| | | if("DISCOUNT".equals(dto.getCouponType())){ |
| | | row.createCell(7).setCellValue("打折"); |
| | | }else if("PRICE".equals(dto.getCouponType())){ |
| | | row.createCell(7).setCellValue("减免现金"); |
| | | }else{ |
| | | row.createCell(7).setCellValue("未知"); |
| | | } |
| | | if ("ALL".equals(dto.getScopeType())) { |
| | | row.createCell(8).setCellValue("全品类"); |
| | | }else if ("PORTION_GOODS_CATEGORY".equals(dto.getScopeType())) { |
| | | row.createCell(8).setCellValue("商品分类"); |
| | | } else if ("PORTION_SHOP_CATEGORY".equals(dto.getScopeType())) { |
| | | row.createCell(8).setCellValue("店铺分类"); |
| | | } else if ("PORTION_GOODS".equals(dto.getScopeType())) { |
| | | row.createCell(8).setCellValue("指定商品"); |
| | | } |
| | | |
| | | row.createCell(9).setCellValue(DateUtil.formatDateTime(dto.getStartTime())); |
| | | row.createCell(10).setCellValue(DateUtil.formatDateTime(dto.getEndTime())); |
| | | } |
| | | return workbook; |
| | | } |
| | | @Override |
| | | public long getMemberCouponNum(String memberId, String couponId) { |
| | | LambdaQueryWrapper<MemberCoupon> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | return this.count(queryWrapper); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 清除无效的会员优惠券 |
| | | * |