first commit

This commit is contained in:
dhp
2026-04-23 17:03:40 +08:00
commit dfd77fe83b
1298 changed files with 163510 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package com.example.demo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class Demo4Application {
public static void main(String[] args) {
SpringApplication.run(Demo4Application.class, args);
}
}

View File

@@ -0,0 +1,21 @@
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("pdmtoken")
.allowCredentials(true)
.maxAge(3600);
}
}

View File

@@ -0,0 +1,18 @@
package com.example.demo.config;
import cn.dev33.satoken.interceptor.SaInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
registry.addInterceptor(new SaInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/**");
}
}

View File

@@ -0,0 +1,21 @@
package com.example.demo.config;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("首达特科技工程有限公司")
.version("1.0")
.description( "首达特科技工程有限公司")
.contact(new Contact().name("首达特").url("www.shoudate.com")));
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,7 @@
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
}

View File

@@ -0,0 +1,41 @@
package com.example.demo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@TableName("admin")
public class Admin {
@TableId(type = IdType.AUTO)
private Long id;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String userpwd;
/**
* 姓名
*/
private String name;
/**
* 性别
*/
private String sex;
/**
* 电话
*/
private String tel;
/**
* 登录token
*/
@Schema(description = "登录token")
@TableField(exist = false)
private String token;
}

View File

@@ -0,0 +1,24 @@
package com.example.demo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
@TableName("industry_news")
public class IndustryNews {
@TableId(type = IdType.AUTO)
private Long id;
private String title;
private String content;
private Integer views;
private LocalDate publishDate;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Integer status;
}

View File

@@ -0,0 +1,24 @@
package com.example.demo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
@TableName("news")
public class News {
@TableId(type = IdType.AUTO)
private Long id;
private String title;
private String content;
private Integer views;
private LocalDate publishDate;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Integer status;
}

View File

