添加统计用接口
Showing
3 changed files
with
76 additions
and
0 deletions
1 | package com.example.controller; | ||
2 | |||
3 | import com.example.mapper.ShareLogMapper; | ||
4 | import com.example.support.model.MessageEntity; | ||
5 | import org.apache.commons.lang3.StringUtils; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | ||
7 | import org.springframework.web.bind.annotation.RequestMapping; | ||
8 | import org.springframework.web.bind.annotation.RequestParam; | ||
9 | import org.springframework.web.bind.annotation.RestController; | ||
10 | |||
11 | import javax.servlet.http.HttpServletRequest; | ||
12 | import java.text.SimpleDateFormat; | ||
13 | import java.util.Date; | ||
14 | import java.util.HashMap; | ||
15 | import java.util.Map; | ||
16 | |||
17 | /** | ||
18 | * Created by JA on 17/7/3. | ||
19 | */ | ||
20 | @RequestMapping("/kmr/statistics") | ||
21 | @RestController | ||
22 | public class StatisticsController { | ||
23 | |||
24 | @Autowired | ||
25 | private ShareLogMapper shareLogMapper; | ||
26 | |||
27 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
28 | |||
29 | @RequestMapping | ||
30 | public MessageEntity statistics(HttpServletRequest request,@RequestParam(required = false)String time) { | ||
31 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | ||
32 | if(StringUtils.isBlank(time)){ | ||
33 | Date date = new Date(); | ||
34 | time = this.sdf.format(date); | ||
35 | } | ||
36 | String startDate = time + " 00:00:00"; | ||
37 | String endDate = time + " 23:59:59"; | ||
38 | int pv = this.shareLogMapper.findPVByDay(startDate, endDate); | ||
39 | int uv = this.shareLogMapper.findUVByDay(startDate, endDate); | ||
40 | int share = this.shareLogMapper.findShareByDay(startDate, endDate); | ||
41 | int img = this.shareLogMapper.findImgByDay(startDate, endDate); | ||
42 | Map<String,Object> map = new HashMap<>(); | ||
43 | map.put("pv",pv); | ||
44 | map.put("uv",uv); | ||
45 | map.put("share",share); | ||
46 | map.put("img",img); | ||
47 | return builder.success(true).code("2000").content(map).create(); | ||
48 | } | ||
49 | |||
50 | } |
... | @@ -11,6 +11,12 @@ public interface ShareLogMapper { | ... | @@ -11,6 +11,12 @@ public interface ShareLogMapper { |
11 | 11 | ||
12 | boolean create(ShareLog shareLog); | 12 | boolean create(ShareLog shareLog); |
13 | 13 | ||
14 | int findPVByDay(@Param("startDate") String startDate,@Param("endDate") String endDate); | ||
15 | int findUVByDay(@Param("startDate") String startDate,@Param("endDate") String endDate); | ||
16 | int findShareByDay(@Param("startDate") String startDate,@Param("endDate") String endDate); | ||
17 | int findImgByDay(@Param("startDate") String startDate,@Param("endDate") String endDate); | ||
18 | |||
19 | |||
14 | long countByDay(@Param("openid") String openid, @Param("startDate") String startDate, | 20 | long countByDay(@Param("openid") String openid, @Param("startDate") String startDate, |
15 | @Param("endDate") String endDate); | 21 | @Param("endDate") String endDate); |
16 | 22 | ... | ... |
... | @@ -29,5 +29,25 @@ | ... | @@ -29,5 +29,25 @@ |
29 | ) | 29 | ) |
30 | </insert> | 30 | </insert> |
31 | 31 | ||
32 | <select id="findPVByDay" resultType="int"> | ||
33 | SELECT count(*) c FROM `t_kmr_stat_log` where `create_at` BETWEEN #{startDate} and #{endDate}; | ||
34 | </select> | ||
35 | |||
36 | <select id="findUVByDay" resultType="int"> | ||
37 | SELECT count(DISTINCT `openid` ) c FROM `t_kmr_stat_log` where `create_at` BETWEEN #{startDate} and #{endDate}; | ||
38 | </select> | ||
39 | |||
40 | <select id="findShareByDay" resultType="int"> | ||
41 | select count(*) c | ||
42 | from `t_kmr_share_log` | ||
43 | where share_time BETWEEN #{startDate} and #{endDate} | ||
44 | </select> | ||
45 | |||
46 | <select id="findImgByDay" resultType="int"> | ||
47 | SELECT count(*) c FROM `t_kmr_img_info` where `create_at` BETWEEN #{startDate} and #{endDate}; | ||
48 | </select> | ||
49 | |||
50 | |||
51 | |||
32 | 52 | ||
33 | </mapper> | 53 | </mapper> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment