<selectid="findNoReceivePage"resultType="com.atguigu.daijia.model.vo.coupon.NoReceiveCouponVo"> select info.id, info.coupon_type, info.name, info.amount, info.discount, info.condition_amount, info.publish_count, info.per_limit, info.expire_time, info.description from coupon_info info left join ( select coupon_id, customer_id, count(customer_id) cnt from customer_coupon where customer_id = #{customerId} group by coupon_id, customer_id ) cus_coup on cus_coup.coupon_id = info.id where info.status = 1 and info.receive_count < info.publish_count and ( info.per_limit =0 or info.per_limit > cus_coup.cnt or cus_coup.cnt is null ) order by info.id desc </select>
2.2、Feign接口
2.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询未领取优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findNoReceivePage/{customerId}/{page}/{limit}") Result<PageVo<NoReceiveCouponVo>> findNoReceivePage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<NoReceiveCouponVo> findNoReceivePage(Long customerId, Long page, Long limit);
2.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<NoReceiveCouponVo> findNoReceivePage(Long customerId, Long page, Long limit) { return couponFeignClient.findNoReceivePage(customerId, page, limit).getData(); }
cstr.receive_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 1 and cstr.expire_time > now() order by cstr.id desc </select>
3.2、Feign接口
3.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询未使用优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findNoUsePage/{customerId}/{page}/{limit}") Result<PageVo<NoUseCouponVo>> findNoUsePage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<NoUseCouponVo> findNoUsePage(Long customerId, Long page, Long limit);
3.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<NoUseCouponVo> findNoUsePage(Long customerId, Long page, Long limit) { return couponFeignClient.findNoUsePage(customerId, page, limit).getData(); }
cstr.id as customerCouponId, cstr.used_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 2 order by cstr.id desc </select>
4.2、Feign接口
4.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询已使用优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findUsedPage/{customerId}/{page}/{limit}") Result<PageVo<UsedCouponVo>> findUsedPage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<UsedCouponVo> findUsedPage(Long customerId, Long page, Long limit);
4.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<UsedCouponVo> findUsedPage(Long customerId, Long page, Long limit) { return couponFeignClient.findUsedPage(customerId, page, limit).getData(); }
@Operation(summary = "领取优惠券") @GetMapping("/receive/{couponId}") public Result<Boolean> receive1(@RequestHeader("customerId") Long customerId, @PathVariable Long couponId) {
intupdateReceiveCountByLimit(@Param("id") Long id);
6.3.2、CouponInfoMapper.xml
1 2 3
<updateid="updateReceiveCountByLimit"> update coupon_info set receive_count = receive_count + 1 where id = #{id} and receive_count < publish_count </update>
cstr.id as customerCouponId, cstr.receive_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 1 and cstr.expire_time > now() order by cstr.id desc </select>
<selectid="findNoReceivePage"resultType="com.atguigu.daijia.model.vo.coupon.NoReceiveCouponVo"> select info.id, info.coupon_type, info.name, info.amount, info.discount, info.condition_amount, info.publish_count, info.per_limit, info.expire_time, info.description from coupon_info info left join ( select coupon_id, customer_id, count(customer_id) cnt from customer_coupon where customer_id = #{customerId} group by coupon_id, customer_id ) cus_coup on cus_coup.coupon_id = info.id where info.status = 1 and info.receive_count < info.publish_count and ( info.per_limit =0 or info.per_limit > cus_coup.cnt or cus_coup.cnt is null ) order by info.id desc </select>
2.2、Feign接口
2.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询未领取优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findNoReceivePage/{customerId}/{page}/{limit}") Result<PageVo<NoReceiveCouponVo>> findNoReceivePage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<NoReceiveCouponVo> findNoReceivePage(Long customerId, Long page, Long limit);
2.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<NoReceiveCouponVo> findNoReceivePage(Long customerId, Long page, Long limit) { return couponFeignClient.findNoReceivePage(customerId, page, limit).getData(); }
cstr.receive_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 1 and cstr.expire_time > now() order by cstr.id desc </select>
3.2、Feign接口
3.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询未使用优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findNoUsePage/{customerId}/{page}/{limit}") Result<PageVo<NoUseCouponVo>> findNoUsePage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<NoUseCouponVo> findNoUsePage(Long customerId, Long page, Long limit);
3.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<NoUseCouponVo> findNoUsePage(Long customerId, Long page, Long limit) { return couponFeignClient.findNoUsePage(customerId, page, limit).getData(); }
cstr.id as customerCouponId, cstr.used_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 2 order by cstr.id desc </select>
4.2、Feign接口
4.2.1、CouponInfoFeignClient
1 2 3 4 5 6 7 8 9 10 11 12
/** * 查询已使用优惠券分页列表 * @param customerId * @param page * @param limit * @return */ @GetMapping("/coupon/info/findUsedPage/{customerId}/{page}/{limit}") Result<PageVo<UsedCouponVo>> findUsedPage( @PathVariable("customerId") Long customerId, @PathVariable("page") Long page, @PathVariable("limit") Long limit);
PageVo<UsedCouponVo> findUsedPage(Long customerId, Long page, Long limit);
4.3.3、CouponServiceImpl
1 2 3 4
@Override public PageVo<UsedCouponVo> findUsedPage(Long customerId, Long page, Long limit) { return couponFeignClient.findUsedPage(customerId, page, limit).getData(); }
@Operation(summary = "领取优惠券") @GetMapping("/receive/{couponId}") public Result<Boolean> receive1(@RequestHeader("customerId") Long customerId, @PathVariable Long couponId) {
intupdateReceiveCountByLimit(@Param("id") Long id);
6.3.2、CouponInfoMapper.xml
1 2 3
<updateid="updateReceiveCountByLimit"> update coupon_info set receive_count = receive_count + 1 where id = #{id} and receive_count < publish_count </update>
cstr.id as customerCouponId, cstr.receive_time from coupon_info info inner join customer_coupon cstr on cstr.coupon_id = info.id where cstr.customer_id = #{customerId} and cstr.status = 1 and cstr.expire_time > now() order by cstr.id desc </select>