From 72d35309428e4a633584a90adbf8b2906b9d9385 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 1 Aug 2025 16:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ycwl/basic/mapper/CouponMapper.java | 15 ++++- .../model/pc/coupon/entity/CouponEntity.java | 3 + .../entity/CouponRecordEntity.java | 3 + .../impl/AppCouponRecordServiceImpl.java | 7 +-- .../service/pc/impl/CouponServiceImpl.java | 5 +- src/main/resources/mapper/CouponMapper.xml | 63 +++++++++++++++++-- .../resources/mapper/CouponRecordMapper.xml | 7 ++- 7 files changed, 85 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ycwl/basic/mapper/CouponMapper.java b/src/main/java/com/ycwl/basic/mapper/CouponMapper.java index 3676c7c..51ee1fd 100644 --- a/src/main/java/com/ycwl/basic/mapper/CouponMapper.java +++ b/src/main/java/com/ycwl/basic/mapper/CouponMapper.java @@ -1,6 +1,5 @@ package com.ycwl.basic.mapper; import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq; import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO; import org.apache.ibatis.annotations.Mapper; @@ -8,10 +7,22 @@ import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface CouponMapper extends BaseMapper { +public interface CouponMapper { List selectByQuery(CouponQueryReq query); int updateStatus(Integer id); CouponEntity getById(Integer couponId); + + int insert(CouponEntity coupon); + + int updateById(CouponEntity coupon); + + int deleteById(Integer id); + + List selectList(); + + CouponEntity selectById(Integer id); + + CouponEntity selectByScenicIdAndTypeAndStatus(Long scenicId, Integer type, Integer status); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/model/pc/coupon/entity/CouponEntity.java b/src/main/java/com/ycwl/basic/model/pc/coupon/entity/CouponEntity.java index c48c558..07edfcd 100644 --- a/src/main/java/com/ycwl/basic/model/pc/coupon/entity/CouponEntity.java +++ b/src/main/java/com/ycwl/basic/model/pc/coupon/entity/CouponEntity.java @@ -46,6 +46,9 @@ public class CouponEntity { */ private Integer status; private Date createAt; + + private Integer deleted; + private Date deletedAt; public BigDecimal calculateDiscountPrice(BigDecimal originalPrice) { if (originalPrice == null) { diff --git a/src/main/java/com/ycwl/basic/model/pc/couponRecord/entity/CouponRecordEntity.java b/src/main/java/com/ycwl/basic/model/pc/couponRecord/entity/CouponRecordEntity.java index 6df4cd9..5b2b29b 100644 --- a/src/main/java/com/ycwl/basic/model/pc/couponRecord/entity/CouponRecordEntity.java +++ b/src/main/java/com/ycwl/basic/model/pc/couponRecord/entity/CouponRecordEntity.java @@ -19,4 +19,7 @@ public class CouponRecordEntity { private Date createTime; private Date usedTime; private Long usedOrderId; + + private Integer deleted; + private Date deletedAt; } diff --git a/src/main/java/com/ycwl/basic/service/mobile/impl/AppCouponRecordServiceImpl.java b/src/main/java/com/ycwl/basic/service/mobile/impl/AppCouponRecordServiceImpl.java index 98a99e8..643e22a 100644 --- a/src/main/java/com/ycwl/basic/service/mobile/impl/AppCouponRecordServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/mobile/impl/AppCouponRecordServiceImpl.java @@ -1,6 +1,5 @@ package com.ycwl.basic.service.mobile.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ycwl.basic.mapper.CouponMapper; import com.ycwl.basic.mapper.CouponRecordMapper; import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; @@ -50,11 +49,7 @@ public class AppCouponRecordServiceImpl implements AppCouponRecordService { } // 查找可用的优惠券 Long scenicId = face.getScenicId(); - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("scenic_id", scenicId) - .eq("type", type) - .eq("status", 1); // 开启状态 - CouponEntity coupon = couponMapper.selectOne(queryWrapper); + CouponEntity coupon = couponMapper.selectByScenicIdAndTypeAndStatus(scenicId, type, 1); if (coupon == null) { throw new RuntimeException("未找到可领取的优惠券"); diff --git a/src/main/java/com/ycwl/basic/service/pc/impl/CouponServiceImpl.java b/src/main/java/com/ycwl/basic/service/pc/impl/CouponServiceImpl.java index 9249adc..7dfbde1 100644 --- a/src/main/java/com/ycwl/basic/service/pc/impl/CouponServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/pc/impl/CouponServiceImpl.java @@ -1,5 +1,4 @@ package com.ycwl.basic.service.pc.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycwl.basic.mapper.CouponMapper; import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq; @@ -11,7 +10,7 @@ import org.springframework.stereotype.Service; import java.util.List; @Service -public class CouponServiceImpl extends ServiceImpl implements CouponService { +public class CouponServiceImpl implements CouponService { @Autowired private CouponMapper couponMapper; @@ -28,7 +27,7 @@ public class CouponServiceImpl extends ServiceImpl i @Override public Boolean delete(Integer id) { - return removeById(id); + return couponMapper.deleteById(id) > 0; } @Override diff --git a/src/main/resources/mapper/CouponMapper.xml b/src/main/resources/mapper/CouponMapper.xml index 50d2e6d..46f2450 100644 --- a/src/main/resources/mapper/CouponMapper.xml +++ b/src/main/resources/mapper/CouponMapper.xml @@ -18,20 +18,75 @@ FROM coupon c LEFT JOIN scenic s ON c.scenic_id = s.id + AND c.deleted = 0 AND scenic_id = #{scenicId} AND c.name = concat('%',#{name},'%') AND type = #{type} AND discount_type = #{discountType} AND c.status = #{status} - AND create_time >= #{createAtStart} - AND create_time <= #{createAtEnd} + AND create_at >= #{createAtStart} + AND create_at <= #{createAtEnd} - ORDER BY create_time DESC + ORDER BY create_at DESC + + + INSERT INTO coupon ( + scenic_id, name, description, countdown, broadcast, + config_ids, discount_price, type, discount_type, + status, create_at, deleted, deleted_at + ) VALUES ( + #{scenicId}, #{name}, #{description}, #{countdown}, #{broadcast}, + #{configIds}, #{discountPrice}, #{type}, #{discountType}, + #{status}, #{createAt}, #{deleted}, #{deletedAt} + ) + + + + UPDATE coupon SET + scenic_id = #{scenicId}, + name = #{name}, + description = #{description}, + countdown = #{countdown}, + broadcast = #{broadcast}, + config_ids = #{configIds}, + discount_price = #{discountPrice}, + type = #{type}, + discount_type = #{discountType}, + status = #{status}, + create_at = #{createAt}, + deleted = #{deleted}, + deleted_at = #{deletedAt} + WHERE id = #{id} + + + + UPDATE coupon SET deleted = 1, deleted_at = NOW() WHERE id = #{id} + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/CouponRecordMapper.xml b/src/main/resources/mapper/CouponRecordMapper.xml index 538658b..a6aa937 100644 --- a/src/main/resources/mapper/CouponRecordMapper.xml +++ b/src/main/resources/mapper/CouponRecordMapper.xml @@ -3,12 +3,12 @@