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.Notices;
import com.ruoyi.admin.service.NoticesService;
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("/notices")
@Api(tags = {"后台-系统设置-系统通知管理"})
public class NoticesController {
@Resource
private NoticesService noticesService;
/**
* 系统通知分页列表
*
* @param pageNum 页码
* @param pageSize 每页显示条数
*/
@RequiresPermissions("system_notice")
@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) {
return R.ok(noticesService.lambdaQuery().eq(Notices::getIsDelete, 0)
.orderByDesc(Notices::getCreateTime).page(Page.of(pageNum, pageSize)));
}
/**
* 系统通知列表
* -- 远程调用
*/
@ApiOperation(value = "系统通知列表(不分页)", tags = {"后台-系统设置-系统通知管理"})
@GetMapping(value = "/noticesList")
public R> noticesList() {
return R.ok(noticesService.lambdaQuery().eq(Notices::getIsDelete, 0)
.orderByDesc(Notices::getCreateTime).list());
}
/**
* 系统通知详情
* -- 远程调用
*/
@ApiOperation(value = "系统通知详情", tags = {"后台-系统设置-系统通知管理"})
@GetMapping(value = "/noticesDetail")
public R noticesDetail(@RequestParam("id") Integer id) {
return R.ok(noticesService.lambdaQuery().eq(Notices::getIsDelete, 0)
.eq(Notices::getId, id).one());
}
/**
* 系统通知详情
*
* @param id 系统通知id
*/
@RequiresPermissions("notice_detail")
@ApiOperation(value = "系统通知详情", tags = {"后台-系统设置-系统通知管理"})
@GetMapping(value = "/detail")
@ApiImplicitParams({
@ApiImplicitParam(value = "系统通知id", name = "id", dataType = "Integer", required = true)
})
public R detail(@RequestParam Integer id) {
return R.ok(noticesService.getById(id));
}
/**
* 新增系统通知
*
* @param notices 系统通知信息
*/
@RequiresPermissions("notice_save")
@ApiOperation(value = "新增系统通知", tags = {"后台-系统设置-系统通知管理"})
@PostMapping(value = "/save")
public R save(@RequestBody Notices notices) {
notices.setNoticeDetail(String.valueOf(notices.getNoticeDetail()));
return noticesService.save(notices) ? R.ok() : R.fail();
}
/**
* 修改系统通知
*
* @param notices 系统通知信息
*/
@RequiresPermissions("notice_update")
@ApiOperation(value = "修改系统通知", tags = {"后台-系统设置-系统通知管理"})
@PostMapping(value = "/update")
public R update(@RequestBody Notices notices) {
return noticesService.updateById(notices) ? R.ok() : R.fail();
}
/**
* 根据id批量删除系统通知
*
* @param ids 系统通知多条id拼接
*/
@RequiresPermissions("notice_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 = noticesService.lambdaQuery().in(Notices::getId, idList).list();
list.forEach(data -> data.setIsDelete(1));
return noticesService.updateBatchById(list) ? R.ok() : R.fail();
}
}