mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 14:39:21 +08:00
fix: 修改文章元信息也会计为每日编辑文章数的问题
This commit is contained in:
parent
a9b864efcb
commit
20361dceb6
@ -50,6 +50,16 @@ public interface ArticleMapper extends BaseMapper<ArticleEntity> {
|
||||
*/
|
||||
void updContentById(ArticleEntity entity);
|
||||
|
||||
/**
|
||||
* 查询某段时间内编辑过内容的文章数
|
||||
*
|
||||
* @param beginUpdTime 开始修改日期
|
||||
* @param endUpdTime 结束修改日期
|
||||
*/
|
||||
ArticleStatRes statUpdArticleCount(@Param("beginUpdTime") String beginUpdTime,
|
||||
@Param("endUpdTime") String endUpdTime,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 修改某段日期内修改的文章数据
|
||||
*
|
||||
|
@ -19,6 +19,7 @@ import com.blossom.backend.server.doc.pojo.DocTreeRes;
|
||||
import com.blossom.backend.server.utils.ArticleUtil;
|
||||
import com.blossom.backend.server.utils.DocUtil;
|
||||
import com.blossom.common.base.exception.XzException404;
|
||||
import com.blossom.common.base.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -188,6 +189,7 @@ public class ArticleService extends ServiceImpl<ArticleMapper, ArticleEntity> {
|
||||
if (req.getHtml() != null) {
|
||||
req.setHtml(req.getHtml().replaceAll("<p><br></p>", ""));
|
||||
}
|
||||
req.setUpdMarkdownTime(DateUtils.date());
|
||||
baseMapper.updContentById(req);
|
||||
referenceService.bind(req.getUserId(), req.getId(), req.getName(), req.getReferences());
|
||||
logService.insert(req.getId(), 0, req.getMarkdown());
|
||||
|
@ -118,6 +118,10 @@ public class ArticleEntity extends AbstractPOJO implements Serializable {
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 文章内容的修改时间
|
||||
*/
|
||||
private Date updMarkdownTime;
|
||||
|
||||
//region ============================== 非数据库字段 ==============================
|
||||
/**
|
||||
|
@ -42,12 +42,12 @@ public class ArticleStatJob {
|
||||
}
|
||||
|
||||
for (UserEntity user : users) {
|
||||
ArticleStatRes statCount = statService.statCount(toDayBegin, toDayEnd, user.getId());
|
||||
statService.updByDate(1, toDay, statCount.getArticleCount(), user.getId());
|
||||
ArticleStatRes statCount = statService.statUpdArticleCount(toDayBegin, toDayEnd, user.getId());
|
||||
statService.updByDate(ArticleStatTypeEnum.ARTICLE_HEATMAP, toDay, statCount.getArticleCount(), user.getId());
|
||||
|
||||
String toMouth = DateUtils.format(DateUtils.beginOfMonth(DateUtils.date()), DateUtils.PATTERN_YYYYMMDD);
|
||||
ArticleStatRes statWord = statService.statCount(null, null, user.getId());
|
||||
statService.updByDate(2, toMouth, statWord.getArticleWords(), user.getId());
|
||||
statService.updByDate(ArticleStatTypeEnum.ARTICLE_WORDS, toMouth, statWord.getArticleWords(), user.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +140,16 @@ public class ArticleStatService extends ServiceImpl<ArticleStatMapper, ArticleSt
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章统计, 文章数, 总字数
|
||||
*
|
||||
* @param beginUpdTime 修改日期的开始范围
|
||||
* @param endUpdTime 修改日期的结束范围
|
||||
*/
|
||||
public ArticleStatRes statUpdArticleCount(String beginUpdTime, String endUpdTime, Long userId) {
|
||||
return articleMapper.statUpdArticleCount(beginUpdTime, endUpdTime, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章统计, 文章数, 总字数
|
||||
*
|
||||
@ -161,7 +171,7 @@ public class ArticleStatService extends ServiceImpl<ArticleStatMapper, ArticleSt
|
||||
return;
|
||||
}
|
||||
for (ArticleWordsRes words : req.getWordsList()) {
|
||||
this.updByDate(ArticleStatTypeEnum.ARTICLE_WORDS.getType(), words.getDate() + "-01", words.getValue(), userId);
|
||||
this.updByDate(ArticleStatTypeEnum.ARTICLE_WORDS, words.getDate() + "-01", words.getValue(), userId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,26 +184,26 @@ public class ArticleStatService extends ServiceImpl<ArticleStatMapper, ArticleSt
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updByDate(Integer type, String date, Integer value, Long userId) {
|
||||
public void updByDate(ArticleStatTypeEnum type, String date, Integer value, Long userId) {
|
||||
if (value == null) {
|
||||
value = 0;
|
||||
}
|
||||
LambdaQueryWrapper<ArticleStatEntity> existWhere = new LambdaQueryWrapper<>();
|
||||
existWhere
|
||||
.eq(ArticleStatEntity::getUserId, userId)
|
||||
.eq(ArticleStatEntity::getType, type)
|
||||
.eq(ArticleStatEntity::getType, type.getType())
|
||||
.eq(ArticleStatEntity::getStatDate, date);
|
||||
if (baseMapper.exists(existWhere)) {
|
||||
LambdaQueryWrapper<ArticleStatEntity> updWhere = new LambdaQueryWrapper<>();
|
||||
updWhere.eq(ArticleStatEntity::getUserId, userId)
|
||||
.eq(ArticleStatEntity::getType, type)
|
||||
.eq(ArticleStatEntity::getType, type.getType())
|
||||
.eq(ArticleStatEntity::getStatDate, date);
|
||||
ArticleStatEntity upd = new ArticleStatEntity();
|
||||
upd.setStatValue(value);
|
||||
baseMapper.update(upd, updWhere);
|
||||
} else {
|
||||
ArticleStatEntity ist = new ArticleStatEntity();
|
||||
ist.setType(type);
|
||||
ist.setType(type.getType());
|
||||
ist.setStatDate(DateUtils.parse(date, DateUtils.PATTERN_YYYYMMDD));
|
||||
ist.setStatValue(value);
|
||||
ist.setUserId(userId);
|
||||
|
@ -92,12 +92,24 @@
|
||||
html = #{html},
|
||||
words = #{words},
|
||||
toc = #{toc},
|
||||
version = version + 1
|
||||
version = version + 1,
|
||||
upd_markdown_time = #{updMarkdownTime}
|
||||
where id = #{id}
|
||||
and user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<!-- ======================================== 统计 ======================================== -->
|
||||
<select id="statUpdArticleCount" resultType="com.blossom.backend.server.article.draft.pojo.ArticleStatRes">
|
||||
select count(*) as articleCount
|
||||
from blossom_article
|
||||
where user_id = #{userId}
|
||||
<if test="beginUpdTime != null and beginUpdTime != ''">
|
||||
and upd_markdown_time >= #{beginUpdTime}
|
||||
</if>
|
||||
<if test="endUpdTime != null and endUpdTime != ''">
|
||||
and #{endUpdTime} >= upd_markdown_time
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="statCount" resultType="com.blossom.backend.server.article.draft.pojo.ArticleStatRes">
|
||||
select count(*) as articleCount, sum(words) as articleWords
|
||||
|
@ -641,4 +641,7 @@ CREATE TABLE IF NOT EXISTS `base_user_param`
|
||||
COLLATE = utf8mb4_bin;
|
||||
|
||||
-- Code that might be wrong goes last
|
||||
alter table blossom_folder add column star_status tinyint(1) NOT NULL DEFAULT 0 COMMENT '收藏 0:否,1:是';
|
||||
-- since 1.14.0
|
||||
alter table blossom_folder add column star_status tinyint(1) NOT NULL DEFAULT 0 COMMENT '收藏 0:否,1:是';
|
||||
-- since 1.15.0
|
||||
alter table blossom_article add column upd_markdown_time datetime COMMENT '文章内容的修改时间';
|
Loading…
Reference in New Issue
Block a user