- 增加:banner
This commit is contained in:
parent
e629319d8b
commit
7fcf954649
|
@ -17,8 +17,9 @@
|
|||
<module>promotion-biz-api</module>
|
||||
<module>promotion-rpc-api</module>
|
||||
<module>promotion-rpc</module>
|
||||
<module>promotion-rest</module>
|
||||
|
||||
<!-- <module>promotion-service-api</module>-->
|
||||
<!-- <module>promotion-service-api</module>-->
|
||||
<!-- <module>promotion-service-impl</module>-->
|
||||
<!-- <module>promotion-start</module>-->
|
||||
</modules>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package cn.iocoder.mall.promotion.biz.api.enums;
|
||||
|
||||
/**
|
||||
* 错误码枚举类
|
||||
*
|
||||
* 营销系统,使用 1-006-000-000 段
|
||||
*/
|
||||
public enum PromotionErrorCodeEnum {
|
||||
|
||||
// ========== Banner 模块 ==========
|
||||
BANNER_NOT_EXISTS(1006000000, "账号不存在"),
|
||||
|
||||
// // ========== PRODUCT RECOMMEND 模块 ==========
|
||||
// PRODUCT_RECOMMEND_NOT_EXISTS(1006001000, "商品推荐不存在"),
|
||||
// PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS(1006001001, "商品不存在"),
|
||||
// PRODUCT_RECOMMEND_EXISTS(1006001002, "该商品推荐已经存在"),
|
||||
//
|
||||
//
|
||||
// // ========== COUPON TEMPLATE 模块 ==========
|
||||
// COUPON_TEMPLATE_NOT_EXISTS(1006002000, "优惠劵模板(码)不存在"),
|
||||
// COUPON_TEMPLATE_NOT_CARD(1006002001, "不是优惠劵模板"),
|
||||
// COUPON_TEMPLATE_NOT_CODE(1006002002, "不是优惠码模板"),
|
||||
// COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE(1006002003, "优惠劵(码)模板的发放数量不能减小"),
|
||||
// COUPON_TEMPLATE_STATUS_NOT_ENABLE(1006002004, "优惠劵模板(码)未开启"),
|
||||
// COUPON_TEMPLATE_TOTAL_NOT_ENOUGH(1006002005, "优惠劵(码)模板的发放量不足"),
|
||||
// COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA(1006002006, "优惠劵领取到达上限"),
|
||||
//
|
||||
// // ========== COUPON CARD 模块 ==========
|
||||
// COUPON_CARD_NOT_EXISTS(1006003000, "优惠劵不存在"),
|
||||
// COUPON_CARD_ERROR_USER(1006003001, "优惠劵不属于当前用户"),
|
||||
// COUPON_CARD_NOT_MATCH(1006003002, "优惠劵不匹配,无法使用"),
|
||||
// COUPON_CARD_STATUS_NOT_UNUSED(1006003003, "优惠劵不处于待使用状态"),
|
||||
// COUPON_CARD_STATUS_NOT_USED(1006003004, "优惠劵不处于已使用状态"),
|
||||
;
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
PromotionErrorCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:25
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.biz.api;
|
|
@ -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;
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>promotion</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>promotion-rest</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>promotion-biz</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-web</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-security</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-swagger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,84 @@
|
|||
package cn.iocoder.mall.promotion.rest.controller.banner;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
|
||||
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 cn.iocoder.mall.promotion.biz.service.banner.BannerService;
|
||||
import cn.iocoder.mall.promotion.rest.convert.BannerConvert;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerAddRequest;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerListRequest;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateRequest;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateStatusRequest;
|
||||
import cn.iocoder.mall.promotion.rest.response.banner.BannerListResponse;
|
||||
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Banner(管理员API)
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admins/banner")
|
||||
@Api(tags = "Banner(管理员API)")
|
||||
public class AdminsBannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "列表-banner列表")
|
||||
public CommonResult<PageResult<BannerListResponse>> page(@RequestBody @Valid BannerListRequest request) {
|
||||
// 获取数据
|
||||
BannerListDTO pageDTO = BannerConvert.INSTANCE.convert(request);
|
||||
PageResult<BannerListBO> pageResult = bannerService.listBanner(pageDTO);
|
||||
// 转换 response
|
||||
List<BannerListResponse> responseList = BannerConvert.INSTANCE.convert(pageResult.getList());
|
||||
return CommonResult.success(new PageResult<BannerListResponse>().setList(responseList).setTotal(pageResult.getTotal()));
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "添加-Banner")
|
||||
public CommonResult<Void> add(@RequestBody @Valid BannerAddRequest request) {
|
||||
BannerAddDTO bannerAddDTO = BannerConvert.INSTANCE.convert(request);
|
||||
bannerAddDTO.setAdminId(AdminSecurityContextHolder.getContext().getAdminId());
|
||||
bannerService.addBanner(bannerAddDTO);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation(value = "更新-Banner信息")
|
||||
public CommonResult<Void> update(@RequestBody @Valid BannerUpdateRequest request) {
|
||||
BannerUpdateDTO bannerUpdateDTO = BannerConvert.INSTANCE.convert(request);
|
||||
bannerUpdateDTO.setAdminId(AdminSecurityContextHolder.getContext().getAdminId());
|
||||
bannerService.updateBanner(bannerUpdateDTO);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@ApiOperation(value = "更新-banner状态")
|
||||
public CommonResult<Void> updateStatus(@RequestBody @Valid BannerUpdateStatusRequest request) {
|
||||
Integer adminId = AdminSecurityContextHolder.getContext().getAdminId();
|
||||
bannerService.updateBannerStatus(adminId, request.getBannerId(), request.getStatus());
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation(value = "删除-根据id删除")
|
||||
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1")
|
||||
public CommonResult<Void> delete(@RequestParam("id") Integer id) {
|
||||
bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.iocoder.mall.promotion.rest.controller.banner;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
|
||||
import cn.iocoder.mall.promotion.biz.service.banner.BannerService;
|
||||
import cn.iocoder.mall.promotion.rest.convert.BannerConvert;
|
||||
import cn.iocoder.mall.promotion.rest.response.banner.BannerListOnReleaseResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Banner(用户API)
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/users/banner")
|
||||
@Api(tags = "Banner(用户API)")
|
||||
public class UsersBannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@GetMapping("/listBannerOnRelease")
|
||||
@ApiOperation("获取-已发布的banner")
|
||||
public CommonResult<List<BannerListOnReleaseResponse>> listBannerOnRelease() {
|
||||
List<BannerListOnReleaseBO> releaseBOList = bannerService.listBannerOnRelease();
|
||||
return CommonResult.success(BannerConvert.INSTANCE.convertReleaseResponse(releaseBOList));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:27
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.rest.controller;
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.mall.promotion.rest.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.dto.banner.BannerAddDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerAddRequest;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerListRequest;
|
||||
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateRequest;
|
||||
import cn.iocoder.mall.promotion.rest.response.banner.BannerListResponse;
|
||||
import cn.iocoder.mall.promotion.rest.response.banner.BannerListOnReleaseResponse;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BannerConvert {
|
||||
|
||||
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
|
||||
|
||||
BannerAddDTO convert(BannerAddRequest request);
|
||||
|
||||
BannerUpdateDTO convert(BannerUpdateRequest request);
|
||||
|
||||
BannerListDTO convert(BannerListRequest request);
|
||||
|
||||
List<BannerListResponse> convert(List<BannerListBO> bannerListBO);
|
||||
|
||||
List<BannerListOnReleaseResponse> convertReleaseResponse(List<BannerListOnReleaseBO> bannerListOnReleaseBOS);
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.mall.promotion.rest.request.banner;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* banner:更新 banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:44
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerAddRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("跳转链接")
|
||||
private Integer url;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("图片链接")
|
||||
private Integer picUrl;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("备注")
|
||||
private Integer memo;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.mall.promotion.rest.request.banner;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* banner:更新 banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:44
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerListRequest extends PageParam {
|
||||
|
||||
@ApiModelProperty("标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private Integer status;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package cn.iocoder.mall.promotion.rest.request.banner;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* banner:更新 banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:44
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerUpdateRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("banner编号")
|
||||
private Integer bannerId;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("跳转链接")
|
||||
private Integer url;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("图片链接")
|
||||
private Integer picUrl;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("备注")
|
||||
private Integer memo;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.mall.promotion.rest.request.banner;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* banner:更新 status
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:44
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerUpdateStatusRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("banner编号")
|
||||
private Integer bannerId;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty("status状态")
|
||||
private Integer status;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 17:00
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.rest.request;
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.mall.promotion.rest.response.banner;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* banner - 已发布的banner
|
||||
*
|
||||
* author: sin
|
||||
* time: 2020/5/14 16:56
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerListOnReleaseResponse implements Serializable {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 跳转链接
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
private String picUrl;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package cn.iocoder.mall.promotion.rest.response.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 BannerListResponse 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,5 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/14 15:26
|
||||
*/
|
||||
package cn.iocoder.mall.promotion.rest.response;
|
Loading…
Reference in New Issue