提交 c4cce942 编写于 作者: yubinCloud's avatar yubinCloud

11-6 后端增加获取统计数值的接口

上级 14a5175f
package io.github.yubincloud.fairywiki.controller;
import io.github.yubincloud.fairywiki.dto.resp.ErrorCode;
import io.github.yubincloud.fairywiki.dto.resp.RestfulModel;
import io.github.yubincloud.fairywiki.dto.resp.StatisticRespDto;
import io.github.yubincloud.fairywiki.service.EbookSnapshotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/ebook-snapshot")
@Api("电子书快照管理")
public class EbookSnapshotController {
@Resource
private EbookSnapshotService ebookSnapshotService;
@GetMapping("/get-statistic")
@ApiOperation(value = "从电子书快照中获取统计数据")
public RestfulModel<List<StatisticRespDto>> getStatistic() {
List<StatisticRespDto> statisticRespDtoList = ebookSnapshotService.getStatistic();
return new RestfulModel<>(ErrorCode.SUCCESS, "", statisticRespDtoList);
}
}
package io.github.yubincloud.fairywiki.dto.resp;
import lombok.Data;
import java.util.Date;
@Data
public class StatisticRespDto {
private Date date;
private int viewCount;
private int voteCount;
private int viewIncrease;
private int voteIncrease;
}
package io.github.yubincloud.fairywiki.mapper;
import io.github.yubincloud.fairywiki.dto.resp.StatisticRespDto;
import java.util.List;
public interface EbookSnapshotMapperCustom {
void genSnapshot();
List<StatisticRespDto> getStatistic();
}
package io.github.yubincloud.fairywiki.service;
import io.github.yubincloud.fairywiki.dto.resp.StatisticRespDto;
import io.github.yubincloud.fairywiki.mapper.EbookSnapshotMapperCustom;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class EbookSnapshotService {
......@@ -14,4 +16,11 @@ public class EbookSnapshotService {
public void genSnapshots() {
ebookSnapshotMapperCustom.genSnapshot();
}
/**
* 获取首页数值数据:总阅读数、总点赞数、今日阅读数、今日点赞数、今日预计阅读数、今日预计阅读增长
*/
public List<StatisticRespDto> getStatistic() {
return ebookSnapshotMapperCustom.getStatistic();
}
}
......@@ -37,4 +37,21 @@
WHERE t1.`date` = curdate();
</update>
<select id="getStatistic" resultType="io.github.yubincloud.fairywiki.dto.resp.StatisticRespDto">
SELECT
t1.`date` AS `date`,
SUM(t1.view_count) AS viewCount,
SUM(t1.vote_count) AS voteCount,
SUM(t1.view_increase) AS viewIncrease,
SUM(t1.vote_increase) AS voteIncrease
FROM
ebook_snapshot t1
WHERE
t1.`date` >= date_sub(curdate(), INTERVAL 1 DAY)
GROUP BY
t1.`date`
ORDER BY
t1.`date` ASC;
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册