From be9604d8695f9b3bd968e9b2a58776cd7e63f196 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Thu, 28 May 2020 01:16:03 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=8F=AA=E6=98=BE=E7=A4=BA=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=8A=A5=E5=90=8D=E7=9A=84=E5=B9=B6=E4=B8=94=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E8=87=AA=E5=B7=B1=E5=8F=91=E5=B8=83=E7=9A=84=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=EF=BC=8C=E5=B7=B2=E6=8A=A5=E5=90=8D=EF=BC=8C=E5=B7=B2?= =?UTF-8?q?=E5=8F=82=E5=8A=A0=E7=9A=84=E6=B4=BB=E5=8A=A8=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E4=BB=8E=E6=88=91=E7=9A=84=E5=B8=AE=E5=8A=A9=E5=A4=84=E6=89=BE?= =?UTF-8?q?=E5=88=B0=202.=20=E6=B1=82=E5=8A=A9=E8=80=85=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=88=AB=E4=BA=BA=E7=9A=84=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E6=B3=95=E5=81=9A=E6=8A=A5=E5=90=8D=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../help/controller/ActivityController.java | 9 ++++---- .../com/share/help/dao/ActivityMapper.java | 7 ++---- .../com/share/help/dao/LeaveWordMapper.java | 4 ++-- .../com/share/help/form/FindActivityForm.java | 11 +++++++++- .../com/share/help/res/account/LoginRes.java | 22 ++++++++++++++----- .../share/help/service/ActivityService.java | 9 ++++---- src/main/resources/application.yaml | 2 +- src/main/resources/logback-spring.xml | 3 ++- src/main/resources/mapping/ActivityMapper.xml | 17 ++++++++++++++ .../com/share/help/HelpApplicationTests.java | 16 ++++++++++---- 10 files changed, 73 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 7dc4ff9..8de3bdc 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -47,11 +47,12 @@ public class ActivityController { * @return 返回活动列表数据 */ @GetMapping(Constants.ACTIVITY_INTERFACE_FIND) - public JSONResponse find(FindActivityForm findActivityForm){ - if(findActivityForm.getCurrentPage()==null){ - return new JSONResponse<>(FindActivityRes.Res.fail,Result.FAIL); - }else{ + public JSONResponse find(FindActivityForm findActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){ + if(findActivityForm.getCurrentPage()!=null&StringUtils.isNotEmpty(userId)){ + findActivityForm.setUserId(userId); return activityService.find(findActivityForm); + }else{ + return new JSONResponse<>(FindActivityRes.Res.fail,Result.FAIL); } } diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 18d2f81..3d928be 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -44,15 +44,12 @@ public interface ActivityMapper { * @param count 查询个数 * @return 返回活动列表 */ - @Select("select activity_id,title,content,activity_img from activity limit #{start},#{count}") - @ResultMap("activitySimpleMap") - List getPage(@Param("start") Integer start, @Param("count") Integer count); + List getPage(@Param("start") Integer start, @Param("count") Integer count,@Param("userId") String userId); /** * 获取活动列表分页数 * @param pageSize 分页大小 * @return 返回分页信息 */ - @Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity") - FindActivityRes count(@Param("pageSize") Integer pageSize); + FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId); } diff --git a/src/main/java/com/share/help/dao/LeaveWordMapper.java b/src/main/java/com/share/help/dao/LeaveWordMapper.java index 671b0ab..1efe23c 100644 --- a/src/main/java/com/share/help/dao/LeaveWordMapper.java +++ b/src/main/java/com/share/help/dao/LeaveWordMapper.java @@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Insert; */ public interface LeaveWordMapper { - @Insert("insert into leave_word(leave_word_id,type,source_user_id,target_user_id,activity_id,create_time)" + - "value(#{leaveWordId},#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})") + @Insert("insert into leave_word(type,source_user_id,target_user_id,activity_id,create_time)" + + "value(#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})") boolean insert(LeaveWordEntity leaveWordEntity); } diff --git a/src/main/java/com/share/help/form/FindActivityForm.java b/src/main/java/com/share/help/form/FindActivityForm.java index bbc3183..35dabe8 100644 --- a/src/main/java/com/share/help/form/FindActivityForm.java +++ b/src/main/java/com/share/help/form/FindActivityForm.java @@ -6,7 +6,8 @@ package com.share.help.form; public class FindActivityForm { //查找分页 private Integer currentPage; - + //排除用户自身发起的活动 + private String userId; //标题信息 private String title; @@ -25,4 +26,12 @@ public class FindActivityForm { public void setCurrentPage(Integer currentPage) { this.currentPage = currentPage; } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } } diff --git a/src/main/java/com/share/help/res/account/LoginRes.java b/src/main/java/com/share/help/res/account/LoginRes.java index dc2d237..e891ccf 100644 --- a/src/main/java/com/share/help/res/account/LoginRes.java +++ b/src/main/java/com/share/help/res/account/LoginRes.java @@ -7,17 +7,21 @@ import com.share.help.entity.UserEntity; */ public class LoginRes { - public LoginRes(UserEntity userEntity) { - this.userId=userEntity.getUserId(); - this.userType=userEntity.getUserType(); - } - //用户id private String userId; //用户身份 private String userType; + //时间币 + private Integer timeScore; + + public LoginRes(UserEntity userEntity) { + this.userId = userEntity.getUserId(); + this.userType = userEntity.getUserType(); + this.timeScore = userEntity.getTimeScore(); + } + public String getUserId() { return userId; } @@ -34,6 +38,14 @@ public class LoginRes { this.userType = userType; } + public Integer getTimeScore() { + return timeScore; + } + + public void setTimeScore(Integer timeScore) { + this.timeScore = timeScore; + } + public enum Res { // 登陆成功 ok, diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index d1fe90c..a082636 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -86,15 +86,15 @@ public class ActivityService{ * @return 返回活动信息 */ public JSONResponse find(FindActivityForm findActivityForm){ - FindActivityRes findActivityRes=activityMapper.count(pageSize); + FindActivityRes findActivityRes=activityMapper.count(pageSize,findActivityForm.getUserId()); findActivityRes.setPageSize(pageSize); findActivityRes.setCurrentPage(findActivityForm.getCurrentPage()); - List activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)*pageSize,pageSize); + List activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)*pageSize,pageSize,findActivityForm.getUserId()); if(!activitySimpleList.isEmpty()){ findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList,rowSize)); return new JSONResponse(FindActivityRes.Res.ok,Result.OK).setBody(findActivityRes); }else{ - return new JSONResponse<>(FindActivityRes.Res.empty, Result.FAIL); + return new JSONResponse<>(FindActivityRes.Res.empty, Result.OK); } } @@ -142,8 +142,9 @@ public class ActivityService{ leaveWordEntity.setTargetUserId(activity.getUserId()); leaveWordEntity.setActivityId(activityForm.getActivityId()); leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis())); - if(leaveWordMapper.insert(leaveWordEntity)){ + if(!leaveWordMapper.insert(leaveWordEntity)){ logger.error("保存留言信息失败"); + return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); } return new JSONResponse<>(ApplyActivityRes.ok,Result.OK); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 6d6fa58..7952791 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -3,7 +3,7 @@ spring: datasource: username: sukura password: 123456 - url: jdbc:mysql://localhost:3306/help + url: jdbc:mysql://localhost:3306/help?serverTimezone=Asia/Shanghai #静态资源目录 mvc: static-path-pattern: /image/** diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index b236f75..278c7cf 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -29,10 +29,11 @@ - INFO + DEBUG + diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index ac8be6c..dfa42ab 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -22,4 +22,21 @@ + + + where user_id!=#{userId} + and + activity_id not in(select distinct activity_id from activity_history where activity_history.user_id=#{userId}) + + + + + \ 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 88ca00b..e2e7e74 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -5,6 +5,7 @@ import com.share.help.dao.UserMapper; import com.share.help.entity.ActivityEntity; import com.share.help.entity.UserEntity; import com.share.help.res.account.FindUserRes; +import com.share.help.res.activity.ActivitySimple; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +23,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.context.WebApplicationContext; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -140,16 +142,22 @@ class HelpApplicationTests { */ @Test public void testActivity(){ - Assertions.assertNotNull(activityMapper.findOne(1L)); + List activityEntityList=activityMapper.getPage(0,10,"123"); + Assertions.assertTrue(activityEntityList.isEmpty()); + activityEntityList=activityMapper.getPage(0,10,"666"); + Assertions.assertFalse(activityEntityList.isEmpty()); + + Assertions.assertNotNull(activityMapper.count(10,"123")); } @Test public void testAddActivity(){ - ActivityEntity activityEntity=activityMapper.findOne(1L); - for(int i=0;i<20;i++){ + ActivityEntity activityEntity=activityMapper.findOne(25L); + activityEntity.setActivityId(null); + activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); activityMapper.insert(activityEntity); - } + } }