fzzj hace 8 meses
padre
commit
842aa8d7f5

+ 4
- 1
RuoYi-Vue/ruoyi-admin/src/main/resources/application.yml Ver fichero

@@ -208,4 +208,7 @@ permit-all:
208 208
     - /webjars/**
209 209
 
210 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 Ver fichero

@@ -51,11 +51,13 @@ public class NovelController extends BaseController {
51 51
     // 添加所有缺失方法
52 52
 
53 53
     @GetMapping("/hot")
54
-    public List<Novel> getHotNovels() {
54
+    public TableDataInfo getHotNovels() {
55
+        //startPage();
55 56
         List<Novel> hotNovels = novelService.getHotNovels();
56 57
         //return novelService.getHotNovels();
57 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 Ver fichero

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

+ 4
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/CategoryMapper.java Ver fichero

@@ -1,12 +1,15 @@
1 1
 package com.ruoyi.novel.mapper;
2 2
 
3
+import com.ruoyi.novel.domain.NovelCategory;
3 4
 import jdk.jfr.Category;
4 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
5 7
 
6 8
 import java.util.List;
7 9
 
8 10
 // CategoryMapper.java
9 11
 @Mapper
10 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 Ver fichero

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

+ 8
- 10
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/impl/NovelServiceImpl.java Ver fichero

@@ -22,6 +22,7 @@ import jdk.jfr.Category;
22 22
 import org.slf4j.Logger;
23 23
 import org.slf4j.LoggerFactory;
24 24
 import org.springframework.beans.factory.annotation.Autowired;
25
+import org.springframework.beans.factory.annotation.Value;
25 26
 import org.springframework.stereotype.Service;
26 27
 import org.springframework.transaction.annotation.Transactional;
27 28
 import org.springframework.web.multipart.MultipartFile;
@@ -37,7 +38,8 @@ public class NovelServiceImpl implements NovelService {
37 38
     private static final Logger logger = LoggerFactory.getLogger(NovelServiceImpl.class);
38 39
     private final NovelRepository novelRepository; // JPA
39 40
 
40
-
41
+    @Value("${novel.amountDay}")
42
+    private Integer amountDay;
41 43
     //private final NovelSearchRepository novelSearchRepository; // ES
42 44
 
43 45
     @Autowired
@@ -252,7 +254,7 @@ public class NovelServiceImpl implements NovelService {
252 254
 
253 255
 
254 256
     @Override
255
-    public List<Category> getAllCategories() {
257
+    public List<NovelCategory> getAllCategories() {
256 258
 
257 259
         return categoryMapper.selectCategoryList();
258 260
     }
@@ -261,22 +263,18 @@ public class NovelServiceImpl implements NovelService {
261 263
     public List<Novel> getHotNovels() {
262 264
         // 获取最近一周热门小说
263 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 267
         return novelMapper.selectHotNovels(params);
266 268
     }
267 269
 
268 270
     @Override
269
-    public List<Novel> getNovelsByCategory(Long categoryId) {
270
-        // 使用若依分页工具
271
-        startPage();
272
-
271
+    public NovelCategory getNovelsByCategory(Long categoryId) {
273 272
         Novel novel = new Novel();
274 273
         if (categoryId != null && categoryId > 0) {
275 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 280
     @Override

+ 25
- 0
RuoYi-Vue/ruoyi-system/src/main/resources/mapper/novel/ChapterMapper.xml Ver fichero

@@ -0,0 +1,25 @@
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>

Loading…
Cancelar
Guardar