| | |
| | | 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.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.List; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | |
| | | // banner实现类 |
| | | private final XpBannerService xpBannerService; |
| | | private final AliOssService aliOssService; |
| | | |
| | | public XpBannerManagementController(XpBannerService xpBannerService) { |
| | | public XpBannerManagementController(XpBannerService xpBannerService, AliOssService aliOssService) { |
| | | this.xpBannerService = xpBannerService; |
| | | this.aliOssService = aliOssService; |
| | | } |
| | | |
| | | |
| | |
| | | PageInfo<XpBanner> pageList = xpBannerService.pageList(query); |
| | | return R.ok(pageList); |
| | | } |
| | | @ApiOperation(value = "新增banner") |
| | | @PostMapping("/saveBanner") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.BANNER_MANAGEMENT, |
| | | operationType = AdminOperationType.ADD, |
| | | content = "新增banner", |
| | | appendRequestData = true |
| | | ) |
| | | public R saveBanner(@RequestBody XpBanner dto) { |
| | | xpBannerService.save(dto); |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "修改banner") |
| | | @PostMapping("/updateBanner") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.BANNER_MANAGEMENT, |
| | | operationType = AdminOperationType.EDIT, |
| | | content = "修改banner", |
| | | appendRequestData = true |
| | | ) |
| | | public R updateBanner(@RequestBody XpBanner dto) { |
| | | xpBannerService.updateById(dto); |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "详情banner") |
| | | @GetMapping("/detailBanner") |
| | | public R<XpBanner> detailBanner(Long id) { |
| | | XpBanner xpBanner = xpBannerService.getById(id); |
| | | |
| | | JSONObject jsonObject = JSON.parseArray(xpBanner.getBannerPictures()).getJSONObject(0); |
| | | String downloadUrl = null; |
| | | try { |
| | | // 1 |
| | | downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | jsonObject.put("url", downloadUrl); |
| | | xpBanner.setBannerPictures(jsonObject.toJSONString()); |
| | | |
| | | |
| | | |
| | | |
| | | return R.ok(xpBanner); |
| | | } |
| | | @ApiOperation(value = "删除banner") |
| | | @DeleteMapping("/deleteBanner") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.BANNER_MANAGEMENT, |
| | | operationType = AdminOperationType.DELETE, |
| | | contentExpression = "'删除banner,id=' + #p0", |
| | | appendRequestData = false |
| | | ) |
| | | public R deleteBanner(Long id) { |
| | | xpBannerService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |