- 增加:banner
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package cn.iocoder.mall.promotion.biz.bo.banner;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* banner:list
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:00
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerListBO implements Serializable {
|
||||
|
||||
|
||||
@ApiModelProperty("编号")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty("跳转链接")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty("图片链接")
|
||||
private String picUrl;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String memo;
|
||||
|
||||
//
|
||||
// 其他
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updatedTime;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createdTime;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.promotion.biz.bo.banner;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* banner - 已发布的banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:56
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerListOnReleaseBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 跳转链接
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
private String picUrl;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:46
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.biz.bo;
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.promotion.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
|
||||
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BannerConvert {
|
||||
|
||||
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
|
||||
|
||||
List<BannerListBO> convert(List<BannerDO> bannerDO);
|
||||
|
||||
List<BannerListOnReleaseBO> convertToBO(List<BannerListBO> bannerList);
|
||||
|
||||
BannerDO convert(BannerAddDTO bannerAddDTO);
|
||||
|
||||
BannerDO convert(BannerUpdateDTO bannerUpdateDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.iocoder.mall.promotion.biz.dao;
|
||||
|
||||
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 14:19
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface BannerMapper extends BaseMapper<BannerDO> {
|
||||
|
||||
/**
|
||||
* 查询 - 列表
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
default IPage<BannerDO> selectBannerList(BannerListDTO dto) {
|
||||
LambdaQueryWrapper<BannerDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isEmpty(dto.getStatus())) {
|
||||
queryWrapper.eq(BannerDO::getStatus, dto.getStatus());
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(dto.getTitle())) {
|
||||
queryWrapper.like(BannerDO::getTitle, dto.getTitle());
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc(BannerDO::getId);
|
||||
IPage<BannerDO> result = selectPage(new Page<>(), queryWrapper);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.mall.promotion.biz.dataobject;
|
||||
|
||||
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Banner 广告页
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 跳转链接
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* {@link cn.iocoder.common.framework.constant.CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
// TODO 芋艿 点击次数。&& 其他数据相关
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.promotion.biz.dto.banner;
|
||||
|
||||
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 BannerAddDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
private Integer adminId;
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.promotion.biz.dto.banner;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Banner 分页 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerListDTO extends PageParam {
|
||||
|
||||
@ApiModelProperty("标题")
|
||||
@NotNull(message = "页码不能为空")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty("标题")
|
||||
@NotNull(message = "页码不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.promotion.biz.dto.banner;
|
||||
|
||||
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 BannerUpdateDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
Integer adminId;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:46
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.biz.dto;
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 14:19
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.biz;
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.iocoder.mall.promotion.biz.service.banner;
|
||||
|
||||
import cn.iocoder.common.framework.constant.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 14:19
|
||||
*/
|
||||
public interface BannerService {
|
||||
|
||||
/**
|
||||
* 列表 - 获取已发布的banner
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<BannerListOnReleaseBO> listBannerOnRelease();
|
||||
|
||||
/**
|
||||
* 列表 - banner 列表
|
||||
*
|
||||
* @param bannerPageDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult<BannerListBO> listBanner(BannerListDTO bannerPageDTO);
|
||||
|
||||
/**
|
||||
* 添加 - 一个banner
|
||||
*
|
||||
* @param adminsBannerAddDTO
|
||||
*/
|
||||
void addBanner(BannerAddDTO adminsBannerAddDTO);
|
||||
|
||||
/**
|
||||
* 更新 - 根据id更新
|
||||
*
|
||||
* @param adminsBannerUpdateDTO
|
||||
*/
|
||||
void updateBanner(BannerUpdateDTO adminsBannerUpdateDTO);
|
||||
|
||||
/**
|
||||
* 更新 - banner 状态
|
||||
*
|
||||
* @param adminId
|
||||
* @param bannerId
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
void updateBannerStatus(Integer adminId, Integer bannerId, @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
|
||||
|
||||
/**
|
||||
* 删除 - 根据id删除一个banner
|
||||
*
|
||||
* @param adminId
|
||||
* @param bannerId
|
||||
*/
|
||||
void deleteBanner(Integer adminId, Integer bannerId);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package cn.iocoder.mall.promotion.biz.service.banner;
|
||||
|
||||
import cn.iocoder.common.framework.constant.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
|
||||
import cn.iocoder.mall.promotion.biz.api.enums.PromotionErrorCodeEnum;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
|
||||
import cn.iocoder.mall.promotion.biz.convert.BannerConvert;
|
||||
import cn.iocoder.mall.promotion.biz.dao.BannerMapper;
|
||||
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 14:19
|
||||
*/
|
||||
@Service
|
||||
public class BannerServiceImpl implements BannerService {
|
||||
|
||||
@Autowired
|
||||
private BannerMapper bannerMapper;
|
||||
|
||||
@Override
|
||||
public List<BannerListOnReleaseBO> listBannerOnRelease() {
|
||||
PageResult<BannerListBO> pageResult = this.listBanner(
|
||||
(BannerListDTO) new BannerListDTO()
|
||||
.setStatus(CommonStatusEnum.ENABLE.getValue())
|
||||
.setTitle(null)
|
||||
.setPageNo(1)
|
||||
.setPageSize(10)
|
||||
);
|
||||
return BannerConvert.INSTANCE.convertToBO(pageResult.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<BannerListBO> listBanner(BannerListDTO dto) {
|
||||
IPage<BannerDO> page = bannerMapper.selectBannerList(dto);
|
||||
List<BannerListBO> list = BannerConvert.INSTANCE.convert(page.getRecords());
|
||||
return new PageResult<BannerListBO>().setList(list).setTotal(page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBanner(BannerAddDTO adminsBannerAddDTO) {
|
||||
// 转换DO
|
||||
BannerDO banner = BannerConvert.INSTANCE.convert(adminsBannerAddDTO);
|
||||
// 设置默认数据
|
||||
banner.setStatus(CommonStatusEnum.ENABLE.getValue());
|
||||
banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
banner.setCreateTime(new Date());
|
||||
// 保存数据
|
||||
bannerMapper.insert(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBanner(BannerUpdateDTO adminsBannerUpdateDTO) {
|
||||
// 校验 Banner 存在
|
||||
if (bannerMapper.selectById(adminsBannerUpdateDTO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
BannerDO updateBanner = BannerConvert.INSTANCE.convert(adminsBannerUpdateDTO);
|
||||
updateBanner.setUpdateTime(new Date());
|
||||
bannerMapper.updateById(updateBanner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void 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();
|
||||
updateBanner.setId(bannerId);
|
||||
updateBanner.setStatus(status);
|
||||
updateBanner.setUpdateTime(new Date());
|
||||
bannerMapper.updateById(updateBanner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBanner(Integer adminId, Integer bannerId) {
|
||||
// 校验 Banner 存在
|
||||
if (bannerMapper.selectById(bannerId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
BannerDO updateBanner = new BannerDO();
|
||||
updateBanner.setId(bannerId);
|
||||
updateBanner.setUpdateTime(new Date());
|
||||
updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
||||
bannerMapper.updateById(updateBanner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:47
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.biz.service;
|
||||
Reference in New Issue
Block a user