增加接口

1.个人信息-我的帮助
master
pan 5 years ago
parent b54fcbb6f3
commit e6de012598
  1. 4
      src/main/java/com/share/help/Constants.java
  2. 2
      src/main/java/com/share/help/Util.java
  3. 41
      src/main/java/com/share/help/controller/ActivityController.java
  4. 1
      src/main/java/com/share/help/controller/UserController.java
  5. 20
      src/main/java/com/share/help/dao/ActivityHistoryMapper.java
  6. 18
      src/main/java/com/share/help/entity/custorm/ActivitySimple.java
  7. 159
      src/main/java/com/share/help/entity/custorm/HelpRes.java
  8. 27
      src/main/java/com/share/help/form/HelpScoreForm.java
  9. 26
      src/main/java/com/share/help/form/QueryHelpForm.java
  10. 55
      src/main/java/com/share/help/service/ActivityService.java
  11. 2
      src/main/java/com/share/help/service/LeaveWordService.java
  12. 7
      src/main/java/com/share/help/service/UserService.java
  13. 17
      src/main/resources/application.yaml
  14. 35
      src/main/resources/mapping/ActivityHistoryMapper.xml
  15. 25
      src/main/resources/mapping/ActivityMapper.xml
  16. 11
      src/test/java/com/share/help/HelpApplicationTests.java
  17. 3
      src/test/resources/clean.sql

@ -49,4 +49,8 @@ public class Constants {
public static final String USER_INTERFACE_FIND_NAME = USER_INTERFACE_FIND+"/name";
//查找留言
public static final String USER_INTERFACE_FIND_LEAVE_WORD = USER_INTERFACE_FIND+"/leaveWord";
//查找帮助信息
public static final String ACTIVITY_INTERFACE_HELP = "/help";
//修改分数
public static final String ACTIVITY_INTERFACE_SCORE = "/score";
}

