完善我的求助我的帮助分页逻辑

master
pan 5 years ago
parent 109e0f57a7
commit 711000eb5a
  1. 7
      src/main/java/com/share/help/controller/ActivityController.java
  2. 5
      src/main/java/com/share/help/dao/ActivityMapper.java
  3. 23
      src/main/java/com/share/help/form/SeekHelpForm.java
  4. 10
      src/main/java/com/share/help/service/ActivityService.java
  5. 4
      src/main/resources/mapping/ActivityHistoryMapper.xml
  6. 38
      src/main/resources/mapping/ActivityMapper.xml
  7. 6
      src/test/java/com/share/help/HelpApplicationTests.java

@ -96,11 +96,12 @@ public class ActivityController {
* @return 返回统计结果 * @return 返回统计结果
*/ */
@GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP) @GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP)
public JSONResponse<DefaultRes, List<SeekHelpSum>> seekHelp(@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes, Page<List<SeekHelpSum>>> seekHelp(SeekHelpForm seekHelpForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId==null){ if(userId==null||seekHelpForm.getCurrentPage()==null){
return new JSONResponse<>(DefaultRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{ }else{
return activityService.seekHelpCount(userId); seekHelpForm.setUserId(userId);
return activityService.seekHelpCount(seekHelpForm);
} }
} }

@ -63,7 +63,10 @@ public interface ActivityMapper {
FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId,@Param("title") String title); FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId,@Param("title") String title);
//求助信息 //求助信息
List<SeekHelpSum> seekHelp(@Param("userId") String userId); List<SeekHelpSum> seekHelp(@Param("userId") String userId,@Param("start") Integer start, @Param("count") Integer count);
//统计分页信息
Page<List<SeekHelpSum>> seekHelpCount(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
//查找管理员信息 //查找管理员信息
List<ManagerActivityRes> queryActivity(@Param("start") Integer start, @Param("count") Integer count); List<ManagerActivityRes> queryActivity(@Param("start") Integer start, @Param("count") Integer count);

@ -0,0 +1,23 @@
package com.share.help.form;
public class SeekHelpForm {
private String userId;
private Integer currentPage;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
}

@ -217,9 +217,12 @@ public class ActivityService{
* 求助信息统计 * 求助信息统计
* @return 返回统计结果 * @return 返回统计结果
*/ */
public JSONResponse<DefaultRes,List<SeekHelpSum>> seekHelpCount(String userId){ public JSONResponse<DefaultRes,Page<List<SeekHelpSum>>> seekHelpCount(SeekHelpForm seekHelpForm){
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp(userId); Page<List<SeekHelpSum>> page=activityMapper.seekHelpCount(helpPageSize,seekHelpForm.getUserId());
return new JSONResponse<DefaultRes,List<SeekHelpSum>>(DefaultRes.ok,Result.OK).setBody(seekHelpSums); List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp(seekHelpForm.getUserId(),(seekHelpForm.getCurrentPage()-1)*helpPageSize,helpPageSize);
page.setBody(seekHelpSums);
page.setCurrentPage(seekHelpForm.getCurrentPage());
return new JSONResponse<DefaultRes,Page<List<SeekHelpSum>>>(DefaultRes.ok,Result.OK).setBody(page);
} }
/** /**
@ -240,6 +243,7 @@ public class ActivityService{
*/ */
public JSONResponse<DefaultRes,Page<List<HelpRes>>> queryHelp(QueryHelpForm queryHelpForm){ public JSONResponse<DefaultRes,Page<List<HelpRes>>> queryHelp(QueryHelpForm queryHelpForm){
Page<List<HelpRes>> page=activityHistoryMapper.count(queryHelpForm.getUserId(),helpPageSize); Page<List<HelpRes>> page=activityHistoryMapper.count(queryHelpForm.getUserId(),helpPageSize);
page.setCurrentPage(queryHelpForm.getCurrentPage());
List<HelpRes> helpRes=activityHistoryMapper.queryMyHelp((queryHelpForm.getCurrentPage()-1)*helpPageSize,helpPageSize,queryHelpForm.getUserId()); List<HelpRes> helpRes=activityHistoryMapper.queryMyHelp((queryHelpForm.getCurrentPage()-1)*helpPageSize,helpPageSize,queryHelpForm.getUserId());
page.setBody(helpRes); page.setBody(helpRes);
return new JSONResponse<DefaultRes,Page<List<HelpRes>>>(DefaultRes.ok,Result.OK).setBody(page); return new JSONResponse<DefaultRes,Page<List<HelpRes>>>(DefaultRes.ok,Result.OK).setBody(page);

@ -39,7 +39,9 @@
<!-- 计算分页--> <!-- 计算分页-->
<select id="count" resultType="com.share.help.res.Page"> <select id="count" resultType="com.share.help.res.Page">
select count(distinct activity.activity_id) as count,ceil(count(distinct activity.activity_id)/#{pageSize}) as totalPage from select count(distinct activity.activity_id) as count,
ceil(count(distinct activity.activity_id)/#{pageSize}) as totalPage,
#{pageSize} as pageSize from
activity,activity_history where activity_history.user_id=#{userId} and activity.activity_id=activity_history.activity_id activity,activity_history where activity_history.user_id=#{userId} and activity.activity_id=activity_history.activity_id
</select> </select>

@ -96,6 +96,43 @@
</select> </select>
<select id="seekHelpCount" resultType="com.share.help.res.Page">
select count(activity_id) as count,ceil(count(activity_id)/#{pageSize}) as totalPage,#{pageSize} as pageSize from(
select activity_id,
activity_img,
seek_help_time,
title,
content,
sum(case activity_status when 'apply' then count else 0 end) as 'apply',
sum(case activity_status when 'join' then count else 0 end) as 'join',
sum(case activity_status when 'complete' then count else 0 end) as 'complete'
from (select activity.activity_id,
activity_img,
seek_help_time,
title,
content,
activity_status,
count(activity_status) as count
from activity,
activity_history
where activity.activity_id = activity_history.activity_id
and activity.user_id = #{userId}
group by activity_id, activity_status) a
group by activity_id
union all
select activity_id,
activity_img,
seek_help_time,
title,
content,
0,
0,
0
from activity
where user_id = #{userId}
and activity_id not in (select activity_id from activity_history)) b
</select>
<!-- 查询用户的求助信息--> <!-- 查询用户的求助信息-->
<select id="seekHelp" resultMap="seekHelpMap"> <select id="seekHelp" resultMap="seekHelpMap">
select activity_id,activity_img,seek_help_time,title,content, select activity_id,activity_img,seek_help_time,title,content,
@ -109,6 +146,7 @@ from (
select activity_id,activity_img,seek_help_time,title,content,0,0,0 from activity where user_id=#{userId} select activity_id,activity_img,seek_help_time,title,content,0,0,0 from activity where user_id=#{userId}
and activity_id not in(select activity_id from activity_history) order by seek_help_time desc and activity_id not in(select activity_id from activity_history) order by seek_help_time desc
limit #{start},#{count}
</select> </select>
<!-- 获取志愿者列表--> <!-- 获取志愿者列表-->

@ -181,8 +181,10 @@ class HelpApplicationTests {
// 求助信息统计 // 求助信息统计
@Test @Test
public void testSeekHelpCount(){ public void testSeekHelpCount(){
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp("123"); Page<List<SeekHelpSum>> page=activityMapper.seekHelpCount(3,"123");
Assertions.assertFalse(seekHelpSums.isEmpty()); Assertions.assertEquals(10, (long) page.getCount());
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp("123",0,3);
Assertions.assertEquals(seekHelpSums.size(),3);
} }

Loading…
Cancel
Save