1. 只显示没有报名的并且不是自己发布的活动,已报名,已参加的活动只能从我的帮助处找到

2. 求助者只能查看别人的活动,无法做报名操作
master
pan 5 years ago
parent a099d3bd89
commit be9604d869
  1. 9
      src/main/java/com/share/help/controller/ActivityController.java
  2. 7
      src/main/java/com/share/help/dao/ActivityMapper.java
  3. 4
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  4. 11
      src/main/java/com/share/help/form/FindActivityForm.java
  5. 22
      src/main/java/com/share/help/res/account/LoginRes.java
  6. 9
      src/main/java/com/share/help/service/ActivityService.java
  7. 2
      src/main/resources/application.yaml
  8. 3
      src/main/resources/logback-spring.xml
  9. 17
      src/main/resources/mapping/ActivityMapper.xml
  10. 16
      src/test/java/com/share/help/HelpApplicationTests.java

@ -47,11 +47,12 @@ public class ActivityController {
* @return 返回活动列表数据 * @return 返回活动列表数据
*/ */
@GetMapping(Constants.ACTIVITY_INTERFACE_FIND) @GetMapping(Constants.ACTIVITY_INTERFACE_FIND)
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){ public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(findActivityForm.getCurrentPage()==null){ if(findActivityForm.getCurrentPage()!=null&StringUtils.isNotEmpty(userId)){
return new JSONResponse<>(FindActivityRes.Res.fail,Result.FAIL); findActivityForm.setUserId(userId);
}else{
return activityService.find(findActivityForm); return activityService.find(findActivityForm);
}else{
return new JSONResponse<>(FindActivityRes.Res.fail,Result.FAIL);
} }
} }

@ -44,15 +44,12 @@ public interface ActivityMapper {
* @param count 查询个数 * @param count 查询个数
* @return 返回活动列表 * @return 返回活动列表
*/ */
@Select("select activity_id,title,content,activity_img from activity limit #{start},#{count}") List<ActivitySimple> getPage(@Param("start") Integer start, @Param("count") Integer count,@Param("userId") String userId);
@ResultMap("activitySimpleMap")
List<ActivitySimple> getPage(@Param("start") Integer start, @Param("count") Integer count);
/** /**
* 获取活动列表分页数 * 获取活动列表分页数
* @param pageSize 分页大小 * @param pageSize 分页大小
* @return 返回分页信息 * @return 返回分页信息
*/ */
@Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity") FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
FindActivityRes count(@Param("pageSize") Integer pageSize);
} }

@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Insert;
*/ */
public interface LeaveWordMapper { public interface LeaveWordMapper {
@Insert("insert into leave_word(leave_word_id,type,source_user_id,target_user_id,activity_id,create_time)" + @Insert("insert into leave_word(type,source_user_id,target_user_id,activity_id,create_time)" +
"value(#{leaveWordId},#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})") "value(#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})")
boolean insert(LeaveWordEntity leaveWordEntity); boolean insert(LeaveWordEntity leaveWordEntity);
} }

@ -6,7 +6,8 @@ package com.share.help.form;
public class FindActivityForm { public class FindActivityForm {
//查找分页 //查找分页
private Integer currentPage; private Integer currentPage;
//排除用户自身发起的活动
private String userId;
//标题信息 //标题信息
private String title; private String title;
@ -25,4 +26,12 @@ public class FindActivityForm {
public void setCurrentPage(Integer currentPage) { public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage; this.currentPage = currentPage;
} }
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
} }

