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 返回活动列表数据
*/
@GetMapping(Constants.ACTIVITY_INTERFACE_FIND)
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){
if(findActivityForm.getCurrentPage()==null){
return new JSONResponse<>(FindActivityRes.Res.fail,Result.FAIL);
}else{
public JSONResponse<FindActivityRes.Res,FindActivityRes> 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);
}
}

@ -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<ActivitySimple> getPage(@Param("start") Integer start, @Param("count") Integer count);
List<ActivitySimple> 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);
}

@ -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);
}

@ -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;
}
}

@ -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,

@ -86,15 +86,15 @@ public class ActivityService{
* @return 返回活动信息
*/
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){
FindActivityRes findActivityRes=activityMapper.count(pageSize);
FindActivityRes findActivityRes=activityMapper.count(pageSize,findActivityForm.getUserId());
findActivityRes.setPageSize(pageSize);
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()){
findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList,rowSize));
return new JSONResponse<FindActivityRes.Res,FindActivityRes>(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);
}

@ -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/**

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

@ -22,4 +22,21 @@
<result property="content" column="content"/>
<result property="activityImg" column="activity_img"/>
</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>

@ -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<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
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);
}
}
}

Loading…
Cancel
Save