Banner 的迁移

商品推荐的迁移
This commit is contained in:
YunaiV
2020-08-24 20:14:06 +08:00
parent c94fae173e
commit f0999eac46
65 changed files with 1195 additions and 1448 deletions

View File

@@ -1,30 +0,0 @@
package cn.iocoder.mall.promotion.biz.convert;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.dto.BannerAddDTO;
import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO;
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
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(BannerAddDTO bannerAddDTO);
@Mappings({})
BannerDO convert(BannerUpdateDTO bannerUpdateDTO);
}

View File

@@ -1,30 +0,0 @@
package cn.iocoder.mall.promotion.biz.convert;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.api.dto.ProductRecommendAddDTO;
import cn.iocoder.mall.promotion.api.dto.ProductRecommendUpdateDTO;
import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductRecommendConvert {
ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class);
@Mappings({})
ProductRecommendBO convertToBO(ProductRecommendDO recommend);
@Mappings({})
List<ProductRecommendBO> convertToBO(List<ProductRecommendDO> recommendList);
@Mappings({})
ProductRecommendDO convert(ProductRecommendAddDTO recommendAddDTO);
@Mappings({})
ProductRecommendDO convert(ProductRecommendUpdateDTO recommendUpdateDTO);
}

View File

@@ -1,26 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BannerMapper {
BannerDO selectById(@Param("id") Integer id);
List<BannerDO> selectListByStatus(@Param("status") Integer status);
List<BannerDO> selectListByTitleLike(@Param("title") String title,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByTitleLike(@Param("title") String title);
void insert(BannerDO bannerDO);
int update(BannerDO bannerDO);
}

View File

@@ -1,30 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductRecommendMapper {
ProductRecommendDO selectById(@Param("id") Integer id);
ProductRecommendDO selectByProductSpuIdAndType(@Param("productSpuId") Integer productSpuId,
@Param("type") Integer type);
List<ProductRecommendDO> selectListByTypeAndStatus(@Param("type") Integer type,
@Param("status") Integer status);
List<ProductRecommendDO> selectPageByType(@Param("type") Integer type,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByType(@Param("type") Integer type);
void insert(ProductRecommendDO bannerDO);
int update(ProductRecommendDO bannerDO);
}

View File

@@ -1,97 +0,0 @@
package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
import cn.iocoder.mall.promotion.api.BannerService;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeEnum;
import cn.iocoder.mall.promotion.api.dto.BannerAddDTO;
import cn.iocoder.mall.promotion.api.dto.BannerPageDTO;
import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.BannerService.version}")
public class BannerServiceImpl implements BannerService {
@Autowired
private BannerMapper bannerMapper;
@Override
public List<BannerBO> getBannerListByStatus(Integer status) {
List<BannerDO> banners = bannerMapper.selectListByStatus(status);
return BannerConvert.INSTANCE.convertToBO(banners);
}
@Override
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;
}
@Override
public BannerBO addBanner(Integer adminId, BannerAddDTO 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);
}
@Override
public Boolean updateBanner(Integer adminId, BannerUpdateDTO 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;
}
@Override
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;
}
@Override
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

