mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.dg.core.controller;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dg.core.ResultData;
import com.dg.core.annotation.Authorization;
import com.dg.core.db.gen.entity.KeywordEntity;
import com.dg.core.service.IKeywordService;
import com.dg.core.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@Api(tags = {"关键词接口"})
@RestController
@RequestMapping("/keyword")
public class KeywordController extends BaseController
{
    @Autowired(required = true)
    IKeywordService iKeywordService;
 
    /**
     * 查询关键词列表
     * @return
     */
    @ApiOperation("关键词列表接口")
    @GetMapping("/getlist")
    @Authorization
    public TableDataInfo selectConfigList(@RequestParam(value = "pageNum",required = false) Integer pageNum,
                                          @RequestParam(value = "pageSize",required = false) Integer pageSize)
    {
        Assert.notNull(pageNum, "pageNum can not be empty");
        Assert.notNull(pageSize, "pageSize can not be empty");
        Page<KeywordEntity> pageParam = new Page<>(pageNum,pageSize);
        List<KeywordEntity> list = iKeywordService.selectConfigList(pageParam,pageSize);
 
        int num=iKeywordService.countNum();
        return getDataTable(list,num);
    }
 
    /**
     * 查询详情
     * @return
     */
    @ApiOperation("关键词详情接口")
    @GetMapping("/getData")
    @Authorization
    public ResultData selectConfigData(@RequestParam(value = "id",required = false) String id,
                                       @RequestParam(value = "name",required = false) String name)
    {
        return ResultData.success(iKeywordService.selectConfigData(id,name));
    }
 
 
    /**
     * 添加关键词
     * @return
     */
    @ApiOperation("关键词添加接口")
    @PostMapping("/add")
    @Authorization
    public ResultData insertConfig(@RequestBody KeywordEntity entity)
    {
        KeywordEntity enti=iKeywordService.selectConfigData("",entity.getName());
        if(enti==null)
        {
            if(iKeywordService.insertConfig(entity)>0)
            {
                enti=iKeywordService.selectConfigData("",entity.getName());
                return ResultData.success(enti);
            }
        }
        else
        {
            return ResultData.success(enti);
        }
        return ResultData.error("创建数据失败");
    }
 
    /**
     * 编辑关键词
     * @return
     */
    @ApiOperation("关键词编辑接口")
    @PostMapping("/update")
    @Authorization
    public ResultData updateConfig(@RequestBody KeywordEntity entity)
    {
        return toAjax(iKeywordService.updateConfig(entity));
    }
 
    /**
     * 删除关键词
     * @param Id
     * @return
     */
    @ApiOperation("关键词删除接口")
    @DeleteMapping("/delete")
    @Authorization
    public ResultData deleteConfigById(String Id)
    {
        return toAjax(iKeywordService.deleteConfigById(Id));
    }
 
}