@ -14,7 +14,7 @@ public class Util {
*/
public static <T> List<List<T>> splitList(Class<T> c,List<T> dataList, int splitSize){
List<List<T>> splitList=new ArrayList<>();
if(dataList.size()<splitSize){
if(dataList.size()<=splitSize){
splitList.add(dataList);
}else {
for (int i = splitSize, j = 0; i < dataList.size(); j = i, i += splitSize) {

@ -3,16 +3,11 @@ 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.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm;
import com.share.help.form.FindUserHelp;
import com.share.help.form.SendHelpForm;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Result;
import com.share.help.res.SendHelpRes;
import com.share.help.form.*;
import com.share.help.res.*;
import com.share.help.service.ActivityService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -114,4 +109,34 @@ public class ActivityController {
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 查找帮助列表
* @param queryHelpForm 查询表单
* @param userId 用户id
* @return 返回帮助信息
*/
@GetMapping(Constants.ACTIVITY_INTERFACE_HELP)
public JSONResponse<DefaultRes, Page<List<HelpRes>>> queryHelp(QueryHelpForm queryHelpForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(queryHelpForm.getCurrentPage(),userId)){
queryHelpForm.setUserId(userId);
return activityService.queryHelp(queryHelpForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 评价活动
* @param helpScoreForm 评价表单
* @return 返回评价结果
*/
@PostMapping(Constants.ACTIVITY_INTERFACE_SCORE)
public JSONResponse<DefaultRes,Void> updateScore(HelpScoreForm helpScoreForm){
if(ObjectUtils.allNotNull(helpScoreForm.getHistoryId(),helpScoreForm.getScore())){
return activityService.updateScore(helpScoreForm);
}else {
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -158,4 +158,5 @@ public class UserController {
}
}
}

@ -1,9 +1,12 @@
package com.share.help.dao;
import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.custorm.HelpRes;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@ -21,6 +24,21 @@ public interface ActivityHistoryMapper {
"(#{activityId},#{userId},#{activityStatus},#{createTime},#{activityScore},#{timeScore})")
boolean insert(ActivityHistoryEntity activityHistoryEntity);
/**
* 获取志愿者列表
* @param activityStatus 活动状态
* @param activityId 活动id
* @return 返回志愿者列表
*/
List<UserWithName> queryUser(@Param("activityStatus") String activityStatus, @Param("activityId") Long activityId);
// 获取我的帮助列表数据
List<HelpRes> queryMyHelp(@Param("start") long start,@Param("count") long count,@Param("userId") String userId);
// 获取分页信息
Page<List<HelpRes>> count(@Param("userId") String userId,@Param("pageSize") Integer pageSize);
//活动评价
@Update("update activity_history set activity_score=#{score} where history_id=#{historyId}")
boolean updateScore(@Param("historyId") Long historyId,@Param("score") Integer score);
}

@ -9,6 +9,24 @@ public class ActivitySimple {
private String title;
private String content;
private String activityImg;
private Boolean hasApply;
private Boolean hasStart;
public Boolean getHasStart() {
return hasStart;
}
public void setHasStart(Boolean hasStart) {
this.hasStart = hasStart;
}
public Boolean getHasApply() {
return hasApply;
}
public void setHasApply(Boolean hasApply) {
this.hasApply = hasApply;
}
public String getUserId() {
return userId;

@ -0,0 +1,159 @@
package com.share.help.entity.custorm;
import java.sql.Timestamp;
/**
* 我的帮助列表
*/
public class HelpRes {
// 活动id
private Long activityId;
// 历史id
private Long historyId;
// 活动背景图
private String activityImg;
// 活动标题
private String title;
// 活动内容
private String content;
// 求助时间
private Timestamp seekHelpTime;
// 活动开始时间
private Timestamp activityStartTime;
// 活动结束时间
private Timestamp activityEndTime;
// 状态
private String status;
// 报名时间
private Timestamp applyTime;
// 参与时间
private Timestamp joinTime;
// 完成时间
private Timestamp completeTime;
// 评分
private Integer activityScore;
//活动开始状态
private Boolean hasStart;
//活动结束状态
private Boolean hasEnd;
public Boolean getHasEnd() {
return hasEnd;
}
public void setHasEnd(Boolean hasEnd) {
this.hasEnd = hasEnd;
}
public Long getHistoryId() {
return historyId;
}
public void setHistoryId(Long historyId) {
this.historyId = historyId;
}
public Boolean getHasStart() {
return hasStart;
}
public void setHasStart(Boolean hasStart) {
this.hasStart = hasStart;
}
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
public String getActivityImg() {
return activityImg;
}
public void setActivityImg(String activityImg) {
this.activityImg = activityImg;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Timestamp getSeekHelpTime() {
return seekHelpTime;
}
public void setSeekHelpTime(Timestamp seekHelpTime) {
this.seekHelpTime = seekHelpTime;
}
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;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Timestamp getApplyTime() {
return applyTime;
}
public void setApplyTime(Timestamp applyTime) {
this.applyTime = applyTime;
}
public Timestamp getJoinTime() {
return joinTime;
}
public void setJoinTime(Timestamp joinTime) {
this.joinTime = joinTime;
}
public Timestamp getCompleteTime() {
return completeTime;
}
public void setCompleteTime(Timestamp completeTime) {
this.completeTime = completeTime;
}
public Integer getActivityScore() {
return activityScore;
}
public void setActivityScore(Integer activityScore) {
this.activityScore = activityScore;
}
}

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 活动评价表单
*/
public class HelpScoreForm {
//历史id
private Long historyId;
//分数
private Integer score;
public Long getHistoryId() {
return historyId;
}
public void setHistoryId(Long historyId) {
this.historyId = historyId;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
}

@ -0,0 +1,26 @@
package com.share.help.form;
/**
* 我的帮助信息搜索条件
*/
public class QueryHelpForm {
private Integer currentPage;
private String userId;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}

@ -7,15 +7,9 @@ import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.LeaveWordEntity;
import com.share.help.entity.custorm.ActivitySimple;
import com.share.help.entity.custorm.FindActivityRes;
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;
import com.share.help.res.Result;
import com.share.help.res.SendHelpRes;
import com.share.help.res.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,11 +39,14 @@ public class ActivityService{
private ImageService imageService;
//活动分页配置
@Value("${activity.page-size}")
private int pageSize;
@Value("${page-size.activity.page-size}")
private int activityPageSize;
@Value("${activity.row-size}")
private int rowSize;
@Value("${page-size.activity.row-size}")
private int activityRowSize;
@Value("${page-size.help}")
private int helpPageSize;
private Logger logger = LoggerFactory.getLogger(ActivityService.class);
@ -84,12 +81,12 @@ public class ActivityService{
* @return 返回活动信息
*/
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){
FindActivityRes findActivityRes=activityMapper.count(pageSize,findActivityForm.getUserId());
findActivityRes.setPageSize(pageSize);
FindActivityRes findActivityRes=activityMapper.count(activityPageSize,findActivityForm.getUserId());
findActivityRes.setPageSize(activityPageSize);
findActivityRes.setCurrentPage(findActivityForm.getCurrentPage());
List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)*pageSize,pageSize,findActivityForm.getUserId());
List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)* activityPageSize, activityPageSize,findActivityForm.getUserId());
if(!activitySimpleList.isEmpty()){
findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList,rowSize));
findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList, activityRowSize));
return new JSONResponse<FindActivityRes.Res,FindActivityRes>(FindActivityRes.Res.ok,Result.OK).setBody(findActivityRes);
}else{
return new JSONResponse<>(FindActivityRes.Res.empty, Result.OK);
@ -165,4 +162,30 @@ public class ActivityService{
List<UserWithName> userList=activityHistoryMapper.queryUser(findUserHelp.getActivityStatus().name(),findUserHelp.getActivityId());
return new JSONResponse<DefaultRes,List<UserWithName>>(DefaultRes.ok,Result.OK).setBody(userList);
}
/**
* 查询帮助列表
* @param queryHelpForm 查询表单
* @return 返回列表
*/
public JSONResponse<DefaultRes,Page<List<HelpRes>>> queryHelp(QueryHelpForm queryHelpForm){
Page<List<HelpRes>> page=activityHistoryMapper.count(queryHelpForm.getUserId(),helpPageSize);
List<HelpRes> helpRes=activityHistoryMapper.queryMyHelp((queryHelpForm.getCurrentPage()-1)*helpPageSize,helpPageSize,queryHelpForm.getUserId());
page.setBody(helpRes);
return new JSONResponse<DefaultRes,Page<List<HelpRes>>>(DefaultRes.ok,Result.OK).setBody(page);
}
/**
* 活动评价
* @param helpScoreForm 评价表单
* @return 返回评价结果
*/
public JSONResponse<DefaultRes,Void> updateScore(HelpScoreForm helpScoreForm){
if(activityHistoryMapper.updateScore(helpScoreForm.getHistoryId(),helpScoreForm.getScore())){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -19,7 +19,7 @@ import java.util.List;
@Service
public class LeaveWordService {
@Value("${leave-word.page-size}")
@Value("${page-size.leave-word}")
private int pageSize;
@Autowired

@ -33,10 +33,10 @@ public class UserService{
private int timeScore;
//用户分页配置
@Value("${activity.page-size}")
@Value("${page-size.user.page-size}")
private int pageSize;
@Value("${activity.row-size}")
@Value("${page-size.user.row-size}")
private int rowSize;
@Autowired
@ -105,7 +105,7 @@ public class UserService{
findUserRes.setBody(Util.splitList(UserEntity.class,userEntityList,rowSize));
return new JSONResponse<FindUserRes.Res,FindUserRes>(FindUserRes.Res.ok,Result.OK).setBody(findUserRes);
}else{
return new JSONResponse<>(FindUserRes.Res.empty, Result.FAIL);
return new JSONResponse<>(FindUserRes.Res.empty, Result.OK);
}
}
@ -191,4 +191,5 @@ public class UserService{
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getUserName(),queryUserForm.getInfo());
return new JSONResponse<DefaultRes, List<UserWithName>>(DefaultRes.ok,Result.OK).setBody(userWithNameList);
}
}

@ -25,14 +25,23 @@ user:
register:
#初始时间币
time-score: 20
#活动
#分页配置
page-size:
#留言列表
leave-word: 3
#活动列表
activity:
# 分页大小
page-size: 6
# 前端一行显示数量
row-size: 3
#留言
leave-word:
#我的帮助列表
help: 3
#志愿者列表
user:
# 分页大小
page-size: 3
page-size: 6
# 前端一行显示数量
row-size: 3

@ -8,4 +8,39 @@
select user_id as userId,name from user where user_id in (select user_id from activity_history where
activity_id=#{activityId} and activity_status=#{activityStatus})
</select>
<!-- 我的帮助记录-->
<select id="queryMyHelp" resultType="com.share.help.entity.custorm.HelpRes">
select activity.activity_id as activityId,activity_img as activityImg,title,content,seek_help_time as seekHelpTime,
activity_start_time as activityStartTime,activity_end_time as activityEndTime,now()>activity_start_time as hasStart,
now()>activity_end_time as hasEnd,
if(group_concat(activity_status order by activity_status)='apply,complete,join',max(history_id),null) as historyId,
case group_concat(activity_status order by activity_status)
when 'apply' then '已报名,待参与'
when 'apply,join' then '已参与,待完成'
when 'apply,complete,join' then '已完成'
end as status
,
case group_concat(activity_status order by activity_status)
when 'apply' then group_concat(create_time)
when 'apply,join' then SUBSTRING_INDEX(group_concat(create_time order by create_time),',',1)
when 'apply,complete,join' then SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(create_time order by create_time),',',1),',',-1)
end as applyTime,
case group_concat(activity_status order by activity_status)
when 'apply,join' then SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(create_time order by create_time),',',2),',',-1)
when 'apply,complete,join' then SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(create_time order by create_time),',',2),',',-1)
end as joinTime,
if(group_concat(activity_status order by activity_status)='apply,complete,join',SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(create_time order by create_time),',',3),',',-1),null) as completeTime,
if(group_concat(activity_status order by activity_status)='apply,complete,join',max(activity_score),null) as activityScore
from activity,activity_history
where activity_history.user_id=#{userId} and activity.activity_id=activity_history.activity_id group by activity.activity_id
limit #{start},#{count}
</select>
<!-- 计算分页-->
<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
activity,activity_history where activity_history.user_id=#{userId} and activity.activity_id=activity_history.activity_id
</select>
</mapper>

