From 3cd574dea81e26b349aa81e84de6eeaa80fab1db Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 30 May 2020 03:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=B4=BB=E5=8A=A8=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E6=97=B6=E9=97=B4=E5=B8=81=E5=B9=B6=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=99=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/share/help/Constants.java | 2 ++ .../share/help/controller/ActivityController.java | 2 +- .../com/share/help/controller/UserController.java | 8 ++++---- .../java/com/share/help/res/account/QueryRes.java | 9 +++++++++ .../com/share/help/service/ActivityService.java | 13 +++++++++---- src/main/resources/mapping/UserMapper.xml | 6 +++++- .../java/com/share/help/HelpApplicationTests.java | 8 +++++--- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java index b5e1261..5573ece 100644 --- a/src/main/java/com/share/help/Constants.java +++ b/src/main/java/com/share/help/Constants.java @@ -36,6 +36,8 @@ public class Constants { //用户查询信息接口 public static final String USER_INTERFACE_FIND_ID = USER_INTERFACE_FIND+"/{targetUserId}"; + //查找自己 + public static final String USER_INTERFACE_FIND_OWN =USER_INTERFACE_FIND+"/own"; //用户信息更新接口 public static final String USER_INTERFACE_UPDATE = "/update"; diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 919b862..2a4cef1 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -77,7 +77,7 @@ public class ActivityController { * @return 返回报名结果 */ @PostMapping(Constants.ACTIVITY_INTERFACE_APPLY) - public JSONResponse apply(UpdateActivityForm updateActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){ + public JSONResponse apply(UpdateActivityForm updateActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){ if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(updateActivityForm.getActivityId(),updateActivityForm.getActivityStatus())){ updateActivityForm.setUserId(userId); try { diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java index 04391a2..39bcc0f 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -88,10 +88,10 @@ public class UserController { * @param userId 用户id * @return 返回用户信息 */ - @GetMapping(Constants.USER_INTERFACE_FIND_ID) - public JSONResponse find(@PathVariable String targetUserId,@CookieValue(Constants.USER_COOKIE) String userId){ - if(!StringUtils.isAllEmpty(targetUserId,userId)){ - return userService.find(targetUserId,userId); + @GetMapping({Constants.USER_INTERFACE_FIND_ID,Constants.USER_INTERFACE_FIND_OWN}) + public JSONResponse find(@PathVariable(required = false) String targetUserId,@CookieValue(Constants.USER_COOKIE) String userId){ + if(userId!=null){ + return userService.find(StringUtils.isNotEmpty(targetUserId)?targetUserId:userId,userId); }else{ return new JSONResponse<>(DefaultRes.fail,Result.FAIL); } diff --git a/src/main/java/com/share/help/res/account/QueryRes.java b/src/main/java/com/share/help/res/account/QueryRes.java index a622699..2ffc40b 100644 --- a/src/main/java/com/share/help/res/account/QueryRes.java +++ b/src/main/java/com/share/help/res/account/QueryRes.java @@ -15,6 +15,15 @@ public class QueryRes { private String info; private Integer age; private boolean isMyFriend; + private Integer timeScore; + + public Integer getTimeScore() { + return timeScore; + } + + public void setTimeScore(Integer timeScore) { + this.timeScore = timeScore; + } @JsonProperty("isMyFriend") public boolean isMyFriend() { diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index dc11122..dffda7b 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -117,7 +117,10 @@ public class ActivityService{ * @return 返回报名结果 */ @Transactional - public JSONResponse apply(UpdateActivityForm activityForm) throws RuntimeException{ + public JSONResponse apply(UpdateActivityForm activityForm) throws RuntimeException{ + //记录用户完成活动返回的时间币 + Integer timeScore = null; + // 保存到活动历史记录 ActivityHistoryEntity activityEntity=new ActivityHistoryEntity(); activityEntity.setActivityId(activityForm.getActivityId()); @@ -126,11 +129,13 @@ public class ActivityService{ activityEntity.setActivityStatus(activityForm.getActivityStatus().name()); //完成活动结算时间币 if(ActivityStatus.complete==activityForm.getActivityStatus()){ - int timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId()); + timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId()); logger.info("奖励时间币:"+timeScore); activityEntity.setTimeScore(timeScore); UserEntity userEntity=userMapper.findOne(activityEntity.getUserId()); - userEntity.setTimeScore(userEntity.getTimeScore()+timeScore); + timeScore+=userEntity.getTimeScore(); + userEntity.setTimeScore(timeScore); + if(!userMapper.update(userEntity)){ throw new RuntimeException("结算时间币失败"); } @@ -153,7 +158,7 @@ public class ActivityService{ if(!leaveWordMapper.insert(leaveWordEntity)){ throw new RuntimeException("保存留言信息失败"); } - return new JSONResponse<>(DefaultRes.ok,Result.OK); + return new JSONResponse(DefaultRes.ok,Result.OK).setBody(timeScore); } /** diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml index 9b22d6d..974bed7 100644 --- a/src/main/resources/mapping/UserMapper.xml +++ b/src/main/resources/mapping/UserMapper.xml @@ -25,7 +25,11 @@ select source_user_id,target_user_id from friend where source_user_id=#{userId} and target_user_id=#{targetUserId} union all select source_user_id,target_user_id from friend where source_user_id=#{targetUserId} and target_user_id=#{userId})a) - as isMyFriend from user where user_id=#{targetUserId} + as isMyFriend + + ,time_score as timeScore + + from user where user_id=#{targetUserId} diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 13ad264..94137e7 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -238,10 +238,12 @@ class HelpApplicationTests { @Test public void queryUserInfo(){ QueryRes queryRes= userMapper.findInfo("123","222"); - Assertions.assertTrue(queryRes.isMyFriend()); + Assertions.assertNull(queryRes.getTimeScore()); + + queryRes= userMapper.findInfo("123","123"); + Assertions.assertNotNull(queryRes.getTimeScore()); + - queryRes= userMapper.findInfo("123","777"); - Assertions.assertFalse(queryRes.isMyFriend()); } @Test