From 09741ca25e6302eb6237d1518a781937015daa60 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 13 Jun 2020 07:17:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E6=B4=BB=E5=8A=A8=E5=8F=91?= =?UTF-8?q?=E8=B5=B7=E8=80=85=E6=97=B6=E9=97=B4=E5=B8=81=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=89=A3=E9=99=A4=202.=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=B4=BB=E5=8A=A8=E7=AE=A1=E7=90=86=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E8=80=85=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/share/help/dao/ActivityMapper.java | 3 ++ .../com/share/help/res/ActivitySendUser.java | 34 +++++++++++++++++++ .../share/help/service/ActivityService.java | 26 ++++++++------ src/main/resources/mapping/ActivityMapper.xml | 8 ++++- .../com/share/help/HelpApplicationTests.java | 8 +++++ 5 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/share/help/res/ActivitySendUser.java 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()); + } }