소스 검색

tj

master
yinshaojie 6 달 전
부모
커밋
f3b279323b

+ 2
- 5
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/AdminNovelController.java 파일 보기

4
 import com.ruoyi.common.core.domain.AjaxResult;
4
 import com.ruoyi.common.core.domain.AjaxResult;
5
 import com.ruoyi.common.core.page.TableDataInfo;
5
 import com.ruoyi.common.core.page.TableDataInfo;
6
 import com.ruoyi.novel.domain.AuthorApplication;
6
 import com.ruoyi.novel.domain.AuthorApplication;
7
-import com.ruoyi.novel.domain.Chapter;
8
 import com.ruoyi.novel.domain.Novel;
7
 import com.ruoyi.novel.domain.Novel;
8
+import com.ruoyi.novel.domain.NovelChapter;
9
 import com.ruoyi.novel.service.NovelService;
9
 import com.ruoyi.novel.service.NovelService;
10
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
11
-import org.springframework.http.HttpStatus;
12
-import org.springframework.http.ResponseEntity;
13
 import org.springframework.web.bind.annotation.*;
11
 import org.springframework.web.bind.annotation.*;
14
 import org.springframework.web.multipart.MultipartFile;
12
 import org.springframework.web.multipart.MultipartFile;
15
 
13
 
16
 import java.util.List;
14
 import java.util.List;
17
-import java.util.Map;
18
 
15
 
19
 @RestController
16
 @RestController
20
 @RequestMapping("/admin/novel")
17
 @RequestMapping("/admin/novel")
44
                                     @RequestParam Long novelId,
41
                                     @RequestParam Long novelId,
