增加接口

1.个人信息-我的留言
master
pan 5 years ago
parent 347c9e6bf3
commit b54fcbb6f3
  1. 4
      src/main/java/com/share/help/Constants.java
  2. 5
      src/main/java/com/share/help/controller/ActivityController.java
  3. 40
      src/main/java/com/share/help/controller/UserController.java
  4. 16
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  5. 20
      src/main/java/com/share/help/dao/UserMapper.java
  6. 89
      src/main/java/com/share/help/entity/custorm/LeaveWordRes.java
  7. 26
      src/main/java/com/share/help/form/FindLeaveWordForm.java
  8. 37
      src/main/java/com/share/help/form/QueryUserForm.java
  9. 44
      src/main/java/com/share/help/service/LeaveWordService.java
  10. 11
      src/main/java/com/share/help/service/UserService.java
  11. 4
      src/main/resources/application.yaml
  12. 54
      src/main/resources/mapping/UserMapper.xml
  13. 31
      src/test/java/com/share/help/HelpApplicationTests.java

@ -45,4 +45,8 @@ public class Constants {
public static final String ACTIVITY_INTERFACE_SEEK_HELP = "/seekHelp"; public static final String ACTIVITY_INTERFACE_SEEK_HELP = "/seekHelp";
//获取求助信息志愿者 //获取求助信息志愿者
public static final String ACTIVITY_INTERFACE_SEEK_HELP_USER = "/seekHelpUser"; public static final String ACTIVITY_INTERFACE_SEEK_HELP_USER = "/seekHelpUser";
//查找用户
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";
} }

