Skip to content

Commit

Permalink
添加统计管理功能
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileZXLee committed Dec 17, 2022
1 parent 730a8d8 commit 3fbab21
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cn.zxlee.znotifyapi.controller;

import cn.zxlee.znotifyapi.pojo.bo.StatisticsPageBO;
import cn.zxlee.znotifyapi.pojo.vo.VersionVO;
import cn.zxlee.znotifyapi.pojo.vo.base.PageResultVO;
import cn.zxlee.znotifyapi.response.Result;
import cn.zxlee.znotifyapi.service.IStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.HashMap;

/**
* @program: z-notify-api
* @description: 统计管理控制器
* @author: zxlee
* @create: 2022-12-07 20:03
**/

@Slf4j
@RestController
@RequestMapping("/v1/statistics")
@Api(value = "统计管理", tags = {"统计管理"})
@Validated
public class StatisticsController {
@Autowired
private IStatisticsService statisticsService;

@GetMapping("/statistics/{project_id}")
@ApiOperation("获取项目下的访问数据列表")
public Result<PageResultVO<VersionVO>> getStatistics(@RequestHeader String token, @NotEmpty @PathVariable(value = "project_id") String projectId, @Validated StatisticsPageBO bo){
HashMap<String, String> params = new HashMap<String, String>() {{
put("token", token);
put("projectId", projectId);
put("keyword", bo.getKeyword());
}};
return Result.success(statisticsService.listByPage(params, bo));
}
}
20 changes: 20 additions & 0 deletions src/main/java/cn/zxlee/znotifyapi/pojo/bo/StatisticsPageBO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.zxlee.znotifyapi.pojo.bo;

import cn.zxlee.znotifyapi.pojo.bo.base.PageBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @program: z-notify-api
* @description: 项目分页BO
* @author: zxlee
* @create: 2022-11-27 00:22
**/

@Data
@ApiModel("版本分页BO")
public class StatisticsPageBO extends PageBO {
@ApiModelProperty("版本搜索关键字")
private String keyword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import cn.zxlee.znotifyapi.mapper.StatisticsMapper;
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.base.PageResultVO;
import cn.zxlee.znotifyapi.service.IStatisticsService;
import cn.zxlee.znotifyapi.service.base.impl.BaseInProjectServiceImpl;
import cn.zxlee.znotifyapi.utils.BeanConvertUtils;
import cn.zxlee.znotifyapi.utils.IpUtils;
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -26,7 +25,7 @@
**/

@Service
public class StatisticsServiceImpl extends BaseInProjectServiceImpl implements IStatisticsService<StatisticsVO, StatisticsBO, Object> {
public class StatisticsServiceImpl extends BaseInProjectServiceImpl implements IStatisticsService<StatisticsVO, StatisticsBO, StatisticsPageBO> {

@Autowired
private StatisticsMapper statisticsMapper;
Expand All @@ -40,8 +39,8 @@ public List<StatisticsVO> list(Map map) {
}

@Override
public PageResultVO<StatisticsVO> listByPage(Map map, Object pageBO) {
return null;
public PageResultVO<StatisticsVO> listByPage(Map map, StatisticsPageBO pageBO) {
return baseListByPage(pageBO, map, StatisticsVO::new, () -> statisticsMapper.list(map));
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/mybatis/mapper/StatisticsMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zxlee.znotifyapi.mapper.StatisticsMapper">
<select id="list" resultType="StatisticsPO" parameterType="Map">
select * from `t_statistics` where project_id = #{projectId}
order by createtime desc
select * from `t_statistics` where `project_id` = #{projectId}
order by `createtime` desc
</select>

<select id="listGroupByIp" resultType="StatisticsPO" parameterType="string">
select * from `t_statistics` where `project_id` = #{projectId} GROUP BY `ip` order by createtime desc
select * from `t_statistics` where `project_id` = #{projectId} GROUP BY `ip` order by `createtime` desc
</select>

<select id="listCount" resultType="int" parameterType="string">
select COUNT(0) from `t_statistics` where `project_id` = #{projectId}
</select>

<select id="listById" resultType="StatisticsPO" parameterType="string">
select * from `t_statistics` where id = #{id}
select * from `t_statistics` where `id` = #{id}
</select>

<insert id="insertOne" parameterType="StatisticsPO">
insert into `t_statistics`(`id`,`ip`,`ip_region`, `project_id`) VALUES (#{id},#{ip},#{ipRegion},#{projectId})
</insert>

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

0 comments on commit 3fbab21

Please sign in to comment.