| | |
| | | package com.xinquan.system.controller; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | 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.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 org.springframework.web.bind.annotation.RestController; |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/system/hot-words") |
| | | public class HotWordsController { |
| | | |
| | | @Resource |
| | | private HotWordsService hotWordsService; |
| | | @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( |
| | | 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(page1); |
| | | 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) { |
| | | int size = hotWordsService.lambdaQuery().list().size(); |
| | | if (size>=20){ |
| | | return R.fail("热词数量已达上限"); |
| | | } |
| | | 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("/delete") |
| | | @ApiOperation(value = "热词管理-删除热词", tags = {"管理后台-运营中心"}) |
| | | public R add(String id) { |
| | | hotWordsService.removeById(Long.valueOf(id)); |
| | | return R.ok(); |
| | | } |
| | | @GetMapping("/queryAddCount") |
| | | @ApiOperation(value = "热词管理-查询还可以上传多少个热词", tags = {"管理后台-运营中心"}) |
| | | public R queryAddCount() { |
| | | int i = 20 - hotWordsService.lambdaQuery().list().size(); |
| | | return R.ok(i); |
| | | } |
| | | } |
| | | |