@ -101,6 +101,11 @@ public class ActivityController {
} }
} }
/**
*
* @param findUserHelp 查找活动志愿者列表
* @return 返回志愿者列表
*/
@GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP_USER) @GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP_USER)
public JSONResponse<DefaultRes,List<UserWithName>> seekHelpUser(FindUserHelp findUserHelp){ public JSONResponse<DefaultRes,List<UserWithName>> seekHelpUser(FindUserHelp findUserHelp){
if(ObjectUtils.allNotNull(findUserHelp.getActivityId(),findUserHelp.getActivityStatus())){ if(ObjectUtils.allNotNull(findUserHelp.getActivityId(),findUserHelp.getActivityStatus())){

@ -2,20 +2,26 @@ 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.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.entity.custorm.UserWithName;
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.Page;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.LoginRes; import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes; import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes; import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes; import com.share.help.res.account.RegisterRes;
import com.share.help.service.LeaveWordService;
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;
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;
/** /**
* 用户接口 * 用户接口
*/ */
@ -26,6 +32,9 @@ public class UserController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private LeaveWordService leaveWordService;
/** /**
* 注册 * 注册
* @param userRegisterForm 注册表单 * @param userRegisterForm 注册表单
@ -118,4 +127,35 @@ public class UserController {
return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL); return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL);
} }
} }
/**
* 查询用户信息
* @param queryUserForm 搜索条件
* @return 返回查询结果
*/
@GetMapping(Constants.USER_INTERFACE_FIND_NAME)
public JSONResponse<DefaultRes, List<UserWithName>> queryUser(QueryUserForm queryUserForm){
if(StringUtils.isNoneEmpty(queryUserForm.getUserName(),queryUserForm.getInfo())){
return userService.queryUser(queryUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
}
}
/**
* 留言列表
* @return 返回留言列表
*/
@GetMapping(Constants.USER_INTERFACE_FIND_LEAVE_WORD)
public JSONResponse<DefaultRes, Page<List<LeaveWordRes>>> queryLeaveWord(FindLeaveWordForm findLeaveWordForm, @CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(findLeaveWordForm.getCurrentPage(),userId)) {
findLeaveWordForm.setUserId(userId);
return leaveWordService.query(findLeaveWordForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
} }

@ -1,14 +1,30 @@
package com.share.help.dao; package com.share.help.dao;
import com.share.help.entity.LeaveWordEntity; import com.share.help.entity.LeaveWordEntity;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* 留言信息数据接口 * 留言信息数据接口
*/ */
public interface LeaveWordMapper { public interface LeaveWordMapper {
// 添加留言
@Insert("insert into leave_word(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(#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})") "value(#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})")
boolean insert(LeaveWordEntity leaveWordEntity); boolean insert(LeaveWordEntity leaveWordEntity);
// 查询留言列表
@Select("select user.user_id as userId,user.name,user.head_img as headImg,user.info,leave_word.type,activity_id as activityId from leave_word,user\n" +
"where leave_word.target_user_id=#{userId} and leave_word.target_user_id=user.user_id order by create_time desc limit #{start},#{count}")
List<LeaveWordRes> select(@Param("start") long start,@Param("count") long count,@Param("userId") String userId);
// 统计留言列表分页数
@Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from leave_word where target_user_id=#{userId}")
Page<List<LeaveWordRes>> count(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
} }

@ -2,6 +2,7 @@ package com.share.help.dao;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.FindUserRes; import com.share.help.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.UserWithName;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;
@ -74,13 +75,6 @@ public interface UserMapper {
* @param count 查询个数 * @param count 查询个数
* @return 返回用户列表 * @return 返回用户列表
*/ */
@Select( " <script>select * from user " +
"<where>"+
"<if test='userTypes.size>0'>and user_type in <foreach collection='userTypes' open='(' item='userType' separator=',' close=')'> #{userType}</foreach></if>"+
"<if test='info!=null and info!=\"\"'>and info like '%${info}%'</if>"+
"<if test='serviceAddress!=null and serviceAddress!=\"\"'>and service_address = #{serviceAddress}</if>"+
"</where></script>" )
@ResultMap("userMap")
List<UserEntity> getPage(@Param("start") Integer start, @Param("count") Integer count, List<UserEntity> getPage(@Param("start") Integer start, @Param("count") Integer count,
@Param("userTypes") List<String> userTypes,@Param("info") String info,@Param("serviceAddress") String serviceAddress); @Param("userTypes") List<String> userTypes,@Param("info") String info,@Param("serviceAddress") String serviceAddress);
@ -89,13 +83,11 @@ public interface UserMapper {
* @param pageSize 分页大小 * @param pageSize 分页大小
* @return 返回分页信息 * @return 返回分页信息
*/ */
@Select( " <script>" +
"select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from user" +
"<where>"+
"<if test='userTypes.size>0'>and user_type in <foreach collection='userTypes' open='(' item='userType' separator=',' close=')'> #{userType}</foreach></if>"+
"<if test='info!=null and info!=\"\"'>and info like '%${info}%'</if>"+
"<if test='serviceAddress!=null and serviceAddress!=\"\"'>and service_address = #{serviceAddress}</if>"+
"</where></script>" )
FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List<String> userTypes,@Param("info") FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List<String> userTypes,@Param("info")
String info,@Param("serviceAddress") String serviceAddress); String info,@Param("serviceAddress") String serviceAddress);
/**
* 查找用户
*/
List<UserWithName> queryUser(@Param("name") String name,@Param("info") String info);
} }

@ -0,0 +1,89 @@
package com.share.help.entity.custorm;
import com.share.help.form.LeaveWordType;
/**
* 留言列表
*/
public class LeaveWordRes {
// 留言用户id
private String userId;
// 留言用户姓名
private String name;
// 留言用户头像
private String headImg;
// 留言类型
private LeaveWordType type;
// 活动id
private Long activityId;
// 留言用户简介
private String info;
//活动标题
private String title;
//活动内容
private String content;
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 String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
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;
}
public String getHeadImg() {
return headImg;
}
public void setHeadImg(String headImg) {
this.headImg = headImg;
}
public LeaveWordType getType() {
return type;
}
public void setType(LeaveWordType type) {
this.type = type;
}
}

@ -0,0 +1,26 @@
package com.share.help.form;
/**
* 查找留言表单
*/
public class FindLeaveWordForm {
private Integer currentPage;
private String userId;
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;
}
}

@ -0,0 +1,37 @@
package com.share.help.form;
/**
* 查找用户
*/
public class QueryUserForm {
//用户id
private String userId;
//用户名
private String userName;
//简介信息
private String info;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}

@ -0,0 +1,44 @@
package com.share.help.service;
import com.share.help.dao.ActivityMapper;
import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.form.FindLeaveWordForm;
import com.share.help.form.LeaveWordType;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Page;
import com.share.help.res.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LeaveWordService {
@Value("${leave-word.page-size}")
private int pageSize;
@Autowired
private LeaveWordMapper leaveWordMapper;
@Autowired
private ActivityMapper activityMapper;
public JSONResponse<DefaultRes, Page<List<LeaveWordRes>>> query(FindLeaveWordForm findLeaveWordForm){
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(pageSize,findLeaveWordForm.getUserId());
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select((findLeaveWordForm.getCurrentPage()-1)*pageSize,pageSize,findLeaveWordForm.getUserId());
for(LeaveWordRes wordRes:leaveWordRes){
if(LeaveWordType.friend!=wordRes.getType()&&wordRes.getActivityId()!=null){
ActivityEntity activityEntity=activityMapper.findOne(wordRes.getActivityId());
wordRes.setTitle(activityEntity.getTitle());
wordRes.setContent(activityEntity.getContent());
}
}
listPage.setBody(leaveWordRes);
return new JSONResponse<DefaultRes,Page<List<LeaveWordRes>>>(DefaultRes.ok, Result.OK).setBody(listPage);
}
}

@ -4,6 +4,7 @@ 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.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.UserWithName;
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;
@ -180,4 +181,14 @@ public class UserService{
return new JSONResponse<>(ModifyPwdRes.pwd_fail,Result.FAIL); return new JSONResponse<>(ModifyPwdRes.pwd_fail,Result.FAIL);
} }
} }
/**
* 查询用户列表
* @param queryUserForm 搜索条件
* @return 返回查询结果
*/
public JSONResponse<DefaultRes, List<UserWithName>> queryUser(QueryUserForm queryUserForm){
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getUserName(),queryUserForm.getInfo());
return new JSONResponse<DefaultRes, List<UserWithName>>(DefaultRes.ok,Result.OK).setBody(userWithNameList);
}
} }

