Files
guoxue-java/src/main/java/com/gxwebsoft/cms/controller/ArticleCommentController.java
T
2026-03-25 15:56:42 +08:00

116 lines
3.7 KiB
Java

package com.gxwebsoft.cms.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.cms.service.ArticleCommentService;
import com.gxwebsoft.cms.entity.ArticleComment;
import com.gxwebsoft.cms.param.ArticleCommentParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 控制器
*
* @author LX
* @since 2025-12-02 16:56:51
*/
@Api(tags = "管理")
@RestController
@RequestMapping("/api/cms/article-comment")
public class ArticleCommentController extends BaseController {
@Resource
private ArticleCommentService articleCommentService;
@ApiOperation("分页查询")
@GetMapping("/page")
public ApiResult<PageResult<ArticleComment>> page(ArticleCommentParam param) {
// 使用关联查询
return success(articleCommentService.pageRel(param));
}
@ApiOperation("查询全部")
@GetMapping()
public ApiResult<List<ArticleComment>> list(ArticleCommentParam param) {
// 使用关联查询
return success(articleCommentService.listRel(param));
}
@PreAuthorize("hasAuthority('cms:articleComment:list')")
@ApiOperation("根据id查询")
@GetMapping("/{id}")
public ApiResult<ArticleComment> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(articleCommentService.getByIdRel(id));
}
@ApiOperation("添加")
@PostMapping()
public ApiResult<?> save(@RequestBody ArticleComment articleComment) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
articleComment.setUserId(loginUser.getUserId());
}
if (articleCommentService.save(articleComment)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("修改")
@PutMapping()
public ApiResult<?> update(@RequestBody ArticleComment articleComment) {
if (articleCommentService.updateById(articleComment)) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("删除")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (articleCommentService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@ApiOperation("批量添加")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ArticleComment> list) {
if (articleCommentService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("批量修改")
@PutMapping("/batch")
public ApiResult<?> updateBatch(@RequestBody BatchParam<ArticleComment> batchParam) {
if (batchParam.update(articleCommentService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("批量删除")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (articleCommentService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}