refactor: 优惠券代码优化

This commit is contained in:
haoxr 2022-11-14 00:30:52 +08:00
parent b9a9f5392c
commit a1906691d0
7 changed files with 19 additions and 20 deletions

View File

@ -17,15 +17,15 @@ import java.util.List;
* @date 2022/5/29
*/
@Mapper(componentModel = "spring")
public interface SmsCouponConverter {
public interface CouponConverter {
@Mappings({
@Mapping(target = "platformLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getPlatform(), com.youlai.mall.sms.common.enums.PlatformEnum.class))"),
@Mapping(target = "typeLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getType(), com.youlai.mall.sms.common.enums.CouponTypeEnum.class))"),
@Mapping(target = "faceValueLabel", expression = "java(com.youlai.mall.sms.common.utils.CouponUtils.getFaceValue(entity.getType(),entity.getFaceValue(),entity.getDiscount()))"),
@Mapping(target = "platformLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getPlatform(), com.youlai.mall.sms.enums.PlatformEnum.class))"),
@Mapping(target = "typeLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(entity.getType(), com.youlai.mall.sms.enums.CouponTypeEnum.class))"),
@Mapping(target = "faceValueLabel", expression = "java(com.youlai.mall.sms.util.CouponUtils.getFaceValue(entity.getType(),entity.getFaceValue(),entity.getDiscount()))"),
@Mapping(
target = "validityPeriodLabel",
expression = "java(com.youlai.mall.sms.common.utils.CouponUtils.getValidityPeriod(entity.getValidityPeriodType(),entity.getValidityDays(),entity.getValidityBeginTime(),entity.getValidityBeginTime()))"
expression = "java(com.youlai.mall.sms.util.CouponUtils.getValidityPeriod(entity.getValidityPeriodType(),entity.getValidityDays(),entity.getValidityBeginTime(),entity.getValidityBeginTime()))"
),
@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)))"),
})

View File

@ -1,4 +1,4 @@
package com.youlai.mall.sms.common.enums;
package com.youlai.mall.sms.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.sms.common.enums;
package com.youlai.mall.sms.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.sms.common.enums;
package com.youlai.mall.sms.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.sms.common.enums;
package com.youlai.mall.sms.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

View File

@ -7,8 +7,8 @@ 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.sms.common.enums.CouponApplicationScopeEnum;
import com.youlai.mall.sms.converter.SmsCouponConverter;
import com.youlai.mall.sms.enums.CouponApplicationScopeEnum;
import com.youlai.mall.sms.converter.CouponConverter;
import com.youlai.mall.sms.mapper.SmsCouponMapper;
import com.youlai.mall.sms.pojo.entity.SmsCoupon;
import com.youlai.mall.sms.pojo.entity.SmsCouponSpu;
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon> implements SmsCouponService {
private final SmsCouponConverter smsCouponConverter;
private final CouponConverter couponConverter;
private final SmsCouponSpuCategoryService smsCouponSpuCategoryService;
@ -54,7 +54,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
// 查询数据
List<SmsCoupon> couponList = this.baseMapper.listCouponPages(page, queryParams);
// 实体转换
List<CouponPageVO> records = smsCouponConverter.entity2PageVO(couponList);
List<CouponPageVO> records = couponConverter.entity2PageVO(couponList);
page.setRecords(records);
return page;
}
@ -69,7 +69,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
public CouponForm getCouponFormData(Long couponId) {
SmsCoupon entity = this.getById(couponId);
// 实体转换entity->form
CouponForm couponForm = smsCouponConverter.entity2Form(entity);
CouponForm couponForm = couponConverter.entity2Form(entity);
Integer applicationScope = couponForm.getApplicationScope();
@ -105,7 +105,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
*/
@Override
public boolean saveCoupon(CouponForm couponForm) {
SmsCoupon entity = smsCouponConverter.form2Entity(couponForm);
SmsCoupon entity = couponConverter.form2Entity(couponForm);
boolean result = this.save(entity);
if (result) {
@ -151,7 +151,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
*/
@Override
public boolean updateCoupon(Long couponId, CouponForm couponForm) {
SmsCoupon entity = smsCouponConverter.form2Entity(couponForm);
SmsCoupon entity = couponConverter.form2Entity(couponForm);
boolean result = this.updateById(entity);
if (result) {

View File

@ -1,11 +1,10 @@
package com.youlai.mall.sms.common.utils;
package com.youlai.mall.sms.util;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.youlai.common.base.IBaseEnum;
import com.youlai.mall.sms.common.enums.CouponFaceValueTypeEnum;
import com.youlai.mall.sms.common.enums.CouponTypeEnum;
import com.youlai.mall.sms.common.enums.ValidityPeriodTypeEnum;
import com.youlai.mall.sms.enums.CouponFaceValueTypeEnum;
import com.youlai.mall.sms.enums.ValidityPeriodTypeEnum;
import java.math.BigDecimal;
import java.util.Date;