@ -7,17 +7,21 @@ import com.share.help.entity.UserEntity;
*/ */
public class LoginRes { public class LoginRes {
public LoginRes(UserEntity userEntity) {
this.userId=userEntity.getUserId();
this.userType=userEntity.getUserType();
}
//用户id //用户id
private String userId; private String userId;
//用户身份 //用户身份
private String userType; 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() { public String getUserId() {
return userId; return userId;
} }
@ -34,6 +38,14 @@ public class LoginRes {
this.userType = userType; this.userType = userType;
} }
public Integer getTimeScore() {
return timeScore;
}
public void setTimeScore(Integer timeScore) {
this.timeScore = timeScore;
}
public enum Res { public enum Res {
// 登陆成功 // 登陆成功
ok, ok,

@ -86,15 +86,15 @@ public class ActivityService{
* @return 返回活动信息 * @return 返回活动信息
*/ */
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){ public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){
FindActivityRes findActivityRes=activityMapper.count(pageSize); FindActivityRes findActivityRes=activityMapper.count(pageSize,findActivityForm.getUserId());
findActivityRes.setPageSize(pageSize); findActivityRes.setPageSize(pageSize);
findActivityRes.setCurrentPage(findActivityForm.getCurrentPage()); findActivityRes.setCurrentPage(findActivityForm.getCurrentPage());
List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)*pageSize,pageSize); List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)*pageSize,pageSize,findActivityForm.getUserId());
if(!activitySimpleList.isEmpty()){ if(!activitySimpleList.isEmpty()){
findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList,rowSize)); findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList,rowSize));
return new JSONResponse<FindActivityRes.Res,FindActivityRes>(FindActivityRes.Res.ok,Result.OK).setBody(findActivityRes); return new JSONResponse<FindActivityRes.Res,FindActivityRes>(FindActivityRes.Res.ok,Result.OK).setBody(findActivityRes);
}else{ }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.setTargetUserId(activity.getUserId());
leaveWordEntity.setActivityId(activityForm.getActivityId()); leaveWordEntity.setActivityId(activityForm.getActivityId());
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis())); leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
if(leaveWordMapper.insert(leaveWordEntity)){ if(!leaveWordMapper.insert(leaveWordEntity)){
logger.error("保存留言信息失败"); logger.error("保存留言信息失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL);
} }
return new JSONResponse<>(ApplyActivityRes.ok,Result.OK); return new JSONResponse<>(ApplyActivityRes.ok,Result.OK);
} }

@ -3,7 +3,7 @@ spring:
datasource: datasource:
username: sukura username: sukura
password: 123456 password: 123456
url: jdbc:mysql://localhost:3306/help url: jdbc:mysql://localhost:3306/help?serverTimezone=Asia/Shanghai
#静态资源目录 #静态资源目录
mvc: mvc:
static-path-pattern: /image/** static-path-pattern: /image/**

@ -29,10 +29,11 @@
</encoder> </encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level> <level>DEBUG</level>
</filter> </filter>
</appender> </appender>
<logger name="com.share.help.dao" level="DEBUG"/>
<root level="DEBUG"> <root level="DEBUG">
<appender-ref ref="DEBUG_FILE" /> <appender-ref ref="DEBUG_FILE" />

@ -22,4 +22,21 @@
<result property="content" column="content"/> <result property="content" column="content"/>
<result property="activityImg" column="activity_img"/> <result property="activityImg" column="activity_img"/>
</resultMap> </resultMap>
<!--查找没有报名的并且不是自己发布的活动-->
<sql id="not_apply">
where user_id!=#{userId}
and
activity_id not in(select distinct activity_id from activity_history where activity_history.user_id=#{userId})
</sql>
<select id="getPage" resultMap="activitySimpleMap">
select activity_id,title,content,activity_img from activity
<include refid="not_apply"/>
limit #{start},#{count}
</select>
<select id="count" resultType="com.share.help.res.activity.FindActivityRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
<include refid="not_apply"/>
</select>
</mapper> </mapper>

@ -5,6 +5,7 @@ import com.share.help.dao.UserMapper;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.res.account.FindUserRes; 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.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -140,16 +142,22 @@ class HelpApplicationTests {
*/ */
@Test @Test
public void testActivity(){ public void testActivity(){
Assertions.assertNotNull(activityMapper.findOne(1L)); List<ActivitySimple> 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 @Test
public void testAddActivity(){ public void testAddActivity(){
ActivityEntity activityEntity=activityMapper.findOne(1L); ActivityEntity activityEntity=activityMapper.findOne(25L);
for(int i=0;i<20;i++){
activityEntity.setActivityId(null); activityEntity.setActivityId(null);
activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis()));
activityMapper.insert(activityEntity); activityMapper.insert(activityEntity);
}
} }
} }

Loading…
Cancel
Save