diff --git a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java index 15e9895..273d19c 100644 --- a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java +++ b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java @@ -34,6 +34,7 @@ import com.cultural.heritage.service.book.BookingDateService; import com.cultural.heritage.service.book.BookingTimeService; import com.cultural.heritage.service.book.PhotoProductsService; import com.cultural.heritage.service.common.CommonService; +import com.cultural.heritage.utils.DecoderUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -321,6 +322,7 @@ public class PhotoProductsController { PhotoProducts photoProducts = photoProductsService.getById(id); PhotoProductsMainInfoVO photoProductsMainInfoVO = new PhotoProductsMainInfoVO(); BeanUtils.copyProperties(photoProducts, photoProductsMainInfoVO); + photoProductsMainInfoVO.setRichText(DecoderUtils.decodeText(photoProductsMainInfoVO.getRichText())); return ResultUtils.success(photoProductsMainInfoVO); } @@ -420,6 +422,7 @@ public class PhotoProductsController { // 封装成BookingPhotoProductsVO列表 PhotoProductsVO photoProductsVO = new PhotoProductsVO(); BeanUtils.copyProperties(photoProducts, photoProductsVO); + photoProductsVO.setRichText(DecoderUtils.decodeText(photoProductsVO.getRichText())); // TODO // photoProductsVO.setIntroImg(FileConstant.SERVER_HOST + photoProductsVO.getIntroImg()); photoProductsVO.setBookingDateVOList(bookingDateVOList); diff --git a/src/main/java/com/cultural/heritage/controller/other/BannerController.java b/src/main/java/com/cultural/heritage/controller/other/BannerController.java new file mode 100644 index 0000000..abe77cd --- /dev/null +++ b/src/main/java/com/cultural/heritage/controller/other/BannerController.java @@ -0,0 +1,155 @@ +package com.cultural.heritage.controller.other; + + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.cultural.heritage.annotation.AuthCheck; +import com.cultural.heritage.common.BaseResponse; +import com.cultural.heritage.common.ErrorCode; +import com.cultural.heritage.common.ResultUtils; +import com.cultural.heritage.constant.UserConstant; +import com.cultural.heritage.exception.BusinessException; +import com.cultural.heritage.exception.ThrowUtils; +import com.cultural.heritage.model.dto.CommonRequest; +import com.cultural.heritage.model.dto.CommonStringRequest; +import com.cultural.heritage.model.dto.banner.BannerAddRequest; +import com.cultural.heritage.model.dto.banner.BannerQueryRequest; +import com.cultural.heritage.model.dto.banner.BannerUpdateRequest; +import com.cultural.heritage.model.entity.Banner; +import com.cultural.heritage.model.vo.banner.BannerVO; +import com.cultural.heritage.service.common.CommonService; +import com.cultural.heritage.service.other.BannerService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/banner") +@Slf4j +@Tag(name = "轮播图管理") +public class BannerController { + + + @Resource + private BannerService bannerService; + + + @Resource + private CommonService commonService; + + + /** + * web端管理员添加轮播图 + * @param bannerAddRequest 轮播图添加请求体 + * @return 是否添加成功 + */ + @PostMapping("/add") + @Operation(summary = "web端管理员添加轮播图", description = "参数:轮播图添加请求体,权限:管理员(boss, admin),方法名:addBanner") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse addBanner(@RequestBody BannerAddRequest bannerAddRequest) { + if (bannerAddRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Banner banner = new Banner(); + BeanUtils.copyProperties(bannerAddRequest, banner); + bannerService.validBanner(banner, false); + boolean result = bannerService.save(banner); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "轮播图添加失败"); + return ResultUtils.success(true); + } + + + + /** + * web端管理员删除轮播图 + * @param commonRequest 轮播图id + * @return 是否成功删除 + */ + @PostMapping("/delete") + @Operation(summary = "web端管理员删除轮播图", description = "参数:轮播图id,权限:管理员(boss, admin),方法名:delBanner") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse delBanner(@RequestBody CommonRequest commonRequest) { + if (commonRequest == null || commonRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = commonRequest.getId(); + boolean result = bannerService.removeById(id); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "轮播图删除失败"); + return ResultUtils.success(true); + } + + + + + /** + * web端管理员更新轮播图 + * @param bannerUpdateRequest 轮播图更新请求体 + * @return 是否更新成功 + */ + @PostMapping("/update") + @Operation(summary = "web端管理员更新轮播图", description = "参数:轮播图更新请求体,权限:管理员(boss, admin),方法名:updateBanner") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse updateBanner(@RequestBody BannerUpdateRequest bannerUpdateRequest) { + if (bannerUpdateRequest == null || bannerUpdateRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Banner banner = new Banner(); + BeanUtils.copyProperties(bannerUpdateRequest, banner); + bannerService.validBanner(banner, true); + boolean result = bannerService.updateById(banner); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "轮播图更新失败"); + return ResultUtils.success(true); + } + + + + + + /** + * Web端管理员分页查看轮播图 + * @return 轮播图列表 + */ + @PostMapping("/query/web") + @Operation(summary = "Web端管理员分页查看轮播图", description = "参数:无,权限:管理员(boss, admin),方法名:listBannerByPage") + public BaseResponse> listBannerByPage(@RequestBody BannerQueryRequest bannerQueryRequest) { + if (bannerQueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR); + long current = bannerQueryRequest.getCurrent(); + long pageSize = bannerQueryRequest.getPageSize(); + Page page = bannerService.page(new Page<>(current, pageSize),null); + List bannerList = page.getRecords(); + List bannerVOList = commonService.convertList(bannerList, BannerVO.class); + Page voPage = new Page<>(); + voPage.setRecords(bannerVOList); + voPage.setPages(page.getPages()); + voPage.setCurrent(page.getCurrent()); + voPage.setTotal(page.getTotal()); + voPage.setSize(page.getSize()); + return ResultUtils.success(voPage); + } + + + + /** + * 小程序用户根据类型查看轮播图 + * @return 轮播图列表 + */ + @GetMapping("/query") + @Operation(summary = "小程序用户根据类型查看轮播图", description = "参数:无,权限:所有人,方法名:queryBannerByType") + public BaseResponse> queryBannerByType(@RequestBody CommonStringRequest commonStringRequest) { + if (commonStringRequest == null || StringUtils.isBlank(commonStringRequest.getType())) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + String type = commonStringRequest.getType(); + List bannerList = commonService.findByFieldEqTargetField("type", type, bannerService); + List bannerVOList = commonService.convertList(bannerList, BannerVO.class); + return ResultUtils.success(bannerVOList); + } + + + +} diff --git a/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java b/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java index 5d01fc8..ffe13c5 100644 --- a/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java +++ b/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java @@ -118,27 +118,9 @@ public class WeChatController { } - - - /** - * 小程序用户查看文章 - * @return 用户地址列表 - */ - @GetMapping("/query") - @Operation(summary = "小程序用户查看文章", description = "参数:无,权限:所有人,方法名:queryAllArticle") - public BaseResponse> queryAllArticle() { - List officialAccountArticleList = weChatOfficialAccountService.list(); - List officialAccountArticleVOS = commonService.convertList(officialAccountArticleList, OfficialAccountArticleVO.class); - Collections.reverse(officialAccountArticleVOS); - return ResultUtils.success(officialAccountArticleVOS); - } - - - - /** * Web端管理员分页查看文章 - * @return 用户地址列表 + * @return 公众号文章列表 */ @PostMapping("/query/web") @Operation(summary = "Web端管理员分页查看文章", description = "参数:无,权限:web端管理员,方法名:listArticleByPage") @@ -160,6 +142,24 @@ public class WeChatController { + /** + * 小程序用户查看文章 + * @return 公众号文章列表 + */ + @GetMapping("/query") + @Operation(summary = "小程序用户查看文章", description = "参数:无,权限:所有人,方法名:queryAllArticle") + public BaseResponse> queryAllArticle() { + List officialAccountArticleList = weChatOfficialAccountService.list(); + List officialAccountArticleVOS = commonService.convertList(officialAccountArticleList, OfficialAccountArticleVO.class); + Collections.reverse(officialAccountArticleVOS); + return ResultUtils.success(officialAccountArticleVOS); + } + + + + + + diff --git a/src/main/java/com/cultural/heritage/mapper/BannerMapper.java b/src/main/java/com/cultural/heritage/mapper/BannerMapper.java new file mode 100644 index 0000000..1e884de --- /dev/null +++ b/src/main/java/com/cultural/heritage/mapper/BannerMapper.java @@ -0,0 +1,8 @@ +package com.cultural.heritage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.cultural.heritage.model.entity.Banner; + +public interface BannerMapper extends BaseMapper { + +} diff --git a/src/main/java/com/cultural/heritage/model/dto/article/OfficialAccountArticleQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/article/OfficialAccountArticleQueryRequest.java index 8a8653e..6e6617d 100644 --- a/src/main/java/com/cultural/heritage/model/dto/article/OfficialAccountArticleQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/article/OfficialAccountArticleQueryRequest.java @@ -2,11 +2,13 @@ package com.cultural.heritage.model.dto.article; import com.cultural.heritage.common.PageRequest; import lombok.Data; +import lombok.EqualsAndHashCode; import java.io.Serial; import java.io.Serializable; +@EqualsAndHashCode(callSuper = true) @Data public class OfficialAccountArticleQueryRequest extends PageRequest implements Serializable { diff --git a/src/main/java/com/cultural/heritage/model/dto/banner/BannerAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/banner/BannerAddRequest.java new file mode 100644 index 0000000..71f0549 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/banner/BannerAddRequest.java @@ -0,0 +1,31 @@ +package com.cultural.heritage.model.dto.banner; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Schema(description = "轮播图添加请求体", requiredProperties = {"type", "url"}) +public class BannerAddRequest implements Serializable { + + + /** + * 类型 + */ + @Schema(description = "类型") + private String type; + + + /** + * URL + */ + @Schema(description = "URL") + private String url; + + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/banner/BannerQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/banner/BannerQueryRequest.java new file mode 100644 index 0000000..a07f20d --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/banner/BannerQueryRequest.java @@ -0,0 +1,19 @@ +package com.cultural.heritage.model.dto.banner; + +import com.cultural.heritage.common.PageRequest; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; +import java.io.Serializable; + +@EqualsAndHashCode(callSuper = true) +@Data +public class BannerQueryRequest extends PageRequest implements Serializable { + + + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/banner/BannerUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/banner/BannerUpdateRequest.java new file mode 100644 index 0000000..91c9d99 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/banner/BannerUpdateRequest.java @@ -0,0 +1,36 @@ +package com.cultural.heritage.model.dto.banner; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Schema(description = "轮播图更新请求体", requiredProperties = {"id", "type", "url"}) +public class BannerUpdateRequest implements Serializable { + + /** + * id + */ + @Schema(description = "id") + private Long id; + + + /** + * 类型 + */ + @Schema(description = "类型") + private String type; + + + /** + * URL + */ + @Schema(description = "URL") + private String url; + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/entity/Banner.java b/src/main/java/com/cultural/heritage/model/entity/Banner.java new file mode 100644 index 0000000..d6fc539 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/entity/Banner.java @@ -0,0 +1,62 @@ +package com.cultural.heritage.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + +/** + * 轮播图 + * @TableName banner + */ +@Data +@TableName("banner") +public class Banner implements Serializable { + + + /** + * id + */ + @TableId(type = IdType.AUTO) + private Long id; + + + /** + * 类型 + */ + private String type; + + + /** + * URL + */ + private String url; + + + /** + * 创建时间 + */ + private Date createTime; + + + /** + * 更新时间 + */ + private Date updateTime; + + + /** + * 是否删除 + */ + private Integer isDelete; + + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/entity/OfficialAccountArticle.java b/src/main/java/com/cultural/heritage/model/entity/OfficialAccountArticle.java index 6fbbe86..5e18756 100644 --- a/src/main/java/com/cultural/heritage/model/entity/OfficialAccountArticle.java +++ b/src/main/java/com/cultural/heritage/model/entity/OfficialAccountArticle.java @@ -7,10 +7,11 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.util.Date; /** - * 商品 + * 公众号文章 * @TableName official_account_article */ @Data @@ -47,6 +48,24 @@ public class OfficialAccountArticle implements Serializable { private String url; + /** + * 创建时间 + */ + private Date createTime; + + + /** + * 更新时间 + */ + private Date updateTime; + + + /** + * 是否删除 + */ + private Integer isDelete; + + @Serial private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/cultural/heritage/model/vo/banner/BannerVO.java b/src/main/java/com/cultural/heritage/model/vo/banner/BannerVO.java new file mode 100644 index 0000000..91e4c2f --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/vo/banner/BannerVO.java @@ -0,0 +1,32 @@ +package com.cultural.heritage.model.vo.banner; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class BannerVO implements Serializable { + + + /** + * id + */ + private Long id; + + + /** + * 类型 + */ + private String type; + + + /** + * URL + */ + private String url; + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/service/other/BannerService.java b/src/main/java/com/cultural/heritage/service/other/BannerService.java new file mode 100644 index 0000000..2b1a6da --- /dev/null +++ b/src/main/java/com/cultural/heritage/service/other/BannerService.java @@ -0,0 +1,13 @@ +package com.cultural.heritage.service.other; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.cultural.heritage.model.entity.Banner; + +public interface BannerService extends IService { + + + /** + * 校验参数 + */ + void validBanner(Banner banner, boolean update); +} diff --git a/src/main/java/com/cultural/heritage/service/other/impl/BannerServiceImpl.java b/src/main/java/com/cultural/heritage/service/other/impl/BannerServiceImpl.java new file mode 100644 index 0000000..97f127d --- /dev/null +++ b/src/main/java/com/cultural/heritage/service/other/impl/BannerServiceImpl.java @@ -0,0 +1,25 @@ +package com.cultural.heritage.service.other.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.cultural.heritage.common.ErrorCode; +import com.cultural.heritage.exception.ThrowUtils; +import com.cultural.heritage.mapper.BannerMapper; +import com.cultural.heritage.model.entity.Banner; +import com.cultural.heritage.service.other.BannerService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +@Service +public class BannerServiceImpl extends ServiceImpl implements BannerService { + + + + @Override + public void validBanner(Banner banner, boolean update) { + Long id = banner.getId(); + String type = banner.getType(); + String url = banner.getUrl(); + ThrowUtils.throwIf(update && id == null, ErrorCode.OPERATION_ERROR, "id参数错误"); + ThrowUtils.throwIf(StringUtils.isAnyBlank(type, url), ErrorCode.OPERATION_ERROR, "存在参数为空"); + } +} diff --git a/src/main/resources/mapper/BannerMapper.xml b/src/main/resources/mapper/BannerMapper.xml new file mode 100644 index 0000000..af59958 --- /dev/null +++ b/src/main/resources/mapper/BannerMapper.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file