diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 38bc8ff..862562c 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -6,6 +6,7 @@ import com.share.help.entity.custorm.ActivitySimple; import com.share.help.entity.custorm.FindActivityRes; import com.share.help.entity.custorm.SeekHelpSum; import com.share.help.form.manager.ActiveUserRes; +import com.share.help.res.ActivitySendUser; import com.share.help.res.ManagerActivityRes; import com.share.help.res.Page; import org.apache.ibatis.annotations.Delete; @@ -80,4 +81,6 @@ public interface ActivityMapper { //查询活跃用户 List queryActiveUser(@Param("userId") String userId,@Param("serviceAddress") String serviceAddress); + //查询活动举办者信息 + ActivitySendUser querySendUser(@Param("activityId") Long activityId); } diff --git a/src/main/java/com/share/help/res/ActivitySendUser.java b/src/main/java/com/share/help/res/ActivitySendUser.java new file mode 100644 index 0000000..9514dd2 --- /dev/null +++ b/src/main/java/com/share/help/res/ActivitySendUser.java @@ -0,0 +1,34 @@ +package com.share.help.res; + +//查询活动举办人信息 +public class ActivitySendUser { + private Long activityId; + + private String userId; + + private Integer timeScore; + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public Integer getTimeScore() { + return timeScore; + } + + public void setTimeScore(Integer timeScore) { + this.timeScore = timeScore; + } +} diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index ca58dbf..95de8d2 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -12,10 +12,7 @@ import com.share.help.entity.UserEntity; import com.share.help.entity.custorm.*; import com.share.help.form.*; import com.share.help.form.manager.ActiveUserRes; -import com.share.help.res.DefaultRes; -import com.share.help.res.JSONResponse; -import com.share.help.res.Page; -import com.share.help.res.Result; +import com.share.help.res.*; import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,7 +168,7 @@ public class ActivityService{ @Transactional public JSONResponse apply(UpdateActivityForm activityForm) throws RuntimeException{ //记录用户完成活动返回的时间币 - Integer timeScore = null; + int resultScore=0; // 保存到活动历史记录 ActivityHistoryEntity activityEntity=new ActivityHistoryEntity(); @@ -181,16 +178,25 @@ public class ActivityService{ activityEntity.setActivityStatus(activityForm.getActivityStatus().name()); //完成活动结算时间币 if(ActivityStatus.complete==activityForm.getActivityStatus()){ - timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId()); - logger.info("奖励时间币:"+timeScore); + int timeScore=activityHistoryMapper.getTimeScore(activityForm.getActivityId(),activityForm.getUserId()); + logger.info("奖励用户"+activityForm.getUserId()+"时间币:"+timeScore); activityEntity.setTimeScore(timeScore); UserEntity userEntity=userMapper.findOne(activityEntity.getUserId()); - timeScore+=userEntity.getTimeScore(); - userEntity.setTimeScore(timeScore); + resultScore=timeScore+userEntity.getTimeScore(); + userEntity.setTimeScore(resultScore); if(!userMapper.update(userEntity)){ throw new RuntimeException("结算时间币失败"); } + + ActivitySendUser activitySendUser=activityMapper.querySendUser(activityForm.getActivityId()); + UserEntity sendUser=userMapper.findOne(activitySendUser.getUserId()); + logger.info("扣除用户"+activitySendUser.getUserId()+"时间币"+timeScore); + sendUser.setTimeScore(sendUser.getTimeScore()-timeScore); + + if(!userMapper.update(sendUser)){ + throw new RuntimeException("扣除时间币失败"); + } } if(!activityHistoryMapper.insert(activityEntity)){ throw new RuntimeException("保存活动历史记录失败"); @@ -210,7 +216,7 @@ public class ActivityService{ if(!leaveWordMapper.insert(leaveWordEntity)){ throw new RuntimeException("保存留言信息失败"); } - return new JSONResponse(DefaultRes.ok,Result.OK).setBody(timeScore); + return new JSONResponse(DefaultRes.ok,Result.OK).setBody(resultScore); } /** diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index b89bc83..91a9a34 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -80,7 +80,7 @@ activity.activity_start_time as activityStartTime, activity.activity_end_time as activityEndTime, activity.user_id as seekHelpUser, - group_concat(activity_history.user_id) as helpUser + group_concat(distinct activity_history.user_id) as helpUser from activity_history,activity where activity.activity_id=activity_history.activity_id group by activity.activity_id union all select activity_id as activityId, @@ -185,4 +185,10 @@ limit #{start},#{count} limit 0,3 + \ No newline at end of file diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index c61f1b1..b73968b 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -7,6 +7,7 @@ import com.share.help.entity.UserEntity; import com.share.help.entity.custorm.*; import com.share.help.form.ActivityStatus; import com.share.help.form.manager.ActiveUserRes; +import com.share.help.res.ActivitySendUser; import com.share.help.res.ManagerActivityRes; import com.share.help.res.Page; import com.share.help.res.TimeScore; @@ -331,4 +332,11 @@ class HelpApplicationTests { TimeScore timeScore= activityHistoryMapper.queryActivityHistory("123",65L); Assertions.assertEquals(24, (int) timeScore.getTimeScore()); } + + //测试查询时间币 + @Test + public void testQuerySendUser(){ + ActivitySendUser activitySendUser=activityMapper.querySendUser(63L); + Assertions.assertEquals(20,activitySendUser.getTimeScore()); + } }