45
                                     @RequestParam(required = false) Integer chapterOrder) {
42
                                     @RequestParam(required = false) Integer chapterOrder) {
46
         try {
43
         try {
47
-            Chapter chapter = novelService.processChapterUpload(file, novelId, chapterOrder);
44
+            NovelChapter chapter = novelService.processChapterUpload(file, novelId, chapterOrder);
48
             return AjaxResult.success(chapter);
45
             return AjaxResult.success(chapter);
49
         } catch (Exception e) {
46
         } catch (Exception e) {
50
             return AjaxResult.error(e.getMessage());
47
             return AjaxResult.error(e.getMessage());

+ 2
- 3
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/NovelController.java 파일 보기

9
 import com.ruoyi.common.core.page.TableDataInfo;
9
 import com.ruoyi.common.core.page.TableDataInfo;
10
 import com.ruoyi.common.core.page.TableSupport;
10
 import com.ruoyi.common.core.page.TableSupport;
11
 import com.ruoyi.novel.domain.AuthorApplicationDTO;
11
 import com.ruoyi.novel.domain.AuthorApplicationDTO;
12
-import com.ruoyi.novel.domain.Chapter;
13
 import com.ruoyi.novel.domain.Novel;
12
 import com.ruoyi.novel.domain.Novel;
14
 import com.ruoyi.novel.domain.NovelCategory;
13
 import com.ruoyi.novel.domain.NovelCategory;
14
+import com.ruoyi.novel.domain.NovelChapter;
15
 import com.ruoyi.novel.mapper.NovelMapper;
15
 import com.ruoyi.novel.mapper.NovelMapper;
16
 import com.ruoyi.novel.service.IAuthService;
16
 import com.ruoyi.novel.service.IAuthService;
17
 import com.ruoyi.novel.service.NovelSearchService;
17
 import com.ruoyi.novel.service.NovelSearchService;
18
 import com.ruoyi.novel.service.NovelService;
18
 import com.ruoyi.novel.service.NovelService;
19
-import jdk.jfr.Category;
20
 import org.springframework.beans.factory.annotation.Autowired;
19
 import org.springframework.beans.factory.annotation.Autowired;
21
 import org.springframework.beans.factory.annotation.Qualifier;
20
 import org.springframework.beans.factory.annotation.Qualifier;
22
 import org.springframework.cache.annotation.Cacheable;
21
 import org.springframework.cache.annotation.Cacheable;
116
     public AjaxResult getChapterContent(@PathVariable("chapterId") Long chapterId) {
115
     public AjaxResult getChapterContent(@PathVariable("chapterId") Long chapterId) {
117
         //return AjaxResult.success(novelService.getChapterContent(chapterId));
116
         //return AjaxResult.success(novelService.getChapterContent(chapterId));
118
 
117
 
119
-        Chapter chapter = novelService.getChapterContent(chapterId);
118
+        NovelChapter chapter = novelService.getChapterContent(chapterId);
120
         if (chapter == null) {
119
         if (chapter == null) {
121
             return AjaxResult.error("章节不存在");
120
             return AjaxResult.error("章节不存在");
122
         }
121
         }

+ 0
- 33
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/domain/Chapter.java 파일 보기

1
-package com.ruoyi.novel.domain;
2
-
3
-
4
-import com.ruoyi.novel.service.NovelService;
5
-import com.ruoyi.system.domain.SysOperLog;
6
-import lombok.Data;
7
-import org.springframework.beans.factory.annotation.Autowired;
8
-
9
-import javax.persistence.*;
10
-import java.util.Date;
11
-
12
-@Data
13
-@Entity
14
-@Table(name = "chapter")
15
-public class Chapter {
16
-
17
-    @Id
18
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
19
-    private Long id;
20
-    @Column(name = "novel_id")
21
-    private Long novelId;
22
-    private String title;
23
-    @Lob
24
-    @Column(columnDefinition = "TEXT")
25
-    private String content;
26
-    @Column(name = "chapter_order")
27
-    private Integer chapterOrder;
28
-
29
-    @Column(name = "create_time")
30
-    private Date createTime;
31
-
32
-    // Getters and setters
33
-}

+ 0
- 15
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/CategoryMapper.java 파일 보기

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

+ 0
- 14
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/ChapterMapper.java 파일 보기

1
-package com.ruoyi.novel.mapper;
2
-
3
-import com.ruoyi.novel.domain.Chapter;
4
-import org.apache.ibatis.annotations.Mapper;
5
-
6
-import java.util.List;
7
-@Mapper
8
-public interface ChapterMapper {
9
-    Chapter selectChapterById(Long id);
10
-    int insertChapter(Chapter chapter);
11
-    List<Chapter> selectChapterList(Chapter chapter);
12
-    Integer selectMaxChapterOrder(Long novelId);
13
-    int selectChapterCountByNovelId(Long novelId);
14
-}

+ 5
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/NovelCategoryMapper.java 파일 보기

3
 import com.ruoyi.novel.domain.NovelCategory;
3
 import com.ruoyi.novel.domain.NovelCategory;
4
 import java.util.List;
4
 import java.util.List;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
6
 
7
 
7
 @Mapper // 确保添加 Mapper 注解
8
 @Mapper // 确保添加 Mapper 注解
8
 public interface NovelCategoryMapper {
9
 public interface NovelCategoryMapper {
9
     List<NovelCategory> selectCategoryList();
10
     List<NovelCategory> selectCategoryList();
10
-    NovelCategory selectById(Integer categoryId);
11
+    //NovelCategory selectById(Integer categoryId);
12
+
13
+//    List<NovelCategory> selectCategoryList();
14
+    NovelCategory selectById(@Param("categoryId") String categoryId);
11
 }
15
 }

+ 6
- 0
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/mapper/NovelChapterMapper.java 파일 보기

27
     Integer selectMaxChapterOrderByNovelId(Long novelId);
27
     Integer selectMaxChapterOrderByNovelId(Long novelId);
28
 
28
 
29
     void updateReadCount(Long id);
29
     void updateReadCount(Long id);
30
+
31
+//    NovelChapter selectChapterById(Long id);
32
+//    int insertChapter(NovelChapter chapter);
33
+    List<NovelChapter> selectChapterList(NovelChapter chapter);
34
+    Integer selectMaxChapterOrder(Long novelId);
35
+    int selectChapterCountByNovelId(Long novelId);
30
 }
36
 }

+ 5
- 5
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/ChapterRepository.java 파일 보기

1
 package com.ruoyi.novel.service;
1
 package com.ruoyi.novel.service;
2
 
2
 
3
-import com.ruoyi.novel.domain.Chapter;
3
+import com.ruoyi.novel.domain.NovelChapter;
4
 import org.apache.ibatis.annotations.Param;
4
 import org.apache.ibatis.annotations.Param;
5
 //import org.springframework.data.elasticsearch.annotations.Query;
5
 //import org.springframework.data.elasticsearch.annotations.Query;
6
 import org.springframework.data.jpa.repository.JpaRepository;
6
 import org.springframework.data.jpa.repository.JpaRepository;
9
 import java.util.List;
9
 import java.util.List;
10
 
10
 
11
 // ChapterRepository.java
11
 // ChapterRepository.java
12
-public interface ChapterRepository extends JpaRepository<Chapter, Long> {
12
+public interface ChapterRepository extends JpaRepository<NovelChapter, Long> {
13
 
13
 
14
-    List<Chapter> findByNovelIdOrderByChapterOrderAsc(Long novelId);
14
+    List<NovelChapter> findByNovelIdOrderByChapterOrderAsc(Long novelId);
15
 
15
 
16
-    @Query("SELECT MAX(c.chapterOrder) FROM Chapter c WHERE c.novelId = :novelId")
17
-    Integer findMaxChapterOrderByNovelId(@Param("novelId") Long novelId);
16
+//    @Query("SELECT MAX(c.chapterOrder) FROM NovelChapter c WHERE c.novelId = :novelId")
17
+//    Integer findMaxChapterOrderByNovelId(@Param("novelId") Long novelId);
18
 }
18
 }

+ 1
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/NovelCategoryService.java 파일 보기

8
 public interface NovelCategoryService {
8
 public interface NovelCategoryService {
9
     List<NovelCategory> list();
9
     List<NovelCategory> list();
10
     List<NovelCategory> selectCategoryList();
10
     List<NovelCategory> selectCategoryList();
11
-    NovelCategory getCategoryById(Integer categoryId);
11
+    NovelCategory getCategoryById(String categoryId);
12
     List<NovelCategory> getCategoryTree();
12
     List<NovelCategory> getCategoryTree();
13
 }
13
 }

+ 3
- 3
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/NovelService.java 파일 보기

34
     List<NovelCategory> getAllCategories();
34
     List<NovelCategory> getAllCategories();
35
     List<Novel> getHotNovels();
35
     List<Novel> getHotNovels();
36
     NovelCategory getNovelsByCategory(Long categoryId);
36
     NovelCategory getNovelsByCategory(Long categoryId);
37
-    List<Chapter> getChaptersByNovelId(Long novelId);
38
-    Chapter getChapterContent(Long chapterId);
37
+    List<NovelChapter> getChaptersByNovelId(Long novelId);
38
+    NovelChapter getChapterContent(Long chapterId);
39
     void submitAuthorApplication(AuthorApplicationDTO dto, Long userId);
39
     void submitAuthorApplication(AuthorApplicationDTO dto, Long userId);
40
 
40
 
41
     List<Novel> getAllNovels();
41
     List<Novel> getAllNovels();
42
 
42
 
43
     Novel processNovelUpload(MultipartFile file, String title, Long authorId);
43
     Novel processNovelUpload(MultipartFile file, String title, Long authorId);
44
 
44
 
45
-    Chapter processChapterUpload(MultipartFile file, Long novelId, Integer chapterOrder);
45
+    NovelChapter processChapterUpload(MultipartFile file, Long novelId, Integer chapterOrder);
46
 
46
 
47
 //    void processNovelUpload(NovelUploadDTO dto);
47
 //    void processNovelUpload(NovelUploadDTO dto);
48
 //
48
 //

+ 1
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/impl/ChapterServiceImpl.java 파일 보기

4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
 import com.ruoyi.novel.domain.NovelChapter;
5
 import com.ruoyi.novel.domain.NovelChapter;
6
 import com.ruoyi.novel.domain.NovelContent;
6
 import com.ruoyi.novel.domain.NovelContent;
7
-import com.ruoyi.novel.mapper.ChapterMapper;
7
+//import com.ruoyi.novel.mapper.ChapterMapper;
8
 import com.ruoyi.novel.mapper.NovelChapterMapper;
8
 import com.ruoyi.novel.mapper.NovelChapterMapper;
9
 import com.ruoyi.novel.mapper.NovelContentMapper;
9
 import com.ruoyi.novel.mapper.NovelContentMapper;
10
 import com.ruoyi.novel.service.ChapterService;
10
 import com.ruoyi.novel.service.ChapterService;

+ 1
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/impl/NovelCategoryServiceImpl.java 파일 보기

26
     }
26
     }
27
 
27
 
28
     @Override
28
     @Override
29
-    public NovelCategory getCategoryById(Integer categoryId) {
29
+    public NovelCategory getCategoryById(String categoryId) {
30
         return novelCategoryMapper.selectById(categoryId);
30
         return novelCategoryMapper.selectById(categoryId);
31
     }
31
     }
32
 
32
 

+ 35
- 22
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/service/impl/NovelServiceImpl.java 파일 보기

10
 import com.ruoyi.novel.config.TableSupport;
10
 import com.ruoyi.novel.config.TableSupport;
11
 import com.ruoyi.novel.domain.*;
11
 import com.ruoyi.novel.domain.*;
12
 import com.ruoyi.novel.mapper.AuthorApplicationMapper;
12
 import com.ruoyi.novel.mapper.AuthorApplicationMapper;
13
-import com.ruoyi.novel.mapper.CategoryMapper;
14
-import com.ruoyi.novel.mapper.ChapterMapper;
13
+import com.ruoyi.novel.mapper.NovelCategoryMapper;
14
+import com.ruoyi.novel.mapper.NovelChapterMapper;
15
 import com.ruoyi.novel.mapper.NovelMapper;
15
 import com.ruoyi.novel.mapper.NovelMapper;
16
 //import com.ruoyi.novel.repository.elastic.NovelSearchRepository;
16
 //import com.ruoyi.novel.repository.elastic.NovelSearchRepository;
17
 
17
 
19
 import com.ruoyi.novel.service.*;
19
 import com.ruoyi.novel.service.*;
20
 import com.ruoyi.novel.utils.Base64Utils;
20
 import com.ruoyi.novel.utils.Base64Utils;
21
 import com.ruoyi.system.mapper.SysUserMapper;
21
 import com.ruoyi.system.mapper.SysUserMapper;
22
-import jdk.jfr.Category;
23
 import org.slf4j.Logger;
22
 import org.slf4j.Logger;
24
 import org.slf4j.LoggerFactory;
23
 import org.slf4j.LoggerFactory;
25
 import org.springframework.beans.factory.annotation.Autowired;
24
 import org.springframework.beans.factory.annotation.Autowired;
46
     @Autowired
45
     @Autowired
47
     private NovelMapper novelMapper;
46
     private NovelMapper novelMapper;
48
     @Autowired
47
     @Autowired
49
-    private ChapterMapper chapterMapper;
48
+    private NovelChapterMapper chapterMapper;
50
 
49
 
51
     @Autowired
50
     @Autowired
52
     private AuthorApplicationMapper authorApplicationMapper;
51
     private AuthorApplicationMapper authorApplicationMapper;
53
 
52
 
54
     @Autowired
53
     @Autowired
55
-    private CategoryMapper categoryMapper;
54
+    private NovelCategoryMapper categoryMapper;
56
 
55
 
57
     @Autowired
56
     @Autowired
58
     private SysUserMapper userMapper;
57
     private SysUserMapper userMapper;
114
             novelMapper.insertNovel(novel);
113
             novelMapper.insertNovel(novel);
115
 
114
 
116
             // 解析并保存章节
115
             // 解析并保存章节
117
-            List<Chapter> chapters = parseChapters(file);
116
+            List<NovelChapter> chapters = parseChapters(file);
118
             for (int i = 0; i < chapters.size(); i++) {
117
             for (int i = 0; i < chapters.size(); i++) {
119
-                Chapter chapter = chapters.get(i);
118
+                NovelChapter chapter = chapters.get(i);
120
                 chapter.setNovelId(novel.getId());
119
                 chapter.setNovelId(novel.getId());
121
                 chapter.setChapterOrder(i + 1);
120
                 chapter.setChapterOrder(i + 1);
122
                 chapter.setCreateTime(new Date());
121
                 chapter.setCreateTime(new Date());
129
         }
128
         }
130
     }
