无关风月
2024-12-31 0c51a577db337520452022d9d6a22b720ef858d4
xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HotWordsController.java
@@ -5,13 +5,16 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinquan.common.core.domain.R;
import com.xinquan.common.core.utils.page.PageDTO;
import com.xinquan.common.security.service.TokenService;
import com.xinquan.common.security.utils.SecurityUtils;
import com.xinquan.system.api.model.LoginUser;
import com.xinquan.system.domain.CommonQuestion;
import com.xinquan.system.domain.HotWords;
import com.xinquan.system.service.HotWordsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -29,20 +32,25 @@
public class HotWordsController {
    @Resource
    private HotWordsService hotWordsService;
    @PostMapping("/list")
    @Autowired
    private TokenService tokenService;
    @GetMapping("/list")
    @ApiOperation(value = "热词管理-列表查询", tags = {"运营中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer")
    })
    public R<PageDTO<HotWords>> list(
            @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
            Integer pageCurr,
             Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.tokenError("登录失效");
        }
        Page<HotWords> page1 = new Page<>(pageCurr, pageSize);
        Page<HotWords> page = hotWordsService.lambdaQuery()
                .orderByDesc(HotWords::getSortNum)
                .page(new Page<>(pageCurr, pageSize));
                .page(page1);
        if (page.getRecords().isEmpty()){
            return R.ok(PageDTO.empty(page));
        }
@@ -54,6 +62,10 @@
    @PostMapping("/add")
    @ApiOperation(value = "热词管理-添加热词", tags = {"管理后台-运营中心"})
    public R add(@RequestBody HotWords hotWords) {
        int size = hotWordsService.lambdaQuery().list().size();
        if (size>=20){
            return R.fail("热词数量已达上限");
        }
        hotWordsService.save(hotWords);
        return R.ok();
    }
@@ -71,13 +83,13 @@
        hotWordsService.update(hotWordsLambdaUpdateWrapper);
        return R.ok();
    }
    @DeleteMapping("/add")
    @DeleteMapping("/delete")
    @ApiOperation(value = "热词管理-删除热词", tags = {"管理后台-运营中心"})
    public R add(String id) {
        hotWordsService.removeById(id);
        hotWordsService.removeById(Long.valueOf(id));
        return R.ok();
    }
    @DeleteMapping("/queryAddCount")
    @GetMapping("/queryAddCount")
    @ApiOperation(value = "热词管理-查询还可以上传多少个热词", tags = {"管理后台-运营中心"})
    public R queryAddCount() {
        int i = 20 - hotWordsService.lambdaQuery().list().size();