Banner模块 for review

This commit is contained in:
xiaxiaoYY 2022-05-31 16:08:10 +08:00
parent e31091c0df
commit 247d299cca
18 changed files with 852 additions and 50 deletions

View File

@ -253,3 +253,35 @@ create table product_sku
collate utf8mb4_general_ci;
---Market-Banner管理SQL
drop table if exists market_banner;
CREATE TABLE `market_banner` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Banner编号',
`title` varchar(64) NOT NULL DEFAULT '' COMMENT 'Banner标题',
`pic_url` varchar(255) NOT NULL COMMENT '图片URL',
`status` tinyint(4) NOT NULL DEFAULT '-1' COMMENT '活动状态',
`url` varchar(255) NOT NULL COMMENT '跳转地址',
`creator` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号',
`sort` tinyint(4) DEFAULT NULL COMMENT '排序',
`memo` varchar(255) DEFAULT NULL COMMENT '描述',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='Banner管理';
-- 菜单 SQL
INSERT INTO `system_menu`(`id`,`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)
VALUES (2002, 'Banner管理', '', 2, 1, 2000, 'brand', '', 'mall/market/banner/index', 0);
-- 按钮父菜单ID
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)
VALUES ('Banner查询', 'market:banner:query', 3, 1, @parentId, '', '', '', 0);
INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)
VALUES ('Banner创建', 'market:banner:create', 3, 2, @parentId, '', '', '', 0);
INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)
VALUES ('Banner更新', 'market:banner:update', 3, 3, @parentId, '', '', '', 0);
INSERT INTO `system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`)
VALUES ('Banner删除', 'market:banner:delete', 3, 4, @parentId, '', '', '', 0);

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.framework.common.enums;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 通用状态枚举
*
@ -10,11 +13,14 @@ import lombok.Getter;
*/
@Getter
@AllArgsConstructor
public enum CommonStatusEnum {
public enum CommonStatusEnum implements IntArrayValuable {
ENABLE(0, "开启"),
DISABLE(1, "关闭");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CommonStatusEnum::getStatus).toArray();
/**
* 状态值
*/
@ -24,4 +30,9 @@ public enum CommonStatusEnum {
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -12,4 +12,7 @@ public interface ErrorCodeConstants {
// ========== 促销活动相关 1003001000============
ErrorCode ACTIVITY_NOT_EXISTS = new ErrorCode(1003001000, "促销活动不存在");
// ========== banner相关 1003002000============
ErrorCode BANNER_NOT_EXISTS = new ErrorCode(1003002000, "Banner不存在");
}

View File

@ -5,6 +5,9 @@ import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
/**
* @author xia
*/
@ApiModel("管理后台 - 促销活动创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)

View File

@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.market.controller.admin.banner;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.*;
import cn.iocoder.yudao.module.market.convert.banner.BannerConvert;
import cn.iocoder.yudao.module.market.dal.dataobject.banner.BannerDO;
import cn.iocoder.yudao.module.market.service.banner.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "管理后台 - Banner管理")
@RestController
@RequestMapping("/market/banner")
@Validated
public class BannerController {
@Resource
private BannerService bannerService;
@PostMapping("/create")
@ApiOperation("创建banner")
@PreAuthorize("@ss.hasPermission('market:banner:create')")
public CommonResult<Long> createBanner(@Valid @RequestBody BannerCreateReqVO createReqVO) {
return success(bannerService.createBanner(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新banner")
@PreAuthorize("@ss.hasPermission('market:banner:update')")
public CommonResult<Boolean> updateBanner(@Valid @RequestBody BannerUpdateReqVO updateReqVO) {
bannerService.updateBanner(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除banner")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('market:banner:delete')")
public CommonResult<Boolean> deleteBanner(@RequestParam("id") Long id) {
bannerService.deleteBanner(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得banner")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('market:banner:query')")
public CommonResult<BannerRespVO> getBanner(@RequestParam("id") Long id) {
BannerDO banner = bannerService.getBanner(id);
return success(BannerConvert.INSTANCE.convert(banner));
}
@GetMapping("/list")
@ApiOperation("获得banner列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('market:banner:query')")
public CommonResult<List<BannerRespVO>> getBannerList(@RequestParam("ids") Collection<Long> ids) {
List<BannerDO> list = bannerService.getBannerList(ids);
return success(BannerConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得Banner分页")
@PreAuthorize("@ss.hasPermission('market:banner:query')")
public CommonResult<PageResult<BannerRespVO>> getBannerPage(@Valid BannerPageReqVO pageVO) {
PageResult<BannerDO> pageResult = bannerService.getBannerPage(pageVO);
return success(BannerConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/update-status")
@ApiOperation("Banner上下架")
@PreAuthorize("@ss.hasPermission('market:banner:update')")
public CommonResult<Boolean> updateBannerStatus(@Valid @RequestBody BannerUpdateStatusReqVO reqVO) {
bannerService.updateBannerStatus(reqVO);
return success(true);
}
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* Banner Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
* @author xia
*/
@Data
public class BannerBaseVO {
@ApiModelProperty(value = "标题", required = true)
@NotNull(message = "标题不能为空")
private String title;
@ApiModelProperty(value = "跳转链接", required = true)
@NotNull(message = "跳转链接不能为空")
/**
* 跳转链接
*/
private String url;
@ApiModelProperty(value = "图片地址", required = true)
@NotNull(message = "图片地址不能为空")
/**
* 图片链接
*/
private String picUrl;
@ApiModelProperty(value = "排序", required = true)
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "状态", required = true)
@NotNull(message = "状态不能为空")
@InEnum(CommonStatusEnum.class)
private Integer status;
@ApiModelProperty(value = "备注")
private String memo;
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
/**
* @author xia
*/
@ApiModel("管理后台 - Banner 创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BannerCreateReqVO extends BannerBaseVO {
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* @author xia
*/
@ApiModel("管理后台 - Banner 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BannerPageReqVO extends PageParam {
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "状态")
@InEnum(CommonStatusEnum.class)
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束创建时间")
private Date endCreateTime;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* @author xia
*/
@ApiModel("管理后台 - Banner Response VO")
@Data
@ToString(callSuper = true)
public class BannerRespVO extends BannerBaseVO {
@ApiModelProperty(value = "banner编号", required = true)
@NotNull(message = "banner编号不能为空")
private Long id;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
/**
* @author xia
*/
@ApiModel("管理后台 - Banner更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BannerUpdateReqVO extends BannerBaseVO {
@ApiModelProperty(value = "banner编号", required = true)
@NotNull(message = "banner编号不能为空")
private Long id;
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.market.controller.admin.banner.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @Copyright: 南京淘点网络科技有限公司
* @author: wangxia
*/
@Data
public class BannerUpdateStatusReqVO {
@ApiModelProperty(value = "banner编号", required = true)
@NotNull(message = "banner编号不能为空")
private Long id;
@ApiModelProperty(value = "状态", required = true)
@NotNull(message = "状态不能为空")
@InEnum(CommonStatusEnum.class)
private Integer status;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.market.convert.banner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerCreateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerRespVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateStatusReqVO;
import cn.iocoder.yudao.module.market.dal.dataobject.banner.BannerDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Banner Convert
*
* @author xia
*/
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
List<BannerRespVO> convertList(List<BannerDO> list);
PageResult<BannerRespVO> convertPage(PageResult<BannerDO> pageResult);
BannerRespVO convert(BannerDO banner);
BannerDO convert(BannerCreateReqVO createReqVO);
BannerDO convert(BannerUpdateReqVO updateReqVO);
BannerDO convert(BannerUpdateStatusReqVO updateStatusReqVO);
}

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.market.dal.dataobject.banner;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* banner DO
*
* @author xia
*/
@TableName("market_banner")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BannerDO extends BaseDO {
/**
* 编号
*/
private Long id;
/**
* 标题
*/
private String title;
/**
* 跳转链接
*/
private String url;
/**
* 图片链接
*/
private String picUrl;
/**
* 排序
*/
private Integer sort;
/**
* 状态 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
*/
private Integer status;
/**
* 备注
*/
private String memo;
// TODO 芋艿 点击次数&& 其他数据相关
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.market.dal.mysql.banner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerPageReqVO;
import cn.iocoder.yudao.module.market.dal.dataobject.banner.BannerDO;
import org.apache.ibatis.annotations.Mapper;
/**
* Banner Mapper
*
* @author xia
*/
@Mapper
public interface BannerMapper extends BaseMapperX<BannerDO> {
default PageResult<BannerDO> selectPage(BannerPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BannerDO>()
.likeIfPresent(BannerDO::getTitle, reqVO.getTitle())
.eqIfPresent(BannerDO::getStatus, reqVO.getStatus())
.betweenIfPresent(BannerDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.betweenIfPresent(BannerDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(BannerDO::getSort));
}
}

View File

@ -1,10 +1,11 @@
package cn.iocoder.yudao.module.market.service.banner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityCreateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityPageReqVO;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityUpdateReqVO;
import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerCreateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerPageReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateStatusReqVO;
import cn.iocoder.yudao.module.market.dal.dataobject.banner.BannerDO;
import javax.validation.Valid;
import java.util.Collection;
@ -15,52 +16,53 @@ import java.util.List;
*
* @author xia
*/
public interface ActivityService {
public interface BannerService {
/**
* 创建促销活动
* 创建Banner
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createActivity(@Valid ActivityCreateReqVO createReqVO);
Long createBanner(@Valid BannerCreateReqVO createReqVO);
/**
* 更新促销活动
* 更新Banner
*
* @param updateReqVO 更新信息
*/
void updateActivity(@Valid ActivityUpdateReqVO updateReqVO);
void updateBanner(@Valid BannerUpdateReqVO updateReqVO);
/**
* 删除促销活动
* 删除Banner
*
* @param id 编号
*/
void deleteActivity(Long id);
void deleteBanner(Long id);
/**
* 获得促销活动
* 获得Banner
*
* @param id 编号
* @return 促销活动
* @return Banner
*/
ActivityDO getActivity(Long id);
BannerDO getBanner(Long id);
/**
* 获得促销活动列表
* 获得Banner列表
*
* @param ids 编号
* @return 促销活动列表
* @return Banner列表
*/
List<ActivityDO> getActivityList(Collection<Long> ids);
List<BannerDO> getBannerList(Collection<Long> ids);
/**
* 获得促销活动分页
* 获得Banner分页
*
* @param pageReqVO 分页查询
* @return 促销活动分页
* @return Banner分页
*/
PageResult<ActivityDO> getActivityPage(ActivityPageReqVO pageReqVO);
PageResult<BannerDO> getBannerPage(BannerPageReqVO pageReqVO);
void updateBannerStatus(BannerUpdateStatusReqVO reqVO);
}

View File

@ -1,12 +1,13 @@
package cn.iocoder.yudao.module.market.service.banner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityCreateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityPageReqVO;
import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityUpdateReqVO;
import cn.iocoder.yudao.module.market.convert.activity.ActivityConvert;
import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO;
import cn.iocoder.yudao.module.market.dal.mysql.activity.ActivityMapper;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerCreateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerPageReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateReqVO;
import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerUpdateStatusReqVO;
import cn.iocoder.yudao.module.market.convert.banner.BannerConvert;
import cn.iocoder.yudao.module.market.dal.dataobject.banner.BannerDO;
import cn.iocoder.yudao.module.market.dal.mysql.banner.BannerMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -15,7 +16,7 @@ import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.market.enums.ErrorCodeConstants.ACTIVITY_NOT_EXISTS;
import static cn.iocoder.yudao.module.market.enums.ErrorCodeConstants.*;
/**
* 首页banner 实现类
@ -24,56 +25,65 @@ import static cn.iocoder.yudao.module.market.enums.ErrorCodeConstants.ACTIVITY_N
*/
@Service
@Validated
public class ActivityServiceImpl implements ActivityService {
public class BannerServiceImpl implements BannerService {
@Resource
private ActivityMapper activityMapper;
private BannerMapper bannerMapper;
@Override
public Long createActivity(ActivityCreateReqVO createReqVO) {
public Long createBanner(BannerCreateReqVO createReqVO) {
// 插入
ActivityDO activity = ActivityConvert.INSTANCE.convert(createReqVO);
activityMapper.insert(activity);
BannerDO banner = BannerConvert.INSTANCE.convert(createReqVO);
bannerMapper.insert(banner);
// 返回
return activity.getId();
return banner.getId();
}
@Override
public void updateActivity(ActivityUpdateReqVO updateReqVO) {
public void updateBanner(BannerUpdateReqVO updateReqVO) {
// 校验存在
this.validateActivityExists(updateReqVO.getId());
this.validateBannerExists(updateReqVO.getId());
// 更新
ActivityDO updateObj = ActivityConvert.INSTANCE.convert(updateReqVO);
activityMapper.updateById(updateObj);
BannerDO updateObj = BannerConvert.INSTANCE.convert(updateReqVO);
bannerMapper.updateById(updateObj);
}
@Override
public void deleteActivity(Long id) {
public void deleteBanner(Long id) {
// 校验存在
this.validateActivityExists(id);
this.validateBannerExists(id);
// 删除
activityMapper.deleteById(id);
bannerMapper.deleteById(id);
}
private void validateActivityExists(Long id) {
if (activityMapper.selectById(id) == null) {
throw exception(ACTIVITY_NOT_EXISTS);
private void validateBannerExists(Long id) {
if (bannerMapper.selectById(id) == null) {
throw exception(BANNER_NOT_EXISTS);
}
}
@Override
public ActivityDO getActivity(Long id) {
return activityMapper.selectById(id);
public BannerDO getBanner(Long id) {
return bannerMapper.selectById(id);
}
@Override
public List<ActivityDO> getActivityList(Collection<Long> ids) {
return activityMapper.selectBatchIds(ids);
public List<BannerDO> getBannerList(Collection<Long> ids) {
return bannerMapper.selectBatchIds(ids);
}
@Override
public PageResult<ActivityDO> getActivityPage(ActivityPageReqVO pageReqVO) {
return activityMapper.selectPage(pageReqVO);
public PageResult<BannerDO> getBannerPage(BannerPageReqVO pageReqVO) {
return bannerMapper.selectPage(pageReqVO);
}
@Override
public void updateBannerStatus(BannerUpdateStatusReqVO updateStatusReqVO) {
// 校验是否可以更新
this.validateBannerExists(updateStatusReqVO.getId());
// 更新状态
BannerDO updateObj = BannerConvert.INSTANCE.convert(updateStatusReqVO);
bannerMapper.updateById(updateObj);
}
}

View File

@ -0,0 +1,54 @@
import request from '@/utils/request'
// 创建Banner
export function createBanner(data) {
return request({
url: '/market/banner/create',
method: 'post',
data: data
})
}
// 更新Banner
export function updateBanner(data) {
return request({
url: '/market/banner/update',
method: 'put',
data: data
})
}
// 删除Banner
export function deleteBanner(id) {
return request({
url: '/market/banner/delete?id=' + id,
method: 'delete'
})
}
// 获得Banner
export function getBanner(id) {
return request({
url: '/market/banner/get?id=' + id,
method: 'get'
})
}
// 获得Banner分页
export function getBannerPage(query) {
return request({
url: '/market/banner/page',
method: 'get',
params: query
})
}
// 导出Banner Excel
export function exportBannerExcel(query) {
return request({
url: '/market/banner/export-excel',
method: 'get',
params: query,
responseType: 'blob'
})
}

View File

@ -0,0 +1,288 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="标题" prop="title">
<el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['market:banner:create']">新增
</el-button>
</el-col>
<!-- <el-col :span="1.5">-->
<!-- <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"-->
<!-- :loading="exportLoading"-->
<!-- v-hasPermi="['market:banner:export']">导出-->
<!-- </el-button>-->
<!-- </el-col>-->
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<el-table-column label="标题" align="center" prop="title"/>
<el-table-column label="缩略图" align="center" prop="picUrl">
<template slot-scope="scope">
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="缩略图片" class="img-height"/>
</template>
</el-table-column>
<el-table-column label="跳转链接" align="center" prop="url"/>
<el-table-column label="排序" align="center" prop="sort"/>
<el-table-column label="描述" align="center" prop="memo"/>
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['market:banner:update']">修改
</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['market:banner:delete']">删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="标题" prop="title">
<el-input v-model="form.title" placeholder="请输入标题"/>
</el-form-item>
<el-form-item label="缩略图" prop="picUrl">
<imageUpload v-model="form.picUrl" :limit="1"/>
</el-form-item>
<el-form-item label="跳转链接" prop="url">
<el-input v-model="form.url" placeholder="请输入跳转链接"/>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input v-model="form.sort" placeholder="请输入排序"/>
</el-form-item>
<el-form-item label="描述" prop="memo">
<el-input v-model="form.memo" type="textarea" placeholder="请输入描述"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
createBanner,
deleteBanner,
exportBannerExcel,
getBanner,
getBannerPage,
updateBanner
} from "@/api/mall/market/banner";
import ImageUpload from '@/components/ImageUpload';
export default {
name: "Banner",
components: {
ImageUpload
},
data() {
return {
//
loading: true,
//
exportLoading: false,
//
showSearch: true,
//
total: 0,
//
list: [],
//
title: "",
//
open: false,
dateRangeCreateTime: [],
//
queryParams: {
pageNo: 1,
pageSize: 10,
title: null,
status: null,
},
//
categoryOptions: [],
//
form: {},
//
rules: {
title: [{required: true, message: "标题不能不空", trigger: "blur"}],
picUrl: [{required: true, message: "图片地址不能为空", trigger: "blur"}],
url: [{required: true, message: "跳转地址不能为空", trigger: "blur"}],
sort: [{required: true, message: "排序不能为空", trigger: "blur"}],
status: [{required: true, message: "状态不能为空", trigger: "change"}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询列表 */
getList() {
this.loading = true;
//
let params = {...this.queryParams};
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
//
getBannerPage(params).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
/** 表单重置 */
reset() {
this.form = {
id: undefined,
title: undefined,
link: undefined,
imgUrl: undefined,
sort: undefined,
memo: undefined,
status: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRangeCreateTime = [];
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加Banner";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id;
getBanner(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改Banner";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
//
if (this.form.id != null) {
updateBanner(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
return;
}
//
createBanner(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除Banner编号为"' + id + '"的数据项?').then(function () {
return deleteBanner(id);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
/** 导出按钮操作 */
handleExport() {
//
let params = {...this.queryParams};
params.pageNo = undefined;
params.pageSize = undefined;
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
//
this.$modal.confirm('是否确认导出所有Banner数据项?').then(() => {
this.exportLoading = true;
return exportBannerExcel(params);
}).then(response => {
this.$download.excel(response, "Banner.xls");
this.exportLoading = false;
}).catch(() => {
});
}
}
};
</script>
<style scoped lang="scss">
//
.img-height {
height: 150px;
}
</style>