package com.ruoyi.admin.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.admin.entity.RecoveryServe; import com.ruoyi.admin.entity.Rotate; import com.ruoyi.admin.service.RecoveryServeService; import com.ruoyi.admin.service.RotateService; import com.ruoyi.admin.vo.RotateResultVO; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.security.annotation.RequiresPermissions; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /** *

* 轮播图图片管理 前端控制器 *

* * @author hjl * @since 2024-05-29 */ @RestController @RequestMapping("/rotate") @Api(tags = {"后台-系统设置-轮播图管理"}) public class RotateController { @Resource private RotateService rotateService; @Resource private RecoveryServeService recoveryServeService; /** * 轮播图图片分页列表 * * @param pageNum 页码 * @param pageSize 每页显示条数 * @return 封装分页数据 */ @RequiresPermissions("system_rotate") @ApiOperation(value = "轮播图分页查询列表", tags = {"后台-系统设置-轮播图管理"}) @GetMapping(value = "/page") @ApiImplicitParams({ @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true), @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true) }) public R> queryPageList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { IPage rotateIPage = rotateService.queryPage(Page.of(pageNum, pageSize)); for (Rotate record : rotateIPage.getRecords()) { if (record.getIsRotate()==0){ record.setServeName("不跳转"); } } return R.ok(rotateIPage); } /** * 轮播图列表 */ @GetMapping(value = "/bannerList") public R> bannerList() { return R.ok(rotateService.lambdaQuery() .eq(Rotate::getIsDelete, 0) .orderByDesc(Rotate::getSort).list()); } /** * 轮播图详情 * * @param id 轮播图id * @return 封装分页数据 */ @RequiresPermissions("rotate_detail") @ApiOperation(value = "轮播图详情", tags = {"后台-系统设置-轮播图管理"}) @GetMapping(value = "/detail") @ApiImplicitParams({ @ApiImplicitParam(value = "轮播图id", name = "id", dataType = "Integer", required = true) }) public R detail(@RequestParam Integer id) { RotateResultVO rotateResultVO = new RotateResultVO(); Rotate rotate = rotateService.getById(id); rotateResultVO.setRotate(rotate); if (null != rotate.getRotateServeId()) { RecoveryServe recoveryServe = recoveryServeService.lambdaQuery() .eq(RecoveryServe::getId, rotate.getRotateServeId()) .eq(RecoveryServe::getIsDelete, 0).one(); rotateResultVO.setRecoveryServe(recoveryServe); } return R.ok(rotateResultVO); } /** * 新增轮播图 * * @param rotate 轮播图信息 * @return 封装分页数据 */ @RequiresPermissions("rotate_save") @ApiOperation(value = "新增轮播图", tags = {"后台-系统设置-轮播图管理"}) @PostMapping(value = "/save") public R save(@RequestBody Rotate rotate) { return rotateService.save(rotate) ? R.ok() : R.fail(); } /** * 修改轮播图 * * @param rotate 轮播图信息 * @return 封装分页数据 */ @RequiresPermissions("rotate_update") @ApiOperation(value = "修改轮播图", tags = {"后台-系统设置-轮播图管理"}) @PostMapping(value = "/update") public R update(@RequestBody Rotate rotate) { return rotateService.updateById(rotate) ? R.ok() : R.fail(); } /** * 根据id批量删除轮播图 * * @param ids 轮播图多条id拼接 * @return 封装分页数据 */ @RequiresPermissions("rotate_delete") @ApiOperation(value = "批量删除轮播图", tags = {"后台-系统设置-轮播图管理"}) @GetMapping(value = "/batchDelete") @ApiImplicitParams({ @ApiImplicitParam(value = "多个id ',' 拼接", name = "ids", dataType = "String", required = true) }) public R batchDelete(@RequestParam String ids) { List idList = Arrays.stream(ids.split(",")).collect(Collectors.toList()); List list = rotateService.lambdaQuery().in(Rotate::getId, idList).list(); list.forEach(data -> data.setIsDelete(1)); return rotateService.updateBatchById(list) ? R.ok() : R.fail(); } }