diff --git a/src/main/java/com/corewing/app/config/SaTokenConfig.java b/src/main/java/com/corewing/app/config/SaTokenConfig.java index ac5df33..5cb6b84 100644 --- a/src/main/java/com/corewing/app/config/SaTokenConfig.java +++ b/src/main/java/com/corewing/app/config/SaTokenConfig.java @@ -27,6 +27,8 @@ public class SaTokenConfig implements WebMvcConfigurer { .excludePathPatterns("/sys/user/login") // 排除反馈接口(支持匿名提交) .excludePathPatterns("/feedback", "/feedback/**") + // 排除教程接口(支持匿名查询) + .excludePathPatterns("/tutorial", "/tutorial/**") // 排除固件查询接口(不需要登录) .excludePathPatterns("/firmware/**") // 排除静态资源 diff --git a/src/main/java/com/corewing/app/controller/TutorialController.java b/src/main/java/com/corewing/app/controller/TutorialController.java new file mode 100644 index 0000000..428b66f --- /dev/null +++ b/src/main/java/com/corewing/app/controller/TutorialController.java @@ -0,0 +1,79 @@ +package com.corewing.app.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.corewing.app.common.Result; +import com.corewing.app.entity.Tutorial; +import com.corewing.app.entity.TutorialCategory; +import com.corewing.app.service.TutorialCategoryService; +import com.corewing.app.service.TutorialService; +import com.corewing.app.util.I18nUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 教程接口 + */ +@RequestMapping("/tutorial") +@RestController +@Slf4j +public class TutorialController { + + private final TutorialService tutorialService; + private final TutorialCategoryService tutorialCategoryService; + + public TutorialController(TutorialService tutorialService, TutorialCategoryService tutorialCategoryService) { + this.tutorialService = tutorialService; + this.tutorialCategoryService = tutorialCategoryService; + } + + /** + * 分类查询列表 + * + * @param firstStatus 置首状态(选填) + * + */ + @GetMapping("/category") + public Result> category( + @RequestParam(required = false, defaultValue = "0") Integer firstStatus + ) { + log.info("当前语言环境:{}", I18nUtil.getCurrentLocale().getLanguage()); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(firstStatus != 0, TutorialCategory::getFirstStatus, firstStatus); + wrapper.eq(TutorialCategory::getLang, I18nUtil.getCurrentLocale().getLanguage()); + List list = tutorialCategoryService.list(wrapper); + return Result.success(list); + } + + /** + * 分页查询教程列表 + * + * @param current 当前页码 + * @param size 每页数量 + * @param categoryId 分类ID(选填) + * @param tutorialTitle 教程标题(选填) + * + */ + @GetMapping("/page") + public Result> getPageList( + @RequestParam(defaultValue = "1") Long current, + @RequestParam(defaultValue = "10") Long size, + @RequestParam(required = false, defaultValue = "0") Integer categoryId, + @RequestParam(required = false) String tutorialTitle) { + try { + Page page = new Page<>(current, size); + IPage pageResult = tutorialService.pageList(page, categoryId, tutorialTitle, I18nUtil.getCurrentLocale().getLanguage()); + return Result.success(pageResult); + } catch (Exception e) { + return Result.error(e.getMessage()); + } + } + + +} diff --git a/src/main/java/com/corewing/app/entity/Tutorial.java b/src/main/java/com/corewing/app/entity/Tutorial.java new file mode 100644 index 0000000..bb2d1ba --- /dev/null +++ b/src/main/java/com/corewing/app/entity/Tutorial.java @@ -0,0 +1,73 @@ +package com.corewing.app.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +/** + * 教程 + */ +@Data +@TableName("app_tutorial") +public class Tutorial implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 教程id + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 教程标题 + */ + private String tutorialTitle; + + /** + * 教程描述 + */ + private String description; + + /** + * 教程详情 + */ + private String content; + + /** + * 查看次数 + */ + private Integer viewCount; + + /** + * 推荐状态:0不推荐,1推荐 + */ + private Integer recommendStatus; + + /** + * 状态:1正常,2关闭 + */ + private Integer status; + + /** + * 语言:中文zh,英文:en + */ + private String lang; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + +} diff --git a/src/main/java/com/corewing/app/entity/TutorialCategory.java b/src/main/java/com/corewing/app/entity/TutorialCategory.java new file mode 100644 index 0000000..624fc23 --- /dev/null +++ b/src/main/java/com/corewing/app/entity/TutorialCategory.java @@ -0,0 +1,70 @@ +package com.corewing.app.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +/** + * 教程分类 + */ +@Data +@TableName("app_tutorial_category") +public class TutorialCategory implements Serializable { + + /** + * 分类id + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 图标 + */ + private String icon; + + /** + * 分类名称 + */ + private String categoryTitle; + + /** + * 分类描述 + */ + private String description; + + /** + * 类别:category分类,tag标签 + */ + private String type; + + /** + * 置首页:0不置首,1置首页 + */ + private Integer firstStatus; + + /** + * 状态:1正常,2关闭 + */ + private Integer status; + + /** + * 语言:中文zh,英文:en + */ + private String lang; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + +} diff --git a/src/main/java/com/corewing/app/entity/TutorialCategoryRelation.java b/src/main/java/com/corewing/app/entity/TutorialCategoryRelation.java new file mode 100644 index 0000000..da7310f --- /dev/null +++ b/src/main/java/com/corewing/app/entity/TutorialCategoryRelation.java @@ -0,0 +1,32 @@ +package com.corewing.app.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 教程与分类关系实体 + */ +@Data +@TableName("app_tutorial_category_relation") +public class TutorialCategoryRelation implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Long id; + + /** + * 教程id + */ + private Long TutorialId; + + /** + * 教程分类id + */ + private Long CategoryId; + +} diff --git a/src/main/java/com/corewing/app/mapper/TutorialCategoryMapper.java b/src/main/java/com/corewing/app/mapper/TutorialCategoryMapper.java new file mode 100644 index 0000000..c6c0ddb --- /dev/null +++ b/src/main/java/com/corewing/app/mapper/TutorialCategoryMapper.java @@ -0,0 +1,12 @@ +package com.corewing.app.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.corewing.app.entity.TutorialCategory; +import org.apache.ibatis.annotations.Mapper; + +/** + * 教程分类 Mapper接口 + */ +@Mapper +public interface TutorialCategoryMapper extends BaseMapper { +} diff --git a/src/main/java/com/corewing/app/mapper/TutorialCategoryRelationMapper.java b/src/main/java/com/corewing/app/mapper/TutorialCategoryRelationMapper.java new file mode 100644 index 0000000..6c2ec38 --- /dev/null +++ b/src/main/java/com/corewing/app/mapper/TutorialCategoryRelationMapper.java @@ -0,0 +1,13 @@ +package com.corewing.app.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.corewing.app.entity.TutorialCategoryRelation; +import org.apache.ibatis.annotations.Mapper; + + +/** + * 教程与教程分类关系Mapper接口 + */ +@Mapper +public interface TutorialCategoryRelationMapper extends BaseMapper { +} diff --git a/src/main/java/com/corewing/app/mapper/TutorialMapper.java b/src/main/java/com/corewing/app/mapper/TutorialMapper.java new file mode 100644 index 0000000..27e1c55 --- /dev/null +++ b/src/main/java/com/corewing/app/mapper/TutorialMapper.java @@ -0,0 +1,17 @@ +package com.corewing.app.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.corewing.app.entity.Tutorial; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 教程 Mapper 接口 + */ + +@Mapper +public interface TutorialMapper extends BaseMapper { + + Page pageList(Page page, @Param("categoryId") int categoryId, @Param("tutorialTitle") String tutorialTitle, @Param("lang") String lang); +} diff --git a/src/main/java/com/corewing/app/service/TutorialCategoryRelationService.java b/src/main/java/com/corewing/app/service/TutorialCategoryRelationService.java new file mode 100644 index 0000000..64c5676 --- /dev/null +++ b/src/main/java/com/corewing/app/service/TutorialCategoryRelationService.java @@ -0,0 +1,7 @@ +package com.corewing.app.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.corewing.app.entity.TutorialCategoryRelation; + +public interface TutorialCategoryRelationService extends IService { +} diff --git a/src/main/java/com/corewing/app/service/TutorialCategoryService.java b/src/main/java/com/corewing/app/service/TutorialCategoryService.java new file mode 100644 index 0000000..fc1b2f5 --- /dev/null +++ b/src/main/java/com/corewing/app/service/TutorialCategoryService.java @@ -0,0 +1,7 @@ +package com.corewing.app.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.corewing.app.entity.TutorialCategory; + +public interface TutorialCategoryService extends IService { +} diff --git a/src/main/java/com/corewing/app/service/TutorialService.java b/src/main/java/com/corewing/app/service/TutorialService.java new file mode 100644 index 0000000..2c74498 --- /dev/null +++ b/src/main/java/com/corewing/app/service/TutorialService.java @@ -0,0 +1,10 @@ +package com.corewing.app.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.corewing.app.entity.Tutorial; + +public interface TutorialService extends IService { + IPage pageList(Page page, int categoryId, String tutorialTitle, String lang); +} diff --git a/src/main/java/com/corewing/app/service/impl/TutorialCategoryRelationServiceImpl.java b/src/main/java/com/corewing/app/service/impl/TutorialCategoryRelationServiceImpl.java new file mode 100644 index 0000000..795d826 --- /dev/null +++ b/src/main/java/com/corewing/app/service/impl/TutorialCategoryRelationServiceImpl.java @@ -0,0 +1,11 @@ +package com.corewing.app.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.entity.TutorialCategoryRelation; +import com.corewing.app.mapper.TutorialCategoryRelationMapper; +import com.corewing.app.service.TutorialCategoryRelationService; +import org.springframework.stereotype.Service; + +@Service +public class TutorialCategoryRelationServiceImpl extends ServiceImpl implements TutorialCategoryRelationService { +} diff --git a/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java b/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java new file mode 100644 index 0000000..06bf878 --- /dev/null +++ b/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java @@ -0,0 +1,11 @@ +package com.corewing.app.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.entity.TutorialCategory; +import com.corewing.app.mapper.TutorialCategoryMapper; +import com.corewing.app.service.TutorialCategoryService; +import org.springframework.stereotype.Service; + +@Service +public class TutorialCategoryServiceImpl extends ServiceImpl implements TutorialCategoryService { +} diff --git a/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java b/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java new file mode 100644 index 0000000..a9e1827 --- /dev/null +++ b/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java @@ -0,0 +1,24 @@ +package com.corewing.app.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.entity.Tutorial; +import com.corewing.app.mapper.TutorialMapper; +import com.corewing.app.service.TutorialService; +import org.springframework.stereotype.Service; + +@Service +public class TutorialServiceImpl extends ServiceImpl implements TutorialService { + + private final TutorialMapper tutorialMapper; + + public TutorialServiceImpl(TutorialMapper tutorialMapper) { + this.tutorialMapper = tutorialMapper; + } + + @Override + public IPage pageList(Page page, int categoryId, String tutorialTitle, String lang) { + return tutorialMapper.pageList(page, categoryId, tutorialTitle, lang); + } +} diff --git a/src/main/java/com/corewing/app/vo/TutorialVO.java b/src/main/java/com/corewing/app/vo/TutorialVO.java new file mode 100644 index 0000000..4bc0ec9 --- /dev/null +++ b/src/main/java/com/corewing/app/vo/TutorialVO.java @@ -0,0 +1,58 @@ +package com.corewing.app.vo; + +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +public class TutorialVO { + + private Long id; + + /** + * 教程标题 + */ + private String tutorialTitle; + + /** + * 教程描述 + */ + private String description; + + /** + * 教程详情 + */ + private String content; + + /** + * 查看次数 + */ + private Integer viewCount; + + /** + * 推荐状态:0不推荐,1推荐 + */ + private Integer recommendStatus; + + /** + * 状态:1正常,2关闭 + */ + private Integer status; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + /** + * 教程分类名称 + */ + private String categoryTitle; + +} diff --git a/src/main/resources/db/app_tutorial.sql b/src/main/resources/db/app_tutorial.sql new file mode 100644 index 0000000..e4cd139 --- /dev/null +++ b/src/main/resources/db/app_tutorial.sql @@ -0,0 +1,44 @@ +/* + Navicat Premium Dump SQL + + Source Server : 120.24.204.180 + Source Server Type : MySQL + Source Server Version : 80036 (8.0.36) + Source Host : 120.24.204.180:3306 + Source Schema : app + + Target Server Type : MySQL + Target Server Version : 80036 (8.0.36) + File Encoding : 65001 + + Date: 28/10/2025 13:46:26 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for app_tutorial +-- ---------------------------- +DROP TABLE IF EXISTS `app_tutorial`; +CREATE TABLE `app_tutorial` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', + `tutorial_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '教程标题', + `description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '教程描述', + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '教程详情', + `view_count` int DEFAULT '0' COMMENT '查看次数', + `recommend_status` int DEFAULT '0' COMMENT '推荐状态:0不推荐,1推荐', + `status` tinyint(1) DEFAULT '1' COMMENT '状态:1正常,2关闭', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='使用教程表'; + +-- ---------------------------- +-- Records of app_tutorial +-- ---------------------------- +BEGIN; +INSERT INTO `app_tutorial` (`id`, `tutorial_title`, `description`, `content`, `view_count`, `recommend_status`, `status`, `create_time`, `update_time`) VALUES (1, '快速开始指南', '了解酷翼应用的基本功能与布局,快速上手使用各项功能。', NULL, 0, 0, 1, '2025-10-28 12:03:52', NULL); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/db/app_tutorial_category.sql b/src/main/resources/db/app_tutorial_category.sql new file mode 100644 index 0000000..92edc6a --- /dev/null +++ b/src/main/resources/db/app_tutorial_category.sql @@ -0,0 +1,44 @@ +/* + Navicat Premium Dump SQL + + Source Server : 120.24.204.180 + Source Server Type : MySQL + Source Server Version : 80036 (8.0.36) + Source Host : 120.24.204.180:3306 + Source Schema : app + + Target Server Type : MySQL + Target Server Version : 80036 (8.0.36) + File Encoding : 65001 + + Date: 28/10/2025 13:46:32 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for app_tutorial_category +-- ---------------------------- +DROP TABLE IF EXISTS `app_tutorial_category`; +CREATE TABLE `app_tutorial_category` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', + `icon` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '图标', + `category_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类名称', + `description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '分类描述', + `first_status` int NOT NULL DEFAULT '2' COMMENT '置首页:1置首,2不置首', + `type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类别:category分类,tag标签', + `status` tinyint(1) DEFAULT '0' COMMENT '状态:1正常,2关闭', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='使用教程分类/标签表'; + +-- ---------------------------- +-- Records of app_tutorial_category +-- ---------------------------- +BEGIN; +INSERT INTO `app_tutorial_category` (`id`, `icon`, `category_title`, `description`, `first_status`, `type`, `status`, `create_time`, `update_time`) VALUES (1, NULL, '快速指南', NULL, 1, 'category', 1, '2025-10-28 12:06:03', NULL); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/db/app_tutorial_category_relation.sql b/src/main/resources/db/app_tutorial_category_relation.sql new file mode 100644 index 0000000..81c49d9 --- /dev/null +++ b/src/main/resources/db/app_tutorial_category_relation.sql @@ -0,0 +1,38 @@ +/* + Navicat Premium Dump SQL + + Source Server : 120.24.204.180 + Source Server Type : MySQL + Source Server Version : 80036 (8.0.36) + Source Host : 120.24.204.180:3306 + Source Schema : app + + Target Server Type : MySQL + Target Server Version : 80036 (8.0.36) + File Encoding : 65001 + + Date: 28/10/2025 13:46:38 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for app_tutorial_category_relation +-- ---------------------------- +DROP TABLE IF EXISTS `app_tutorial_category_relation`; +CREATE TABLE `app_tutorial_category_relation` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', + `tutorial_id` bigint DEFAULT NULL COMMENT '教程id', + `category_id` bigint DEFAULT NULL COMMENT '教程分类id', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='教程与教程分类关系表'; + +-- ---------------------------- +-- Records of app_tutorial_category_relation +-- ---------------------------- +BEGIN; +INSERT INTO `app_tutorial_category_relation` (`id`, `tutorial_id`, `category_id`) VALUES (1, 1, 1); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/mapper/TutorialMapper.xml b/src/main/resources/mapper/TutorialMapper.xml new file mode 100644 index 0000000..9b7316e --- /dev/null +++ b/src/main/resources/mapper/TutorialMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + select c.*, cc.category_title + from app_tutorial c + left join app_tutorial_category_relation ccr on c.id = ccr.tutorial_id + left join app_tutorial_category cc on cc.id = ccr.category_id + + + + + +