fix promotion优惠券工程继续迁移,未完成,再再提交下

pull/4/MERGE
wuwenbin 2020-07-26 17:52:41 +08:00
parent 67f8b61f47
commit 9a9407641c
6 changed files with 275 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.promotionservice.convert.banner;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerAddBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
@Mappings({})
BannerBO convertToBO(BannerDO banner);
@Mappings({})
List<BannerBO> convertToBO(List<BannerDO> bannerList);
@Mappings({})
BannerDO convert(BannerAddBO bannerAddDTO);
@Mappings({})
BannerDO convert(BannerUpdateBO bannerUpdateDTO);
}

View File

@ -0,0 +1,98 @@
package cn.iocoder.mall.promotionservice.service.banner;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageDTO;
import cn.iocoder.mall.promotionservice.convert.activity.PromotionActivityConvert;
import cn.iocoder.mall.promotionservice.convert.banner.BannerConvert;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity.PromotionActivityMapper;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.banner.BannerMapper;
import cn.iocoder.mall.promotionservice.service.activity.bo.PromotionActivityPageBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerAddBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerPageBO;
import cn.iocoder.mall.promotionservice.service.banner.bo.BannerUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import java.util.*;
@Service
@Validated
public class BannerService {
@Autowired
private BannerMapper bannerMapper;
public List<BannerBO> getBannerListByStatus(Integer status) {
List<BannerDO> banners = bannerMapper.selectListByStatus(status);
return BannerConvert.INSTANCE.convertToBO(banners);
}
public BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO) {
BannerPageBO bannerPageBO = new BannerPageBO();
// 查询分页数据
int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize();
bannerPageBO.setList(BannerConvert.INSTANCE.convertToBO(bannerMapper.selectListByTitleLike(bannerPageDTO.getTitle(),
offset, bannerPageDTO.getPageSize())));
// 查询分页总数
bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle()));
return bannerPageBO;
}
public BannerBO addBanner(Integer adminId, BannerAddBO bannerAddDTO) {
// 保存到数据库
BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue());
banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date());
bannerMapper.insert(banner);
// 返回成功
return BannerConvert.INSTANCE.convertToBO(banner);
}
public Boolean updateBanner(Integer adminId, BannerUpdateBO bannerUpdateDTO) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO);
bannerMapper.update(updateBanner);
// 返回成功
return true;
}
public Boolean updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status);
bannerMapper.update(updateBanner);
// 返回成功
return true;
}
public Boolean deleteBanner(Integer adminId, Integer bannerId) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId);
updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
bannerMapper.update(updateBanner);
// 返回成功
return true;
}
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.promotionservice.service.banner.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerAddBO implements Serializable {
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@NotEmpty(message = "图片链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@NotNull(message = "排序不能为空")
private Integer sort;
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.mall.promotionservice.service.banner.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* Banner BO
*/
@Data
@Accessors(chain = true)
public class BannerBO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*/
private String url;
/**
*
*/
private String picUrl;
/**
*
*/
private Integer sort;
/**
*
*/
private Integer status;
/**
*
*/
private String memo;
/**
*
*/
private Date createTime;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.promotionservice.service.banner.bo;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerPageBO implements Serializable {
/**
* Banner
*/
private List<BannerBO> list;
/**
*
*/
private Integer total;
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.mall.promotionservice.service.banner.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerUpdateBO implements Serializable {
@NotNull(message = "编号不能为空")
private Integer id;
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@NotEmpty(message = "图片链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@NotNull(message = "排序不能为空")
private Integer sort;
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}