增加接口

1.个人信息-我的求助
master
pan 5 years ago
parent 59194d7e76
commit 347c9e6bf3
  1. 4
      src/main/java/com/share/help/Constants.java
  2. 29
      src/main/java/com/share/help/controller/ActivityController.java
  3. 6
      src/main/java/com/share/help/controller/UserController.java
  4. 5
      src/main/java/com/share/help/dao/ActivityHistoryMapper.java
  5. 8
      src/main/java/com/share/help/dao/ActivityMapper.java
  6. 2
      src/main/java/com/share/help/dao/UserMapper.java
  7. 2
      src/main/java/com/share/help/entity/custorm/ActivitySimple.java
  8. 2
      src/main/java/com/share/help/entity/custorm/FindActivityRes.java
  9. 2
      src/main/java/com/share/help/entity/custorm/FindUserRes.java
  10. 89
      src/main/java/com/share/help/entity/custorm/SeekHelpSum.java
  11. 23
      src/main/java/com/share/help/entity/custorm/UserWithName.java
  12. 1
      src/main/java/com/share/help/form/ApplyActivityForm.java
  13. 26
      src/main/java/com/share/help/form/FindUserHelp.java
  14. 29
      src/main/java/com/share/help/service/ActivityService.java
  15. 6
      src/main/java/com/share/help/service/UserService.java
  16. 11
      src/main/resources/mapping/ActivityHistoryMapper.xml
  17. 33
      src/main/resources/mapping/ActivityMapper.xml
  18. 28
      src/test/java/com/share/help/HelpApplicationTests.java

@ -41,4 +41,8 @@ public class Constants {
public static final String USER_INTERFACE_UPDATE = "/update"; public static final String USER_INTERFACE_UPDATE = "/update";
//更新密码接口 //更新密码接口
public static final String USER_INTERFACE_PWD = "/updatePwd"; public static final String USER_INTERFACE_PWD = "/updatePwd";
//求助信息统计
public static final String ACTIVITY_INTERFACE_SEEK_HELP = "/seekHelp";
//获取求助信息志愿者
public static final String ACTIVITY_INTERFACE_SEEK_HELP_USER = "/seekHelpUser";
} }

@ -2,20 +2,25 @@ package com.share.help.controller;
import com.share.help.Constants; import com.share.help.Constants;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
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.form.ApplyActivityForm; import com.share.help.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm; import com.share.help.form.FindActivityForm;
import com.share.help.form.FindUserHelp;
import com.share.help.form.SendHelpForm; import com.share.help.form.SendHelpForm;
import com.share.help.res.DefaultRes; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.FindActivityRes;
import com.share.help.service.ActivityService; import com.share.help.service.ActivityService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@RequestMapping(Constants.ACTIVITY_INTERFACE) @RequestMapping(Constants.ACTIVITY_INTERFACE)
public class ActivityController { public class ActivityController {
@ -82,4 +87,26 @@ public class ActivityController {
return new JSONResponse<>(DefaultRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
} }
/**
* 统计求助信息数据
* @return 返回统计结果
*/
@GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP)
public JSONResponse<DefaultRes, List<SeekHelpSum>> seekHelp(@CookieValue(Constants.USER_COOKIE) String userId){
if(userId==null){
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{
return activityService.seekHelpCount(userId);
}
}
@GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP_USER)
public JSONResponse<DefaultRes,List<UserWithName>> seekHelpUser(FindUserHelp findUserHelp){
if(ObjectUtils.allNotNull(findUserHelp.getActivityId(),findUserHelp.getActivityStatus())){
return activityService.seekHelpList(findUserHelp);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
} }

@ -1,11 +1,15 @@
package com.share.help.controller; package com.share.help.controller;
import com.share.help.Constants; import com.share.help.Constants;
import com.share.help.entity.custorm.FindUserRes;
import com.share.help.form.*; import com.share.help.form.*;
import com.share.help.res.DefaultRes; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.*; import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes;
import com.share.help.service.UserService; import com.share.help.service.UserService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

@ -1,7 +1,11 @@
package com.share.help.dao; package com.share.help.dao;
import com.share.help.entity.ActivityHistoryEntity; import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.custorm.UserWithName;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 活动历史记录 * 活动历史记录
@ -18,4 +22,5 @@ public interface ActivityHistoryMapper {
boolean insert(ActivityHistoryEntity activityHistoryEntity); boolean insert(ActivityHistoryEntity activityHistoryEntity);
List<UserWithName> queryUser(@Param("activityStatus") String activityStatus, @Param("activityId") Long activityId);
} }

