fzzj 8 месяцев назад
Родитель
Сommit
842aa8d7f5

+ 4
- 1
RuoYi-Vue/ruoyi-admin/src/main/resources/application.yml Просмотреть файл

208
     - /webjars/**
208
     - /webjars/**
209
 
209
 
210
 cors:
210
 cors:
211
-  allowed-origins: http://localhost:9090
211
+  allowed-origins: http://localhost:9090
212
+
213
+novel:
214
+  amountDay: 900

+ 4
- 2
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/NovelController.java Просмотреть файл

51
     // 添加所有缺失方法
51
     // 添加所有缺失方法
52
 
52
 
53
     @GetMapping("/hot")
53
     @GetMapping("/hot")
54
-    public List<Novel> getHotNovels() {
54
+    public TableDataInfo getHotNovels() {
55
+        //startPage();
55
         List<Novel> hotNovels = novelService.getHotNovels();
56
         List<Novel> hotNovels = novelService.getHotNovels();
56
         //return novelService.getHotNovels();
57
         //return novelService.getHotNovels();
57
         // 返回统一格式 { code, msg, data }
58
         // 返回统一格式 { code, msg, data }
58
-        return (List<Novel>) AjaxResult.success(hotNovels);
59
+        return getDataTable(hotNovels);
60
+        //return (List<Novel>) AjaxResult.success(hotNovels);
59
     }
61
     }
60
 
62
 
61
     // 获取分类列表
63
     // 获取分类列表

+ 1
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/domain/Novel.java Просмотреть файл

44
     private Long categoryId;
44
     private Long categoryId;
45
     //@Field(type = FieldType.Keyword)
45
     //@Field(type = FieldType.Keyword)
46
     @TableField("status")
46
     @TableField("status")
47
-    private Integer status = 0; // 0: 连载中, 1: 已完结// 连载/完本
47
+    private Integer status = 1; // 0: 连载中, 1: 已完结// 连载/完本
48
     //@Field(type = FieldType.Text, analyzer = "ik_smart")
48
     //@Field(type = FieldType.Text, analyzer = "ik_smart")
49
     // 添加其他在 XML 中使用的字段
49
     // 添加其他在 XML 中使用的字段
50
     @TableField(exist = false)
50
     @TableField(exist = false)

+ 4
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/CategoryMapper.java Просмотреть файл

1
 package com.ruoyi.novel.mapper;
1
 package com.ruoyi.novel.mapper;
2
 
2
 
3
+import com.ruoyi.novel.domain.NovelCategory;
3
 import jdk.jfr.Category;
4
 import jdk.jfr.Category;
4
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
5
 
7
 
6
 import java.util.List;
8
 import java.util.List;
7
 
9
 
8
 // CategoryMapper.java
10
 // CategoryMapper.java
9
 @Mapper
11
 @Mapper
10
 public interface CategoryMapper {
12
 public interface CategoryMapper {
11
-    List<Category> selectCategoryList();
13
+    List<NovelCategory> selectCategoryList();
14
+    NovelCategory selectById(@Param("categoryId") String categoryId);
12
 }
15
 }

+ 3
- 7
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/NovelService.java Просмотреть файл

1
 package com.ruoyi.novel.service;
1
 package com.ruoyi.novel.service;
2
 
2
 
3
-import com.ruoyi.novel.domain.AuthorApplication;
4
-import com.ruoyi.novel.domain.AuthorApplicationDTO;
5
-import com.ruoyi.novel.domain.Chapter;
6
-import com.ruoyi.novel.domain.Novel;
3
+import com.ruoyi.novel.domain.*;
7
 //import com.ruoyi.novel.repository.elastic.NovelSearchRepository;
4
 //import com.ruoyi.novel.repository.elastic.NovelSearchRepository;
8
 import com.ruoyi.novel.repository.jpa.NovelRepository;
5
 import com.ruoyi.novel.repository.jpa.NovelRepository;
9
 import jdk.jfr.Category;
6
 import jdk.jfr.Category;
10
 //import org.elasticsearch.client.tasks.ElasticsearchException;
7
 //import org.elasticsearch.client.tasks.ElasticsearchException;
11
-import org.springframework.scheduling.annotation.Async;
12
 import org.springframework.stereotype.Service;
8
 import org.springframework.stereotype.Service;
13
 import org.springframework.transaction.annotation.Propagation;
9
 import org.springframework.transaction.annotation.Propagation;
14
 import org.springframework.transaction.annotation.Transactional;
10
 import org.springframework.transaction.annotation.Transactional;
35
     void rejectAuthorApplication(Long applicationId);
31
     void rejectAuthorApplication(Long applicationId);
36
 
32
 
37
     // 添加所有缺失方法声明
33
     // 添加所有缺失方法声明
38
-    List<Category> getAllCategories();
34
+    List<NovelCategory> getAllCategories();
39
     List<Novel> getHotNovels();
35
     List<Novel> getHotNovels();
40
-    List<Novel> getNovelsByCategory(Long categoryId);
36
+    NovelCategory getNovelsByCategory(Long categoryId);
41
     List<Chapter> getChaptersByNovelId(Long novelId);
37
     List<Chapter> getChaptersByNovelId(Long novelId);
42
     Chapter getChapterContent(Long chapterId);
38
     Chapter getChapterContent(Long chapterId);
43
     void submitAuthorApplication(AuthorApplicationDTO dto, Long userId);
39
     void submitAuthorApplication(AuthorApplicationDTO dto, Long userId);

+ 8
- 10
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/impl/NovelServiceImpl.java Просмотреть файл

22
 import org.slf4j.Logger;
22
 import org.slf4j.Logger;
23
 import org.slf4j.LoggerFactory;
23
 import org.slf4j.LoggerFactory;
24
 import org.springframework.beans.factory.annotation.Autowired;
24
 import org.springframework.beans.factory.annotation.Autowired;
25
+import org.springframework.beans.factory.annotation.Value;
25
 import org.springframework.stereotype.Service;
26
 import org.springframework.stereotype.Service;
26
 import org.springframework.transaction.annotation.Transactional;
27
 import org.springframework.transaction.annotation.Transactional;
27
 import org.springframework.web.multipart.MultipartFile;
28
 import org.springframework.web.multipart.MultipartFile;
37
     private static final Logger logger = LoggerFactory.getLogger(NovelServiceImpl.class);
38
     private static final Logger logger = LoggerFactory.getLogger(NovelServiceImpl.class);
38
     private final NovelRepository novelRepository; // JPA
39
     private final NovelRepository novelRepository; // JPA
39
 
40
 
40
-
41
+    @Value("${novel.amountDay}")
42
+    private Integer amountDay;
41
     //private final NovelSearchRepository novelSearchRepository; // ES
43
     //private final NovelSearchRepository novelSearchRepository; // ES
42
 
44
 
43
     @Autowired
45
     @Autowired
252
 
254
 
253
 
255
 
254
     @Override
256
     @Override
255
-    public List<Category> getAllCategories() {
257
+    public List<NovelCategory> getAllCategories() {
256
 
258
 
257
         return categoryMapper.selectCategoryList();
259
         return categoryMapper.selectCategoryList();
258
     }
260
     }
261
     public List<Novel> getHotNovels() {
263
     public List<Novel> getHotNovels() {
262
         // 获取最近一周热门小说
264
         // 获取最近一周热门小说
263
         Map<String, Object> params = new HashMap<>();
265
         Map<String, Object> params = new HashMap<>();
264
-        params.put("beginTime", DateUtils.addDays(new Date(), -7));
266
+        params.put("beginTime", DateUtils.addDays(new Date(), -amountDay));
265
         return novelMapper.selectHotNovels(params);
267
         return novelMapper.selectHotNovels(params);
266
     }
268
     }
267
 
269
 
268
     @Override
270
     @Override
269
-    public List<Novel> getNovelsByCategory(Long categoryId) {
270
-        // 使用若依分页工具
271
-        startPage();
272
-
271
+    public NovelCategory getNovelsByCategory(Long categoryId) {
273
         Novel novel = new Novel();
272
         Novel novel = new Novel();
274
         if (categoryId != null && categoryId > 0) {
273
         if (categoryId != null && categoryId > 0) {
275
             novel.setCategoryId(categoryId);
274
             novel.setCategoryId(categoryId);
276
         }
275
         }
277
-
278
-        List<Novel> list = novelMapper.selectNovelList(novel,null);
279
-        return (List<Novel>) getDataTable(list);
276
+        NovelCategory novelCategory = categoryMapper.selectById(categoryId.toString());
277
+        return novelCategory;
280
     }
278
     }
281
 
279
 
282
     @Override
280
     @Override

+ 25
- 0
RuoYi-Vue/ruoyi-system/src/main/resources/mapper/novel/ChapterMapper.xml Просмотреть файл

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.ruoyi.novel.mapper.CategoryMapper">
4
+
5
+    <resultMap id="NovelCategoryResult" type="NovelCategory">
6
+        <id property="id" column="id" />
7
+        <result property="title" column="title" />
8
+        <result property="pid" column="pid" />
9
+        <result property="sort" column="sort" />
10
+        <!-- 其他字段映射 -->
11
+    </resultMap>
12
+
13
+    <select id="selectCategoryList" resultMap="NovelCategoryResult">
14
+        SELECT id, title, pid, sort
15
+        FROM novel_category
16
+        WHERE status = 1
17
+        ORDER BY sort ASC
18
+    </select>
19
+
20
+    <select id="selectById" parameterType="String" resultMap="NovelCategoryResult">
21
+        SELECT id, title, pid, sort
22
+        FROM novel_category
23
+        WHERE id = #{categoryId}
24
+    </select>
25
+</mapper>

Загрузка…
Отмена
Сохранить