From e31091c0df6577f13ef372bc6226b648bca111fe Mon Sep 17 00:00:00 2001 From: xiaxiaoYY Date: Tue, 31 May 2022 15:57:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Banner=E7=AE=A1=E7=90=86-for=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/service/banner/BannerService.java | 66 ++++++++++++++++ .../service/banner/BannerServiceImpl.java | 79 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java new file mode 100644 index 000000000..2c57a4cee --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java @@ -0,0 +1,66 @@ +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 javax.validation.Valid; +import java.util.Collection; +import java.util.List; + +/** + * 首页Banner Service 接口 + * + * @author xia + */ +public interface ActivityService { + + /** + * 创建促销活动 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createActivity(@Valid ActivityCreateReqVO createReqVO); + + /** + * 更新促销活动 + * + * @param updateReqVO 更新信息 + */ + void updateActivity(@Valid ActivityUpdateReqVO updateReqVO); + + /** + * 删除促销活动 + * + * @param id 编号 + */ + void deleteActivity(Long id); + + /** + * 获得促销活动 + * + * @param id 编号 + * @return 促销活动 + */ + ActivityDO getActivity(Long id); + + /** + * 获得促销活动列表 + * + * @param ids 编号 + * @return 促销活动列表 + */ + List getActivityList(Collection ids); + + /** + * 获得促销活动分页 + * + * @param pageReqVO 分页查询 + * @return 促销活动分页 + */ + PageResult getActivityPage(ActivityPageReqVO pageReqVO); + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java new file mode 100644 index 000000000..70157c817 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java @@ -0,0 +1,79 @@ +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 org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +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; + +/** + * 首页banner 实现类 + * + * @author xia + */ +@Service +@Validated +public class ActivityServiceImpl implements ActivityService { + + @Resource + private ActivityMapper activityMapper; + + @Override + public Long createActivity(ActivityCreateReqVO createReqVO) { + // 插入 + ActivityDO activity = ActivityConvert.INSTANCE.convert(createReqVO); + activityMapper.insert(activity); + // 返回 + return activity.getId(); + } + + @Override + public void updateActivity(ActivityUpdateReqVO updateReqVO) { + // 校验存在 + this.validateActivityExists(updateReqVO.getId()); + // 更新 + ActivityDO updateObj = ActivityConvert.INSTANCE.convert(updateReqVO); + activityMapper.updateById(updateObj); + } + + @Override + public void deleteActivity(Long id) { + // 校验存在 + this.validateActivityExists(id); + // 删除 + activityMapper.deleteById(id); + } + + private void validateActivityExists(Long id) { + if (activityMapper.selectById(id) == null) { + throw exception(ACTIVITY_NOT_EXISTS); + } + } + + @Override + public ActivityDO getActivity(Long id) { + return activityMapper.selectById(id); + } + + @Override + public List getActivityList(Collection ids) { + return activityMapper.selectBatchIds(ids); + } + + @Override + public PageResult getActivityPage(ActivityPageReqVO pageReqVO) { + return activityMapper.selectPage(pageReqVO); + } + +} From 247d299cca2f6a068b657202cff16ede6c875321 Mon Sep 17 00:00:00 2001 From: xiaxiaoYY Date: Tue, 31 May 2022 16:08:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Banner=E6=A8=A1=E5=9D=97=20for=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mall.sql | 32 ++ .../common/enums/CommonStatusEnum.java | 13 +- .../market/enums/ErrorCodeConstants.java | 3 + .../activity/vo/ActivityCreateReqVO.java | 3 + .../admin/banner/BannerController.java | 91 ++++++ .../admin/banner/vo/BannerBaseVO.java | 50 +++ .../admin/banner/vo/BannerCreateReqVO.java | 22 ++ .../admin/banner/vo/BannerPageReqVO.java | 42 +++ .../admin/banner/vo/BannerRespVO.java | 26 ++ .../admin/banner/vo/BannerUpdateReqVO.java | 27 ++ .../banner/vo/BannerUpdateStatusReqVO.java | 25 ++ .../market/convert/banner/BannerConvert.java | 36 +++ .../dal/dataobject/banner/BannerDO.java | 53 ++++ .../market/dal/mysql/banner/BannerMapper.java | 27 ++ .../market/service/banner/BannerService.java | 42 +-- .../service/banner/BannerServiceImpl.java | 68 +++-- yudao-ui-admin/src/api/mall/market/banner.js | 54 ++++ .../src/views/mall/market/banner/index.vue | 288 ++++++++++++++++++ 18 files changed, 852 insertions(+), 50 deletions(-) create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/BannerController.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerBaseVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerRespVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateStatusReqVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/banner/BannerConvert.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/banner/BannerDO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/banner/BannerMapper.java create mode 100644 yudao-ui-admin/src/api/mall/market/banner.js create mode 100644 yudao-ui-admin/src/views/mall/market/banner/index.vue diff --git a/sql/mall.sql b/sql/mall.sql index 7b3d8ce5b..9493c3bcf 100644 --- a/sql/mall.sql +++ b/sql/mall.sql @@ -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); diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/CommonStatusEnum.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/CommonStatusEnum.java index 68e0ead10..cd1b9dc5e 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/CommonStatusEnum.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/CommonStatusEnum.java @@ -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; + } + } diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/ErrorCodeConstants.java index 101e84325..d63b52465 100644 --- a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/ErrorCodeConstants.java @@ -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不存在"); } diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java index c031a361a..0ca112709 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java @@ -5,6 +5,9 @@ import java.util.*; import io.swagger.annotations.*; import javax.validation.constraints.*; +/** + * @author xia + */ @ApiModel("管理后台 - 促销活动创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/BannerController.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/BannerController.java new file mode 100644 index 000000000..f5154d6c1 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/BannerController.java @@ -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 createBanner(@Valid @RequestBody BannerCreateReqVO createReqVO) { + return success(bannerService.createBanner(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新banner") + @PreAuthorize("@ss.hasPermission('market:banner:update')") + public CommonResult 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 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 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> getBannerList(@RequestParam("ids") Collection ids) { + List list = bannerService.getBannerList(ids); + return success(BannerConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得Banner分页") + @PreAuthorize("@ss.hasPermission('market:banner:query')") + public CommonResult> getBannerPage(@Valid BannerPageReqVO pageVO) { + PageResult pageResult = bannerService.getBannerPage(pageVO); + return success(BannerConvert.INSTANCE.convertPage(pageResult)); + } + + + @GetMapping("/update-status") + @ApiOperation("Banner上下架") + @PreAuthorize("@ss.hasPermission('market:banner:update')") + public CommonResult updateBannerStatus(@Valid @RequestBody BannerUpdateStatusReqVO reqVO) { + bannerService.updateBannerStatus(reqVO); + return success(true); + } + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerBaseVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerBaseVO.java new file mode 100644 index 000000000..cfdbb8b5e --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerBaseVO.java @@ -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; + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerCreateReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerCreateReqVO.java new file mode 100644 index 000000000..0bb0c1bcf --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerCreateReqVO.java @@ -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 { + + + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerPageReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerPageReqVO.java new file mode 100644 index 000000000..79a9c40c7 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerPageReqVO.java @@ -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; + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerRespVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerRespVO.java new file mode 100644 index 000000000..f4045b991 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerRespVO.java @@ -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; + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateReqVO.java new file mode 100644 index 000000000..774b0c5e9 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateReqVO.java @@ -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; + + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateStatusReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateStatusReqVO.java new file mode 100644 index 000000000..74919cebe --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/banner/vo/BannerUpdateStatusReqVO.java @@ -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; +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/banner/BannerConvert.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/banner/BannerConvert.java new file mode 100644 index 000000000..0e5d66e14 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/banner/BannerConvert.java @@ -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 convertList(List list); + + PageResult convertPage(PageResult pageResult); + + BannerRespVO convert(BannerDO banner); + + BannerDO convert(BannerCreateReqVO createReqVO); + + BannerDO convert(BannerUpdateReqVO updateReqVO); + + BannerDO convert(BannerUpdateStatusReqVO updateStatusReqVO); +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/banner/BannerDO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/banner/BannerDO.java new file mode 100644 index 000000000..1f48f7144 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/banner/BannerDO.java @@ -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 芋艿 点击次数。&& 其他数据相关 + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/banner/BannerMapper.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/banner/BannerMapper.java new file mode 100644 index 000000000..05c8cd3c9 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/banner/BannerMapper.java @@ -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 { + + default PageResult selectPage(BannerPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .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)); + } + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java index 2c57a4cee..29ae4adac 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java @@ -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 getActivityList(Collection ids); + List getBannerList(Collection ids); /** - * 获得促销活动分页 + * 获得Banner分页 * * @param pageReqVO 分页查询 - * @return 促销活动分页 + * @return Banner分页 */ - PageResult getActivityPage(ActivityPageReqVO pageReqVO); + PageResult getBannerPage(BannerPageReqVO pageReqVO); + void updateBannerStatus(BannerUpdateStatusReqVO reqVO); } diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java index 70157c817..bd3ded681 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java @@ -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 getActivityList(Collection ids) { - return activityMapper.selectBatchIds(ids); + public List getBannerList(Collection ids) { + return bannerMapper.selectBatchIds(ids); } @Override - public PageResult getActivityPage(ActivityPageReqVO pageReqVO) { - return activityMapper.selectPage(pageReqVO); + public PageResult 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); } } diff --git a/yudao-ui-admin/src/api/mall/market/banner.js b/yudao-ui-admin/src/api/mall/market/banner.js new file mode 100644 index 000000000..57c55def9 --- /dev/null +++ b/yudao-ui-admin/src/api/mall/market/banner.js @@ -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' + }) +} diff --git a/yudao-ui-admin/src/views/mall/market/banner/index.vue b/yudao-ui-admin/src/views/mall/market/banner/index.vue new file mode 100644 index 000000000..be2e4b213 --- /dev/null +++ b/yudao-ui-admin/src/views/mall/market/banner/index.vue @@ -0,0 +1,288 @@ + + + + + From bb0edc2a654b5eb8c64f112383196db40a021731 Mon Sep 17 00:00:00 2001 From: xiaxiaoYY Date: Tue, 31 May 2022 18:30:24 +0800 Subject: [PATCH 3/3] Banner app api for reveiew --- .../app/banner/AppBannerController.java | 41 +++++++++++++++++++ .../market/service/banner/BannerService.java | 6 +++ .../service/banner/BannerServiceImpl.java | 5 +++ 3 files changed, 52 insertions(+) create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/app/banner/AppBannerController.java diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/app/banner/AppBannerController.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/app/banner/AppBannerController.java new file mode 100644 index 000000000..783179e85 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/app/banner/AppBannerController.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.market.controller.app.banner; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.market.controller.admin.banner.vo.BannerRespVO; +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.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +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; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * @author: XIA + */ +@RestController +@RequestMapping("/market/banner") +@Api(tags = "用户APP- 首页Banner") +@Validated +public class AppBannerController { + + @Autowired + private BannerService bannerService; + + @GetMapping("/list") + @ApiOperation("获得banner列表") + @PreAuthorize("@ss.hasPermission('market:banner:query')") + public CommonResult> getBannerList() { + List list = bannerService.getBannerList(); + return success(BannerConvert.INSTANCE.convertList(list)); + } + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java index 29ae4adac..f69898187 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java @@ -56,6 +56,12 @@ public interface BannerService { */ List getBannerList(Collection ids); + /** + * 获得所有Banner列表 + * @return Banner列表 + */ + List getBannerList(); + /** * 获得Banner分页 * diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java index bd3ded681..d2b25c0a7 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java @@ -72,6 +72,11 @@ public class BannerServiceImpl implements BannerService { return bannerMapper.selectBatchIds(ids); } + @Override + public List getBannerList() { + return bannerMapper.selectList(); + } + @Override public PageResult getBannerPage(BannerPageReqVO pageReqVO) { return bannerMapper.selectPage(pageReqVO);