@ -1,8 +1,9 @@
package com.share.help.dao; package com.share.help.dao;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
import com.share.help.res.activity.ActivitySimple; import com.share.help.entity.custorm.ActivitySimple;
import com.share.help.res.activity.FindActivityRes; import com.share.help.entity.custorm.FindActivityRes;
import com.share.help.entity.custorm.SeekHelpSum;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;
@ -52,4 +53,7 @@ public interface ActivityMapper {
* @return 返回分页信息 * @return 返回分页信息
*/ */
FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId); FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
//求助信息
List<SeekHelpSum> seekHelp(@Param("userId") String userId);
} }

@ -1,7 +1,7 @@
package com.share.help.dao; package com.share.help.dao;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.res.account.FindUserRes; import com.share.help.entity.custorm.FindUserRes;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;

@ -1,4 +1,4 @@
package com.share.help.res.activity; package com.share.help.entity.custorm;
/** /**
* 活动列表实体 * 活动列表实体

@ -1,4 +1,4 @@
package com.share.help.res.activity; package com.share.help.entity.custorm;
import com.share.help.res.Page; import com.share.help.res.Page;

@ -1,4 +1,4 @@
package com.share.help.res.account; package com.share.help.entity.custorm;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.res.Page; import com.share.help.res.Page;

@ -0,0 +1,89 @@
package com.share.help.entity.custorm;
import java.sql.Timestamp;
/**
* 统计用户求助信息
*/
public class SeekHelpSum {
//活动id
private Long activityId;
//活动背景图
private String activityImg;
//求助时间
private Timestamp seekHelpTime;
//活动标题
private String title;
//活动内容
private String content;
//报名人数
private Integer apply;
//参与人数
private Integer join;
//完成人数
private Integer complete;
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 Timestamp getSeekHelpTime() {
return seekHelpTime;
}
public void setSeekHelpTime(Timestamp seekHelpTime) {
this.seekHelpTime = seekHelpTime;
}
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 Integer getApply() {
return apply;
}
public void setApply(Integer apply) {
this.apply = apply;
}
public Integer getJoin() {
return join;
}
public void setJoin(Integer join) {
this.join = join;
}
public Integer getComplete() {
return complete;
}
public void setComplete(Integer complete) {
this.complete = complete;
}
}

@ -0,0 +1,23 @@
package com.share.help.entity.custorm;
public class UserWithName {
private String userId;
private String name;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

@ -5,6 +5,5 @@ package com.share.help.form;
*/ */
public class ApplyActivityForm extends UpdateActivityForm{ public class ApplyActivityForm extends UpdateActivityForm{
} }

@ -0,0 +1,26 @@
package com.share.help.form;
/**
* 获取志愿者列表信息
*/
public class FindUserHelp {
private Long activityId;
private ActivityStatus activityStatus;
public ActivityStatus getActivityStatus() {
return activityStatus;
}
public void setActivityStatus(ActivityStatus activityStatus) {
this.activityStatus = activityStatus;
}
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
}

@ -7,16 +7,15 @@ import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
import com.share.help.entity.ActivityHistoryEntity; import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.LeaveWordEntity; import com.share.help.entity.LeaveWordEntity;
import com.share.help.form.ApplyActivityForm; import com.share.help.entity.custorm.ActivitySimple;
import com.share.help.form.FindActivityForm; import com.share.help.entity.custorm.FindActivityRes;
import com.share.help.form.LeaveWordType; import com.share.help.entity.custorm.SeekHelpSum;
import com.share.help.form.SendHelpForm; import com.share.help.entity.custorm.UserWithName;
import com.share.help.form.*;
import com.share.help.res.DefaultRes; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.ActivitySimple;
import com.share.help.res.activity.FindActivityRes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -148,4 +147,22 @@ public class ActivityService{
return new JSONResponse<>(DefaultRes.ok,Result.OK); return new JSONResponse<>(DefaultRes.ok,Result.OK);
} }
/**
* 求助信息统计
* @return 返回统计结果
*/
public JSONResponse<DefaultRes,List<SeekHelpSum>> seekHelpCount(String userId){
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp(userId);
return new JSONResponse<DefaultRes,List<SeekHelpSum>>(DefaultRes.ok,Result.OK).setBody(seekHelpSums);
}
/**
* 求助信息志愿者列表
* @param findUserHelp 查询条件
* @return 返回搜索结果
*/
public JSONResponse<DefaultRes,List<UserWithName>> seekHelpList(FindUserHelp findUserHelp){
List<UserWithName> userList=activityHistoryMapper.queryUser(findUserHelp.getActivityStatus().name(),findUserHelp.getActivityId());
return new JSONResponse<DefaultRes,List<UserWithName>>(DefaultRes.ok,Result.OK).setBody(userList);
}
} }

@ -3,11 +3,15 @@ package com.share.help.service;
import com.share.help.Util; import com.share.help.Util;
import com.share.help.dao.UserMapper; import com.share.help.dao.UserMapper;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.FindUserRes;
import com.share.help.form.*; import com.share.help.form.*;
import com.share.help.res.DefaultRes; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.*; import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.share.help.dao.ActivityHistoryMapper">
<!-- 获取志愿者列表-->
<select id="queryUser" resultType="com.share.help.entity.custorm.UserWithName">
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>

@ -15,7 +15,7 @@
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
</resultMap> </resultMap>
<resultMap id="activitySimpleMap" type="com.share.help.res.activity.ActivitySimple"> <resultMap id="activitySimpleMap" type="com.share.help.entity.custorm.ActivitySimple">
<id property="activityId" column="activity_id"/> <id property="activityId" column="activity_id"/>
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="title" column="title"/> <result property="title" column="title"/>
@ -35,8 +35,37 @@
limit #{start},#{count} limit #{start},#{count}
</select> </select>
<select id="count" resultType="com.share.help.res.activity.FindActivityRes"> <select id="count" resultType="com.share.help.entity.custorm.FindActivityRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
<include refid="not_apply"/> <include refid="not_apply"/>
</select> </select>
<resultMap id="seekHelpMap" type="com.share.help.entity.custorm.SeekHelpSum">
<id property="activityId" column="activity_id"/>
<result property="activityImg" column="activity_img"/>
<result property="seekHelpTime" column="seek_help_time"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="apply" column="apply"/>
<result property="join" column="join"/>
<result property="complete" column="complete"/>
</resultMap>
<!-- 查询用户的求助信息-->
<select id="seekHelp" resultMap="seekHelpMap">
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.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>
<!-- 获取志愿者列表-->
<select id="queryUser" resultType="com.share.help.entity.custorm.UserWithName">
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> </mapper>

@ -1,11 +1,15 @@
package com.share.help; package com.share.help;
import com.share.help.dao.ActivityHistoryMapper;
import com.share.help.dao.ActivityMapper; import com.share.help.dao.ActivityMapper;
import com.share.help.dao.UserMapper; 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.entity.custorm.ActivitySimple;
import com.share.help.res.activity.ActivitySimple; import com.share.help.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.SeekHelpSum;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.form.ActivityStatus;
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;
@ -44,6 +48,9 @@ class HelpApplicationTests {
@Autowired @Autowired
private ActivityMapper activityMapper; private ActivityMapper activityMapper;
@Autowired
private ActivityHistoryMapper activityHistoryMapper;
private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class);
@BeforeEach @BeforeEach
@ -153,11 +160,26 @@ class HelpApplicationTests {
@Test @Test
public void testAddActivity(){ public void testAddActivity(){
ActivityEntity activityEntity=activityMapper.findOne(25L); ActivityEntity activityEntity=activityMapper.findOne(46L);
activityEntity.setActivityId(null); activityEntity.setActivityId(null);
activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis()));
activityMapper.insert(activityEntity); activityMapper.insert(activityEntity);
} }
// 求助信息统计
@Test
public void testSeekHelpCount(){
List<SeekHelpSum> seekHelpSums=activityMapper.seekHelp("777");
Assertions.assertFalse(seekHelpSums.isEmpty());
}
//求助信息用户
@Test
public void testSeekHelpUser(){
List<UserWithName> userWithNames=activityHistoryMapper.queryUser(ActivityStatus.join.name(),47L);
Assertions.assertFalse(userWithNames.isEmpty());
}
} }

Loading…
Cancel
Save