This commit is contained in:
xiongxiaoyang 2020-04-22 12:55:24 +08:00
parent d7e3dee2af
commit 8aa724bd69
7 changed files with 339 additions and 208 deletions

View File

@ -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 {

View File

@ -27,4 +27,15 @@ public interface BookParseLogMapper {
int updateByPrimaryKeySelective(BookParseLog record);
int updateByPrimaryKey(BookParseLog record);
/**
* 增加小说更新次数
*
* @param logs*/
void addBookUpdateCount(List<BookParseLog> logs);
/**
* 查询解析日志
* */
List<BookParseLog> queryBookParseLogs();
}

View File

@ -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;
}
}

View File

@ -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<Byte> values) {
addCriterion("update_count in", values, "updateCount");
return (Criteria) this;
}
public Criteria andUpdateCountNotIn(List<Byte> 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 {

View File

@ -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<BookParseLog> queryBookParseLogs() {
PageHelper.startPage(1,100);
BookParseLogExample example = new BookParseLogExample();
example.setOrderByClause("priority asc,create_time desc");
List<BookParseLog> logs = bookParseLogMapper.selectByExample(example);
List<BookParseLog> logs = bookParseLogMapper.queryBookParseLogs();
SpringUtil.getBean(BookService.class).addBookUpdateCount(logs);
return logs;
}
/**
* 增加小说更新次数
* */
@Async
public void addBookUpdateCount(List<BookParseLog> logs) {
bookParseLogMapper.addBookUpdateCount(logs);
}
/**
* 删除已经成功更新的解析日志
* */

View File

@ -1,228 +1,268 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="xyz.zinglizingli.books.mapper.BookParseLogMapper" >
<resultMap id="BaseResultMap" type="xyz.zinglizingli.books.po.BookParseLog" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="book_url" property="bookUrl" jdbcType="VARCHAR" />
<result column="book_name" property="bookName" jdbcType="VARCHAR" />
<result column="score" property="score" jdbcType="REAL" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="priority" property="priority" jdbcType="TINYINT" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
<mapper namespace="xyz.zinglizingli.books.mapper.BookParseLogMapper">
<resultMap id="BaseResultMap" type="xyz.zinglizingli.books.po.BookParseLog">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="book_url" property="bookUrl" jdbcType="VARCHAR"/>
<result column="book_name" property="bookName" jdbcType="VARCHAR"/>
<result column="score" property="score" jdbcType="REAL"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="priority" property="priority" jdbcType="TINYINT"/>
<result column="update_count" property="updateCount" jdbcType="TINYINT"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</trim>
</where>
</sql>
<sql id="Base_Column_List">
id, book_url, book_name, score, create_time, priority, update_count
</sql>
<select id="selectByExample" resultMap="BaseResultMap"
parameterType="xyz.zinglizingli.books.po.BookParseLogExample">
select
<if test="distinct">
distinct
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
id, book_url, book_name, score, create_time, priority
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="xyz.zinglizingli.books.po.BookParseLogExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from book_parse_log
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from book_parse_log
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
<include refid="Base_Column_List"/>
from book_parse_log
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from book_parse_log
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from book_parse_log
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="xyz.zinglizingli.books.po.BookParseLogExample" >
delete from book_parse_log
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="xyz.zinglizingli.books.po.BookParseLog" >
<delete id="deleteByExample" parameterType="xyz.zinglizingli.books.po.BookParseLogExample">
delete from book_parse_log
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="xyz.zinglizingli.books.po.BookParseLog">
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>
<insert id="insertSelective" parameterType="xyz.zinglizingli.books.po.BookParseLog" >
insert into book_parse_log
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="bookUrl != null" >
book_url,
</if>
<if test="bookName != null" >
book_name,
</if>
<if test="score != null" >
score,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="priority != null" >
priority,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="bookUrl != null" >
#{bookUrl,jdbcType=VARCHAR},
</if>
<if test="bookName != null" >
#{bookName,jdbcType=VARCHAR},
</if>
<if test="score != null" >
#{score,jdbcType=REAL},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="priority != null" >
#{priority,jdbcType=TINYINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="xyz.zinglizingli.books.po.BookParseLogExample" resultType="java.lang.Integer" >
select count(*) from book_parse_log
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update book_parse_log
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.bookUrl != null" >
<insert id="insertSelective" parameterType="xyz.zinglizingli.books.po.BookParseLog">
insert into book_parse_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="bookUrl != null">
book_url,
</if>
<if test="bookName != null">
book_name,
</if>
<if test="score != null">
score,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="priority != null">
priority,
</if>
<if test="updateCount != null">
update_count,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="bookUrl != null">
#{bookUrl,jdbcType=VARCHAR},
</if>
<if test="bookName != null">
#{bookName,jdbcType=VARCHAR},
</if>
<if test="score != null">
#{score,jdbcType=REAL},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="priority != null">
#{priority,jdbcType=TINYINT},
</if>
<if test="updateCount != null">
#{updateCount,jdbcType=TINYINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="xyz.zinglizingli.books.po.BookParseLogExample"
resultType="java.lang.Integer">
select count(*) from book_parse_log
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update book_parse_log
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.bookUrl != null">
book_url = #{record.bookUrl,jdbcType=VARCHAR},
</if>
<if test="record.bookName != null">
book_name = #{record.bookName,jdbcType=VARCHAR},
</if>
<if test="record.score != null">
score = #{record.score,jdbcType=REAL},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.priority != null">
priority = #{record.priority,jdbcType=TINYINT},
</if>
<if test="record.updateCount != null">
update_count = #{record.updateCount,jdbcType=TINYINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
update book_parse_log
set id = #{record.id,jdbcType=BIGINT},
book_url = #{record.bookUrl,jdbcType=VARCHAR},
</if>
<if test="record.bookName != null" >
book_name = #{record.bookName,jdbcType=VARCHAR},
</if>
<if test="record.score != null" >
score = #{record.score,jdbcType=REAL},
</if>
<if test="record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.priority != null" >
priority = #{record.priority,jdbcType=TINYINT},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
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}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="xyz.zinglizingli.books.po.BookParseLog" >
update book_parse_log
<set >
<if test="bookUrl != null" >
book_url = #{bookUrl,jdbcType=VARCHAR},
</if>
<if test="bookName != null" >
book_name = #{bookName,jdbcType=VARCHAR},
</if>
<if test="score != null" >
score = #{score,jdbcType=REAL},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="priority != null" >
priority = #{priority,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="xyz.zinglizingli.books.po.BookParseLog" >
update_count = #{record.updateCount,jdbcType=TINYINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="xyz.zinglizingli.books.po.BookParseLog">
update book_parse_log
<set>
<if test="bookUrl != null">
book_url = #{bookUrl,jdbcType=VARCHAR},
</if>
<if test="bookName != null">
book_name = #{bookName,jdbcType=VARCHAR},
</if>
<if test="score != null">
score = #{score,jdbcType=REAL},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="priority != null">
priority = #{priority,jdbcType=TINYINT},
</if>
<if test="updateCount != null">
update_count = #{updateCount,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="xyz.zinglizingli.books.po.BookParseLog">
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>
<update id="addBookUpdateCount">
update book_parse_log set update_count = update_count + 1
where id in
<foreach collection="list" item="log" separator="," open="(" close=")">
#{log.id}
</foreach>
</update>
<select id="queryBookParseLogs" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from book_parse_log
where update_count <![CDATA[ < ]]> 5
order by priority asc,create_time desc
limit 100
</select>
</mapper>

1
sql/2020-04-22.sql Normal file
View File

@ -0,0 +1 @@
alter table book_parse_log add column `update_count` TINYINT(2) not null default 0 ;