From 3c10058dbd8a9083ca2682ff5e96d2aeaa45d0b9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 1 Nov 2022 00:37:07 +0800 Subject: [PATCH] =?UTF-8?q?promotion=EF=BC=9A=E5=AE=9E=E7=8E=B0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BC=98=E6=83=A0=E5=8A=B5=E6=A8=A1=E6=9D=BF=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/string/StrUtils.java | 8 + .../core/type/LongListTypeHandler.java | 57 +++ .../admin/coupon/vo/CouponTemplateBaseVO.java | 9 + .../dataobject/coupon/CouponTemplateDO.java | 4 +- .../src/api/promotion/couponTemplate.js | 54 +++ .../views/promotion/couponTemplate/index.vue | 345 ++++++++++++++++++ 6 files changed, 475 insertions(+), 2 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/LongListTypeHandler.java create mode 100755 yudao-ui-admin/src/api/promotion/couponTemplate.js create mode 100755 yudao-ui-admin/src/views/promotion/couponTemplate/index.vue diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java index 3f79ceea6..88ba22d87 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java @@ -3,7 +3,10 @@ package cn.iocoder.yudao.framework.common.util.string; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; +import java.util.Arrays; import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; /** * 字符串工具类 @@ -37,4 +40,9 @@ public class StrUtils { return false; } + public static List splitToLong(String value, CharSequence separator) { + long[] longs = StrUtil.splitToLong(value, separator); + return Arrays.stream(longs).boxed().collect(Collectors.toList()); + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/LongListTypeHandler.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/LongListTypeHandler.java new file mode 100644 index 000000000..8c30f3df8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/LongListTypeHandler.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.framework.mybatis.core.type; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.util.string.StrUtils; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; +import org.apache.ibatis.type.TypeHandler; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * List 的类型转换器实现类,对应数据库的 varchar 类型 + * + * @author 芋道源码 + */ +@MappedJdbcTypes(JdbcType.VARCHAR) +@MappedTypes(List.class) +public class LongListTypeHandler implements TypeHandler> { + + private static final String COMMA = ","; + + @Override + public void setParameter(PreparedStatement ps, int i, List strings, JdbcType jdbcType) throws SQLException { + // 设置占位符 + ps.setString(i, CollUtil.join(strings, COMMA)); + } + + @Override + public List getResult(ResultSet rs, String columnName) throws SQLException { + String value = rs.getString(columnName); + return getResult(value); + } + + @Override + public List getResult(ResultSet rs, int columnIndex) throws SQLException { + String value = rs.getString(columnIndex); + return getResult(value); + } + + @Override + public List getResult(CallableStatement cs, int columnIndex) throws SQLException { + String value = cs.getString(columnIndex); + return getResult(value); + } + + private List getResult(String value) { + if (value == null) { + return null; + } + return StrUtils.splitToLong(value, COMMA); + } +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateBaseVO.java index 813c31c6b..f41b8181b 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateBaseVO.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -92,48 +93,56 @@ public class CouponTemplateBaseVO { private Integer discountPriceLimit; @AssertTrue(message = "商品 SPU 编号的数组不能为空") + @JsonIgnore public boolean isProductSpuIdsValid() { return Objects.equals(productScope, PromotionProductScopeEnum.ALL.getScope()) // 全部范围时,可以为空 || CollUtil.isNotEmpty(productSpuIds); } @AssertTrue(message = "生效开始时间不能为空") + @JsonIgnore public boolean isValidStartTimeValid() { return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.DATE.getType()) || validStartTime != null; } @AssertTrue(message = "生效结束时间不能为空") + @JsonIgnore public boolean isValidEndTimeValid() { return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.DATE.getType()) || validEndTime != null; } @AssertTrue(message = "开始天数不能为空") + @JsonIgnore public boolean isFixedStartTermValid() { return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.TERM.getType()) || fixedStartTerm != null; } @AssertTrue(message = "结束天数不能为空") + @JsonIgnore public boolean isFixedEndTermValid() { return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.TERM.getType()) || fixedEndTerm != null; } @AssertTrue(message = "折扣百分比不能为空") + @JsonIgnore public boolean isDiscountPercentValid() { return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType()) || discountPercent != null; } @AssertTrue(message = "优惠金额不能为空") + @JsonIgnore public boolean isDiscountPriceValid() { return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PRICE.getType()) || discountPrice != null; } @AssertTrue(message = "折扣上限不能为空") + @JsonIgnore public boolean isDiscountPriceLimit() { return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType()) || discountPriceLimit != null; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponTemplateDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponTemplateDO.java index c583a30b1..78a207e98 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponTemplateDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponTemplateDO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.coupon; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; @@ -10,7 +11,6 @@ import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; @@ -85,7 +85,7 @@ public class CouponTemplateDO extends BaseDO { /** * 商品 SPU 编号的数组 */ - @TableField(typeHandler = JacksonTypeHandler.class) + @TableField(typeHandler = LongListTypeHandler.class) private List productSpuIds; /** * 生效日期类型 diff --git a/yudao-ui-admin/src/api/promotion/couponTemplate.js b/yudao-ui-admin/src/api/promotion/couponTemplate.js new file mode 100755 index 000000000..67d821cf0 --- /dev/null +++ b/yudao-ui-admin/src/api/promotion/couponTemplate.js @@ -0,0 +1,54 @@ +import request from '@/utils/request' + +// 创建优惠劵模板 +export function createCouponTemplate(data) { + return request({ + url: '/promotion/coupon-template/create', + method: 'post', + data: data + }) +} + +// 更新优惠劵模板 +export function updateCouponTemplate(data) { + return request({ + url: '/promotion/coupon-template/update', + method: 'put', + data: data + }) +} + +// 删除优惠劵模板 +export function deleteCouponTemplate(id) { + return request({ + url: '/promotion/coupon-template/delete?id=' + id, + method: 'delete' + }) +} + +// 获得优惠劵模板 +export function getCouponTemplate(id) { + return request({ + url: '/promotion/coupon-template/get?id=' + id, + method: 'get' + }) +} + +// 获得优惠劵模板分页 +export function getCouponTemplatePage(query) { + return request({ + url: '/promotion/coupon-template/page', + method: 'get', + params: query + }) +} + +// 导出优惠劵模板 Excel +export function exportCouponTemplateExcel(query) { + return request({ + url: '/promotion/coupon-template/export-excel', + method: 'get', + params: query, + responseType: 'blob' + }) +} diff --git a/yudao-ui-admin/src/views/promotion/couponTemplate/index.vue b/yudao-ui-admin/src/views/promotion/couponTemplate/index.vue new file mode 100755 index 000000000..ad0dc137c --- /dev/null +++ b/yudao-ui-admin/src/views/promotion/couponTemplate/index.vue @@ -0,0 +1,345 @@ + + +