@ -31,4 +31,8 @@ activity:
page-size: 6 page-size: 6
# 前端一行显示数量 # 前端一行显示数量
row-size: 3 row-size: 3
#留言
leave-word:
# 分页大小
page-size: 3

@ -13,6 +13,47 @@
<result property="chatStatus" column="chat_status"/> <result property="chatStatus" column="chat_status"/>
</resultMap> </resultMap>
<!-- 统计用户分页数-->
<select id="count" resultType="com.share.help.entity.custorm.FindUserRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from user
<where>
<if test='userTypes.size>0'>
and user_type in
<foreach collection='userTypes' open='(' item='userType' separator=',' close=')'>
#{userType}
</foreach>
</if>
<if test="info!=null and info!=''">
and info like '%${info}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address = #{serviceAddress}
</if>
</where>
</select>
<!-- 分页查询-->
<select id="getPage" resultMap="userMap">
select * from user
<where>
<if test='userTypes.size>0'>
user_type in
<foreach collection='userTypes' open='(' item='userType' separator=',' close=')'>
#{userType}
</foreach>
</if>
<if test="info!=null and info!=''">
and info like '%${info}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address = #{serviceAddress}
</if>
</where>
limit #{start},#{count}
</select>
<!-- 更新用户-->
<update id="update"> <update id="update">
update user update user
<set> <set>
@ -52,4 +93,17 @@
</set> </set>
where user_id=#{userId} where user_id=#{userId}
</update> </update>
<!-- 查找用户-->
<select id="queryUser" resultType="com.share.help.entity.custorm.UserWithName">
select user_id as userId,name from user
<where>
<if test="name!=null and name!=''">
name like '%${name}%'
</if>
<if test="info!=null and info!=''">
and info like '%${info}%'
</if>
</where>
</select>
</mapper> </mapper>

@ -2,14 +2,13 @@ package com.share.help;
import com.share.help.dao.ActivityHistoryMapper; import com.share.help.dao.ActivityHistoryMapper;
import com.share.help.dao.ActivityMapper; import com.share.help.dao.ActivityMapper;
import com.share.help.dao.LeaveWordMapper;
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.entity.custorm.ActivitySimple; import com.share.help.entity.custorm.*;
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 com.share.help.form.ActivityStatus;
import com.share.help.res.Page;
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;
@ -51,6 +50,9 @@ class HelpApplicationTests {
@Autowired @Autowired
private ActivityHistoryMapper activityHistoryMapper; private ActivityHistoryMapper activityHistoryMapper;
@Autowired
private LeaveWordMapper leaveWordMapper;
private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class);
@BeforeEach @BeforeEach
@ -130,6 +132,8 @@ class HelpApplicationTests {
}}; }};
FindUserRes findUserRes=userMapper.count(10,list,null,null); FindUserRes findUserRes=userMapper.count(10,list,null,null);
Assertions.assertNotNull(findUserRes);
List<UserEntity> userEntities=userMapper.getPage(0,10,list,null,null); List<UserEntity> userEntities=userMapper.getPage(0,10,list,null,null);
Assertions.assertFalse(userEntities.isEmpty()); Assertions.assertFalse(userEntities.isEmpty());
@ -182,4 +186,23 @@ class HelpApplicationTests {
List<UserWithName> userWithNames=activityHistoryMapper.queryUser(ActivityStatus.join.name(),47L); List<UserWithName> userWithNames=activityHistoryMapper.queryUser(ActivityStatus.join.name(),47L);
Assertions.assertFalse(userWithNames.isEmpty()); Assertions.assertFalse(userWithNames.isEmpty());
} }
//查询用户列表
@Test
public void queryUser(){
List<UserWithName> userWithNames =userMapper.queryUser("6",null);
Assertions.assertFalse(userWithNames.isEmpty());
userWithNames =userMapper.queryUser("6","2");
Assertions.assertFalse(userWithNames.isEmpty());
}
//留言列表
@Test
public void queryLeaveWord(){
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(10,"222");
Assertions.assertNotNull(listPage);
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"222");
Assertions.assertFalse(leaveWordRes.isEmpty());
}
} }

Loading…
Cancel
Save