增加分享次数
Showing
6 changed files
with
245 additions
and
120 deletions
| ... | @@ -32,125 +32,140 @@ import java.util.Map; | ... | @@ -32,125 +32,140 @@ import java.util.Map; |
| 32 | @RestController | 32 | @RestController |
| 33 | public class ScoreLogInfoController { | 33 | public class ScoreLogInfoController { |
| 34 | 34 | ||
| 35 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 35 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 36 | 36 | ||
| 37 | @Autowired | 37 | @Autowired |
| 38 | private ScoreLogInfoService scoreLogInfoService; | 38 | private ScoreLogInfoService scoreLogInfoService; |
| 39 | 39 | ||
| 40 | @Autowired | 40 | @Autowired |
| 41 | private ConfigInfoMapper configInfoMapper; | 41 | private ConfigInfoMapper configInfoMapper; |
| 42 | 42 | ||
| 43 | @Autowired | 43 | @Autowired |
| 44 | HttpPostService httpPostService; | 44 | HttpPostService httpPostService; |
| 45 | 45 | ||
| 46 | 46 | @RequestMapping("/save") | |
| 47 | @RequestMapping("/save") | 47 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, |
| 48 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, | 48 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, |
| 49 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) { | 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; |
| 58 | try { | 58 | try { |
| 59 | map = objectMapper.readValue(jsondata, Map.class); | 59 | map = objectMapper.readValue(jsondata, Map.class); |
| 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 | scoreLogInfo.setGtmcUid(map.get("gtmc_uid").toString()); | 66 | // +rands +jsondata +secret); |
| 67 | scoreLogInfo.setGtmcDepartment(map.get("gtmc_department").toString()); | 67 | // if(checksum1.equals(checksum)){ |
| 68 | scoreLogInfo.setGtmcName(map.get("gtmc_name").toString()); | 68 | scoreLogInfo.setGtmcUid(map.get("gtmc_uid").toString()); |
| 69 | code = this.scoreLogInfoService.save(scoreLogInfo); | 69 | scoreLogInfo.setGtmcDepartment(map.get("gtmc_department").toString()); |
| 70 | if(code.equals("2000")){ | 70 | scoreLogInfo.setGtmcName(map.get("gtmc_name").toString()); |
| 71 | flag = true; | 71 | code = this.scoreLogInfoService.save(scoreLogInfo); |
| 72 | } | 72 | if (code.equals("2000")) { |
| 73 | // } | 73 | flag = true; |
| 74 | // } | 74 | } |
| 75 | } | 75 | // } |
| 76 | return builder.success(flag).code(code).create(); | 76 | // } |
| 77 | } | 77 | } |
| 78 | 78 | return builder.success(flag).code(code).create(); | |
| 79 | @RequestMapping("/ranking") | 79 | } |
| 80 | public MessageEntity ranking(HttpServletRequest request, @RequestParam String openid,@RequestParam(defaultValue = "10") Long limit) { | 80 | |
| 81 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 81 | @RequestMapping("/ranking") |
| 82 | Map<String,Object> map = new HashMap<>(); | 82 | public MessageEntity ranking(HttpServletRequest request, @RequestParam String openid, |
| 83 | List<Map<String, Object>> rankingList = this.scoreLogInfoService.getRankingList(limit); | 83 | @RequestParam(defaultValue = "10") Long limit) { |
| 84 | Map<String, Object> myRanking = this.scoreLogInfoService.getMyRanking(openid); | 84 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 85 | map.put("rankingList",rankingList); | 85 | Map<String, Object> map = new HashMap<>(); |
| 86 | map.put("myRanking",myRanking); | 86 | List<Map<String, Object>> rankingList = this.scoreLogInfoService.getRankingList(limit); |
| 87 | return builder.success(true).code("2000").content(map).create(); | 87 | Map<String, Object> myRanking = this.scoreLogInfoService.getMyRanking(openid); |
| 88 | } | 88 | map.put("rankingList", rankingList); |
| 89 | 89 | map.put("myRanking", myRanking); | |
| 90 | @RequestMapping("/counttoday") | 90 | return builder.success(true).code("2000").content(map).create(); |
| 91 | public MessageEntity counttoday(HttpServletRequest request, @RequestParam String openid) { | 91 | } |
| 92 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 92 | |
| 93 | long l = this.scoreLogInfoService.countToDay(openid); | 93 | @RequestMapping("/counttoday") |
| 94 | ConfigInfo configInfo = configInfoMapper.get(); | 94 | public MessageEntity counttoday(HttpServletRequest request, @RequestParam String openid) { |
| 95 | Long maxTime = configInfo.getMaxTime(); | 95 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 96 | long lastTime = maxTime - l; | 96 | long l = this.scoreLogInfoService.countToDay(openid); |
| 97 | return builder.success(true).code("2000").content(lastTime).create(); | 97 | long s = this.scoreLogInfoService.shareToday(openid); |
| 98 | } | 98 | if (s > 5) { |
| 99 | 99 | s = 5; | |
| 100 | @RequestMapping("/sum") | 100 | } |
| 101 | public MessageEntity sum(HttpServletRequest request, @RequestParam String openid) { | 101 | ConfigInfo configInfo = configInfoMapper.get(); |
| 102 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 102 | Long maxTime = configInfo.getMaxTime(); |
| 103 | long l = this.scoreLogInfoService.countSum(openid); | 103 | long lastTime = maxTime - l + s; |
| 104 | return builder.success(true).code("2000").content(l).create(); | 104 | return builder.success(true).code("2000").content(lastTime).create(); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | 107 | @RequestMapping("/sum") | |
| 108 | // public static void main(String[] args) { | 108 | public MessageEntity sum(HttpServletRequest request, @RequestParam String openid) { |
| 109 | // String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | 109 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 110 | // String openid="111"; | 110 | long l = this.scoreLogInfoService.countSum(openid); |
| 111 | // String state="xxxx"; | 111 | return builder.success(true).code("2000").content(l).create(); |
| 112 | // String timestamp="1511923072"; | 112 | } |
| 113 | // String rands="KeXxdzc7gQxkw6sE"; | 113 | |
| 114 | // String jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"); | 114 | @RequestMapping("/saveShare") |
| 115 | // System.out.println(jsondata); | 115 | public MessageEntity saveShare(HttpServletRequest request, @RequestParam String openid) { |
| 116 | // String secret="digi-campaign-2015"; | 116 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 117 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 117 | long l = this.scoreLogInfoService.saveShare(openid); |
| 118 | // System.out.println(checksum1); | 118 | return builder.success(true).code("2000").content(l).create(); |
| 119 | // } | 119 | } |
| 120 | 120 | ||
| 121 | @RequestMapping("/test") | 121 | // public static void main(String[] args) { |
| 122 | public MessageEntity test(HttpServletRequest request,@RequestParam String open) { | 122 | // String |
| 123 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 123 | // access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; |
| 124 | for(int i = 0; i < 20;i++){ | 124 | // String openid="111"; |
| 125 | String openid = open + i; | 125 | // String state="xxxx"; |
| 126 | String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | 126 | // String timestamp="1511923072"; |
| 127 | String state="xxxx"; | 127 | // String rands="KeXxdzc7gQxkw6sE"; |
| 128 | String timestamp="1511923072"; | 128 | // String |
| 129 | String rands="KeXxdzc7gQxkw6sE"; | 129 | // jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"); |
| 130 | String jsondata="{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"; | 130 | // System.out.println(jsondata); |
| 131 | jsondata = URLDecoder.decode(jsondata); | 131 | // String secret="digi-campaign-2015"; |
| 132 | String secret="digi-campaign-2015"; | 132 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp |
| 133 | String checksum = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 133 | // +rands +jsondata +secret); |
| 134 | jsondata = URLEncoder.encode(jsondata); | 134 | // System.out.println(checksum1); |
| 135 | String url = "http://114.215.122.43:9922/kmr/rank/save"; | 135 | // } |
| 136 | url = url + "?state="+state; | 136 | |
| 137 | url = url + "&access_token="+access_token; | 137 | @RequestMapping("/test") |
| 138 | url = url + "&openid="+openid; | 138 | public MessageEntity test(HttpServletRequest request, @RequestParam String open) { |
| 139 | url = url + "×tamp="+timestamp; | 139 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 140 | url = url + "&rands="+rands; | 140 | for (int i = 0; i < 20; i++) { |
| 141 | url = url + "&jsondata="+jsondata; | 141 | String openid = open + i; |
| 142 | url = url + "&secret="+secret; | 142 | String access_token = "4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; |
| 143 | url = url + "&checksum="+checksum; | 143 | String state = "xxxx"; |
| 144 | url = url + "&nickname=xxxx"; | 144 | String timestamp = "1511923072"; |
| 145 | url = url + "&avater=xxxx"; | 145 | String rands = "KeXxdzc7gQxkw6sE"; |
| 146 | url = url + "&score=12"; | 146 | String jsondata = "{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"; |
| 147 | System.out.println(url); | 147 | jsondata = URLDecoder.decode(jsondata); |
| 148 | TestThread ds1 = new TestThread(httpPostService,url); | 148 | String secret = "digi-campaign-2015"; |
| 149 | Thread t1 = new Thread(ds1); | 149 | String checksum = MD5Utils.hash(access_token + openid + state + timestamp + rands + jsondata + secret); |
| 150 | t1.start(); | 150 | jsondata = URLEncoder.encode(jsondata); |
| 151 | } | 151 | String url = "http://114.215.122.43:9922/kmr/rank/save"; |
| 152 | return builder.success(true).code("2000").create(); | 152 | url = url + "?state=" + state; |
| 153 | } | 153 | url = url + "&access_token=" + access_token; |
| 154 | 154 | url = url + "&openid=" + openid; | |
| 155 | url = url + "×tamp=" + timestamp; | ||
| 156 | url = url + "&rands=" + rands; | ||
| 157 | url = url + "&jsondata=" + jsondata; | ||
| 158 | url = url + "&secret=" + secret; | ||
| 159 | url = url + "&checksum=" + checksum; | ||
| 160 | url = url + "&nickname=xxxx"; | ||
| 161 | url = url + "&avater=xxxx"; | ||
| 162 | url = url + "&score=12"; | ||
| 163 | System.out.println(url); | ||
| 164 | TestThread ds1 = new TestThread(httpPostService, url); | ||
| 165 | Thread t1 = new Thread(ds1); | ||
| 166 | t1.start(); | ||
| 167 | } | ||
| 168 | return builder.success(true).code("2000").create(); | ||
| 169 | } | ||
| 155 | 170 | ||
| 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 | } |
| ... | @@ -16,6 +16,11 @@ public interface ScoreLogInfoService { | ... | @@ -16,6 +16,11 @@ public interface ScoreLogInfoService { |
| 16 | Map<String,Object> getMyRanking(String openid); | 16 | Map<String,Object> getMyRanking(String openid); |
| 17 | 17 | ||
| 18 | long countToDay(String openid); | 18 | long countToDay(String openid); |
| 19 | |||
| 20 | long shareToday(String openid); | ||
| 19 | 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 | ||
| ... | @@ -25,6 +28,9 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { | ... | @@ -25,6 +28,9 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { |
| 25 | 28 | ||
| 26 | @Autowired | 29 | @Autowired |
| 27 | private ConfigInfoMapper configInfoMapper; | 30 | private ConfigInfoMapper configInfoMapper; |
| 31 | |||
| 32 | @Autowired | ||
| 33 | private ShareLogMapper shareLogMapper; | ||
| 28 | 34 | ||
| 29 | @Override | 35 | @Override |
| 30 | public String save(ScoreLogInfo scoreLogInfo) { | 36 | public String save(ScoreLogInfo scoreLogInfo) { |
| ... | @@ -78,11 +84,29 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { | ... | @@ -78,11 +84,29 @@ public class ScoreLogInfoServiceImpl implements ScoreLogInfoService { |
| 78 | String endDate = format + " 23:59:59"; | 84 | String endDate = format + " 23:59:59"; |
| 79 | return this.scoreLogInfoMapper.countByDay(openid,startDate,endDate); | 85 | return this.scoreLogInfoMapper.countByDay(openid,startDate,endDate); |
| 80 | } | 86 | } |
| 87 | |||
| 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 | } | ||
| 81 | 96 | ||
| 82 | @Override | 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 | } |
| 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 | } | ||
| 86 | 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