diff --git a/novel-front/src/main/java/xyz/zinglizingli/BookApplication.java b/novel-front/src/main/java/xyz/zinglizingli/BookApplication.java index e1cfe44..6a1acc5 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/BookApplication.java +++ b/novel-front/src/main/java/xyz/zinglizingli/BookApplication.java @@ -7,12 +7,14 @@ import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @SpringBootApplication @EnableCaching @EnableScheduling +@EnableAsync @MapperScan({"xyz.zinglizingli.*.mapper"}) @ServletComponentScan public class BookApplication { diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/mapper/BookParseLogMapper.java b/novel-front/src/main/java/xyz/zinglizingli/books/mapper/BookParseLogMapper.java index 54a15bf..6140e0a 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/mapper/BookParseLogMapper.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/mapper/BookParseLogMapper.java @@ -27,4 +27,15 @@ public interface BookParseLogMapper { int updateByPrimaryKeySelective(BookParseLog record); int updateByPrimaryKey(BookParseLog record); + + /** + * 增加小说更新次数 + * + * @param logs*/ + void addBookUpdateCount(List logs); + + /** + * 查询解析日志 + * */ + List queryBookParseLogs(); } \ No newline at end of file diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLog.java b/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLog.java index 25a6802..bd9bcb5 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLog.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLog.java @@ -15,6 +15,8 @@ public class BookParseLog { private Byte priority; + private Byte updateCount; + public Long getId() { return id; } @@ -62,4 +64,12 @@ public class BookParseLog { public void setPriority(Byte priority) { this.priority = priority; } + + public Byte getUpdateCount() { + return updateCount; + } + + public void setUpdateCount(Byte updateCount) { + this.updateCount = updateCount; + } } \ No newline at end of file diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLogExample.java b/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLogExample.java index 39e4a84..e11e208 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLogExample.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/po/BookParseLogExample.java @@ -484,6 +484,66 @@ public class BookParseLogExample { addCriterion("priority not between", value1, value2, "priority"); return (Criteria) this; } + + public Criteria andUpdateCountIsNull() { + addCriterion("update_count is null"); + return (Criteria) this; + } + + public Criteria andUpdateCountIsNotNull() { + addCriterion("update_count is not null"); + return (Criteria) this; + } + + public Criteria andUpdateCountEqualTo(Byte value) { + addCriterion("update_count =", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountNotEqualTo(Byte value) { + addCriterion("update_count <>", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountGreaterThan(Byte value) { + addCriterion("update_count >", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountGreaterThanOrEqualTo(Byte value) { + addCriterion("update_count >=", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountLessThan(Byte value) { + addCriterion("update_count <", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountLessThanOrEqualTo(Byte value) { + addCriterion("update_count <=", value, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountIn(List values) { + addCriterion("update_count in", values, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountNotIn(List values) { + addCriterion("update_count not in", values, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountBetween(Byte value1, Byte value2) { + addCriterion("update_count between", value1, value2, "updateCount"); + return (Criteria) this; + } + + public Criteria andUpdateCountNotBetween(Byte value1, Byte value2) { + addCriterion("update_count not between", value1, value2, "updateCount"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java b/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java index 745557c..c06636e 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import tk.mybatis.orderbyhelper.OrderByHelper; @@ -457,13 +458,19 @@ public class BookService { * 查询解析日志 * */ public List queryBookParseLogs() { - PageHelper.startPage(1,100); - BookParseLogExample example = new BookParseLogExample(); - example.setOrderByClause("priority asc,create_time desc"); - List logs = bookParseLogMapper.selectByExample(example); + List logs = bookParseLogMapper.queryBookParseLogs(); + SpringUtil.getBean(BookService.class).addBookUpdateCount(logs); return logs; } + /** + * 增加小说更新次数 + * */ + @Async + public void addBookUpdateCount(List logs) { + bookParseLogMapper.addBookUpdateCount(logs); + } + /** * 删除已经成功更新的解析日志 * */ diff --git a/novel-front/src/main/resources/mybatis/mapping/BookParseLogMapper.xml b/novel-front/src/main/resources/mybatis/mapping/BookParseLogMapper.xml index 7aded6d..a53741c 100644 --- a/novel-front/src/main/resources/mybatis/mapping/BookParseLogMapper.xml +++ b/novel-front/src/main/resources/mybatis/mapping/BookParseLogMapper.xml @@ -1,228 +1,268 @@ - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - + + + + id, book_url, book_name, score, create_time, priority, update_count + + - select - - distinct - - - from book_parse_log - - - - - order by ${orderByClause} - - - - + + from book_parse_log + + + + + order by ${orderByClause} + + + + delete from book_parse_log where id = #{id,jdbcType=BIGINT} - - delete from book_parse_log - - - - - + + delete from book_parse_log + + + + + insert into book_parse_log (id, book_url, book_name, - score, create_time, priority - ) + score, create_time, priority, + update_count) values (#{id,jdbcType=BIGINT}, #{bookUrl,jdbcType=VARCHAR}, #{bookName,jdbcType=VARCHAR}, - #{score,jdbcType=REAL}, #{createTime,jdbcType=TIMESTAMP}, #{priority,jdbcType=TINYINT} - ) + #{score,jdbcType=REAL}, #{createTime,jdbcType=TIMESTAMP}, #{priority,jdbcType=TINYINT}, + #{updateCount,jdbcType=TINYINT}) - - insert into book_parse_log - - - id, - - - book_url, - - - book_name, - - - score, - - - create_time, - - - priority, - - - - - #{id,jdbcType=BIGINT}, - - - #{bookUrl,jdbcType=VARCHAR}, - - - #{bookName,jdbcType=VARCHAR}, - - - #{score,jdbcType=REAL}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{priority,jdbcType=TINYINT}, - - - - - - update book_parse_log - - - id = #{record.id,jdbcType=BIGINT}, - - + + insert into book_parse_log + + + id, + + + book_url, + + + book_name, + + + score, + + + create_time, + + + priority, + + + update_count, + + + + + #{id,jdbcType=BIGINT}, + + + #{bookUrl,jdbcType=VARCHAR}, + + + #{bookName,jdbcType=VARCHAR}, + + + #{score,jdbcType=REAL}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{priority,jdbcType=TINYINT}, + + + #{updateCount,jdbcType=TINYINT}, + + + + + + update book_parse_log + + + id = #{record.id,jdbcType=BIGINT}, + + + book_url = #{record.bookUrl,jdbcType=VARCHAR}, + + + book_name = #{record.bookName,jdbcType=VARCHAR}, + + + score = #{record.score,jdbcType=REAL}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + priority = #{record.priority,jdbcType=TINYINT}, + + + update_count = #{record.updateCount,jdbcType=TINYINT}, + + + + + + + + update book_parse_log + set id = #{record.id,jdbcType=BIGINT}, book_url = #{record.bookUrl,jdbcType=VARCHAR}, - - book_name = #{record.bookName,jdbcType=VARCHAR}, - - score = #{record.score,jdbcType=REAL}, - - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - - priority = #{record.priority,jdbcType=TINYINT}, - - - - - - - - update book_parse_log - set id = #{record.id,jdbcType=BIGINT}, - book_url = #{record.bookUrl,jdbcType=VARCHAR}, - book_name = #{record.bookName,jdbcType=VARCHAR}, - score = #{record.score,jdbcType=REAL}, - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - priority = #{record.priority,jdbcType=TINYINT} - - - - - - update book_parse_log - - - book_url = #{bookUrl,jdbcType=VARCHAR}, - - - book_name = #{bookName,jdbcType=VARCHAR}, - - - score = #{score,jdbcType=REAL}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - priority = #{priority,jdbcType=TINYINT}, - - - where id = #{id,jdbcType=BIGINT} - - + update_count = #{record.updateCount,jdbcType=TINYINT} + + + + + + update book_parse_log + + + book_url = #{bookUrl,jdbcType=VARCHAR}, + + + book_name = #{bookName,jdbcType=VARCHAR}, + + + score = #{score,jdbcType=REAL}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + priority = #{priority,jdbcType=TINYINT}, + + + update_count = #{updateCount,jdbcType=TINYINT}, + + + where id = #{id,jdbcType=BIGINT} + + update book_parse_log set book_url = #{bookUrl,jdbcType=VARCHAR}, book_name = #{bookName,jdbcType=VARCHAR}, score = #{score,jdbcType=REAL}, create_time = #{createTime,jdbcType=TIMESTAMP}, - priority = #{priority,jdbcType=TINYINT} + priority = #{priority,jdbcType=TINYINT}, + update_count = #{updateCount,jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} + + + + update book_parse_log set update_count = update_count + 1 + where id in + + #{log.id} + + + + + + \ No newline at end of file diff --git a/sql/2020-04-22.sql b/sql/2020-04-22.sql new file mode 100644 index 0000000..584ba62 --- /dev/null +++ b/sql/2020-04-22.sql @@ -0,0 +1 @@ +alter table book_parse_log add column `update_count` TINYINT(2) not null default 0 ;