@@ -1,119 +0,0 @@
package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.rpc.api.ProductSpuRpc;
import cn.iocoder.mall.promotion.api.ProductRecommendService;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO;
import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeEnum;
import cn.iocoder.mall.promotion.api.dto.ProductRecommendAddDTO;
import cn.iocoder.mall.promotion.api.dto.ProductRecommendPageDTO;
import cn.iocoder.mall.promotion.api.dto.ProductRecommendUpdateDTO;
import cn.iocoder.mall.promotion.biz.convert.ProductRecommendConvert;
import cn.iocoder.mall.promotion.biz.dao.ProductRecommendMapper;
import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductRecommendService.version}")
public class ProductRecommendServiceImpl implements ProductRecommendService {
@Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}")
private ProductSpuRpc productSpuRpc;
@Autowired
private ProductRecommendMapper productRecommendMapper;
@Override
public List<ProductRecommendBO> getProductRecommendList(Integer type, Integer status) {
List<ProductRecommendDO> productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status);
return ProductRecommendConvert.INSTANCE.convertToBO(productRecommends);
}
@Override
public ProductRecommendPageBO getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO) {
ProductRecommendPageBO productRecommendPageBO = new ProductRecommendPageBO();
// 查询分页数据
int offset = (productRecommendPageDTO.getPageNo() - 1) * productRecommendPageDTO.getPageSize();
productRecommendPageBO.setList(ProductRecommendConvert.INSTANCE.convertToBO(productRecommendMapper.selectPageByType(productRecommendPageDTO.getType(),
offset, productRecommendPageDTO.getPageSize())));
// 查询分页总数
productRecommendPageBO.setTotal(productRecommendMapper.selectCountByType(productRecommendPageDTO.getType()));
return productRecommendPageBO;
}
@Override
public ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO) {
// 校验商品不存在
if (productSpuRpc.getProductSpuDetail(productRecommendAddDTO.getProductSpuId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode());
}
// 校验商品是否已经推荐
if (productRecommendMapper.selectByProductSpuIdAndType(productRecommendAddDTO.getProductSpuId(), productRecommendAddDTO.getType()) != null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode());
}
// 保存到数据库
ProductRecommendDO productRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue());
productRecommend.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date());
productRecommendMapper.insert(productRecommend);
// 返回成功
return ProductRecommendConvert.INSTANCE.convertToBO(productRecommend);
}
@Override
public Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO) {
// 校验更新的商品推荐存在
if (productRecommendMapper.selectById(productRecommendUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode());
}
// 校验商品不存在
if (productSpuRpc.getProductSpuDetail(productRecommendUpdateDTO.getProductSpuId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode());
}
// 校验商品是否已经推荐
ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(productRecommendUpdateDTO.getProductSpuId(), productRecommendUpdateDTO.getType());
if (existProductRecommend != null && !existProductRecommend.getId().equals(productRecommendUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode());
}
// 更新到数据库
ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendUpdateDTO);
productRecommendMapper.update(updateProductRecommend);
// 返回成功
return true;
}
@Override
public Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status) {
// 校验更新的商品推荐存在
if (productRecommendMapper.selectById(productRecommendId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode());
}
// 更新到数据库
ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId).setStatus(status);
productRecommendMapper.update(updateProductRecommend);
// 返回成功
return true;
}
@Override
public Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId) {
// 校验更新的商品推荐存在
if (productRecommendMapper.selectById(productRecommendId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode());
}
// 更新到数据库
ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId);
updateProductRecommend.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
productRecommendMapper.update(updateProductRecommend);
// 返回成功
return true;
}
}

View File

