Skip to content

Commit

Permalink
添加数据统计分析&优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileZXLee committed Dec 18, 2022
1 parent 38c683f commit e4b7bd9
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.zxlee.znotifyapi.controller;

import cn.zxlee.znotifyapi.pojo.bo.StatisticsPageBO;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsAnalysisResultVO;
import cn.zxlee.znotifyapi.pojo.vo.VersionVO;
import cn.zxlee.znotifyapi.pojo.vo.base.PageResultVO;
import cn.zxlee.znotifyapi.response.Result;
Expand Down Expand Up @@ -41,4 +42,10 @@ public Result<PageResultVO<VersionVO>> getStatistics(@RequestHeader String token
}};
return Result.success(statisticsService.listByPage(params, bo));
}

@GetMapping("/analysis/{project_id}")
@ApiOperation("获取项目下的访问数据分析")
public Result<StatisticsAnalysisResultVO> getStatisticsAnalysis(@RequestHeader String token, @NotEmpty @PathVariable(value = "project_id") String projectId){
return Result.success(statisticsService.getStatisticsAnalysisResult(token, projectId));
}
}
20 changes: 20 additions & 0 deletions src/main/java/cn/zxlee/znotifyapi/mapper/StatisticsMapper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cn.zxlee.znotifyapi.mapper;

