无关风月
2024-10-14 039a33d1bfa6ef041161666bbd120c34086fe7c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.xinquan.system.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.utils.SecurityUtils;
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.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 热词表     前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/system/hot-words")
public class HotWordsController {
    @Resource
    private HotWordsService hotWordsService;
    @PostMapping("/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("登录失效");
        Page<HotWords> page = hotWordsService.lambdaQuery()
                .orderByDesc(HotWords::getSortNum)
                .page(new Page<>(pageCurr, pageSize));
        if (page.getRecords().isEmpty()){
            return R.ok(PageDTO.empty(page));
        }
        for (HotWords record : page.getRecords()) {
            record.setUid(record.getId()+"");
        }
        return R.ok(PageDTO.of(page, HotWords.class));
    }
    @PostMapping("/add")
    @ApiOperation(value = "热词管理-添加热词", tags = {"管理后台-运营中心"})
    public R add(@RequestBody HotWords hotWords) {
        hotWordsService.save(hotWords);
        return R.ok();
    }
    @PostMapping("/update")
    @ApiOperation(value = "热词管理-编辑热词", tags = {"管理后台-运营中心"})
    public R update(@RequestBody HotWords hotWords) {
        LambdaUpdateWrapper<HotWords> hotWordsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        if (hotWords.getSortNum()==null){
            hotWordsLambdaUpdateWrapper.set(HotWords::getSortNum,null);
        }else{
            hotWordsLambdaUpdateWrapper.set(HotWords::getSortNum,hotWords.getSortNum());
        }
        hotWordsLambdaUpdateWrapper.set(HotWords::getWordName,hotWords.getWordName());
        hotWordsLambdaUpdateWrapper.eq(HotWords::getId,hotWords.getId());
        hotWordsService.update(hotWordsLambdaUpdateWrapper);
        return R.ok();
    }
    @DeleteMapping("/add")
    @ApiOperation(value = "热词管理-删除热词", tags = {"管理后台-运营中心"})
    public R add(String id) {
        hotWordsService.removeById(id);
        return R.ok();
    }
    @DeleteMapping("/queryAddCount")
    @ApiOperation(value = "热词管理-查询还可以上传多少个热词", tags = {"管理后台-运营中心"})
    public R queryAddCount() {
        int i = 20 - hotWordsService.lambdaQuery().list().size();
        return R.ok(i);
    }
}