first commit
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.example.demo.entity.Admin;
|
||||
import com.example.demo.exception.BusinessException;
|
||||
import com.example.demo.response.R;
|
||||
import com.example.demo.response.ResponseCode;
|
||||
import com.example.demo.service.AdminService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class AdminController {
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
|
||||
/**
|
||||
* 新增管理员信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "增加管理员")
|
||||
@PostMapping("/admin/add")
|
||||
@CrossOrigin
|
||||
public R add(@RequestBody Admin admin){
|
||||
LambdaQueryWrapper<Admin> adminWrapper = new LambdaQueryWrapper<>();
|
||||
adminWrapper.eq(Admin::getUsername, admin.getUsername());
|
||||
long count = adminService.count(adminWrapper);
|
||||
if (count > 0) {
|
||||
throw new BusinessException(ResponseCode.USERNAME_EXIST);
|
||||
}
|
||||
adminService.save(admin);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有管理员信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询管理员列表")
|
||||
@PostMapping("/admin/list")
|
||||
@CrossOrigin
|
||||
public R<PageInfo<Admin>> list(@RequestBody Admin admin, @RequestParam Integer pagenum, @RequestParam Integer pagesize){
|
||||
LambdaQueryWrapper<Admin> adminWrapper = new LambdaQueryWrapper<>();
|
||||
if(ObjectUtils.isNotEmpty(admin.getName())){
|
||||
adminWrapper.like(Admin::getName,admin.getName());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(admin.getTel())){
|
||||
adminWrapper.like(Admin::getTel,admin.getTel());
|
||||
}
|
||||
PageHelper.startPage(pagenum,pagesize);
|
||||
List<Admin> adminList = adminService.list(adminWrapper);
|
||||
PageInfo<Admin> pageInfo = new PageInfo<>(adminList);
|
||||
return R.data(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改管理员信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改管理员")
|
||||
@PostMapping("/admin/update")
|
||||
@CrossOrigin
|
||||
public R update(@RequestBody Admin admin){
|
||||
adminService.updateById(admin);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除管理员")
|
||||
@PostMapping("/admin/delete")
|
||||
@CrossOrigin
|
||||
public R delete(@RequestParam List<Long> ids){
|
||||
adminService.removeByIds(ids);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "管理员登录")
|
||||
@PostMapping("/admin/login")
|
||||
@CrossOrigin
|
||||
public R<Admin> login(@RequestParam String username, @RequestParam String userpwd){
|
||||
LambdaQueryWrapper<Admin> adminWrapper = new LambdaQueryWrapper<>();
|
||||
adminWrapper.eq(Admin::getUsername,username);
|
||||
adminWrapper.eq(Admin::getUserpwd,userpwd);
|
||||
Admin admin = adminService.getOne(adminWrapper);
|
||||
if(admin == null){
|
||||
throw new BusinessException(ResponseCode.USERNAME_USERPWD_ERROR);
|
||||
}
|
||||
StpUtil.login(admin.getId());
|
||||
admin.setToken(StpUtil.getTokenValue());
|
||||
return R.data(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员退出登录
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "管理员退出登录")
|
||||
@PostMapping("/admin/loginout")
|
||||
@CrossOrigin
|
||||
public R loginout(){
|
||||
StpUtil.logout();
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验用户名是否唯一
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/admin/checkUsername")
|
||||
@CrossOrigin
|
||||
public R checkUsername(@RequestParam String username) {
|
||||
LambdaQueryWrapper<Admin> adminWrapper = new LambdaQueryWrapper<>();
|
||||
adminWrapper.eq(Admin::getUsername,username);
|
||||
List<Admin> adminList = adminService.list(adminWrapper);
|
||||
if (adminList != null && adminList.size() > 0) {
|
||||
return R.fail(ResponseCode.USERNAME_EXIST);
|
||||
}
|
||||
return R.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.example.demo.entity.IndustryNews;
|
||||
import com.example.demo.response.R;
|
||||
import com.example.demo.service.IndustryNewsService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/industry")
|
||||
public class IndustryNewsController {
|
||||
|
||||
@Resource
|
||||
private IndustryNewsService industryNewsService;
|
||||
|
||||
/**
|
||||
* 新增行业动态
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新增行业动态")
|
||||
@PostMapping("/add")
|
||||
@CrossOrigin
|
||||
public R add(@RequestBody IndustryNews industryNews){
|
||||
industryNewsService.save(industryNews);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有行业动态(支持分页和条件查询)
|
||||
* @param industryNews 行业动态查询条件
|
||||
* @param pagenum 页码
|
||||
* @param pagesize 每页数量
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询行业动态列表")
|
||||
@PostMapping("/list")
|
||||
@CrossOrigin
|
||||
public R<PageInfo<IndustryNews>> list(@RequestBody IndustryNews industryNews, @RequestParam Integer pagenum, @RequestParam Integer pagesize){
|
||||
LambdaQueryWrapper<IndustryNews> industryNewsWrapper = new LambdaQueryWrapper<>();
|
||||
if(ObjectUtils.isNotEmpty(industryNews.getTitle())){
|
||||
industryNewsWrapper.like(IndustryNews::getTitle, industryNews.getTitle());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(industryNews.getContent())){
|
||||
industryNewsWrapper.like(IndustryNews::getContent, industryNews.getContent());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(industryNews.getStatus())){
|
||||
industryNewsWrapper.eq(IndustryNews::getStatus, industryNews.getStatus());
|
||||
}
|
||||
PageHelper.startPage(pagenum, pagesize);
|
||||
List<IndustryNews> industryNewsList = industryNewsService.list(industryNewsWrapper);
|
||||
PageInfo<IndustryNews> pageInfo = new PageInfo<>(industryNewsList);
|
||||
return R.data(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改行业动态
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改行业动态")
|
||||
@PostMapping("/update")
|
||||
@CrossOrigin
|
||||
public R update(@RequestBody IndustryNews industryNews){
|
||||
industryNewsService.updateById(industryNews);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除行业动态
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除行业动态")
|
||||
@PostMapping("/delete")
|
||||
@CrossOrigin
|
||||
public R delete(@RequestParam Long id){
|
||||
industryNewsService.removeById(id);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加行业动态访问量
|
||||
* @param id 行业动态ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "增加访问量")
|
||||
@PostMapping("/increaseViews")
|
||||
@CrossOrigin
|
||||
public R increaseViews(@RequestParam Long id){
|
||||
// 查询行业动态
|
||||
IndustryNews industryNews = industryNewsService.getById(id);
|
||||
if(industryNews != null){
|
||||
// 访问量+1
|
||||
industryNews.setViews(industryNews.getViews() == null ? 1 : industryNews.getViews() + 1);
|
||||
// 更新数据库
|
||||
industryNewsService.updateById(industryNews);
|
||||
}
|
||||
return R.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.example.demo.entity.News;
|
||||
import com.example.demo.response.R;
|
||||
import com.example.demo.service.NewsService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class NewsController {
|
||||
|
||||
@Resource
|
||||
private NewsService newsService;
|
||||
|
||||
/**
|
||||
* 新增新闻
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新增新闻")
|
||||
@PostMapping("/news/add")
|
||||
@CrossOrigin
|
||||
public R add(@RequestBody News news){
|
||||
newsService.save(news);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有新闻(支持分页和条件查询)
|
||||
* @param news 新闻查询条件
|
||||
* @param pagenum 页码
|
||||
* @param pagesize 每页数量
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询新闻列表")
|
||||
@PostMapping("/news/list")
|
||||
@CrossOrigin
|
||||
public R<PageInfo<News>> list(@RequestBody News news, @RequestParam Integer pagenum, @RequestParam Integer pagesize){
|
||||
LambdaQueryWrapper<News> newsWrapper = new LambdaQueryWrapper<>();
|
||||
if(ObjectUtils.isNotEmpty(news.getTitle())){
|
||||
newsWrapper.like(News::getTitle, news.getTitle());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(news.getContent())){
|
||||
newsWrapper.like(News::getContent, news.getContent());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(news.getStatus())){
|
||||
newsWrapper.eq(News::getStatus, news.getStatus());
|
||||
}
|
||||
PageHelper.startPage(pagenum, pagesize);
|
||||
List<News> newsList = newsService.list(newsWrapper);
|
||||
PageInfo<News> pageInfo = new PageInfo<>(newsList);
|
||||
return R.data(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改新闻
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改新闻")
|
||||
@PostMapping("/news/update")
|
||||
@CrossOrigin
|
||||
public R update(@RequestBody News news){
|
||||
newsService.updateById(news);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除新闻
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除新闻")
|
||||
@PostMapping("/news/delete")
|
||||
@CrossOrigin
|
||||
public R delete(@RequestParam Long id){
|
||||
newsService.removeById(id);
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加新闻访问量
|
||||
* @param id 新闻ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "增加访问量")
|
||||
@PostMapping("/news/increaseViews")
|
||||
@CrossOrigin
|
||||
public R increaseViews(@RequestParam Long id){
|
||||
// 查询新闻
|
||||
News news = newsService.getById(id);
|
||||
if(news != null){
|
||||
// 访问量+1
|
||||
news.setViews(news.getViews() == null ? 1 : news.getViews() + 1);
|
||||
// 更新数据库
|
||||
newsService.updateById(news);
|
||||
}
|
||||
return R.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
}
|
||||
Reference in New Issue
Block a user