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

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

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

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

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

@ -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);
}
/**
* 删除已经成功更新的解析日志
* */

@ -8,6 +8,7 @@
<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>
@ -27,7 +28,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
@ -56,7 +58,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
@ -68,9 +71,10 @@
</where>
</sql>
<sql id="Base_Column_List">
id, book_url, book_name, score, create_time, priority
id, book_url, book_name, score, create_time, priority, update_count
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="xyz.zinglizingli.books.po.BookParseLogExample" >
<select id="selectByExample" resultMap="BaseResultMap"
parameterType="xyz.zinglizingli.books.po.BookParseLogExample">
select
<if test="distinct">
distinct
@ -102,11 +106,11 @@
</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
@ -129,6 +133,9 @@
<if test="priority != null">
priority,
</if>
<if test="updateCount != null">
update_count,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -149,9 +156,13 @@
<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 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"/>
@ -178,6 +189,9 @@
<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"/>
@ -190,7 +204,8 @@
book_name = #{record.bookName,jdbcType=VARCHAR},
score = #{record.score,jdbcType=REAL},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
priority = #{record.priority,jdbcType=TINYINT}
priority = #{record.priority,jdbcType=TINYINT},
update_count = #{record.updateCount,jdbcType=TINYINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
@ -213,6 +228,9 @@
<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>
@ -222,7 +240,29 @@
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

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