@ -21,23 +21,19 @@
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="activityImg" column="activity_img"/>
<result property="hasApply" column="hasApply"/>
<result property="hasStart" column="hasStart"/>
</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"/>
select activity_id,user_id,title,content,activity_img,(activity_id in(select distinct activity_id from activity_history
where activity_history.user_id=#{userId})) as hasApply,now()>activity_start_time as hasStart from activity
limit #{start},#{count}
</select>
<select id="count" resultType="com.share.help.entity.custorm.FindActivityRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
<include refid="not_apply"/>
</select>
<resultMap id="seekHelpMap" type="com.share.help.entity.custorm.SeekHelpSum">
@ -58,9 +54,12 @@
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.user_id=#{userId} and activity.activity_id=activity_history.activity_id group by
activity_id,activity_img,seek_help_time,title,content,activity_status) a group by activity_id;
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) order by seek_help_time desc
</select>
<!-- 获取志愿者列表-->
@ -68,4 +67,6 @@
select user_id as userId,name from user where user_id in (select user_id from activity_history where
activity_id=#{activityId} and activity_status=#{activityStatus};
</select>
</mapper>

@ -175,7 +175,7 @@ class HelpApplicationTests {
// 求助信息统计
@Test
public void testSeekHelpCount(){
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp("777");
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp("123");
Assertions.assertFalse(seekHelpSums.isEmpty());
}
@ -205,4 +205,13 @@ class HelpApplicationTests {
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"222");
Assertions.assertFalse(leaveWordRes.isEmpty());
}
//查询我的帮助信息
@Test
public void queryMyhelp(){
Page<List<HelpRes>> page=activityHistoryMapper.count("123",10);
Assertions.assertNotNull(page);
List<HelpRes> list= activityHistoryMapper.queryMyHelp(0,2,"123");
Assertions.assertFalse(list.isEmpty());
}
}

@ -1,2 +1,3 @@
delete from activity_history;
delete from leave_word;
delete from activity;
delete from user;
Loading…
Cancel
Save