Kaynağa Gözat

轮播图代码调整

wangzhijun 2 gün önce
ebeveyn
işleme
275fef8f17

+ 0 - 1
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/CouponController.java

@@ -9,7 +9,6 @@ import com.ylx.common.core.domain.R;
 import com.ylx.common.enums.BusinessType;
 import com.ylx.common.utils.StringUtils;
 import com.ylx.massage.domain.Coupon;
-import com.ylx.massage.domain.TLbt;
 import com.ylx.massage.service.CouponService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;

+ 20 - 20
nightFragrance-massage/src/main/java/com/ylx/banner/BannerController.java → nightFragrance-massage/src/main/java/com/ylx/banner/controller/BannerController.java

@@ -1,4 +1,4 @@
-package com.ylx.banner;
+package com.ylx.banner.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -8,9 +8,9 @@ import com.ylx.common.annotation.Log;
 import com.ylx.common.core.domain.R;
 import com.ylx.common.enums.BusinessType;
 import com.ylx.common.exception.ServiceException;
-import com.ylx.massage.domain.TLbt;
+import com.ylx.banner.domain.Banner;
 import com.ylx.massage.domain.dto.TLbtStatusDTO;
-import com.ylx.massage.service.TLbtService;
+import com.ylx.banner.service.BannerService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -33,7 +33,7 @@ import java.util.List;
 public class BannerController {
 
     @Resource
-    private TLbtService lbtService;
+    private BannerService lbtService;
 
     /**
      * 获取轮播图
@@ -42,11 +42,11 @@ public class BannerController {
      */
     @ApiOperation("获取轮播图")
     @RequestMapping(value = "/getAll", method = RequestMethod.GET)
-    public R<List<TLbt>> getAll() {
+    public R<List<Banner>> getAll() {
         try {
-            QueryWrapper<TLbt> wrapper = new QueryWrapper<>();
-            wrapper.lambda().orderByAsc(TLbt::getSort);
-            List<TLbt> list = lbtService.list(wrapper);
+            QueryWrapper<Banner> wrapper = new QueryWrapper<>();
+            wrapper.lambda().orderByAsc(Banner::getSort);
+            List<Banner> list = lbtService.list(wrapper);
             return R.ok(list);
         } catch (Exception e) {
             e.printStackTrace();
@@ -63,7 +63,7 @@ public class BannerController {
     @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
     @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
     @ApiOperation("添加或者更新轮播图")
-    public R addOrUpdate(@RequestBody TLbt lbt) {
+    public R addOrUpdate(@RequestBody Banner lbt) {
         try {
             log.info("请求参数:{}", JSON.toJSONString(lbt));
             return R.ok(lbtService.addOrUpdate(lbt));
@@ -85,14 +85,14 @@ public class BannerController {
      */
     @ApiOperation("分页查询数据")
     @RequestMapping(value = "/select", method = RequestMethod.GET)
-    public R<Page<TLbt>> selectSpfl(Page<TLbt> page, TLbt lbt) {
+    public R<Page<Banner>> selectSpfl(Page<Banner> page, Banner lbt) {
         try {
-            LambdaQueryWrapper<TLbt> tLbtLambdaQueryWrapper = new LambdaQueryWrapper<>();
-            tLbtLambdaQueryWrapper.like(StringUtils.isNotBlank(lbt.getTitle()), TLbt::getTitle, lbt.getTitle()).orderByAsc(TLbt::getSort);
+            LambdaQueryWrapper<Banner> tLbtLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            tLbtLambdaQueryWrapper.like(StringUtils.isNotBlank(lbt.getTitle()), Banner::getTitle, lbt.getTitle()).orderByAsc(Banner::getSort);
             //查询条件添加显示状态
-            tLbtLambdaQueryWrapper.eq(lbt.getStatus() != null, TLbt::getStatus, lbt.getStatus());
+            tLbtLambdaQueryWrapper.eq(lbt.getStatus() != null, Banner::getStatus, lbt.getStatus());
             // 获取查询返回结果
-            Page<TLbt> pageSelect = lbtService.page(page, tLbtLambdaQueryWrapper);
+            Page<Banner> pageSelect = lbtService.page(page, tLbtLambdaQueryWrapper);
             return R.ok(pageSelect);
         } catch (Exception e) {
             e.printStackTrace();
@@ -103,15 +103,15 @@ public class BannerController {
     /**
      * 删除轮播图
      *
-     * @param tLbt
+     * @param banner
      * @return R
      */
     @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
     @RequestMapping(value = "/del", method = RequestMethod.POST)
     @ApiOperation("删除轮播图")
-    public R del(@RequestBody TLbt tLbt) {
+    public R del(@RequestBody Banner banner) {
         try {
-            return R.ok(lbtService.del(tLbt));
+            return R.ok(lbtService.del(banner));
         } catch (ServiceException s) {
             log.error(s.toString());
             return R.fail(s.getMessage());
@@ -145,12 +145,12 @@ public class BannerController {
     /**
      * 根据id查询轮播图
      *
-     * @param tLbt
+     * @param banner
      * @return R
      */
     @ApiOperation("根据id查询轮播图")
     @RequestMapping(value = "/wx/getByid", method = RequestMethod.POST)
-    public R getById(@RequestBody TLbt tLbt) {
-        return R.ok(lbtService.getById(tLbt.getId()));
+    public R getById(@RequestBody Banner banner) {
+        return R.ok(lbtService.getById(banner.getId()));
     }
 }

+ 35 - 0
nightFragrance-massage/src/main/java/com/ylx/banner/controller/ClientBannerController.java

@@ -0,0 +1,35 @@
+package com.ylx.banner.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ylx.banner.domain.Banner;
+import com.ylx.banner.domain.vo.BannerVO;
+import com.ylx.banner.service.BannerService;
+import com.ylx.common.core.domain.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("/banner")
+@Api(tags = {"客户端轮播图"})
+@Slf4j
+public class ClientBannerController {
+
+    @Resource
+    private BannerService bannerService;
+
+    @PreAuthorize("@customerAuth.isCustomer()")
+    @ApiOperation("客户端首页分页查询轮播图数据")
+    @PostMapping("/page")
+    public R<Page<BannerVO>> page(Page<Banner> page) {
+        Page<BannerVO> pageData = this.bannerService.page(page);
+        return R.ok(pageData);
+    }
+
+}

+ 4 - 4
nightFragrance-massage/src/main/java/com/ylx/massage/domain/TLbt.java → nightFragrance-massage/src/main/java/com/ylx/banner/domain/Banner.java

@@ -1,4 +1,4 @@
-package com.ylx.massage.domain;
+package com.ylx.banner.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
@@ -23,9 +23,9 @@ import java.util.Date;
 @Getter
 @Setter
 @Accessors(chain = true)
-@TableName("t_lbt")
-@ApiModel(value = "TLbt", description = "轮播图")
-public class TLbt implements Serializable {
+@TableName("banner")
+@ApiModel(value = "Banner", description = "轮播图")
+public class Banner implements Serializable {
 
     private static final long serialVersionUID = 1L;
 

+ 31 - 0
nightFragrance-massage/src/main/java/com/ylx/banner/domain/vo/BannerVO.java

@@ -0,0 +1,31 @@
+package com.ylx.banner.domain.vo;
+
+import com.ylx.banner.domain.Banner;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel("客户端轮播图VO")
+@Data
+public class BannerVO {
+
+    @ApiModelProperty("主键")
+    private String id;
+
+    @ApiModelProperty("标题")
+    private String title;
+
+    @ApiModelProperty("图片地址")
+    private String imgUrl;
+
+    @ApiModelProperty("跳转地址,支持HTTP链接或内部路由")
+    private String jumpUrl;
+
+    public BannerVO(Banner entity) {
+        this.id = entity.getId();
+        this.title = entity.getTitle();
+        this.imgUrl = entity.getImgUrl();
+        this.jumpUrl = entity.getJumpUrl();
+    }
+
+}

+ 6 - 6
nightFragrance-massage/src/main/java/com/ylx/massage/mapper/TLbtMapper.java → nightFragrance-massage/src/main/java/com/ylx/banner/mapper/BannerMapper.java

@@ -1,15 +1,15 @@
-package com.ylx.massage.mapper;
+package com.ylx.banner.mapper;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
-import com.ylx.massage.domain.TLbt;
+import com.ylx.banner.domain.Banner;
 
 /**
  * 轮播图 Mapper 接口
  */
 @Mapper
-public interface TLbtMapper extends BaseMapper<TLbt> {
+public interface BannerMapper extends BaseMapper<Banner> {
 
     /**
      * 根据ID查询轮播图。
@@ -17,7 +17,7 @@ public interface TLbtMapper extends BaseMapper<TLbt> {
      * @param id 轮播图ID
      * @return 轮播图
      */
-    default TLbt selectLbtById(String id) {
+    default Banner selectLbtById(String id) {
         return selectById(id);
     }
 
@@ -28,7 +28,7 @@ public interface TLbtMapper extends BaseMapper<TLbt> {
      * @return 数量
      */
     default Long countByStatus(Integer status) {
-        return selectCount(new LambdaQueryWrapper<TLbt>().eq(TLbt::getStatus, status));
+        return selectCount(new LambdaQueryWrapper<Banner>().eq(Banner::getStatus, status));
     }
 
     /**
@@ -37,7 +37,7 @@ public interface TLbtMapper extends BaseMapper<TLbt> {
      * @param lbt 轮播图
      * @return 影响行数
      */
-    default int updateLbtById(TLbt lbt) {
+    default int updateLbtById(Banner lbt) {
         return updateById(lbt);
     }
 }

+ 26 - 0
nightFragrance-massage/src/main/java/com/ylx/banner/service/BannerService.java

@@ -0,0 +1,26 @@
+package com.ylx.banner.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ylx.banner.domain.Banner;
+import com.ylx.banner.domain.vo.BannerVO;
+import com.ylx.massage.domain.dto.TLbtStatusDTO;
+
+/**
+ * <p>
+ * 轮播图 服务类
+ * </p>
+ *
+ * @author YJR
+ * @since 2023-11-24
+ */
+public interface BannerService extends IService<Banner> {
+
+    Boolean addOrUpdate(Banner lbt);
+
+    Boolean del(Banner banner);
+
+    Boolean updateStatus(TLbtStatusDTO dto);
+
+    Page<BannerVO> page(Page<Banner> page);
+}

+ 50 - 18
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TLbtServiceImpl.java → nightFragrance-massage/src/main/java/com/ylx/banner/service/impl/BannerServiceImpl.java

@@ -1,31 +1,38 @@
-package com.ylx.massage.service.impl;
+package com.ylx.banner.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ylx.banner.domain.vo.BannerVO;
 import com.ylx.common.exception.ServiceException;
 import com.ylx.common.utils.uuid.IdUtils;
-import com.ylx.massage.domain.TLbt;
+import com.ylx.banner.domain.Banner;
+import com.ylx.giftCard.domain.GiftCard;
+import com.ylx.giftCard.domain.vo.GiftCardVO;
 import com.ylx.massage.domain.dto.TLbtStatusDTO;
-import com.ylx.massage.mapper.TLbtMapper;
-import com.ylx.massage.service.TLbtService;
+import com.ylx.banner.mapper.BannerMapper;
+import com.ylx.banner.service.BannerService;
 import com.ylx.common.utils.DateUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 轮播图 服务实现类
  */
 @Service
-public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TLbtService {
+public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {
     private static final int STATUS_HIDE = 0;
     private static final int STATUS_SHOW = 1;
     private static final long MAX_SHOW_COUNT = 5L;
     private static final long MIN_SHOW_COUNT = 1L;
+    private static final int NOT_DELETE = 0;
 
     @Override
-    public Boolean addOrUpdate(TLbt lbt) {
+    public Boolean addOrUpdate(Banner lbt) {
         if (StringUtils.isBlank(lbt.getImgUrl())) {
             throw new ServiceException("图片不能为空");
         }
@@ -33,8 +40,8 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
             throw new ServiceException("序号不能为空");
         }
         Integer i = lbt.getSort();
-        LambdaQueryWrapper<TLbt> query = new LambdaQueryWrapper<TLbt>().eq(TLbt::getSort, i);
-        TLbt one = getOne(query);
+        LambdaQueryWrapper<Banner> query = new LambdaQueryWrapper<Banner>().eq(Banner::getSort, i);
+        Banner one = getOne(query);
         if (StringUtils.isBlank(lbt.getId())) {
             //新增
             lbt.setId(IdUtils.simpleUUID());
@@ -43,7 +50,7 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
             }
         } else {
             //修改
-            query.ne(TLbt::getId, lbt.getId());
+            query.ne(Banner::getId, lbt.getId());
             if (getOne(query) != null) {
                 batchLbt(i);
             }
@@ -56,22 +63,22 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
      * @param i
      */
     private void batchLbt(Integer i) {
-        LambdaQueryWrapper<TLbt> query1 = new LambdaQueryWrapper<TLbt>().ge(TLbt::getSort, i);
-        List<TLbt> lbts = list(query1);
+        LambdaQueryWrapper<Banner> query1 = new LambdaQueryWrapper<Banner>().ge(Banner::getSort, i);
+        List<Banner> lbts = list(query1);
         lbts.forEach(tLbt1 -> tLbt1.setSort(tLbt1.getSort() + 1));
         updateBatchById(lbts);
     }
 
     @Override
-    public Boolean del(TLbt tLbt) {
-        if (tLbt == null) {
+    public Boolean del(Banner banner) {
+        if (banner == null) {
             throw new ServiceException("参数不能为空");
         }
-        if (StringUtils.isBlank(tLbt.getId())) {
+        if (StringUtils.isBlank(banner.getId())) {
             throw new ServiceException("ID不能为空");
         }
 
-        TLbt exists = baseMapper.selectLbtById(tLbt.getId());
+        Banner exists = baseMapper.selectLbtById(banner.getId());
         if (exists == null) {
             throw new ServiceException("轮播图不存在");
         }
@@ -79,7 +86,7 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
             throw new ServiceException("当前banner已显示,不可删除!");
         }
 
-        boolean removed = this.removeById(tLbt.getId());
+        boolean removed = this.removeById(banner.getId());
         if (!removed) {
             throw new ServiceException("轮播图删除失败");
         }
@@ -98,7 +105,7 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
             throw new ServiceException("显示状态值不正确");
         }
 
-        TLbt exists = baseMapper.selectLbtById(dto.getId());
+        Banner exists = baseMapper.selectLbtById(dto.getId());
         if (exists == null) {
             throw new ServiceException("轮播图不存在");
         }
@@ -114,7 +121,7 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
             throw new ServiceException("当前banner已是最后一条显示,不可关闭!");
         }
 
-        TLbt update = new TLbt();
+        Banner update = new Banner();
         update.setId(dto.getId());
         update.setStatus(dto.getStatus());
         update.setUpdateTime(DateUtils.getNowDate());
@@ -124,4 +131,29 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
         }
         return true;
     }
+
+    @Override
+    public Page<BannerVO> page(Page<Banner> page) {
+
+        LambdaQueryWrapper<Banner> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Banner::getIsDelete, NOT_DELETE);
+        wrapper.eq(Banner::getStatus, STATUS_SHOW);
+        wrapper.orderByDesc(Banner::getSort);
+
+        Page<Banner> bannerPage = this.baseMapper.selectPage(page, wrapper);
+        Page<BannerVO> pageData = new Page<>(
+                bannerPage.getCurrent(),
+                bannerPage.getSize(),
+                bannerPage.getTotal()
+        );
+
+        if (CollectionUtil.isNotEmpty(bannerPage.getRecords())) {
+            List<BannerVO> voList = bannerPage.getRecords().stream()
+                    .map(BannerVO::new)
+                    .collect(Collectors.toList());
+            pageData.setRecords(voList);
+        }
+
+        return pageData;
+    }
 }

+ 1 - 1
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/vo/GiftCardDetailVO.java

@@ -7,7 +7,7 @@ import lombok.Data;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 
-@ApiModel("购物卡详情DTO")
+@ApiModel("购物卡详情VO")
 @Data
 public class GiftCardDetailVO {
 

+ 0 - 22
nightFragrance-massage/src/main/java/com/ylx/massage/service/TLbtService.java

@@ -1,22 +0,0 @@
-package com.ylx.massage.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.ylx.massage.domain.TLbt;
-import com.ylx.massage.domain.dto.TLbtStatusDTO;
-
-/**
- * <p>
- * 轮播图 服务类
- * </p>
- *
- * @author YJR
- * @since 2023-11-24
- */
-public interface TLbtService extends IService<TLbt> {
-
-    Boolean addOrUpdate(TLbt lbt);
-
-    Boolean del(TLbt tLbt);
-
-    Boolean updateStatus(TLbtStatusDTO dto);
-}

+ 2 - 2
nightFragrance-massage/src/main/resources/mapper/massage/TLbtMapper.xml → nightFragrance-massage/src/main/resources/mapper/banner/BannerMapper.xml

@@ -1,9 +1,9 @@
 <?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="com.ylx.massage.mapper.TLbtMapper">
+<mapper namespace="com.ylx.banner.mapper.BannerMapper">
 
     <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.ylx.massage.domain.TLbt">
+    <resultMap id="BaseResultMap" type="com.ylx.banner.domain.Banner">
         <id column="id" property="id" />
         <result column="title" property="title" />
         <result column="img_url" property="imgUrl" />