From 541f73dd389ed94a9362dde294582816ff831ab9 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 30 May 2020 07:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B4=BB=E5=8A=A8=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../help/controller/ActivityController.java | 12 +++------ .../com/share/help/dao/ActivityMapper.java | 10 +++++--- .../help/entity/custorm/ActivityDetail.java | 25 +++++++++++++++++++ .../share/help/service/ActivityService.java | 10 ++++---- .../share/help/service/LeaveWordService.java | 4 +-- src/main/resources/mapping/ActivityMapper.xml | 9 ++++++- .../com/share/help/HelpApplicationTests.java | 10 ++------ 7 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/share/help/entity/custorm/ActivityDetail.java diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 141369a..7b5c8f5 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -1,11 +1,7 @@ package com.share.help.controller; import com.share.help.Constants; -import com.share.help.entity.ActivityEntity; -import com.share.help.entity.custorm.FindActivityRes; -import com.share.help.entity.custorm.HelpRes; -import com.share.help.entity.custorm.SeekHelpSum; -import com.share.help.entity.custorm.UserWithName; +import com.share.help.entity.custorm.*; import com.share.help.form.*; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; @@ -67,11 +63,11 @@ public class ActivityController { * @return 返回活动列表 */ @GetMapping(Constants.ACTIVITY_INTERFACE_FIND_ID) - public JSONResponse find(@PathVariable Long activityId){ - if(activityId==null){ + public JSONResponse find(@PathVariable Long activityId,@CookieValue(Constants.USER_COOKIE) String userId){ + if(activityId==null||StringUtils.isEmpty(userId)){ return new JSONResponse<>(DefaultRes.fail,Result.FAIL); }else{ - return activityService.find(activityId); + return activityService.find(activityId,userId); } } diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 0306c1c..7f90e7f 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -1,10 +1,14 @@ package com.share.help.dao; import com.share.help.entity.ActivityEntity; +import com.share.help.entity.custorm.ActivityDetail; import com.share.help.entity.custorm.ActivitySimple; import com.share.help.entity.custorm.FindActivityRes; import com.share.help.entity.custorm.SeekHelpSum; -import org.apache.ibatis.annotations.*; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -36,9 +40,7 @@ public interface ActivityMapper { * @param activityId 活动id * @return 返回活动信息 */ - @Select("select * from activity where activity_id=#{activityId}") - @ResultMap("activityMap") - ActivityEntity findOne(@Param("activityId") Long activityId); + ActivityDetail findOne(@Param("activityId") Long activityId,@Param("userId") String userId); /** * 分页查询活动 diff --git a/src/main/java/com/share/help/entity/custorm/ActivityDetail.java b/src/main/java/com/share/help/entity/custorm/ActivityDetail.java new file mode 100644 index 0000000..39bd48f --- /dev/null +++ b/src/main/java/com/share/help/entity/custorm/ActivityDetail.java @@ -0,0 +1,25 @@ +package com.share.help.entity.custorm; + +import java.sql.Timestamp; + +public class ActivityDetail extends ActivitySimple{ + private Timestamp activityStartTime; + + private Timestamp activityEndTime; + + public Timestamp getActivityStartTime() { + return activityStartTime; + } + + public void setActivityStartTime(Timestamp activityStartTime) { + this.activityStartTime = activityStartTime; + } + + public Timestamp getActivityEndTime() { + return activityEndTime; + } + + public void setActivityEndTime(Timestamp activityEndTime) { + this.activityEndTime = activityEndTime; + } +} diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index c92d4c8..98395d9 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -139,12 +139,12 @@ public class ActivityService{ * @param activityId 活动id * @return 返回活动详情信息 */ - public JSONResponse find(Long activityId){ - ActivityEntity activityEntity=activityMapper.findOne(activityId); - if(activityEntity==null){ + public JSONResponse find(Long activityId,String userId){ + ActivityDetail activityDetail=activityMapper.findOne(activityId,userId); + if(activityDetail==null){ return new JSONResponse<>(DefaultRes.fail,Result.FAIL); }else{ - return new JSONResponse(DefaultRes.ok,Result.OK).setBody(activityEntity); + return new JSONResponse(DefaultRes.ok,Result.OK).setBody(activityDetail); } } @@ -185,7 +185,7 @@ public class ActivityService{ LeaveWordEntity leaveWordEntity=new LeaveWordEntity(); leaveWordEntity.setType(activityForm.getActivityStatus().name()); leaveWordEntity.setSourceUserId(activityForm.getUserId()); - ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId()); + ActivityDetail activity=activityMapper.findOne(activityForm.getActivityId(),activityForm.getUserId()); if(activity==null){ throw new RuntimeException("查询活动记录失败"); } diff --git a/src/main/java/com/share/help/service/LeaveWordService.java b/src/main/java/com/share/help/service/LeaveWordService.java index e85a018..0583fb2 100644 --- a/src/main/java/com/share/help/service/LeaveWordService.java +++ b/src/main/java/com/share/help/service/LeaveWordService.java @@ -3,9 +3,9 @@ package com.share.help.service; import com.share.help.dao.ActivityMapper; import com.share.help.dao.FriendMapper; import com.share.help.dao.LeaveWordMapper; -import com.share.help.entity.ActivityEntity; import com.share.help.entity.FriendEntity; import com.share.help.entity.LeaveWordEntity; +import com.share.help.entity.custorm.ActivityDetail; import com.share.help.entity.custorm.LeaveWordRes; import com.share.help.form.*; import com.share.help.res.DefaultRes; @@ -48,7 +48,7 @@ public class LeaveWordService { List leaveWordRes=leaveWordMapper.select((findLeaveWordForm.getCurrentPage()-1)*pageSize,pageSize,findLeaveWordForm.getUserId()); for(LeaveWordRes wordRes:leaveWordRes){ if(LeaveWordType.friend!=wordRes.getType()&&wordRes.getActivityId()!=null){ - ActivityEntity activityEntity=activityMapper.findOne(wordRes.getActivityId()); + ActivityDetail activityEntity=activityMapper.findOne(wordRes.getActivityId(),findLeaveWordForm.getUserId()); wordRes.setTitle(activityEntity.getTitle()); wordRes.setContent(activityEntity.getContent()); } diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index 9e275b4..9ac5ef8 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -15,7 +15,7 @@ - + @@ -32,6 +32,13 @@ limit #{start},#{count} + + diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 148b099..5cdd2de 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -1,7 +1,6 @@ package com.share.help; import com.share.help.dao.*; -import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityHistoryEntity; import com.share.help.entity.UserEntity; import com.share.help.entity.custorm.*; @@ -167,12 +166,7 @@ class HelpApplicationTests { @Test public void testAddActivity(){ - ActivityEntity activityEntity=activityMapper.findOne(63L); - - activityEntity.setActivityId(null); - activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); - activityMapper.insert(activityEntity); - + ActivitySimple activityEntity=activityMapper.findOne(63L,"222"); } // 求助信息统计 @@ -208,7 +202,7 @@ class HelpApplicationTests { public void queryLeaveWord(){ Page> listPage=leaveWordMapper.count(10,"777"); Assertions.assertNotNull(listPage); - List leaveWordRes=leaveWordMapper.select(0,3,"777"); + List leaveWordRes=leaveWordMapper.select(0,3,"123"); Assertions.assertFalse(leaveWordRes.isEmpty()); }