@@ -0,0 +1,28 @@
package com.example.demo.exception;
import com.example.demo.response.ResponseCode;
import lombok.Data;
@Data
public class BusinessException extends RuntimeException {
/**
* 错误码
*/
private Integer code;
/**
* 错误信息
*/
private String message;
public BusinessException(ResponseCode responseCode) {
this.code = responseCode.getCode();
this.message = responseCode.getDesc();
}
public BusinessException(Integer code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -0,0 +1,40 @@
package com.example.demo.exception;
import cn.dev33.satoken.exception.NotLoginException;
import com.example.demo.response.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class ControllerExceptionHandler {
/**
* 业务异常统一处理
* @param e
* @return
*/
@ExceptionHandler(value = BusinessException.class)
public R businessExceptionHandler(BusinessException e) {
return R.fail(e.getCode(), e.getMessage());
}
/**
* 未登录异常处理
* @param e
* @return
*/
@ExceptionHandler(value = NotLoginException.class)
public R loginExceptionHandler(NotLoginException e) {
return R.fail(e.getCode(), e.getMessage());
}
/**
* 其他异常
* @param e
* @return
*/
@ExceptionHandler({Exception.class})
public R exceptionHandler(Exception e) {
return R.fail(e.getMessage());
}
}

View File

@@ -0,0 +1,7 @@
package com.example.demo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Admin;
public interface AdminMapper extends BaseMapper<Admin> {
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.IndustryNews;
public interface IndustryNewsMapper extends BaseMapper<IndustryNews> {
}

View File

@@ -0,0 +1,7 @@
package com.example.demo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.News;
public interface NewsMapper extends BaseMapper<News> {
}

View File

@@ -0,0 +1,66 @@
package com.example.demo.response;
import lombok.Data;
import lombok.Getter;
@Getter
public class R<T> {
/**
* 状态码
*/
private Integer code;
/**
* 描述
*/
private String message;
/**
* 返回泛型数据,自定义类型
*/
private T data;
private R(Integer code) {
this.code = code;
}
private R(Integer code, String message) {
this.code = code;
this.message = message;
}
private R(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public static <T> R<T> success() {
return new R<T>(ResponseCode.SUCCESS.getCode());
}
public static <T> R<T> success(String message) {
return new R<T>(ResponseCode.SUCCESS.getCode(), message);
}
public static <T> R<T> data(T data) {
return new R<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(), data);
}
public static <T> R<T> fail() {
return new R<T>(ResponseCode.ERROR.getCode());
}
public static <T> R<T> fail(String message) {
return new R<T>(ResponseCode.ERROR.getCode(), message);
}
public static <T> R<T> fail(Integer code, String message) {
return new R<T>(code, message);
}
public static <T> R<T> fail(ResponseCode responseCode) {
return new R<T>(responseCode.getCode(), responseCode.getDesc());
}
}

View File

@@ -0,0 +1,39 @@
package com.example.demo.response;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 公用返回状态码
*/
@AllArgsConstructor
@Getter
public enum ResponseCode {
/**
* 用户名已存在
*/
USERNAME_EXIST(1001, "用户名已存在"),
/**
* 用户名密码错误
*/
USERNAME_USERPWD_ERROR(1002, "用户名密码错误"),
/**
* 成功
*/
SUCCESS(200, "操作成功!"),
/**
* 错误
*/
ERROR(500, "操作失败!");
/**
* 状态码
*/
private Integer code;
/**
* 状态描述
*/
private String desc;
}

View File

@@ -0,0 +1,7 @@
package com.example.demo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo.entity.Admin;
public interface AdminService extends IService<Admin> {
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo.entity.IndustryNews;
public interface IndustryNewsService extends IService<IndustryNews> {
}

View File

@@ -0,0 +1,7 @@
package com.example.demo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo.entity.News;
public interface NewsService extends IService<News> {
}

View File

@@ -0,0 +1,11 @@
package com.example.demo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Admin;
import com.example.demo.mapper.AdminMapper;
import com.example.demo.service.AdminService;
import org.springframework.stereotype.Service;
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
}

View File

@@ -0,0 +1,12 @@
package com.example.demo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.IndustryNews;
import com.example.demo.mapper.IndustryNewsMapper;
import com.example.demo.service.IndustryNewsService;
import org.springframework.stereotype.Service;
@Service
public class IndustryNewsServiceImpl extends ServiceImpl<IndustryNewsMapper, IndustryNews> implements IndustryNewsService {
}

View File

@@ -0,0 +1,11 @@
package com.example.demo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.News;
import com.example.demo.mapper.NewsMapper;
import com.example.demo.service.NewsService;
import org.springframework.stereotype.Service;
@Service
public class NewsServiceimpl extends ServiceImpl<NewsMapper, News> implements NewsService {
}

View File

@@ -0,0 +1 @@
spring.application.name=demo4

View File

@@ -0,0 +1,62 @@
server:
servlet:
context-path: /sdtadmin
port: 8081
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/demo_news?characterEncoding=UTF-8&&serverTimezone=GMT
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 10
max-active: 20
max-wait: 60000
validation-query: SELECT 1
test-on-borrow: true
test-while-idle: true
test-on-return: false
mybatis-plus:
configuration:
# MyBatis 配置 开启驼峰功能
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#为MyBatis引用的实体类自定义别名
type-aliases-package: com.panduoma.pdmadmin.entity
# springdoc-openapi项目配置
springdoc:
swagger-ui:
path: /swagger-ui.html
tags-sorter: alpha
operations-sorter: alpha
api-docs:
path: /v3/api-docs
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.shoudate.sdtadmin.controller
# knife4j的增强配置不需要增强可以不配
knife4j:
enable: true
setting:
language: zh_cn
swagger-model-name: 实体类列表
sa-token:
# token 名称(同时也是 cookie 名称)
token-name: pdmtoken
# token 有效期(单位:秒) 默认30天-1 代表永久有效
timeout: 2592000
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
active-timeout: -1
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token
is-share: true
# token 风格默认可取值uuid、simple-uuid、random-32、random-64、random-128、tik
token-style: uuid
# 是否输出操作日志
is-log: true

View File

@@ -0,0 +1,13 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Demo4ApplicationTests {
@Test
void contextLoads() {
}
}