LAOP-admin/src/main/java/com/haisen/laop/controller/AppBannerController.java
2026-09-18 16:45:38 +08:00

135 lines
4.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.haisen.laop.controller;
import com.haisen.laop.common.Result;
import com.haisen.laop.dto.AppBannerQueryDTO;
import com.haisen.laop.dto.AppBannerSaveDTO;
import com.haisen.laop.service.AppBannerService;
import com.haisen.laop.vo.AppBannerVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* 轮播图模块 —— Web 后台管理端 Controller。
*
* <p><b>消费端:</b>Web 管理后台(管理员电脑端操作)。
* <p><b>路径前缀:</b>{@code /banner/*},与小程序端展示接口(待扩展)严格隔离。
* <p><b>职责:</b>承载首页轮播图的维护操作(分页查询、详情、新增、编辑、排序调整、启停、删除),
* 业务逻辑全部委托 {@link AppBannerService},本层只做参数接收与 Result 包装。</p>
*
* @author duhao
*/
@RestController
@RequestMapping("/banner")
@RequiredArgsConstructor
public class AppBannerController {
private final AppBannerService appBannerService;
/**
* 轮播图分页列表。
*
* <p>返回结构与项目其他分页约定保持一致:{list, totalElements, totalPages, pageNo, pageSize},
* 其中 pageNo 为 0 基页码。</p>
*
* @param query 筛选条件(GET 参数自动绑定,全部可选)
* @return 轮播图 VO 分页数据
*/
@GetMapping("/list")
public Result<Map<String, Object>> list(AppBannerQueryDTO query) {
Page<AppBannerVO> page = appBannerService.page(query);
Map<String, Object> data = new HashMap<>();
data.put("list", page.getContent());
data.put("totalElements", page.getTotalElements());
data.put("totalPages", page.getTotalPages());
data.put("pageNo", page.getNumber());
data.put("pageSize", page.getSize());
return Result.success(data);
}
/**
* 轮播图详情,用于编辑回显。
*
* @param id 轮播图 ID
* @return 轮播图 VO
*/
@GetMapping("/{id}")
public Result<AppBannerVO> detail(@PathVariable Long id) {
return Result.success(appBannerService.detail(id));
}
/**
* 新增轮播图。
*
* @param dto 轮播图表单全部字段
* @return 新增轮播图的 ID
*/
@PostMapping
public Result<Long> create(@Valid @RequestBody AppBannerSaveDTO dto) {
return Result.success(appBannerService.create(dto));
}
/**
* 编辑轮播图(全量更新)。
*
* @param id 轮播图 ID
* @param dto 轮播图表单全部字段
* @return 空数据成功响应
*/
@PutMapping("/{id}")
public Result<Void> update(@PathVariable Long id, @Valid @RequestBody AppBannerSaveDTO dto) {
appBannerService.update(id, dto);
return Result.success();
}
/**
* 删除轮播图(软删除)。
*
* @param id 轮播图 ID
* @return 空数据成功响应
*/
@DeleteMapping("/{id}")
public Result<Void> remove(@PathVariable Long id) {
appBannerService.delete(id);
return Result.success();
}
/**
* 切换轮播图展示状态(显示/隐藏)。
*
* @param id 轮播图 ID
* @param status 目标状态:0隐藏 1显示
* @return 空数据成功响应
*/
@PostMapping("/{id}/status")
public Result<Void> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
appBannerService.updateStatus(id, status);
return Result.success();
}
/**
* 调整轮播图排序值。
*
* @param id 轮播图 ID
* @param sortOrder 目标排序值
* @return 空数据成功响应
*/
@PostMapping("/{id}/sort")
public Result<Void> updateSort(@PathVariable Long id, @RequestParam Integer sortOrder) {
appBannerService.updateSort(id, sortOrder);
return Result.success();
}
}