增加分享次数
Showing
6 changed files
with
170 additions
and
45 deletions
... | @@ -43,15 +43,15 @@ public class ScoreLogInfoController { | ... | @@ -43,15 +43,15 @@ public class ScoreLogInfoController { |
43 | @Autowired | 43 | @Autowired |
44 | HttpPostService httpPostService; | 44 | HttpPostService httpPostService; |
45 | 45 | ||
46 | |||
47 | @RequestMapping("/save") | 46 | @RequestMapping("/save") |
48 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, | 47 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, |
49 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) { | 48 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, |
49 | String secret) { | ||
50 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 50 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
51 | boolean flag = false; | 51 | boolean flag = false; |
52 | String code = "9000"; | 52 | String code = "9000"; |
53 | String openid = scoreLogInfo.getOpenid(); | 53 | String openid = scoreLogInfo.getOpenid(); |
54 | if(StringUtils.isNotBlank(jsondata)){ | 54 | if (StringUtils.isNotBlank(jsondata)) { |
55 | jsondata = URLDecoder.decode(jsondata); | 55 | jsondata = URLDecoder.decode(jsondata); |
56 | ObjectMapper objectMapper = new ObjectMapper(); | 56 | ObjectMapper objectMapper = new ObjectMapper(); |
57 | Map map = null; | 57 | Map map = null; |
... | @@ -60,30 +60,33 @@ public class ScoreLogInfoController { | ... | @@ -60,30 +60,33 @@ public class ScoreLogInfoController { |
60 | } catch (IOException e) { | 60 | } catch (IOException e) { |
61 | e.printStackTrace(); | 61 | e.printStackTrace(); |
62 | } | 62 | } |
63 | // if(map != null && map.containsKey("gtmc_code") && map.get("gtmc_code").toString().equals("200")){ | 63 | // if(map != null && map.containsKey("gtmc_code") && |
64 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 64 | // map.get("gtmc_code").toString().equals("200")){ |
65 | // if(checksum1.equals(checksum)){ | 65 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp |
66 | // +rands +jsondata +secret); | ||
67 | // if(checksum1.equals(checksum)){ | ||
66 | scoreLogInfo.setGtmcUid(map.get("gtmc_uid").toString()); | 68 | scoreLogInfo.setGtmcUid(map.get("gtmc_uid").toString()); |
67 | scoreLogInfo.setGtmcDepartment(map.get("gtmc_department").toString()); | 69 | scoreLogInfo.setGtmcDepartment(map.get("gtmc_department").toString()); |
68 | scoreLogInfo.setGtmcName(map.get("gtmc_name").toString()); | 70 | scoreLogInfo.setGtmcName(map.get("gtmc_name").toString()); |
69 | code = this.scoreLogInfoService.save(scoreLogInfo); | 71 | code = this.scoreLogInfoService.save(scoreLogInfo); |
70 | if(code.equals("2000")){ | 72 | if (code.equals("2000")) { |
71 | flag = true; | 73 | flag = true; |
72 | } | 74 | } |
73 | // } | 75 | // } |
74 | // } | 76 | // } |
75 | } | 77 | } |
76 | return builder.success(flag).code(code).create(); | 78 | return builder.success(flag).code(code).create(); |
77 | } | 79 | } |
78 | 80 | ||
79 | @RequestMapping("/ranking") | 81 | @RequestMapping("/ranking") |
80 | public MessageEntity ranking(HttpServletRequest request, @RequestParam String openid,@RequestParam(defaultValue = "10") Long limit) { | 82 | public MessageEntity ranking(HttpServletRequest request, @RequestParam String openid, |
83 | @RequestParam(defaultValue = "10") Long limit) { | ||
81 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 84 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
82 | Map<String,Object> map = new HashMap<>(); | 85 | Map<String, Object> map = new HashMap<>(); |
83 | List<Map<String, Object>> rankingList = this.scoreLogInfoService.getRankingList(limit); | 86 | List<Map<String, Object>> rankingList = this.scoreLogInfoService.getRankingList(limit); |
84 | Map<String, Object> myRanking = this.scoreLogInfoService.getMyRanking(openid); | 87 | Map<String, Object> myRanking = this.scoreLogInfoService.getMyRanking(openid); |
85 | map.put("rankingList",rankingList); | 88 | map.put("rankingList", rankingList); |
86 | map.put("myRanking",myRanking); | 89 | map.put("myRanking", myRanking); |
87 | return builder.success(true).code("2000").content(map).create(); | 90 | return builder.success(true).code("2000").content(map).create(); |
88 | } | 91 | } |
89 | 92 | ||
... | @@ -91,9 +94,13 @@ public class ScoreLogInfoController { | ... | @@ -91,9 +94,13 @@ public class ScoreLogInfoController { |
91 | public MessageEntity counttoday(HttpServletRequest request, @RequestParam String openid) { | 94 | public MessageEntity counttoday(HttpServletRequest request, @RequestParam String openid) { |
92 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 95 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
93 | long l = this.scoreLogInfoService.countToDay(openid); | 96 | long l = this.scoreLogInfoService.countToDay(openid); |
97 | long s = this.scoreLogInfoService.shareToday(openid); | ||
98 | if (s > 5) { | ||
99 | s = 5; | ||
100 | } | ||
94 | ConfigInfo configInfo = configInfoMapper.get(); | 101 | ConfigInfo configInfo = configInfoMapper.get(); |
95 | Long maxTime = configInfo.getMaxTime(); | 102 | Long maxTime = configInfo.getMaxTime(); |
96 | long lastTime = maxTime - l; | 103 | long lastTime = maxTime - l + s; |
97 | return builder.success(true).code("2000").content(lastTime).create(); | 104 | return builder.success(true).code("2000").content(lastTime).create(); |
98 | } | 105 | } |
99 | 106 | ||
... | @@ -104,53 +111,61 @@ public class ScoreLogInfoController { | ... | @@ -104,53 +111,61 @@ public class ScoreLogInfoController { |
104 | return builder.success(true).code("2000").content(l).create(); | 111 | return builder.success(true).code("2000").content(l).create(); |
105 | } | 112 | } |
106 | 113 | ||
114 | @RequestMapping("/saveShare") | ||
115 | public MessageEntity saveShare(HttpServletRequest request, @RequestParam String openid) { | ||
116 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | ||
117 | long l = this.scoreLogInfoService.saveShare(openid); | ||
118 | return builder.success(true).code("2000").content(l).create(); | ||
119 | } | ||
107 | 120 | ||
108 | // public static void main(String[] args) { | 121 | // public static void main(String[] args) { |
109 | // String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | 122 | // String |
110 | // String openid="111"; | 123 | // access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; |
111 | // String state="xxxx"; | 124 | // String openid="111"; |
112 | // String timestamp="1511923072"; | 125 | // String state="xxxx"; |
113 | // String rands="KeXxdzc7gQxkw6sE"; | 126 | // String timestamp="1511923072"; |
114 | // String jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"); | 127 | // String rands="KeXxdzc7gQxkw6sE"; |
115 | // System.out.println(jsondata); | 128 | // String |
116 | // String secret="digi-campaign-2015"; | 129 | // jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"); |
117 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 130 | // System.out.println(jsondata); |
118 | // System.out.println(checksum1); | 131 | // String secret="digi-campaign-2015"; |
119 | // } | 132 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp |
133 | // +rands +jsondata +secret); | ||
134 | // System.out.println(checksum1); | ||
135 | // } | ||
120 | 136 | ||
121 | @RequestMapping("/test") | 137 | @RequestMapping("/test") |
122 | public MessageEntity test(HttpServletRequest request,@RequestParam String open) { | 138 | public MessageEntity test(HttpServletRequest request, @RequestParam String open) { |
123 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 139 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
124 | for(int i = 0; i < 20;i++){ | 140 | for (int i = 0; i < 20; i++) { |
125 | String openid = open + i; | 141 | String openid = open + i; |
126 | String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | 142 | String access_token = "4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; |
127 | String state="xxxx"; | 143 | String state = "xxxx"; |
128 | String timestamp="1511923072"; | 144 | String timestamp = "1511923072"; |
129 | String rands="KeXxdzc7gQxkw6sE"; | 145 | String rands = "KeXxdzc7gQxkw6sE"; |
130 | String jsondata="{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"; | 146 | String jsondata = "{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"; |
131 | jsondata = URLDecoder.decode(jsondata); | 147 | jsondata = URLDecoder.decode(jsondata); |
132 | String secret="digi-campaign-2015"; | 148 | String secret = "digi-campaign-2015"; |
133 | String checksum = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 149 | String checksum = MD5Utils.hash(access_token + openid + state + timestamp + rands + jsondata + secret); |
134 | jsondata = URLEncoder.encode(jsondata); | 150 | jsondata = URLEncoder.encode(jsondata); |
135 | String url = "http://114.215.122.43:9922/kmr/rank/save"; | 151 | String url = "http://114.215.122.43:9922/kmr/rank/save"; |
136 | url = url + "?state="+state; | 152 | url = url + "?state=" + state; |
137 | url = url + "&access_token="+access_token; | 153 | url = url + "&access_token=" + access_token; |
138 | url = url + "&openid="+openid; | 154 | url = url + "&openid=" + openid; |
139 | url = url + "×tamp="+timestamp; | 155 | url = url + "×tamp=" + timestamp; |
140 | url = url + "&rands="+rands; | 156 | url = url + "&rands=" + rands; |
141 | url = url + "&jsondata="+jsondata; | 157 | url = url + "&jsondata=" + jsondata; |
142 | url = url + "&secret="+secret; | 158 | url = url + "&secret=" + secret; |
143 | url = url + "&checksum="+checksum; | 159 | url = url + "&checksum=" + checksum; |
144 | url = url + "&nickname=xxxx"; | 160 | url = url + "&nickname=xxxx"; |
145 | url = url + "&avater=xxxx"; | 161 | url = url + "&avater=xxxx"; |
146 | url = url + "&score=12"; | 162 | url = url + "&score=12"; |
147 | System.out.println(url); | 163 | System.out.println(url); |
148 | TestThread ds1 = new TestThread(httpPostService,url); | 164 | TestThread ds1 = new TestThread(httpPostService, url); |
149 | Thread t1 = new Thread(ds1); | 165 | Thread t1 = new Thread(ds1); |
150 | t1.start(); | 166 | t1.start(); |
151 | } | 167 | } |
152 | return builder.success(true).code("2000").create(); | 168 | return builder.success(true).code("2000").create(); |
153 | } | 169 | } |
154 | 170 | ||
155 | |||
156 | } | 171 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | package com.example.mapper; | ||
2 | |||
3 | import org.apache.ibatis.annotations.Param; | ||
4 | |||
5 | import com.example.models.ShareLog; | ||
6 | |||
7 | /** | ||
8 | * Created by JA on 17/7/17. | ||
9 | */ | ||
10 | public interface ShareLogMapper { | ||
11 | |||
12 | boolean create(ShareLog shareLog); | ||
13 | |||
14 | long countByDay(@Param("openid") String openid, @Param("startDate") String startDate, | ||
15 | @Param("endDate") String endDate); | ||
16 | |||
17 | } |
1 | package com.example.models; | ||
2 | |||
3 | import java.util.Date; | ||
4 | |||
5 | /** | ||
6 | * Created by JA on 17/7/17. | ||
7 | */ | ||
8 | public class ShareLog { | ||
9 | |||
10 | private Long id; | ||
11 | private String openid; | ||
12 | Date shareTime; | ||
13 | |||
14 | public Long getId() { | ||
15 | return id; | ||
16 | } | ||
17 | |||
18 | public void setId(Long id) { | ||
19 | this.id = id; | ||
20 | } | ||
21 | |||
22 | public String getOpenid() { | ||
23 | return openid; | ||
24 | } | ||
25 | |||
26 | public void setOpenid(String openid) { | ||
27 | this.openid = openid; | ||
28 | } | ||
29 | |||
30 | public Date getShareTime() { | ||
31 | return shareTime; | ||
32 | } | ||
33 | |||
34 | public void setShareTime(Date shareTime) { | ||
35 | this.shareTime = shareTime; | ||
36 | } | ||
37 | |||
38 | } |
... | @@ -17,5 +17,10 @@ public interface ScoreLogInfoService { | ... | @@ -17,5 +17,10 @@ public interface ScoreLogInfoService { |
17 | 17 | ||
18 | long countToDay(String openid); | 18 | long countToDay(String openid); |
19 | 19 | ||
20 | long shareToday(String openid); | ||
21 | |||
20 | long countSum(String openid); | 22 | long countSum(String openid); |
23 | |||
24 | long saveShare(String openid); | ||
25 | |||
21 | } | 26 | } | ... | ... |
... | @@ -2,8 +2,11 @@ package com.example.service; | ... | @@ -2,8 +2,11 @@ package com.example.service; |
2 | 2 | ||
3 | import com.example.mapper.ConfigInfoMapper; | 3 | import com.example.mapper.ConfigInfoMapper; |
4 | import com.example.mapper.ScoreLogInfoMapper; | 4 | import com.example.mapper.ScoreLogInfoMapper; |
5 | import com.example.mapper.ShareLogMapper; | ||
5 | import com.example.models.ConfigInfo; | 6 | import com.example.models.ConfigInfo; |
6 | import com.example.models.ScoreLogInfo; | 7 | import com.example.models.ScoreLogInfo; |
8 | import com.example.models.ShareLog; | ||
9 | |||
7 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
9 | 12 | ||
... | @@ -26,6 +29,9 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { | ... | @@ -26,6 +29,9 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { |
26 | @Autowired | 29 | @Autowired |
27 | private ConfigInfoMapper configInfoMapper; | 30 | private ConfigInfoMapper configInfoMapper; |
28 | 31 | ||
32 | @Autowired | ||
33 | private ShareLogMapper shareLogMapper; | ||
34 | |||
29 | @Override | 35 | @Override |
30 | public String save(ScoreLogInfo scoreLogInfo) { | 36 | public String save(ScoreLogInfo scoreLogInfo) { |
31 | String code = "2000"; | 37 | String code = "2000"; |
... | @@ -80,9 +86,27 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { | ... | @@ -80,9 +86,27 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { |
80 | } | 86 | } |
81 | 87 | ||
82 | @Override | 88 | @Override |
89 | public long shareToday(String openid) { | ||
90 | Date date = new Date(); | ||
91 | String format = sdf.format(date); | ||
92 | String startDate = format + " 00:00:00"; | ||
93 | String endDate = format + " 23:59:59"; | ||
94 | return this.shareLogMapper.countByDay(openid,startDate,endDate); | ||
95 | } | ||
96 | |||
97 | @Override | ||
83 | public long countSum(String openid) { | 98 | public long countSum(String openid) { |
84 | return this.scoreLogInfoMapper.countSum(openid); | 99 | return this.scoreLogInfoMapper.countSum(openid); |
85 | } | 100 | } |
86 | 101 | ||
102 | @Override | ||
103 | public long saveShare(String openid) { | ||
104 | ShareLog shareLog = new ShareLog(); | ||
105 | shareLog.setOpenid(openid); | ||
106 | shareLog.setShareTime(new Date()); | ||
107 | shareLogMapper.create(shareLog); | ||
108 | return 0; | ||
109 | } | ||
110 | |||
87 | 111 | ||
88 | } | 112 | } | ... | ... |
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | <mapper namespace="com.example.mapper.ShareLogMapper"> | ||
4 | |||
5 | <insert id="create"> | ||
6 | insert into `t_kmr_share_log` ( | ||
7 | `openid`, | ||
8 | `share_time` | ||
9 | ) | ||
10 | values( | ||
11 | #{openid}, | ||
12 | #{share_time} | ||
13 | ); | ||
14 | </insert> | ||
15 | |||
16 | |||
17 | <select id="countByDay" resultType="long"> | ||
18 | select count(*) c | ||
19 | from `t_kmr_share_log` | ||
20 | where share_time BETWEEN #{startDate} and #{endDate} | ||
21 | and openid= #{openid}; | ||
22 | </select> | ||
23 | |||
24 | |||
25 | |||
26 | </mapper> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment