mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
代码结构调整,数据库无效数据定时清理
This commit is contained in:
parent
3dcabd3cf3
commit
be3cf1bb91
@ -30,4 +30,9 @@ public interface BookContentMapper {
|
||||
int updateByPrimaryKey(BookContent record);
|
||||
|
||||
void insertBatch(List<BookContent> bookContent);
|
||||
|
||||
/**
|
||||
* 清除无效内容
|
||||
* */
|
||||
void clearInvilidContent();
|
||||
}
|
@ -33,7 +33,10 @@ public interface BookIndexMapper {
|
||||
|
||||
void insertBatch(List<BookIndex> bookIndex);
|
||||
|
||||
String queryNewstIndexName(@Param("bookId") Long bookId);
|
||||
|
||||
|
||||
/**
|
||||
* 清除无效章节
|
||||
* */
|
||||
void clearInvilidIndex();
|
||||
}
|
@ -36,10 +36,14 @@ public interface BookMapper {
|
||||
void addVisitCount(@Param("bookId") Long bookId);
|
||||
|
||||
|
||||
List<String> queryEndBookIdList();
|
||||
|
||||
/**
|
||||
* 查询推荐书籍数据
|
||||
* */
|
||||
List<Book> queryRecBooks(List<Map<String, String>> configMap);
|
||||
|
||||
/**
|
||||
* 清理无效书籍(1个月前更新的无章节书籍)
|
||||
* */
|
||||
void clearInvilidBook();
|
||||
}
|
@ -15,11 +15,11 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.orderbyhelper.OrderByHelper;
|
||||
import xyz.zinglizingli.books.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.books.enums.PicSaveType;
|
||||
import xyz.zinglizingli.common.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.common.enums.PicSaveType;
|
||||
import xyz.zinglizingli.books.mapper.*;
|
||||
import xyz.zinglizingli.books.po.*;
|
||||
import xyz.zinglizingli.books.util.UUIDUtils;
|
||||
import xyz.zinglizingli.common.utils.UUIDUtils;
|
||||
import xyz.zinglizingli.common.cache.CommonCacheUtil;
|
||||
import xyz.zinglizingli.common.utils.RestTemplateUtil;
|
||||
|
||||
@ -536,4 +536,19 @@ public class BookService {
|
||||
public List<Book> queryRecBooks(List<Map<String, String>> configMap) {
|
||||
return bookMapper.queryRecBooks(configMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理数据库中无效数据
|
||||
* */
|
||||
public void clearInvilidData() {
|
||||
|
||||
//清除无效内容
|
||||
bookContentMapper.clearInvilidContent();
|
||||
|
||||
//清除无效章节
|
||||
bookIndexMapper.clearInvilidIndex();
|
||||
|
||||
//清楚无效书籍
|
||||
bookMapper.clearInvilidBook();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import xyz.zinglizingli.books.po.User;
|
||||
import xyz.zinglizingli.books.po.UserExample;
|
||||
import xyz.zinglizingli.books.po.UserRefBook;
|
||||
import xyz.zinglizingli.books.po.UserRefBookExample;
|
||||
import xyz.zinglizingli.books.util.MD5Util;
|
||||
import xyz.zinglizingli.common.utils.MD5Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -2,16 +2,14 @@ package xyz.zinglizingli.books.web;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import xyz.zinglizingli.books.po.User;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
import xyz.zinglizingli.books.service.UserService;
|
||||
import xyz.zinglizingli.books.util.UUIDUtils;
|
||||
import xyz.zinglizingli.common.utils.UUIDUtils;
|
||||
import xyz.zinglizingli.common.cache.CommonCacheUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.constant;
|
||||
package xyz.zinglizingli.common.constant;
|
||||
|
||||
public class CacheKeyConstans {
|
||||
public static final String HOT_BOOK_LIST_KEY = "hotBookListKey";
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.enums;
|
||||
package xyz.zinglizingli.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
@ -0,0 +1,33 @@
|
||||
package xyz.zinglizingli.common.schedule;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
|
||||
/**
|
||||
* 清理数据库中无效数据
|
||||
*
|
||||
* @author 11797*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class ClearInvilidDataSchedule {
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
/**
|
||||
* 每天凌晨两点清理一次
|
||||
*/
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void clear() {
|
||||
|
||||
log.debug("ClearInvilidDataSchedule。。。。。。。。。。。。");
|
||||
|
||||
bookService.clearInvilidData();
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import xyz.zinglizingli.books.po.Book;
|
||||
import xyz.zinglizingli.books.po.BookContent;
|
||||
import xyz.zinglizingli.books.po.BookIndex;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
import xyz.zinglizingli.books.util.ExcutorUtils;
|
||||
import xyz.zinglizingli.common.utils.ExcutorUtils;
|
||||
import xyz.zinglizingli.common.utils.RestTemplateUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -88,7 +88,6 @@ public class CrawlBooksSchedule {
|
||||
Pattern pattern = compile("value=\"(\\d+)/(\\d+)\"");
|
||||
Matcher matcher = pattern.matcher(forObject);
|
||||
boolean isFind = matcher.find();
|
||||
System.out.println("匹配分页数" + isFind);
|
||||
if (isFind) {
|
||||
//解析第一页书籍的数据
|
||||
Pattern bookPatten = compile("href=\"/(\\d+_\\d+)/\"");
|
||||
@ -283,7 +282,6 @@ public class CrawlBooksSchedule {
|
||||
Pattern pattern = compile("value=\"(\\d+)/(\\d+)\"");
|
||||
Matcher matcher = pattern.matcher(forObject);
|
||||
boolean isFind = matcher.find();
|
||||
System.out.println("匹配分页数" + isFind);
|
||||
if (isFind) {
|
||||
//解析第一页书籍的数据
|
||||
Pattern bookPatten = compile("href=\"/(bqge\\d+)/\"");
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.util;
|
||||
package xyz.zinglizingli.common.utils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.util;
|
||||
package xyz.zinglizingli.common.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.util;
|
||||
package xyz.zinglizingli.common.utils;
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.zinglizingli.books.util;
|
||||
package xyz.zinglizingli.common.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -2,11 +2,10 @@ package xyz.zinglizingli.common.web;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import xyz.zinglizingli.books.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.common.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.books.po.Book;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
import xyz.zinglizingli.common.cache.CommonCacheUtil;
|
||||
|
@ -3,9 +3,9 @@ server:
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://47.106.243.172:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: books
|
||||
password: books!8888
|
||||
password: books
|
||||
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
# username: root
|
||||
# password: test123456
|
||||
|
@ -56,7 +56,7 @@
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||
<logger name="*" level="ERROR">
|
||||
<logger name="xyz.zinglizingli" level="DEBUG">
|
||||
<appender-ref ref="debug" />
|
||||
</logger>
|
||||
</configuration>
|
@ -225,4 +225,12 @@
|
||||
</trim>
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="clearInvilidContent">
|
||||
delete t1 from book_content t1 left join book_index t2
|
||||
on t1.book_id = t2.book_id and t1.index_num = t2.index_num
|
||||
left join book t3 on t1.book_id = t3.id
|
||||
where t2.id is null or t3.id is null
|
||||
|
||||
</delete>
|
||||
</mapper>
|
@ -213,11 +213,13 @@
|
||||
</insert>
|
||||
|
||||
|
||||
<select id="queryNewstIndexName" parameterType="long" resultType="string">
|
||||
|
||||
select index_name from book_index where book_id = #{bookId,jdbcType=BIGINT} order by index_num desc limit 1
|
||||
</select>
|
||||
<delete id="clearInvilidIndex">
|
||||
delete t1 from book_index t1 left join book_content t2
|
||||
on t1.book_id = t2.book_id and t1.index_num = t2.index_num
|
||||
left join book t3 on t1.book_id = t3.id
|
||||
where t2.id is null or t3.id is null
|
||||
|
||||
</delete>
|
||||
|
||||
|
||||
</mapper>
|
@ -388,4 +388,11 @@
|
||||
</where>
|
||||
limit 3
|
||||
</select>
|
||||
|
||||
|
||||
<delete id="clearInvilidBook">
|
||||
delete from book
|
||||
where id not in (select book_id from book_index)
|
||||
and update_time <![CDATA[ <= ]]> DATE_SUB(curdate(),INTERVAL 10 DAY)
|
||||
</delete>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user