import cn.zxlee.znotifyapi.mapper.base.BaseMapper;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsDateCountVO;
import cn.zxlee.znotifyapi.pojo.po.StatisticsPO;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsRegionCountVO;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -11,5 +13,23 @@ public interface StatisticsMapper extends BaseMapper<StatisticsPO> {

List<StatisticsPO> listGroupByIp(String projectId);

List<StatisticsPO> todayListGroupByIp(String projectId);

List<StatisticsPO> yesterdayListGroupByIp(String projectId);

List<StatisticsRegionCountVO> ipRegionCountList(String projectId);

int listCount(String projectId);

int todayListCount(String projectId);

int yesterdayListCount(String projectId);

int days7ListCount(String projectId);

int days30ListCount(String projectId);

List<StatisticsDateCountVO> days10CountList(String projectId);

List<StatisticsDateCountVO> months12CountList(String projectId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cn.zxlee.znotifyapi.pojo.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
* @program: z-notify-api
* @description: StatisticsDetailResultVO
* @author: zxlee
* @create: 2022-12-18 18:38
**/

@Data
@ApiModel("统计结果详情VO")
public class StatisticsAnalysisResultVO {
@ApiModelProperty("访问次数")
private Integer viewCount;
@ApiModelProperty("访问人数,根据ip区分访问次数,相同ip只算一次")
private Integer visitorCount;
@ApiModelProperty("今日总访问次数")
private Integer todayViewCount;
@ApiModelProperty("今日总访问人数")
private Integer todayVisitorCount;
@ApiModelProperty("昨日总访问次数")
private Integer yesterdayViewCount;
@ApiModelProperty("昨日总访问人数")
private Integer yesterdayVisitorCount;
@ApiModelProperty("近7天总访问次数")
private Integer days7ViewCount;
@ApiModelProperty("近30天总访问次数")
private Integer days30ViewCount;

@ApiModelProperty("近10天每天的访问次数")
private List<StatisticsDateCountVO> days10CountList;
@ApiModelProperty("近12个月每月的访问次数")
private List<StatisticsDateCountVO> months12CountList;
@ApiModelProperty("各个ip归属地数量")
private List<StatisticsRegionCountVO> ipRegionCountList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.zxlee.znotifyapi.pojo.vo;

import cn.zxlee.znotifyapi.pojo.BasePOJO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @program: z-notify-api
* @description: StatisticsDateCountVO
* @author: zxlee
* @create: 2022-12-17 17:05
**/

@Data
@ApiModel("统计结果数量VO")
public class StatisticsDateCountVO {
@ApiModelProperty("日期")
private String date;
@ApiModelProperty("访问次数")
private Integer count;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.zxlee.znotifyapi.pojo.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @program: z-notify-api
* @description: StatisticsRegionCountVO
* @author: zxlee
* @create: 2022-12-17 17:05
**/

@Data
@ApiModel("统计结果ip归属地VO")
public class StatisticsRegionCountVO {
@ApiModelProperty("ip归属地")
private String region;
@ApiModelProperty("访问次数")
private Integer count;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cn.zxlee.znotifyapi.pojo.vo;

import cn.zxlee.znotifyapi.pojo.BasePOJO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @program: z-notify-api
* @description: StatisticsBO
* @description: StatisticsResultVO
* @author: zxlee
* @create: 2022-12-17 17:05
**/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.zxlee.znotifyapi.service;

import cn.zxlee.znotifyapi.pojo.vo.StatisticsAnalysisResultVO;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsResultVO;
import cn.zxlee.znotifyapi.service.base.IBaseService;

Expand All @@ -8,4 +9,6 @@ public interface IStatisticsService<V, B, PB> extends IBaseService<V, B, PB> {
int publicSaveOne(String ip, String projectId);

StatisticsResultVO publicGetStatisticsResult(String projectId);

StatisticsAnalysisResultVO getStatisticsAnalysisResult(String token, String projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import cn.zxlee.znotifyapi.pojo.bo.StatisticsBO;
import cn.zxlee.znotifyapi.pojo.bo.StatisticsPageBO;
import cn.zxlee.znotifyapi.pojo.po.StatisticsPO;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsResultVO;
import cn.zxlee.znotifyapi.pojo.vo.StatisticsVO;
import cn.zxlee.znotifyapi.pojo.vo.*;
import cn.zxlee.znotifyapi.pojo.vo.base.PageResultVO;
import cn.zxlee.znotifyapi.service.IStatisticsService;
import cn.zxlee.znotifyapi.service.base.impl.BaseInProjectServiceImpl;
Expand Down Expand Up @@ -77,4 +76,35 @@ public StatisticsResultVO publicGetStatisticsResult(String projectId) {
statisticsResultVO.setVisitorCount(null == statisticsPOS ? 0 : statisticsPOS.size());
return statisticsResultVO;
}

@Override
public StatisticsAnalysisResultVO getStatisticsAnalysisResult(String token, String projectId) {
checkIsCurrentProject(token, projectId);

List<StatisticsPO> statisticsPOS = statisticsMapper.listGroupByIp(projectId);
List<StatisticsPO> statisticsTodayPOS = statisticsMapper.todayListGroupByIp(projectId);
List<StatisticsPO> statisticsYesterdayPOS = statisticsMapper.yesterdayListGroupByIp(projectId);
List<StatisticsRegionCountVO> statisticsIpRegionCountVOS = statisticsMapper.ipRegionCountList(projectId);
int statisticsListCount = statisticsMapper.listCount(projectId);
int todayListCount = statisticsMapper.todayListCount(projectId);
int yesterdayListCount = statisticsMapper.yesterdayListCount(projectId);
int days7ListCount = statisticsMapper.days7ListCount(projectId);
int days30ListCount = statisticsMapper.days30ListCount(projectId);
List<StatisticsDateCountVO> statisticsDateDays10CountVOS = statisticsMapper.days10CountList(projectId);
List<StatisticsDateCountVO> statisticsDateMonths12CountVOS = statisticsMapper.months12CountList(projectId);

StatisticsAnalysisResultVO statisticsResultVO = new StatisticsAnalysisResultVO();
statisticsResultVO.setViewCount(statisticsListCount);
statisticsResultVO.setVisitorCount(null == statisticsPOS ? 0 : statisticsPOS.size());
statisticsResultVO.setTodayVisitorCount(null == statisticsTodayPOS ? 0 : statisticsTodayPOS.size());
statisticsResultVO.setYesterdayVisitorCount(null == statisticsYesterdayPOS ? 0 : statisticsYesterdayPOS.size());
statisticsResultVO.setTodayViewCount(todayListCount);
statisticsResultVO.setYesterdayViewCount(yesterdayListCount);
statisticsResultVO.setDays7ViewCount(days7ListCount);
statisticsResultVO.setDays30ViewCount(days30ListCount);
statisticsResultVO.setDays10CountList(statisticsDateDays10CountVOS);
statisticsResultVO.setMonths12CountList(statisticsDateMonths12CountVOS);
statisticsResultVO.setIpRegionCountList(statisticsIpRegionCountVOS);
return statisticsResultVO;
}
}
18 changes: 9 additions & 9 deletions src/main/resources/mybatis/mapper/FeedbackMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@
</resultMap>

<select id="list" resultMap="listResultMap" parameterType="Map">
select * from `t_feedback` where project_id = #{projectId}
SELECT * FROM `t_feedback` WHERE project_id = #{projectId}
<if test="keyword!='' and keyword!=null">
<bind name="pattern" value="'%' + keyword + '%'"/>
and `username` like #{pattern}
AND `username` LIKE #{pattern}
</if>
order by updatetime, createtime desc
ORDER BY updatetime, createtime DESC
</select>

<select id="listById" resultType="FeedbackPO" parameterType="string">
select * from `t_feedback` where id = #{id}
SELECT * FROM `t_feedback` WHERE id = #{id}
</select>

<select id="listByUsername" resultMap="listResultMap" parameterType="string">
select * from `t_feedback` where `project_id` = #{projectId} and `username` = #{username} order by createtime desc
SELECT * FROM `t_feedback` WHERE `project_id` = #{projectId} AND `username` = #{username} ORDER BY createtime DESC
</select>

<insert id="insertOne" parameterType="FeedbackPO">
insert into `t_feedback`(`id`,`username`,`contact`,`content`,`extra_info`,`img_urls`,`project_id`) VALUES (#{id},#{username},#{contact},#{content},#{extraInfo},#{imgUrls, typeHandler=cn.zxlee.znotifyapi.resolver.ImgsTypeHandler},#{projectId})
INSERT INTO `t_feedback`(`id`,`username`,`contact`,`content`,`extra_info`,`img_urls`,`project_id`) VALUES (#{id},#{username},#{contact},#{content},#{extraInfo},#{imgUrls, typeHandler=cn.zxlee.znotifyapi.resolver.ImgsTypeHandler},#{projectId})
</insert>

<update id="updateReply">
update `t_feedback`
UPDATE `t_feedback`
<set>
<if test="bo.reply != null and bo.reply != ''">
`reply` = #{bo.reply},
</if>
</set>
where id = #{id}
WHERE id = #{id}
</update>

<delete id="deleteById" parameterType="string">
delete from `t_feedback` where id = #{id}
DELETE FROM `t_feedback` WHERE id = #{id}
</delete>
</mapper>

28 changes: 14 additions & 14 deletions src/main/resources/mybatis/mapper/NoticeMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zxlee.znotifyapi.mapper.NoticeMapper">
<select id="list" resultType="NoticePO" parameterType="string">
select `id`, `title`, `content`, `project_id`, `createtime`, `updatetime`, `expiretime`, `expiretime` is null or `expiretime` > now() as `status`
from `t_notice`
where `project_id` = #{projectId}
order by `status` desc, `createtime` desc
SELECT `id`, `title`, `content`, `project_id`, `createtime`, `updatetime`, `expiretime`, `expiretime` IS NULL OR `expiretime` > now() AS `status`
FROM `t_notice`
WHERE `project_id` = #{projectId}
ORDER BY `status` DESC, `createtime` DESC
</select>

<select id="listByExipretime" resultType="NoticePO" parameterType="string">
select * from `t_notice` where `project_id` = #{projectId}
SELECT * FROM `t_notice` WHERE `project_id` = #{projectId}
<![CDATA[
and (
`expiretime` is null
or
AND (
`expiretime` IS NULL
OR
`expiretime` >= now()
)
]]>
order by `createtime` desc
ORDER BY `createtime` DESC
</select>

<select id="listById" resultType="NoticePO" parameterType="string">
select * from `t_notice` where `id` = #{id}
SELECT * FROM `t_notice` WHERE `id` = #{id}
</select>

<insert id="insertOne" parameterType="NoticePO">
insert into `t_notice`(`id`, `title`, `content`, `project_id`, `expiretime`) VALUES (#{id},#{title},#{content},#{projectId},#{expiretime})
INSERT INTO `t_notice`(`id`, `title`, `content`, `project_id`, `expiretime`) VALUES (#{id},#{title},#{content},#{projectId},#{expiretime})
</insert>

<update id="updateOne">
update `t_notice`
UPDATE `t_notice`
<set>
<if test="po.title != null and po.title != ''">
`title` = #{po.title},
Expand All @@ -43,11 +43,11 @@
`expiretime` = #{po.expiretime},
</if>
</set>
where `id` = #{id}
WHERE `id` = #{id}
</update>

<delete id="deleteById" parameterType="string">
delete from `t_notice` where id = #{id}
delete FROM `t_notice` WHERE id = #{id}
</delete>
</mapper>

28 changes: 14 additions & 14 deletions src/main/resources/mybatis/mapper/ProjectMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zxlee.znotifyapi.mapper.ProjectMapper">
<select id="list" resultType="ProjectPO">
select `id`, `project_name`, `createtime`, `updatetime`, `user_id`,
(SELECT COUNT(0) from `t_notice` WHERE `t_notice`.`project_id` = `t_project`.`id`) as `notice_count`,
(SELECT COUNT(0) from `t_text` WHERE `t_text`.`project_id` = `t_project`.`id`) as `text_count`,
(SELECT COUNT(0) from `t_version` WHERE `t_version`.`project_id` = `t_project`.`id`) as `version_count`,
(SELECT COUNT(0) from `t_feedback` WHERE `t_feedback`.`project_id` = `t_project`.`id`) as `feedback_count`
from `t_project`
where `user_id` = #{userId}
SELECT `id`, `project_name`, `createtime`, `updatetime`, `user_id`,
(SELECT COUNT(0) FROM `t_notice` WHERE `t_notice`.`project_id` = `t_project`.`id`) AS `notice_count`,
(SELECT COUNT(0) FROM `t_text` WHERE `t_text`.`project_id` = `t_project`.`id`) AS `text_count`,
(SELECT COUNT(0) FROM `t_version` WHERE `t_version`.`project_id` = `t_project`.`id`) AS `version_count`,
(SELECT COUNT(0) FROM `t_feedback` WHERE `t_feedback`.`project_id` = `t_project`.`id`) AS `feedback_count`
FROM `t_project`
WHERE `user_id` = #{userId}
<if test="keyword!='' and keyword!=null">
<bind name="pattern" value="'%' + keyword + '%'"/>
and `project_name` like #{pattern}
AND `project_name` LIKE #{pattern}
</if>
order by `createtime` desc
ORDER BY `createtime` DESC
</select>

<select id="listByName" resultType="ProjectPO" parameterType="string">
select * from `t_project` where `user_id` = #{userId} and `project_name` = #{projectName}
SELECT * FROM `t_project` WHERE `user_id` = #{userId} AND `project_name` = #{projectName}
</select>

<select id="listByUserIdAndId" resultType="ProjectPO" parameterType="string">
select * from `t_project` where `user_id` = #{userId} and `id` = #{id}
SELECT * FROM `t_project` WHERE `user_id` = #{userId} AND `id` = #{id}
</select>

<select id="publicListById" resultType="ProjectPO" parameterType="string">
select * from `t_project` where `id` = #{id}
SELECT * FROM `t_project` WHERE `id` = #{id}
</select>

<insert id="insertOne">
insert into `t_project` (`id`, `project_name`, `user_id`) VALUES (#{id},#{projectName},#{userId})
INSERT INTO `t_project` (`id`, `project_name`, `user_id`) VALUES (#{id},#{projectName},#{userId})
</insert>

<delete id="deleteById" parameterType="string">
delete from `t_project` where `id` = #{id}
DELETE FROM `t_project` WHERE `id` = #{id}
</delete>
</mapper>

Loading

0 comments on commit e4b7bd9

Please sign in to comment.