129
     }
131
 
130
 
132
-    private List<Chapter> parseChapters(MultipartFile file) throws IOException {
133
-        List<Chapter> chapters = new ArrayList<>();
131
+    private List<NovelChapter> parseChapters(MultipartFile file) throws IOException {
132
+        List<NovelChapter> chapters = new ArrayList<>();
134
         try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
133
         try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
135
             StringBuilder content = new StringBuilder();
134
             StringBuilder content = new StringBuilder();
136
             String line;
135
             String line;
165
                         line.matches("第\\d+章\\s+.+"));
164
                         line.matches("第\\d+章\\s+.+"));
166
     }
165
     }
167
 
166
 
168
-    private Chapter createChapter(String title, String content) {
169
-        Chapter chapter = new Chapter();
167
+    private NovelChapter createChapter(String title, String content) {
168
+        NovelChapter chapter = new NovelChapter();
170
         chapter.setTitle(title);
169
         chapter.setTitle(title);
171
         chapter.setContent(content);
170
         chapter.setContent(content);
172
         return chapter;
171
         return chapter;
173
     }
172
     }
174
     @Override
173
     @Override
175
     @Transactional
174
     @Transactional
176
-    public Chapter processChapterUpload(MultipartFile file, Long novelId, Integer chapterOrder) {
175
+    public NovelChapter processChapterUpload(MultipartFile file, Long novelId, Integer chapterOrder) {
177
         try {
176
         try {
178
             // 验证小说存在
177
             // 验证小说存在
179
             Novel novel = novelMapper.selectNovelById(novelId);
178
             Novel novel = novelMapper.selectNovelById(novelId);
192
             String content = new String(file.getBytes());
191
             String content = new String(file.getBytes());
193
 
192
 
194
             // 创建章节
193
             // 创建章节
195
-            Chapter chapter = new Chapter();
194
+            NovelChapter chapter = new NovelChapter();
196
             chapter.setNovelId(novelId);
195
             chapter.setNovelId(novelId);
197
             chapter.setTitle("第" + chapterOrder + "章");
196
             chapter.setTitle("第" + chapterOrder + "章");
198
             chapter.setContent(content);
197
             chapter.setContent(content);
279
     }
278
     }
280
 
279
 
281
     @Override
280
     @Override
282
-    public List<Chapter> getChaptersByNovelId(Long novelId) {
283
-        Chapter chapter = new Chapter();
281
+    public List<NovelChapter> getChaptersByNovelId(Long novelId) {
282
+        NovelChapter chapter = new NovelChapter();
284
         chapter.setNovelId(novelId);
283
         chapter.setNovelId(novelId);
285
         return chapterMapper.selectChapterList(chapter);
284
         return chapterMapper.selectChapterList(chapter);
286
     }
285
     }
287
 
286
 
287
+//    @Override
288
+//    public Chapter getChapterContent(Long chapterId) {
289
+//        Chapter chapter = chapterMapper.selectChapterById(chapterId);
290
+//        if (chapter != null && chapter.getContent() != null) {
291
+//            // 解码Base64内容
292
+//            String decodedContent = Base64Utils.decode(chapter.getContent());
293
+//            chapter.setContent(decodedContent);
294
+//        }
295
+//        return chapter;
296
+//        //return chapterMapper.selectChapterById(chapterId);
297
+//    }
288
     @Override
298
     @Override
289
-    public Chapter getChapterContent(Long chapterId) {
290
-        Chapter chapter = chapterMapper.selectChapterById(chapterId);
299
+    public NovelChapter getChapterContent(Long chapterId) {
300
+        NovelChapter chapter = chapterMapper.selectChapterById(chapterId);
291
         if (chapter != null && chapter.getContent() != null) {
301
         if (chapter != null && chapter.getContent() != null) {
292
-            // 解码Base64内容
293
-            String decodedContent = Base64Utils.decode(chapter.getContent());
294
-            chapter.setContent(decodedContent);
302
+            try {
303
+                // 解码Base64内容
304
+                String decodedContent = Base64Utils.decode(chapter.getContent());
305
+                chapter.setContent(decodedContent);
306
+            } catch (Exception e) {
307
+                logger.error("Base64解码失败,章节ID: " + chapterId, e);
308
+                // 如果解码失败,保持原内容不变
309
+            }
295
         }
310
         }
296
         return chapter;
311
         return chapter;
297
-        //return chapterMapper.selectChapterById(chapterId);
298
     }
312
     }
299
-
300
     @Override
313
     @Override
301
     @Transactional
314
     @Transactional
302
     public void submitAuthorApplication(AuthorApplicationDTO dto, Long userId) {
315
     public void submitAuthorApplication(AuthorApplicationDTO dto, Long userId) {

RuoYi-Vue/ruoyi-system/src/main/resources/mapper/novel/ChapterMapper.xml → RuoYi-Vue/ruoyi-system/src/main/resources/mapper/novel/NovelCategoryMapper.xml 파일 보기

1
 <?xml version="1.0" encoding="UTF-8"?>
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">
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">
3
+<mapper namespace="com.ruoyi.novel.mapper.NovelCategoryMapper">
4
 
4
 
5
     <resultMap id="NovelCategoryResult" type="NovelCategory">
5
     <resultMap id="NovelCategoryResult" type="NovelCategory">
6
         <id property="id" column="id" />
6
         <id property="id" column="id" />
17
         ORDER BY sort ASC
17
         ORDER BY sort ASC
18
     </select>
18
     </select>
19
 
19
 
20
-    <select id="selectById" parameterType="String" resultMap="NovelCategoryResult">
20
+    <select id="selectById" resultMap="NovelCategoryResult">
21
         SELECT id, title, pid, sort
21
         SELECT id, title, pid, sort
22
         FROM novel_category
22
         FROM novel_category
23
         WHERE id = #{categoryId}
23
         WHERE id = #{categoryId}
24
     </select>
24
     </select>
25
-    <select id="selectChapterCountByNovelId" parameterType="Long" resultType="int">
26
-        SELECT COUNT(*) FROM novel_chapter WHERE novel_id = #{novelId}
27
-    </select>
28
 </mapper>
25
 </mapper>

+ 72
- 15
RuoYi-Vue/ruoyi-system/src/main/resources/mapper/novel/NovelChapterMapper.xml 파일 보기

1
 <?xml version="1.0" encoding="UTF-8"?>
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">
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.NovelCategoryMapper">
3
+<mapper namespace="com.ruoyi.novel.mapper.NovelChapterMapper">
4
 
4
 
5
-    <resultMap id="NovelCategoryResult" type="NovelCategory">
5
+    <resultMap id="NovelChapterResult" type="NovelChapter">
6
         <id property="id" column="id" />
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
-        <!-- 其他字段映射 -->
7
+        <result property="novelId" column="novel_id" />
8
+        <result property="chapterTitle" column="chapter_title" />
9
+        <result property="chapterOrder" column="chapter_order" />
10
+        <result property="publishTime" column="publish_time" />
11
+        <result property="isVip" column="is_vip" />
12
+        <result property="createTime" column="create_time" />
13
+        <result property="updateTime" column="update_time" />
14
+        <result property="content" column="content" />
15
+        <result property="novelType" column="novel_type" />
16
+        <result property="updated" column="updated" />
17
+        <result property="reurl" column="reurl" />
11
     </resultMap>
18
     </resultMap>
12
 
19
 
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
20
+    <sql id="selectChapterVo">
21
+        select id, novel_id, chapter_title, chapter_order, publish_time, is_vip, create_time, update_time, content, novel_type, updated, reurl
22
+        from novel_chapter
23
+    </sql>
24
+
25
+    <!-- 根据ID查询章节 -->
26
+    <select id="selectChapterById" parameterType="Long" resultMap="NovelChapterResult">
27
+        <include refid="selectChapterVo"/>
28
+        where id = #{id}
29
+    </select>
30
+
31
+    <!-- 插入章节 -->
32
+    <insert id="insertChapter" parameterType="NovelChapter" useGeneratedKeys="true" keyProperty="id">
33
+        insert into novel_chapter (
34
+            novel_id,
35
+            chapter_title,
36
+            chapter_order,
37
+            publish_time,
38
+            is_vip,
39
+            create_time,
40
+            update_time,
41
+            content,
42
+            novel_type,
43
+            updated,
44
+            reurl
45
+        ) values (
46
+                     #{novelId},
47
+                     #{chapterTitle},
48
+                     #{chapterOrder},
49
+                     #{publishTime},
50
+                     #{isVip},
51
+                     #{createTime},
52
+                     #{updateTime},
53
+                     #{content},
54
+                     #{novelType},
55
+                     #{updated},
56
+                     #{reurl}
57
+                 )
58
+    </insert>
59
+
60
+    <!-- 查询章节列表 -->
61
+    <select id="selectChapterList" parameterType="NovelChapter" resultMap="NovelChapterResult">
62
+        <include refid="selectChapterVo"/>
63
+        <where>
64
+            <if test="novelId != null"> and novel_id = #{novelId}</if>
65
+            <if test="chapterTitle != null and chapterTitle != ''"> and chapter_title like concat('%', #{chapterTitle}, '%')</if>
66
+            <if test="chapterOrder != null"> and chapter_order = #{chapterOrder}</if>
67
+            <if test="isVip != null"> and is_vip = #{isVip}</if>
68
+        </where>
69
+        order by chapter_order asc
18
     </select>
70
     </select>
19
 
71
 
20
-    <select id="selectById" resultMap="NovelCategoryResult">
21
-        SELECT id, title, pid, sort
22
-        FROM novel_category
23
-        WHERE id = #{categoryId}
72
+    <!-- 查询小说的最大章节序号 -->
73
+    <select id="selectMaxChapterOrder" parameterType="Long" resultType="Integer">
74
+        select max(chapter_order) from novel_chapter where novel_id = #{novelId}
24
     </select>
75
     </select>
76
+
77
+    <!-- 查询小说的章节数量 -->
78
+    <select id="selectChapterCountByNovelId" parameterType="Long" resultType="int">
79
+        select count(*) from novel_chapter where novel_id = #{novelId}
80
+    </select>
81
+
25
 </mapper>
82
 </mapper>

Loading…
취소
저장