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 @@ + + +