@@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.mall.promotion.biz.dao.BannerMapper">
<sql id="FIELDS">
id, title, url, pic_url, sort,
status, memo, create_time
</sql>
<!-- <select id="selectListByPidAndStatusOrderBySort" resultType="BannerDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM banner-->
<!-- WHERE pid = #{pid}-->
<!-- AND status = #{status}-->
<!-- AND deleted = 0-->
<!-- ORDER BY sort ASC-->
<!-- </select>-->
<!-- <select id="selectList" resultType="BannerDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM banner-->
<!-- WHERE deleted = 0-->
<!-- </select>-->
<select id="selectById" parameterType="Integer" resultType="BannerDO">
SELECT
<include refid="FIELDS" />
FROM banner
WHERE id = #{id}
AND deleted = 0
</select>
<select id="selectListByStatus" parameterType="Integer" resultType="BannerDO">
SELECT
<include refid="FIELDS" />
FROM banner
<where>
<if test="status != null">
status = #{status}
</if>
AND deleted = 0
</where>
</select>
<select id="selectListByTitleLike" resultType="BannerDO">
SELECT
<include refid="FIELDS" />
FROM banner
<where>
<if test="title != null">
title LIKE "%"#{title}"%"
</if>
AND deleted = 0
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByTitleLike" resultType="Integer">
SELECT
COUNT(1)
FROM banner
<where>
<if test="title != null">
title LIKE "%"#{title}"%"
</if>
AND deleted = 0
</where>
</select>
<insert id="insert" parameterType="BannerDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO banner (
title, url, pic_url, sort, status,
memo, create_time, deleted
) VALUES (
#{title}, #{url}, #{picUrl}, #{sort}, #{status},
#{memo}, #{createTime}, #{deleted}
)
</insert>
<update id="update" parameterType="BannerDO">
UPDATE banner
<set>
<if test="title != null">
title = #{title},
</if>
<if test="url != null">
url = #{url},
</if>
<if test="picUrl != null">
pic_url = #{picUrl} ,
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="memo != null">
memo = #{memo},
</if>
<if test="deleted != null">
deleted = #{deleted}
</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -1,125 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.mall.promotion.biz.dao.ProductRecommendMapper">
<sql id="FIELDS">
id, type, product_spu_id, sort,
status, memo, create_time
</sql>
<!-- <select id="selectListByPidAndStatusOrderBySort" resultType="ProductRecommendDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM product_recommend-->
<!-- WHERE pid = #{pid}-->
<!-- AND status = #{status}-->
<!-- AND deleted = 0-->
<!-- ORDER BY sort ASC-->
<!-- </select>-->
<!-- <select id="selectList" resultType="ProductRecommendDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM product_recommend-->
<!-- WHERE deleted = 0-->
<!-- </select>-->
<select id="selectById" parameterType="Integer" resultType="ProductRecommendDO">
SELECT
<include refid="FIELDS" />
FROM product_recommend
WHERE id = #{id}
AND deleted = 0
</select>
<select id="selectByProductSpuIdAndType" resultType="ProductRecommendDO">
SELECT
<include refid="FIELDS" />
FROM product_recommend
<where>
<if test="productSpuId != null">
product_spu_id = #{productSpuId}
</if>
<if test="type != null">
AND type = #{type}
</if>
AND deleted = 0
</where>
</select>
<select id="selectListByTypeAndStatus" parameterType="Integer" resultType="ProductRecommendDO">
SELECT
<include refid="FIELDS" />
FROM product_recommend
<where>
<if test="type != null">
type = #{type}
</if>
<if test="status != null">
AND status = #{status}
</if>
AND deleted = 0
</where>
</select>
<select id="selectPageByType" resultType="ProductRecommendDO">
SELECT
<include refid="FIELDS" />
FROM product_recommend
<where>
<if test="type != null">
type = #{type}
</if>
AND deleted = 0
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByType" resultType="Integer">
SELECT
COUNT(1)
FROM product_recommend
<where>
<if test="type != null">
type = #{type}
</if>
AND deleted = 0
</where>
</select>
<insert id="insert" parameterType="ProductRecommendDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO product_recommend (
type, product_spu_id, sort, status, memo,
create_time, deleted
) VALUES (
#{type}, #{productSpuId}, #{sort}, #{status}, #{memo},
#{createTime}, #{deleted}
)
</insert>
<update id="update" parameterType="ProductRecommendDO">
UPDATE product_recommend
<set>
<if test="type != null">
type = #{type},
</if>
<if test="productSpuId != null">
product_spu_id = #{productSpuId},
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="memo != null">
memo = #{memo},
</if>
<if test="deleted != null">
deleted = #{deleted}
</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -1,132 +0,0 @@
<?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-start</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>product-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-service-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>system-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<!-- 服务保障相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-security</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-security</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- 打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,101 +0,0 @@
package cn.iocoder.mall.promotion.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.BannerService;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.api.dto.BannerAddDTO;
import cn.iocoder.mall.promotion.api.dto.BannerPageDTO;
import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO;
import cn.iocoder.mall.promotion.application.convert.BannerConvert;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/banner")
@Api("Banner 模块")
public class AdminsBannerController {
@Reference(validation = "true", version = "${dubbo.provider.BannerService.version}")
private BannerService bannerService;
@GetMapping("/page")
@ApiOperation(value = "Banner 分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "title", value = "标题,模糊匹配", example = "活动 A"),
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
})
public CommonResult<AdminsBannerPageVO> page(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
BannerPageBO result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize));
return success(BannerConvert.ADMINS.convert3(result));
}
@PostMapping("/add")
@ApiOperation(value = "创建 Banner")
@ApiImplicitParams({
@ApiImplicitParam(name = "title", value = "标题", required = true, example = "活动A"),
@ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"),
@ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"),
@ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"),
@ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"),
})
public CommonResult<AdminsBannerVO> add(@RequestParam("title") String title,
@RequestParam("url") String url,
@RequestParam("picUrl") String picUrl,
@RequestParam("sort") Integer sort,
@RequestParam(value = "memo", required = false) String memo) {
BannerAddDTO bannerAddDTO = new BannerAddDTO().setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return success(BannerConvert.ADMINS.convert(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO)));
}
@PostMapping("/update")
@ApiOperation(value = "更新 Banner")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"),
@ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"),
@ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"),
@ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"),
@ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"),
})
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
@RequestParam("title") String title,
@RequestParam("url") String url,
@RequestParam("picUrl") String picUrl,
@RequestParam("sort") Integer sort,
@RequestParam(value = "memo", required = false) String memo) {
BannerUpdateDTO bannerUpdateDTO = new BannerUpdateDTO().setId(id).setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return success(bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO));
}
@PostMapping("/update_status")
@ApiOperation(value = "更新 Banner 状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return success(bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
@PostMapping("/delete")
@ApiOperation(value = "删除 Banner")
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1")
public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
return success(bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}

View File

@@ -93,17 +93,6 @@ public class AdminsProductRecommendController {
return success(productRecommendService.updateProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO));
}
@PostMapping("/update_status")
@ApiOperation(value = "更新商品推荐状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return success(productRecommendService.updateProductRecommendStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
@PostMapping("/delete")
@ApiOperation(value = "删除商品推荐")
@ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1")

View File

@@ -1,39 +0,0 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerVO;
import cn.iocoder.mall.promotion.application.vo.users.UsersBannerVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
public interface BannerConvert {
Users USERS = Mappers.getMapper(Users.class);
Admins ADMINS = Mappers.getMapper(Admins.class);
@Mapper
interface Admins {
@Mappings({})
AdminsBannerVO convert(BannerBO bannerBO);
@Mappings({})
AdminsBannerPageVO convert3(BannerPageBO bannerPageBO);
}
@Mapper
interface Users {
@Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners);
}
}

View File

@@ -1,30 +0,0 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendPageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendVO;
import cn.iocoder.mall.promotion.application.vo.users.UsersProductRecommendVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductRecommendConvert {
ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class);
@Mappings({})
AdminsProductRecommendVO convert(ProductRecommendBO bannerBO);
@Mappings({})
AdminsProductRecommendPageVO convert(ProductRecommendPageBO result);
@Mappings({})
UsersProductRecommendVO convert(ProductSpuBO productSpu);
// @Mappings({})
// List<UsersProductRecommendVO> convertList(List<ProductRecommendBO> banners);
}

View File

@@ -1,32 +0,0 @@
package cn.iocoder.mall.promotion.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("Banner VO")
@Data
@Accessors(chain = true)
public class AdminsBannerVO {
@ApiModelProperty(value = "Banner 编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "标题", required = true, example = "活动 A")
private String title;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com")
private String url;
@ApiModelProperty(value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg")
private String picUrl;
@ApiModelProperty(value = "排序", required = true, example = "10")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼")
private String memo;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
}