From a7f23328815e48b712aa9db683e0f4fcf059ee79 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Mon, 2 Sep 2024 00:29:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=BE=AE=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=BB=93=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/youlai/mall/sale/SaleApplication.java | 24 ++ .../controller/admin/AdvertController.java | 80 ++++++ .../controller/admin/CouponController.java | 63 +++++ .../controller/app/AdvertAppController.java | 31 +++ .../mall/sale/converter/AdvertConverter.java | 28 +++ .../mall/sale/converter/CouponConverter.java | 48 ++++ .../enums/CouponApplicationScopeEnum.java | 37 +++ .../sale/enums/CouponFaceValueTypeEnum.java | 27 ++ .../mall/sale/enums/CouponTypeEnum.java | 29 +++ .../youlai/mall/sale/enums/PlatformEnum.java | 28 +++ .../sale/enums/ValidityPeriodTypeEnum.java | 27 ++ .../youlai/mall/sale/mapper/AdvertMapper.java | 20 ++ .../mall/sale/mapper/CouponHistoryMapper.java | 15 ++ .../youlai/mall/sale/mapper/CouponMapper.java | 21 ++ .../sale/mapper/CouponSpuCategoryMapper.java | 20 ++ .../mall/sale/mapper/CouponSpuMapper.java | 20 ++ .../youlai/mall/sale/model/entity/Advert.java | 49 ++++ .../youlai/mall/sale/model/entity/Coupon.java | 120 +++++++++ .../mall/sale/model/entity/CouponHistory.java | 79 ++++++ .../mall/sale/model/entity/CouponSpu.java | 43 ++++ .../sale/model/entity/CouponSpuCategory.java | 34 +++ .../mall/sale/model/form/CouponForm.java | 76 ++++++ .../sale/model/query/AdvertPageQuery.java | 22 ++ .../sale/model/query/CouponPageQuery.java | 25 ++ .../mall/sale/model/vo/AdvertPageVO.java | 46 ++++ .../youlai/mall/sale/model/vo/BannerVO.java | 19 ++ .../mall/sale/model/vo/CouponPageVO.java | 44 ++++ .../mall/sale/service/AdvertService.java | 23 ++ .../sale/service/CouponHistoryService.java | 11 + .../mall/sale/service/CouponService.java | 58 +++++ .../service/CouponSpuCategoryService.java | 11 + .../mall/sale/service/CouponSpuService.java | 11 + .../sale/service/impl/AdvertServiceImpl.java | 57 +++++ .../impl/CouponHistoryServiceImpl.java | 20 ++ .../sale/service/impl/CouponServiceImpl.java | 231 ++++++++++++++++++ .../impl/CouponSpuCategoryServiceImpl.java | 20 ++ .../service/impl/CouponSpuServiceImpl.java | 20 ++ .../youlai/mall/sale/util/CouponUtils.java | 69 ++++++ 38 files changed, 1606 insertions(+) create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/SaleApplication.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/AdvertController.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/CouponController.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/app/AdvertAppController.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/AdvertConverter.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/CouponConverter.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponApplicationScopeEnum.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponFaceValueTypeEnum.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponTypeEnum.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/PlatformEnum.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/ValidityPeriodTypeEnum.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/AdvertMapper.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponHistoryMapper.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponMapper.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuCategoryMapper.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuMapper.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Advert.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Coupon.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponHistory.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpu.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpuCategory.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/form/CouponForm.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/AdvertPageQuery.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/CouponPageQuery.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/AdvertPageVO.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/BannerVO.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/CouponPageVO.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/AdvertService.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponHistoryService.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponService.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuCategoryService.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuService.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/AdvertServiceImpl.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponHistoryServiceImpl.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponServiceImpl.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuCategoryServiceImpl.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuServiceImpl.java create mode 100644 mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/util/CouponUtils.java diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/SaleApplication.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/SaleApplication.java new file mode 100644 index 000000000..5219246c5 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/SaleApplication.java @@ -0,0 +1,24 @@ +package com.youlai.mall.sale; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * 营销服务启动类 + * + * @author ray + * @since 0.0.1 + */ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@EnableScheduling +public class SaleApplication { + + public static void main(String[] args) { + SpringApplication.run(SaleApplication.class, args); + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/AdvertController.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/AdvertController.java new file mode 100644 index 000000000..01d1bdb64 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/AdvertController.java @@ -0,0 +1,80 @@ +package com.youlai.mall.sale.controller.admin; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.common.result.PageResult; +import com.youlai.common.result.Result; +import com.youlai.mall.sale.model.entity.Advert; +import com.youlai.mall.sale.model.query.AdvertPageQuery; +import com.youlai.mall.sale.service.AdvertService; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; + +@Tag(name = "Admin-营销广告") +@RestController +@RequestMapping("/api/v1/adverts") +@RequiredArgsConstructor +public class AdvertController { + + private final AdvertService advertService; + + @Operation(summary= "广告分页列表") + @GetMapping("/page") + public PageResult getAdvertPage(AdvertPageQuery queryParams) { + + // 查询参数 + int pageNum = queryParams.getPageNum(); + int pageSize = queryParams.getPageSize(); + String keywords = queryParams.getKeywords(); + + // 分页查询 + Page result = advertService.page( + new Page<>(pageNum, pageSize), + new LambdaQueryWrapper() + .like(StrUtil.isNotBlank(keywords), Advert::getTitle, keywords) + .orderByAsc(Advert::getSort) + ); + return PageResult.success(result); + } + + @Operation(summary= "广告详情") + @GetMapping("/{id}") + public Result getAdvertDetail( + @Parameter(description = "广告ID") @PathVariable Long id + ) { + Advert advert = advertService.getById(id); + return Result.success(advert); + } + + @Operation(summary= "新增广告") + @PostMapping + public Result addAvert(@RequestBody Advert advert) { + boolean status = advertService.save(advert); + return Result.judge(status); + } + + @Operation(summary= "修改广告") + @PutMapping(value = "/{id}") + public Result updateAdvert( + @Parameter(description = "广告ID") @PathVariable Long id, + @RequestBody Advert advert) { + boolean status = advertService.updateById(advert); + return Result.judge(status); + } + + @Operation(summary= "删除广告") + @DeleteMapping("/{ids}") + public Result deleteAdverts(@Parameter(description = "广告ID,多个以英文逗号(,)分割") @PathVariable("ids") String ids) { + boolean status = advertService.removeByIds(Arrays.asList(ids.split(","))); + return Result.judge(status); + + + } + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/CouponController.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/CouponController.java new file mode 100644 index 000000000..2fdcb032f --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/admin/CouponController.java @@ -0,0 +1,63 @@ +package com.youlai.mall.sale.controller.admin; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.common.result.PageResult; +import com.youlai.common.result.Result; +import com.youlai.mall.sale.model.form.CouponForm; +import com.youlai.mall.sale.model.query.CouponPageQuery; +import com.youlai.mall.sale.model.vo.CouponPageVO; +import com.youlai.mall.sale.service.CouponService; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import jakarta.validation.Valid; + +@Tag(name = "Admin-优惠券管理") +@RestController +@RequestMapping("/api/v1/coupons") +@RequiredArgsConstructor +public class CouponController { + + private final CouponService couponService; + + @Operation(summary= "优惠券分页列表") + @GetMapping("/pages") + public PageResult getCouponPage(CouponPageQuery queryParams) { + Page result = couponService.getCouponPage(queryParams); + return PageResult.success(result); + } + + @Operation(summary= "优惠券表单数据") + @GetMapping("/{couponId}/form_data") + public Result getCouponFormData(@Parameter(description = "优惠券ID") @PathVariable Long couponId) { + CouponForm couponForm = couponService.getCouponFormData(couponId); + return Result.success(couponForm); + } + + @Operation(summary ="新增优惠券") + @PostMapping + public Result saveCoupon(@RequestBody @Valid CouponForm couponForm) { + boolean result = couponService.saveCoupon(couponForm); + return Result.judge(result); + } + + @Operation(summary ="修改优惠券") + @PutMapping("/{couponId}") + public Result updateCoupon( + @PathVariable Long couponId, + @RequestBody @Valid CouponForm couponForm + ) { + boolean result = couponService.updateCoupon(couponId,couponForm); + return Result.judge(result); + } + + @Operation(summary= "删除优惠券") + @DeleteMapping("/{ids}") + public Result deleteCoupons(@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids) { + boolean result = couponService.deleteCoupons(ids); + return Result.judge(result); + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/app/AdvertAppController.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/app/AdvertAppController.java new file mode 100644 index 000000000..dda240937 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/controller/app/AdvertAppController.java @@ -0,0 +1,31 @@ +package com.youlai.mall.sale.controller.app; + +import com.youlai.common.result.Result; +import com.youlai.mall.sale.model.vo.BannerVO; +import com.youlai.mall.sale.service.AdvertService; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "App-营销广告") +@RestController +@RequestMapping("/app-api/v1/adverts") +@Slf4j +@AllArgsConstructor +public class AdvertAppController { + + private AdvertService advertService; + + @Operation(summary= "APP首页广告横幅列表") + @GetMapping("/banners") + public Result> getBannerList() { + List list = advertService.getBannerList(); + return Result.success(list); + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/AdvertConverter.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/AdvertConverter.java new file mode 100644 index 000000000..ce81ae922 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/AdvertConverter.java @@ -0,0 +1,28 @@ +package com.youlai.mall.sale.converter; + + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.mall.sale.model.entity.Advert; +import com.youlai.mall.sale.model.vo.BannerVO; +import com.youlai.mall.sale.model.vo.AdvertPageVO; +import org.mapstruct.Mapper; + +import java.util.List; + +/** + * advert实体转换器 + * + * @author Ray + * @since 2022/5/29 + */ +@Mapper(componentModel = "spring") +public interface AdvertConverter { + + AdvertPageVO entity2PageVo(Advert entity); + + Page entity2PageVo(Page po); + + BannerVO entity2BannerVo(Advert entity); + + List entity2BannerVo(List entities); +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/CouponConverter.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/CouponConverter.java new file mode 100644 index 000000000..8b74d79bf --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/converter/CouponConverter.java @@ -0,0 +1,48 @@ +package com.youlai.mall.sale.converter; + + +import com.youlai.mall.sale.model.entity.Coupon; +import com.youlai.mall.sale.model.form.CouponForm; +import com.youlai.mall.sale.model.vo.CouponPageVO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +import java.util.List; + +/** + * 优惠券对象转换器 + * + * @author Ray + * @since 2022/5/29 + */ +@Mapper(componentModel = "spring") +public interface CouponConverter { + + @Mappings({ + @Mapping(target = "platformLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getPlatform(), com.youlai.mall.sale.enums.PlatformEnum.class))"), + @Mapping(target = "typeLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getType(), com.youlai.mall.sale.enums.CouponTypeEnum.class))"), + @Mapping(target = "faceValueLabel", expression = "java(com.youlai.mall.sale.util.CouponUtils.getFaceValue(entity.getType(),entity.getFaceValue(),entity.getDiscount()))"), + @Mapping( + target = "validityPeriodLabel", + expression = "java(com.youlai.mall.sale.util.CouponUtils.getValidityPeriod(entity.getValidityPeriodType(),entity.getValidityDays(),entity.getValidityStartTime(),entity.getValidityEndTime()))" + ), + @Mapping(target = "minPointLabel", expression = "java(cn.hutool.core.util.NumberUtil.toStr(cn.hutool.core.util.NumberUtil.div(entity.getMinPoint(),new java.math.BigDecimal(100)).setScale(2)))"), + }) + CouponPageVO entity2PageVO(Coupon entity); + + + List entity2PageVO(List entities); + + + @Mappings({ + @Mapping(target = "discount",expression = "java(cn.hutool.core.util.NumberUtil.div(form.getDiscount(),10L))"), + }) + Coupon toEntity(CouponForm form); + + + @Mappings({ + @Mapping(target = "discount",expression = "java(cn.hutool.core.util.NumberUtil.mul(entity.getDiscount(),10L))"), + }) + CouponForm convertToForm(Coupon entity); +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponApplicationScopeEnum.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponApplicationScopeEnum.java new file mode 100644 index 000000000..1a9f93d70 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponApplicationScopeEnum.java @@ -0,0 +1,37 @@ +package com.youlai.mall.sale.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.youlai.common.base.IBaseEnum; +import lombok.Getter; + +/** + * 优惠券适用类型枚举 + * + * @author Ray + * @since 2022/7/13 + */ +@Getter +public enum CouponApplicationScopeEnum implements IBaseEnum { + + ALL(0, "全场通用"), + /** + * 指定商品分类 + */ + SPU_CATEGORY(1, "指定商品分类"), + SPU(2, "指定商品"), + ; + + @Getter + @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值 + private Integer value; + + @Getter + @JsonValue // 表示对枚举序列化时返回此字段 + private String label; + + CouponApplicationScopeEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponFaceValueTypeEnum.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponFaceValueTypeEnum.java new file mode 100644 index 000000000..f2a3ed1ca --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponFaceValueTypeEnum.java @@ -0,0 +1,27 @@ +package com.youlai.mall.sale.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.youlai.common.base.IBaseEnum; +import lombok.Getter; + +@Getter +public enum CouponFaceValueTypeEnum implements IBaseEnum { + + CASH(1, "现金"), + DISCOUNT(2, "折扣"), + ; + + @Getter + @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值 + private Integer value; + + @Getter + @JsonValue // 表示对枚举序列化时返回此字段 + private String label; + + CouponFaceValueTypeEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponTypeEnum.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponTypeEnum.java new file mode 100644 index 000000000..d1c269ee2 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/CouponTypeEnum.java @@ -0,0 +1,29 @@ +package com.youlai.mall.sale.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.youlai.common.base.IBaseEnum; +import lombok.Getter; + +@Getter +public enum CouponTypeEnum implements IBaseEnum { + + WZ(0, null), + MJ(1, "满减券"), + ZJ(2, "直减券"), + ZK(3, "折扣券") + ; + + @Getter + @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值 + private Integer value; + + @Getter + @JsonValue // 表示对枚举序列化时返回此字段 + private String label; + + CouponTypeEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/PlatformEnum.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/PlatformEnum.java new file mode 100644 index 000000000..7ff182ce0 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/PlatformEnum.java @@ -0,0 +1,28 @@ +package com.youlai.mall.sale.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.youlai.common.base.IBaseEnum; +import lombok.Getter; + +@Getter +public enum PlatformEnum implements IBaseEnum { + + ALL(0, "全平台"), + APP(1, "APP"), + PC(2, "PC"), + ; + + @Getter + @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值 + private Integer value; + + @Getter + @JsonValue // 表示对枚举序列化时返回此字段 + private String label; + + PlatformEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/ValidityPeriodTypeEnum.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/ValidityPeriodTypeEnum.java new file mode 100644 index 000000000..9c3e17395 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/enums/ValidityPeriodTypeEnum.java @@ -0,0 +1,27 @@ +package com.youlai.mall.sale.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; +import com.youlai.common.base.IBaseEnum; +import lombok.Getter; + +@Getter +public enum ValidityPeriodTypeEnum implements IBaseEnum { + + UNKNOWN(0, null), + DATE_RANGE(1, "日期范围"), + FIXED_DAYS(2, "固定天数"), + ; + @Getter + @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值 + private Integer value; + + @Getter + @JsonValue // 表示对枚举序列化时返回此字段 + private String label; + + ValidityPeriodTypeEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/AdvertMapper.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/AdvertMapper.java new file mode 100644 index 000000000..6b009c43f --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/AdvertMapper.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.mall.sale.model.entity.Advert; +import com.youlai.mall.sale.model.query.AdvertPageQuery; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface AdvertMapper extends BaseMapper { + + /** + * 广告分页列表 + * + * @param page + * @param queryParams + * @return + */ + Page getAdvertPage(Page page, AdvertPageQuery queryParams); +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponHistoryMapper.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponHistoryMapper.java new file mode 100644 index 000000000..bf187eee4 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponHistoryMapper.java @@ -0,0 +1,15 @@ +package com.youlai.mall.sale.mapper; + +import com.youlai.mall.sale.model.entity.CouponHistory; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + + +@Mapper +public interface CouponHistoryMapper extends BaseMapper { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponMapper.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponMapper.java new file mode 100644 index 000000000..8a15d131c --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponMapper.java @@ -0,0 +1,21 @@ +package com.youlai.mall.sale.mapper; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.mall.sale.model.entity.Coupon; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.youlai.mall.sale.model.query.CouponPageQuery; +import com.youlai.mall.sale.model.vo.CouponPageVO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + + +@Mapper +public interface CouponMapper extends BaseMapper { + + List getCouponPage(Page page, CouponPageQuery queryParams); +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuCategoryMapper.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuCategoryMapper.java new file mode 100644 index 000000000..ad5616aba --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuCategoryMapper.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.mapper; + +import com.youlai.mall.sale.model.entity.CouponSpuCategory; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * 优惠券商品分类关联持久层 + * + * @author Ray + * @since 2022/6/30 + */ +@Mapper +public interface CouponSpuCategoryMapper extends BaseMapper { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuMapper.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuMapper.java new file mode 100644 index 000000000..714bd866b --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/mapper/CouponSpuMapper.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.mapper; + +import com.youlai.mall.sale.model.entity.CouponSpu; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * 优惠券商品关联持久层 + * + * @author Ray + * @since 2022/6/30 + */ +@Mapper +public interface CouponSpuMapper extends BaseMapper { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Advert.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Advert.java new file mode 100644 index 000000000..b6c4ea84d --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Advert.java @@ -0,0 +1,49 @@ +package com.youlai.mall.sale.model.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.youlai.common.base.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 营销广告 + * + * @author Ray Hao + * @since 2024/6/7 + */ +@EqualsAndHashCode(callSuper = true) +@TableName("sms_advert") +@Data +public class Advert extends BaseEntity { + + private String title; + + private String imageUrl; + + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startTime; + + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endTime; + + /** + * 状态 + */ + private Integer status; + + /** + * 排序 + */ + private Integer sort; + + /** + * 跳转URL + */ + private String redirectUrl; + + private String remark; + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Coupon.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Coupon.java new file mode 100644 index 000000000..6e73e8152 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/Coupon.java @@ -0,0 +1,120 @@ +package com.youlai.mall.sale.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.youlai.common.base.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * 优惠券表 + * + * @author Ray Hao + * @since 2024/6/7 + */ +@EqualsAndHashCode(callSuper = true) +@TableName("sms_coupon") +@Data +public class Coupon extends BaseEntity { + /** + * ID + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 优惠券类型(1:满减券;2:直减券;3:折扣券) + */ + private Integer type; + + /** + * 优惠券名称 + */ + private String name; + + /** + * 优惠券码 + */ + private String code; + + /** + * 使用平台(0:全平台;1:移动端;2:PC端) + */ + private Integer platform; + + /** + * 优惠券面值类型((1:金额;2:折扣) + */ + private Integer faceValueType; + + /** + * 优惠券面值金额(单位:分) + */ + private Long faceValue; + + /** + * 优惠券折扣 + */ + private BigDecimal discount; + + /** + * 使用门槛(0:无门槛) + */ + private Long minPoint; + + /** + * 每人限领张数(0:不限制) + */ + private Integer perLimit; + + /** + * 有效期类型(1:自领取之起有效天数;2:有效起止时间) + */ + private Integer validityPeriodType; + + /** + * 自领取之日起有效天数 + */ + private Integer validityDays; + + /** + * 有效期起始时间 + */ + private Date validityStartTime; + + /** + * 有效期截止时间 + */ + private Date validityEndTime; + + /** + * 使用类型(0-全场通用;1-指定商品分类;2-指定商品) + */ + private Integer applicationScope; + + /** + * 发行量(-1:无限制) + */ + private Integer circulation; + + /** + * 已领取的优惠券数量(统计) + */ + private Integer receivedCount; + + /** + * 已使用的优惠券数量(统计) + */ + private Integer usedCount; + + /** + * 备注 + */ + private String remark; + +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponHistory.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponHistory.java new file mode 100644 index 000000000..d0e8de0b4 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponHistory.java @@ -0,0 +1,79 @@ +package com.youlai.mall.sale.model.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * 优惠券领取历史记录 + */ +@TableName(value ="sms_coupon_history") +@Data +public class CouponHistory implements Serializable { + /** + * + */ + @TableId + private Long id; + + /** + * 优惠券ID + */ + private Long couponId; + + /** + * 会员ID + */ + private Long memberId; + + /** + * 会员昵称 + */ + private String memberNickname; + + /** + * 优惠券码 + */ + private String couponCode; + + /** + * 获取类型(1:后台增删;2:主动领取) + */ + private Integer getType; + + /** + * 状态(0:未使用;1:已使用;2:已过期) + */ + private Integer status; + + /** + * 使用时间 + */ + private Date useTime; + + /** + * 订单ID + */ + private Long orderId; + + /** + * 订单号 + */ + private String orderSn; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpu.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpu.java new file mode 100644 index 000000000..c998f5bc3 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpu.java @@ -0,0 +1,43 @@ +package com.youlai.mall.sale.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 优惠券与产品关联表 + */ + +@TableName(value ="sms_coupon_spu") +@Data +@Accessors(chain = true) +public class CouponSpu implements Serializable { + /** + * + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 优惠券ID + */ + private Long couponId; + + /** + * 商品ID + */ + private Long spuId; + + /** + * 商品名称 + */ + private String spuName; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpuCategory.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpuCategory.java new file mode 100644 index 000000000..25e9d2f25 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/entity/CouponSpuCategory.java @@ -0,0 +1,34 @@ +package com.youlai.mall.sale.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@TableName(value ="sms_coupon_spu_category") +@Data +@Accessors(chain = true) +public class CouponSpuCategory implements Serializable { + /** + * + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 优惠券ID + */ + private Long couponId; + + /** + * 商品分类ID + */ + private Long categoryId; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/form/CouponForm.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/form/CouponForm.java new file mode 100644 index 000000000..019e953aa --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/form/CouponForm.java @@ -0,0 +1,76 @@ +package com.youlai.mall.sale.model.form; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 优惠券表单对象 + * + * @author Ray + * @since 2022/6/23 + */ +@Schema(description = "优惠券表单对象") +@Data +public class CouponForm { + + @Schema(description="ID") + private Long id; + + @Schema(description="优惠券名称") + private String name; + + @Schema(description="优惠券类型(1:满减券;2:直减券;3:折扣券)") + private Integer type; + + @Schema(description="优惠券面值类型((1:金额;2:折扣)") + private Integer faceValueType; + + @Schema(description="优惠券面值金额(单位:分)") + private Long faceValue; + + @Schema(description="优惠券折扣") + private BigDecimal discount; + + @Schema(description="优惠券码") + private String code; + + @Schema(description="使用平台(0-全平台;1-移动端;2-PC;)") + private Integer platform; + + @Schema(description="发行量(-1:无限制)") + private Integer circulation; + + @Schema(description="使用门槛(0:无门槛)") + private Long minPoint; + + @Schema(description="每人限领张数(-1:不限制)") + private Integer perLimit; + + @Schema(description="有效期类型(1:日期范围;2:固定天数)") + private Integer validityPeriodType; + + @Schema(description="自领取之日起有效天数") + private Integer validityDays; + + @Schema(description="有效期开始时间") + private Date validityBeginTime; + + @Schema(description="有效期截止时间") + private Date validityEndTime; + + @Schema(description="应用范围(0:全场通用;1:指定商品分类;2:指定商品)") + private Integer applicationScope; + + @Schema(description="备注") + private String remark; + + @Schema(description="优惠券适用商品分类ID集合") + private List spuCategoryIds; + + @Schema(description="优惠券适用商品列表") + private List spuIds; +} \ No newline at end of file diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/AdvertPageQuery.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/AdvertPageQuery.java new file mode 100644 index 000000000..997fe9e10 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/AdvertPageQuery.java @@ -0,0 +1,22 @@ +package com.youlai.mall.sale.model.query; + +import com.youlai.common.base.BasePageQuery; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 广告分页列表查询对象 + * + * @author Ray + * @since 2021/7/11 + */ +@EqualsAndHashCode(callSuper = true) +@Schema(description = "广告分页查询对象") +@Data +public class AdvertPageQuery extends BasePageQuery { + + @Schema(description="关键字") + private String keywords; + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/CouponPageQuery.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/CouponPageQuery.java new file mode 100644 index 000000000..fd9343375 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/query/CouponPageQuery.java @@ -0,0 +1,25 @@ +package com.youlai.mall.sale.model.query; + +import com.youlai.common.base.BasePageQuery; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author xinyi + * @desc: 优惠券分页查询对象 + * @since 2021/7/11 + */ +@Schema(description = "优惠券分页查询对象") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CouponPageQuery extends BasePageQuery { + + @Schema(description="状态") + private Integer status; + + @Schema(description="优惠券码") + private String code; +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/AdvertPageVO.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/AdvertPageVO.java new file mode 100644 index 000000000..76b498bdb --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/AdvertPageVO.java @@ -0,0 +1,46 @@ +package com.youlai.mall.sale.model.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + + +/** + * 广告分页视图对象 + * + * @author Ray + * @since 2022/11/12 + */ +@Schema(description = "广告分页视图对象") +@Data +public class AdvertPageVO { + + @Schema(description="广告ID") + private Integer id; + + @Schema(description="广告标题") + private String title; + + @Schema(description="广告图片") + private String imgUrl; + + @Schema(description="开始时间") + @JsonFormat( pattern = "yyyy-MM-dd") + private Date beginTime; + + @Schema(description="截止时间") + @JsonFormat(pattern = "yyyy-MM-dd") + private Date endTime; + + @Schema(description="状态") + private Integer status; + + private Integer sort; + + private String redirectUrl; + + private String remark; + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/BannerVO.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/BannerVO.java new file mode 100644 index 000000000..46a011eea --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/BannerVO.java @@ -0,0 +1,19 @@ +package com.youlai.mall.sale.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "横幅视图对象") +@Data +public class BannerVO { + + @Schema(description="广告标题") + private String title; + + @Schema(description="横幅图片URL") + private String imageUrl; + + @Schema(description="跳转URL") + private String redirectUrl; + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/CouponPageVO.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/CouponPageVO.java new file mode 100644 index 000000000..9e8f8ca39 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/model/vo/CouponPageVO.java @@ -0,0 +1,44 @@ +package com.youlai.mall.sale.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + + +/** + * 优惠券分页视图对象 + * + * @author Ray + * @since 2022/6/26 + */ +@Schema(description = "优惠券分页视图对象") +@Data +public class CouponPageVO { + + @Schema(description="ID") + private Long id; + + @Schema(description="优惠券名称") + private String name; + + @Schema(description="优惠券码") + private String code; + + @Schema(description="使用平台") + private String platformLabel; + + @Schema(description="优惠券类型标签") + private String typeLabel; + + @Schema(description="优惠券面值") + private String faceValueLabel; + + @Schema(description="使用门槛") + private String minPointLabel; + + @Schema(description="优惠券有效期") + private String validityPeriodLabel; + + @Schema(description="使用说明") + private String remark; + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/AdvertService.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/AdvertService.java new file mode 100644 index 000000000..9e7ac0b31 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/AdvertService.java @@ -0,0 +1,23 @@ +package com.youlai.mall.sale.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.mall.sale.model.entity.Advert; +import com.youlai.mall.sale.model.query.AdvertPageQuery; +import com.youlai.mall.sale.model.vo.BannerVO; +import com.youlai.mall.sale.model.vo.AdvertPageVO; + +import java.util.List; + +public interface AdvertService extends IService { + + /** + * 广告分页列表 + * + * @param queryParams + * @return + */ + Page getAdvertPage(AdvertPageQuery queryParams); + + List getBannerList(); +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponHistoryService.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponHistoryService.java new file mode 100644 index 000000000..45ec222cd --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponHistoryService.java @@ -0,0 +1,11 @@ +package com.youlai.mall.sale.service; + +import com.youlai.mall.sale.model.entity.CouponHistory; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface CouponHistoryService extends IService { + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponService.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponService.java new file mode 100644 index 000000000..2f2260639 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponService.java @@ -0,0 +1,58 @@ +package com.youlai.mall.sale.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.mall.sale.model.entity.Coupon; +import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.mall.sale.model.form.CouponForm; +import com.youlai.mall.sale.model.query.CouponPageQuery; +import com.youlai.mall.sale.model.vo.CouponPageVO; + +/** + * 优惠券业务接口 + * + * @author Ray + * @since 2022/5/29 + */ +public interface CouponService extends IService { + + /** + * 优惠券分页列表 + * + * @param queryParams + * @return + */ + Page getCouponPage(CouponPageQuery queryParams); + + /** + * 新增优惠券 + * + * @param couponForm + * @return + */ + boolean saveCoupon(CouponForm couponForm); + + /** + * 修改优惠券 + * + * @param couponId 优惠券ID + * @param couponForm 优惠券表单 + * @return + */ + boolean updateCoupon(Long couponId, CouponForm couponForm); + + /** + * 删除优惠券 + * + * @param ids 优惠券ID,多个以英文逗号(,)分割 + * @return + */ + boolean deleteCoupons(String ids); + + /** + * 优惠券表单数据 + * + * @param couponId + * @return + */ + CouponForm getCouponFormData(Long couponId); +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuCategoryService.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuCategoryService.java new file mode 100644 index 000000000..851c6ba1a --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuCategoryService.java @@ -0,0 +1,11 @@ +package com.youlai.mall.sale.service; + +import com.youlai.mall.sale.model.entity.CouponSpuCategory; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface CouponSpuCategoryService extends IService { + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuService.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuService.java new file mode 100644 index 000000000..46ce7f142 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/CouponSpuService.java @@ -0,0 +1,11 @@ +package com.youlai.mall.sale.service; + +import com.youlai.mall.sale.model.entity.CouponSpu; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface CouponSpuService extends IService { + +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/AdvertServiceImpl.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/AdvertServiceImpl.java new file mode 100644 index 000000000..d42eca038 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/AdvertServiceImpl.java @@ -0,0 +1,57 @@ +package com.youlai.mall.sale.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.common.enums.StatusEnum; +import com.youlai.mall.sale.converter.AdvertConverter; +import com.youlai.mall.sale.model.entity.Advert; +import com.youlai.mall.sale.mapper.AdvertMapper; +import com.youlai.mall.sale.model.query.AdvertPageQuery; +import com.youlai.mall.sale.model.vo.BannerVO; +import com.youlai.mall.sale.model.vo.AdvertPageVO; +import com.youlai.mall.sale.service.AdvertService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 广告业务实现类 + * + * @author Ray Hao + * @since 2022/5/28 + */ +@Service +@RequiredArgsConstructor +public class AdvertServiceImpl extends ServiceImpl implements AdvertService { + + private final AdvertConverter advertConverter; + + /** + * 广告分页列表 + * + * @param queryParams 查询参数 + * @return 广告分页列表 + */ + @Override + public Page getAdvertPage(AdvertPageQuery queryParams) { + Page page = this.baseMapper.getAdvertPage(new Page<>(queryParams.getPageNum(), + queryParams.getPageSize()), + queryParams); + return advertConverter.entity2PageVo(page); + } + + /** + * 获取广告横幅列表 + */ + @Override + public List getBannerList() { + + List entities = this.list(new LambdaQueryWrapper(). + eq(Advert::getStatus, StatusEnum.ENABLE.getValue()) + .select(Advert::getTitle, Advert::getImageUrl, Advert::getRedirectUrl) + ); + return advertConverter.entity2BannerVo(entities); + } +} diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponHistoryServiceImpl.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponHistoryServiceImpl.java new file mode 100644 index 000000000..9bed01572 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponHistoryServiceImpl.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.mall.sale.model.entity.CouponHistory; +import com.youlai.mall.sale.service.CouponHistoryService; +import com.youlai.mall.sale.mapper.CouponHistoryMapper; +import org.springframework.stereotype.Service; + +/** + * + */ +@Service +public class CouponHistoryServiceImpl extends ServiceImpl +implements CouponHistoryService { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponServiceImpl.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponServiceImpl.java new file mode 100644 index 000000000..055719714 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponServiceImpl.java @@ -0,0 +1,231 @@ +package com.youlai.mall.sale.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.common.base.IBaseEnum; +import com.youlai.mall.sale.enums.CouponApplicationScopeEnum; +import com.youlai.mall.sale.converter.CouponConverter; +import com.youlai.mall.sale.mapper.CouponMapper; +import com.youlai.mall.sale.model.entity.Coupon; +import com.youlai.mall.sale.model.entity.CouponSpu; +import com.youlai.mall.sale.model.entity.CouponSpuCategory; +import com.youlai.mall.sale.model.form.CouponForm; +import com.youlai.mall.sale.model.query.CouponPageQuery; +import com.youlai.mall.sale.model.vo.CouponPageVO; +import com.youlai.mall.sale.service.CouponService; +import com.youlai.mall.sale.service.CouponSpuCategoryService; +import com.youlai.mall.sale.service.CouponSpuService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 优惠券业务实现类 + * + * @author Ray + * @since 2022/5/29 + */ +@Service +@RequiredArgsConstructor +public class CouponServiceImpl extends ServiceImpl implements CouponService { + + private final CouponConverter couponConverter; + + private final CouponSpuCategoryService couponSpuCategoryService; + + private final CouponSpuService couponSpuService; + + /** + * 优惠券分页列表 + * + * @param queryParams + * @return + */ + @Override + public Page getCouponPage(CouponPageQuery queryParams) { + Page page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize()); + // 查询数据 + List couponList = this.baseMapper.getCouponPage(page, queryParams); + // 实体转换 + List records = couponConverter.entity2PageVO(couponList); + page.setRecords(records); + return page; + } + + /** + * 优惠券表单数据 + * + * @param couponId + * @return + */ + @Override + public CouponForm getCouponFormData(Long couponId) { + Coupon entity = this.getById(couponId); + // 实体转换entity->form + CouponForm couponForm = couponConverter.convertToForm(entity); + + Integer applicationScope = couponForm.getApplicationScope(); + + CouponApplicationScopeEnum applicationScopeEnum = IBaseEnum.getEnumByValue(applicationScope, CouponApplicationScopeEnum.class); + if (applicationScopeEnum != null) { + switch (applicationScopeEnum) { + case SPU_CATEGORY: + List couponSpuCategoryList = couponSpuCategoryService.list(new LambdaQueryWrapper() + .eq(CouponSpuCategory::getCouponId, couponId) + .select(CouponSpuCategory::getCategoryId) + ); + List categoryIds = couponSpuCategoryList.stream().map(item -> item.getCategoryId()).collect(Collectors.toList()); + couponForm.setSpuCategoryIds(categoryIds); + break; + case SPU: + List couponSpuList = couponSpuService.list(new LambdaQueryWrapper() + .eq(CouponSpu::getCouponId, couponId) + .select(CouponSpu::getSpuId) + ); + List spuIds = couponSpuList.stream().map(item -> item.getSpuId()).collect(Collectors.toList()); + couponForm.setSpuIds(spuIds); + break; + } + } + return couponForm; + } + + /** + * 新增优惠券 + * + * @param couponForm 优惠券表单 + * @return + */ + @Override + public boolean saveCoupon(CouponForm couponForm) { + Coupon entity = couponConverter.toEntity(couponForm); + boolean result = this.save(entity); + + if (result) { + // 根据优惠券适用商品范围保存对应的关联关系 + // 指定商品分类: 优惠券 <-> 商品分类 + // 指定商品: 优惠券 <-> 商品 + Long couponId = entity.getId(); + Integer applicationScope = couponForm.getApplicationScope(); + CouponApplicationScopeEnum applicationScopeEnum = IBaseEnum.getEnumByValue(applicationScope, CouponApplicationScopeEnum.class); + + Assert.isTrue(applicationScopeEnum != null, "请指定优惠券适用范围"); + switch (applicationScopeEnum) { + case SPU_CATEGORY: + List spuCategoryIds = couponForm.getSpuCategoryIds(); + if (CollectionUtil.isNotEmpty(spuCategoryIds)) { + List smsCouponSpuCategories = spuCategoryIds.stream() + .map(spuCategoryId -> new CouponSpuCategory().setCouponId(couponId).setCategoryId(spuCategoryId)) + .collect(Collectors.toList()); + couponSpuCategoryService.saveBatch(smsCouponSpuCategories); + } + break; + + case SPU: + List spuIds = couponForm.getSpuIds(); + if (CollectionUtil.isNotEmpty(spuIds)) { + List couponSpuList = spuIds.stream() + .map(spuId -> new CouponSpu().setCouponId(couponId).setSpuId(spuId)) + .collect(Collectors.toList()); + couponSpuService.saveBatch(couponSpuList); + } + break; + } + } + return result; + } + + /** + * 修改优惠券 + * + * @param couponId 优惠券ID + * @param couponForm 优惠券表单 + * @return + */ + @Override + public boolean updateCoupon(Long couponId, CouponForm couponForm) { + Coupon entity = couponConverter.toEntity(couponForm); + boolean result = this.updateById(entity); + + if (result) { + // 根据优惠券适用商品范围保存对应的关联关系 + // 全场通用: 删除所有关联 + // 指定商品分类: 优惠券 <-> 商品分类 + // 指定商品: 优惠券 <-> 商品 + Integer applicationScope = couponForm.getApplicationScope(); + CouponApplicationScopeEnum applicationScopeEnum = IBaseEnum.getEnumByValue(applicationScope, CouponApplicationScopeEnum.class); + + Assert.isTrue(applicationScopeEnum != null, "请指定优惠券适用范围"); + switch (applicationScopeEnum) { + case ALL: + couponSpuCategoryService.remove(new LambdaQueryWrapper() + .eq(CouponSpuCategory::getCouponId, couponId) + ); + couponSpuService.remove(new LambdaQueryWrapper() + .eq(CouponSpu::getCouponId, couponId) + ); + + break; + case SPU_CATEGORY: + List spuCategoryIds = couponForm.getSpuCategoryIds(); + if (CollectionUtil.isNotEmpty(spuCategoryIds)) { + couponSpuCategoryService.remove(new LambdaQueryWrapper() + .eq(CouponSpuCategory::getCouponId, couponId) + ); + List smsCouponSpuCategories = spuCategoryIds.stream() + .map(spuCategoryId -> new CouponSpuCategory().setCouponId(couponId) + .setCategoryId(spuCategoryId)) + .collect(Collectors.toList()); + couponSpuCategoryService.saveBatch(smsCouponSpuCategories); + } + break; + case SPU: + List spuIds = couponForm.getSpuIds(); + if (CollectionUtil.isNotEmpty(spuIds)) { + couponSpuService.remove(new LambdaQueryWrapper() + .eq(CouponSpu::getCouponId, couponId) + ); + List couponSpuList = spuIds.stream() + .map(spuId -> new CouponSpu().setCouponId(couponId).setSpuId(spuId)) + .collect(Collectors.toList()); + couponSpuService.saveBatch(couponSpuList); + } + break; + } + } + + return result; + } + + + /** + * 删除优惠券 + * + * @param idsStr 优惠券ID,多个以英文逗号(,)分割 + * @return + */ + @Override + @Transactional + public boolean deleteCoupons(String idsStr) { + Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的优惠券数据为空"); + // 逻辑删除 + List ids = Arrays.stream(idsStr.split(",")) + .map(Long::parseLong) + .collect(Collectors.toList()); + return this.removeByIds(ids); + } + + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuCategoryServiceImpl.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuCategoryServiceImpl.java new file mode 100644 index 000000000..ac0d19799 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuCategoryServiceImpl.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.mall.sale.model.entity.CouponSpuCategory; +import com.youlai.mall.sale.service.CouponSpuCategoryService; +import com.youlai.mall.sale.mapper.CouponSpuCategoryMapper; +import org.springframework.stereotype.Service; + +/** + * + */ +@Service +public class CouponSpuCategoryServiceImpl extends ServiceImpl +implements CouponSpuCategoryService { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuServiceImpl.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuServiceImpl.java new file mode 100644 index 000000000..85d71b26d --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/service/impl/CouponSpuServiceImpl.java @@ -0,0 +1,20 @@ +package com.youlai.mall.sale.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.mall.sale.model.entity.CouponSpu; +import com.youlai.mall.sale.service.CouponSpuService; +import com.youlai.mall.sale.mapper.CouponSpuMapper; +import org.springframework.stereotype.Service; + +/** + * + */ +@Service +public class CouponSpuServiceImpl extends ServiceImpl +implements CouponSpuService { + +} + + + + diff --git a/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/util/CouponUtils.java b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/util/CouponUtils.java new file mode 100644 index 000000000..33c42cde0 --- /dev/null +++ b/mall-sale/sale-boot/src/main/java/com/youlai/mall/sale/util/CouponUtils.java @@ -0,0 +1,69 @@ +package com.youlai.mall.sale.util; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; +import com.youlai.common.base.IBaseEnum; +import com.youlai.mall.sale.enums.CouponFaceValueTypeEnum; +import com.youlai.mall.sale.enums.ValidityPeriodTypeEnum; + +import java.math.BigDecimal; +import java.util.Date; + +public class CouponUtils { + + + /** + * 计算优惠券面值 + * + * @param faceValueType 面值类型 + * @param faceValue + * @param discount + * @return + */ + public static String getFaceValue(Integer faceValueType, Long faceValue, BigDecimal discount) { + String faceValueLabel = null; + + if (faceValueType == null) { + return null; + } + + CouponFaceValueTypeEnum couponFaceValueTypeEnum = IBaseEnum.getEnumByValue(faceValueType, CouponFaceValueTypeEnum.class); + switch (couponFaceValueTypeEnum) { + case CASH: + faceValueLabel = NumberUtil.toStr(NumberUtil.div(faceValue, new Float(100), 2)) + "元"; + break; + case DISCOUNT: + faceValueLabel = NumberUtil.mul(discount, 10) + "折"; + break; + + } + return faceValueLabel; + } + + + /** + * 计算优惠券有效期 + * + * @param validityPeriodType + * @param validityDays + * @param validityBeginTime + * @param validityEndTime + * @return + */ + public static String getValidityPeriod(Integer validityPeriodType, Integer validityDays, Date validityBeginTime, Date validityEndTime) { + String validityPeriodLabel = null; + if (validityPeriodType == null) { + return null; + } + ValidityPeriodTypeEnum validityPeriodTypeEnum = IBaseEnum.getEnumByValue(validityPeriodType, ValidityPeriodTypeEnum.class); + switch (validityPeriodTypeEnum) { + case DATE_RANGE: + validityPeriodLabel = DateUtil.format(validityBeginTime, "yyyy/MM/dd") + "~" + DateUtil.format(validityEndTime, "yyyy/MM/dd"); + break; + case FIXED_DAYS: + validityPeriodLabel = "领取后" + validityDays + "天有效"; + break; + } + return validityPeriodLabel; + } +}