package com.xiaopeng.operation.controller; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.xiaopeng.api.model.operation.XpBanner; import com.xiaopeng.api.model.operation.XpWhitelist; import com.xiaopeng.common.core.domain.R; import com.xiaopeng.common.core.web.controller.BaseController; import com.xiaopeng.common.core.web.page.PageInfo; import com.xiaopeng.evi.oss.service.AliOssService; import com.xiaopeng.operation.query.BannerPageListQuery; import com.xiaopeng.operation.query.WhitelistPageListQuery; import com.xiaopeng.operation.service.XpBannerService; import com.xiaopeng.operation.vo.XpBannerListVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import java.io.UnsupportedEncodingException; import java.util.List; @Slf4j @RestController @RequestMapping("/api/v1/banner") @Api(tags = "管理后台-banner模块") public class XpBannerManagementController extends BaseController { // banner实现类 private final XpBannerService xpBannerService; private final AliOssService aliOssService; public XpBannerManagementController(XpBannerService xpBannerService, AliOssService aliOssService) { this.xpBannerService = xpBannerService; this.aliOssService = aliOssService; } @ApiOperation(value = "banner分页列表") @PostMapping("/pageList") public R> pageList(@RequestBody BannerPageListQuery query) { PageInfo pageList = xpBannerService.pageList(query); return R.ok(pageList); } @ApiOperation(value = "新增banner") @PostMapping("/saveBanner") public R saveBanner(@RequestBody XpBanner dto) { xpBannerService.save(dto); return R.ok(); } @ApiOperation(value = "修改banner") @PostMapping("/updateBanner") public R updateBanner(@RequestBody XpBanner dto) { xpBannerService.updateById(dto); return R.ok(); } @ApiOperation(value = "详情banner") @GetMapping("/detailBanner") public R detailBanner(Long id) { XpBanner xpBanner = xpBannerService.getById(id); JSONObject jsonObject = JSON.parseArray(xpBanner.getBannerPictures()).getJSONObject(0); String downloadUrl = null; try { // 2 downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } xpBanner.setBannerPictures(downloadUrl); return R.ok(xpBanner); } @ApiOperation(value = "删除banner") @DeleteMapping("/deleteBanner") public R deleteBanner(Long id) { xpBannerService.removeById(id); return R.ok(); } }