forked from YunaiV/yudao-cloud
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wuwenbin
committed
Jul 26, 2020
1 parent
67f8b61
commit 9a94076
Showing
6 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...vice-app/src/main/java/cn/iocoder/mall/promotionservice/convert/banner/BannerConvert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...vice-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/BannerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...ice-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerAddBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ervice-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...ce-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerPageBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
37 changes: 37 additions & 0 deletions
37
...-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerUpdateBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |