Commit e5b2b132 by 吕明尚

时长劵返回值增加以赠送数量

parent c4e85090
......@@ -23,6 +23,7 @@ import share.common.enums.CouponTypeEnum;
import share.common.enums.RoomType;
import share.common.enums.StoreType;
import share.system.domain.SCoupon;
import share.system.domain.vo.SCouponVo;
import share.system.service.ISCouponService;
import share.common.utils.poi.ExcelUtil;
import share.common.core.page.TableDataInfo;
......@@ -58,10 +59,7 @@ public class SCouponController extends BaseController
@PreAuthorize("@ss.hasPermi('system:coupon:list')")
@GetMapping("/list/duration")
public TableDataInfo listDuration(SCoupon sCoupon) {
startPage();
sCoupon.setCouponType(CouponTypeEnum.DURATION.getCode());
List<SCoupon> list = sCouponService.listDuration(sCoupon);
return getDataTable(list);
return sCouponService.listDuration(sCoupon);
}
/**
......
package share.system.domain.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import share.system.domain.SCoupon;
import java.math.BigDecimal;
import java.util.Date;
/**
* 优惠券对象 s_coupon
*
* @author ruoyi
* @date 2023-09-27
*/
@Data
public class SCouponVo extends SCoupon {
private Integer givNumber;
}
......@@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import share.system.domain.SCoupon;
import share.system.domain.SmsLog;
import share.system.domain.vo.SCouponVo;
/**
* 优惠券Mapper接口
......
......@@ -3,8 +3,10 @@ package share.system.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.common.core.page.TableDataInfo;
import share.system.domain.DeviceLog;
import share.system.domain.SCoupon;
import share.system.domain.vo.SCouponVo;
/**
* 优惠券Service接口
......@@ -73,7 +75,7 @@ public interface ISCouponService extends IService<SCoupon>
List<SCoupon> queryShopDeal();
List<SCoupon> listDuration(SCoupon sCoupon);
TableDataInfo listDuration(SCoupon sCoupon);
List<SCoupon> selectSCouponByDealgroupId(Long dealgroupId);
}
......@@ -10,23 +10,24 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouDealQueryShopDealResponseEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import share.common.core.page.PageDomain;
import share.common.core.page.TableDataInfo;
import share.common.core.page.TableSupport;
import share.common.enums.CouponTypeEnum;
import share.common.enums.RoomType;
import share.common.enums.StoreType;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.SStore;
import share.system.domain.SmsLog;
import share.system.domain.*;
import share.system.domain.vo.SCouponVo;
import share.system.domain.vo.SRoomVo;
import share.system.mapper.SCouponMapper;
import share.system.domain.SCoupon;
import share.system.mapper.SmsLogMapper;
import share.system.service.ISCouponService;
import share.system.service.ISStoreService;
import share.system.service.QPService;
import share.system.service.SmsLogService;
import share.system.service.*;
/**
* 优惠券Service业务层处理
......@@ -42,6 +43,8 @@ public class SCouponServiceImpl extends ServiceImpl<SCouponMapper, SCoupon> impl
private ISStoreService storeService;
@Autowired
private QPService qpService;
@Autowired
private ISConsumerCouponService sConsumerCouponService;
//默认时长
private static final String DEFAULT_DURATION = "0";
//默认折扣最大时长
......@@ -216,8 +219,49 @@ public class SCouponServiceImpl extends ServiceImpl<SCouponMapper, SCoupon> impl
}
@Override
public List<SCoupon> listDuration(SCoupon sCoupon) {
return sCouponMapper.listDuration(sCoupon);
public TableDataInfo listDuration(SCoupon sCoupon) {
sCoupon.setCouponType(CouponTypeEnum.DURATION.getCode());
List<SCoupon> sCouponList = sCouponMapper.listDuration(sCoupon);
List<SCouponVo> sCouponVoList = convertDoListToVoList(sCouponList);
//获取sCouponVoList的id集合
List<Long> ids = sCouponVoList.stream().map(SCoupon::getId).collect(Collectors.toList());
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponService.list(new LambdaQueryWrapper<>(SConsumerCoupon.class).in(SConsumerCoupon::getCouponId, ids));
//统计每个couponId的出现次数
Map<Long, Long> collect = sConsumerCoupons.stream().collect(Collectors.groupingBy(SConsumerCoupon::getCouponId, Collectors.counting()));
sCouponVoList.stream().forEach(item -> {
Long count = collect.get(item.getId());
if (ObjectUtils.isEmpty(count)) {
item.setGivNumber(0);
} else {
item.setGivNumber(count.intValue());
}
});
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
sCouponVoList.sort(Comparator.comparing(SCouponVo::getCreateTime).reversed());
int start = (pageNum - 1) * pageSize;
int end = Math.min(start + pageSize, sCouponVoList.size());
List<SCouponVo> pagedList = sCouponVoList.subList(start, end);
TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setRows(pagedList);
tableDataInfo.setTotal(sCouponVoList.size());
tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功");
return tableDataInfo;
}
private List<SCouponVo> convertDoListToVoList(List<SCoupon> roomList) {
List<SCouponVo> voList = new ArrayList<>();
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(roomList)) {
roomList.stream().forEach(o -> {
SCouponVo vo = new SCouponVo();
BeanUtils.copyProperties(o, vo);
voList.add(vo);
});
}
return voList;
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment