完成活动奖励时间币并返回给客户端

master
pan 5 years ago
parent 38d15997c3
commit 3cd574dea8
  1. 2
      src/main/java/com/share/help/Constants.java
  2. 2
      src/main/java/com/share/help/controller/ActivityController.java
  3. 8
      src/main/java/com/share/help/controller/UserController.java
  4. 9
      src/main/java/com/share/help/res/account/QueryRes.java
  5. 13
      src/main/java/com/share/help/service/ActivityService.java
  6. 6
      src/main/resources/mapping/UserMapper.xml
  7. 8
      src/test/java/com/share/help/HelpApplicationTests.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_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"; public static final String USER_INTERFACE_UPDATE = "/update";

@ -77,7 +77,7 @@ public class ActivityController {
* @return 返回报名结果 * @return 返回报名结果
*/ */
@PostMapping(Constants.ACTIVITY_INTERFACE_APPLY) @PostMapping(Constants.ACTIVITY_INTERFACE_APPLY)
public JSONResponse<DefaultRes,Void> apply(UpdateActivityForm updateActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes,Integer> apply(UpdateActivityForm updateActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(updateActivityForm.getActivityId(),updateActivityForm.getActivityStatus())){ if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(updateActivityForm.getActivityId(),updateActivityForm.getActivityStatus())){
updateActivityForm.setUserId(userId); updateActivityForm.setUserId(userId);
try { try {

@ -88,10 +88,10 @@ public class UserController {
* @param userId 用户id * @param userId 用户id
* @return 返回用户信息 * @return 返回用户信息
*/ */
@GetMapping(Constants.USER_INTERFACE_FIND_ID) @GetMapping({Constants.USER_INTERFACE_FIND_ID,Constants.USER_INTERFACE_FIND_OWN})
public JSONResponse<DefaultRes, QueryRes> find(@PathVariable String targetUserId,@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes, QueryRes> find(@PathVariable(required = false) String targetUserId,@CookieValue(Constants.USER_COOKIE) String userId){
if(!StringUtils.isAllEmpty(targetUserId,userId)){ if(userId!=null){
return userService.find(targetUserId,userId); return userService.find(StringUtils.isNotEmpty(targetUserId)?targetUserId:userId,userId);
}else{ }else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }

@ -15,6 +15,15 @@ public class QueryRes {
private String info; private String info;
private Integer age; private Integer age;
private boolean isMyFriend; private boolean isMyFriend;
private Integer timeScore;
public Integer getTimeScore() {
return timeScore;
}
public void setTimeScore(Integer timeScore) {
this.timeScore = timeScore;
}
@JsonProperty("isMyFriend") @JsonProperty("isMyFriend")
public boolean isMyFriend() { public boolean isMyFriend() {

@ -117,7 +117,10 @@ public class ActivityService{
* @return 返回报名结果 * @return 返回报名结果
*/ */
@Transactional @Transactional
public JSONResponse<DefaultRes,Void> apply(UpdateActivityForm activityForm) throws RuntimeException{ public JSONResponse<DefaultRes,Integer> apply(UpdateActivityForm activityForm) throws RuntimeException{
//记录用户完成活动返回的时间币
Integer timeScore = null;
// 保存到活动历史记录 // 保存到活动历史记录
ActivityHistoryEntity activityEntity=new ActivityHistoryEntity(); ActivityHistoryEntity activityEntity=new ActivityHistoryEntity();
activityEntity.setActivityId(activityForm.getActivityId()); activityEntity.setActivityId(activityForm.getActivityId());
@ -126,11 +129,13 @@ public class ActivityService{
activityEntity.setActivityStatus(activityForm.getActivityStatus().name()); activityEntity.setActivityStatus(activityForm.getActivityStatus().name());
//完成活动结算时间币 //完成活动结算时间币
if(ActivityStatus.complete==activityForm.getActivityStatus()){ if(ActivityStatus.complete==activityForm.getActivityStatus()){
int timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId()); timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId());
logger.info("奖励时间币:"+timeScore); logger.info("奖励时间币:"+timeScore);
activityEntity.setTimeScore(timeScore); activityEntity.setTimeScore(timeScore);
UserEntity userEntity=userMapper.findOne(activityEntity.getUserId()); UserEntity userEntity=userMapper.findOne(activityEntity.getUserId());
userEntity.setTimeScore(userEntity.getTimeScore()+timeScore); timeScore+=userEntity.getTimeScore();
userEntity.setTimeScore(timeScore);
if(!userMapper.update(userEntity)){ if(!userMapper.update(userEntity)){
throw new RuntimeException("结算时间币失败"); throw new RuntimeException("结算时间币失败");
} }
@ -153,7 +158,7 @@ public class ActivityService{
if(!leaveWordMapper.insert(leaveWordEntity)){ if(!leaveWordMapper.insert(leaveWordEntity)){
throw new RuntimeException("保存留言信息失败"); throw new RuntimeException("保存留言信息失败");
} }
return new JSONResponse<>(DefaultRes.ok,Result.OK); return new JSONResponse<DefaultRes,Integer>(DefaultRes.ok,Result.OK).setBody(timeScore);
} }
/** /**

@ -25,7 +25,11 @@
select source_user_id,target_user_id from friend where source_user_id=#{userId} and target_user_id=#{targetUserId} select source_user_id,target_user_id from friend where source_user_id=#{userId} and target_user_id=#{targetUserId}
union all union all
select source_user_id,target_user_id from friend where source_user_id=#{targetUserId} and target_user_id=#{userId})a) 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
<if test="userId==targetUserId">
,time_score as timeScore
</if>
from user where user_id=#{targetUserId}
</select> </select>
<!-- 统计用户分页数--> <!-- 统计用户分页数-->

@ -238,10 +238,12 @@ class HelpApplicationTests {
@Test @Test
public void queryUserInfo(){ public void queryUserInfo(){
QueryRes queryRes= userMapper.findInfo("123","222"); 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 @Test

Loading…
Cancel
Save