diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java index 40ee1e7..81606eb 100644 --- a/src/main/java/com/share/help/Constants.java +++ b/src/main/java/com/share/help/Constants.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_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"; } diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 0d8d59e..0092c01 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -101,6 +101,11 @@ public class ActivityController { } } + /** + * + * @param findUserHelp 查找活动志愿者列表 + * @return 返回志愿者列表 + */ @GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP_USER) public JSONResponse> seekHelpUser(FindUserHelp findUserHelp){ if(ObjectUtils.allNotNull(findUserHelp.getActivityId(),findUserHelp.getActivityStatus())){ diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java index 2f50de1..744af7c 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -2,20 +2,26 @@ package com.share.help.controller; import com.share.help.Constants; 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.res.DefaultRes; import com.share.help.res.JSONResponse; +import com.share.help.res.Page; import com.share.help.res.Result; 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.LeaveWordService; import com.share.help.service.UserService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * 用户接口 */ @@ -26,6 +32,9 @@ public class UserController { @Autowired private UserService userService; + @Autowired + private LeaveWordService leaveWordService; + /** * 注册 * @param userRegisterForm 注册表单 @@ -118,4 +127,35 @@ public class UserController { return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL); } } + + + + /** + * 查询用户信息 + * @param queryUserForm 搜索条件 + * @return 返回查询结果 + */ + @GetMapping(Constants.USER_INTERFACE_FIND_NAME) + public JSONResponse> 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>> 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); + } + + } } diff --git a/src/main/java/com/share/help/dao/LeaveWordMapper.java b/src/main/java/com/share/help/dao/LeaveWordMapper.java index 1efe23c..540aeee 100644 --- a/src/main/java/com/share/help/dao/LeaveWordMapper.java +++ b/src/main/java/com/share/help/dao/LeaveWordMapper.java @@ -1,14 +1,30 @@ package com.share.help.dao; 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.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * 留言信息数据接口 */ public interface LeaveWordMapper { +// 添加留言 @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); + +// 查询留言列表 + @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 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> count(@Param("pageSize") Integer pageSize,@Param("userId") String userId); } diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java index ba9d331..0ade9a9 100644 --- a/src/main/java/com/share/help/dao/UserMapper.java +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -2,6 +2,7 @@ package com.share.help.dao; import com.share.help.entity.UserEntity; import com.share.help.entity.custorm.FindUserRes; +import com.share.help.entity.custorm.UserWithName; import org.apache.ibatis.annotations.*; import java.util.List; @@ -74,13 +75,6 @@ public interface UserMapper { * @param count 查询个数 * @return 返回用户列表 */ - @Select( " " ) - @ResultMap("userMap") List getPage(@Param("start") Integer start, @Param("count") Integer count, @Param("userTypes") List userTypes,@Param("info") String info,@Param("serviceAddress") String serviceAddress); @@ -89,13 +83,11 @@ public interface UserMapper { * @param pageSize 分页大小 * @return 返回分页信息 */ - @Select( " " ) FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List userTypes,@Param("info") String info,@Param("serviceAddress") String serviceAddress); + + /** + * 查找用户 + */ + List queryUser(@Param("name") String name,@Param("info") String info); } diff --git a/src/main/java/com/share/help/entity/custorm/LeaveWordRes.java b/src/main/java/com/share/help/entity/custorm/LeaveWordRes.java new file mode 100644 index 0000000..ef4961e --- /dev/null +++ b/src/main/java/com/share/help/entity/custorm/LeaveWordRes.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/FindLeaveWordForm.java b/src/main/java/com/share/help/form/FindLeaveWordForm.java new file mode 100644 index 0000000..0745697 --- /dev/null +++ b/src/main/java/com/share/help/form/FindLeaveWordForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/QueryUserForm.java b/src/main/java/com/share/help/form/QueryUserForm.java new file mode 100644 index 0000000..6f7b0d6 --- /dev/null +++ b/src/main/java/com/share/help/form/QueryUserForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/service/LeaveWordService.java b/src/main/java/com/share/help/service/LeaveWordService.java new file mode 100644 index 0000000..e673d61 --- /dev/null +++ b/src/main/java/com/share/help/service/LeaveWordService.java @@ -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>> query(FindLeaveWordForm findLeaveWordForm){ + Page> listPage=leaveWordMapper.count(pageSize,findLeaveWordForm.getUserId()); + List 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.ok, Result.OK).setBody(listPage); + } +} diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index 22a2a34..1dbd3fa 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -4,6 +4,7 @@ import com.share.help.Util; import com.share.help.dao.UserMapper; import com.share.help.entity.UserEntity; import com.share.help.entity.custorm.FindUserRes; +import com.share.help.entity.custorm.UserWithName; import com.share.help.form.*; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; @@ -180,4 +181,14 @@ public class UserService{ return new JSONResponse<>(ModifyPwdRes.pwd_fail,Result.FAIL); } } + + /** + * 查询用户列表 + * @param queryUserForm 搜索条件 + * @return 返回查询结果 + */ + public JSONResponse> queryUser(QueryUserForm queryUserForm){ + List userWithNameList=userMapper.queryUser(queryUserForm.getUserName(),queryUserForm.getInfo()); + return new JSONResponse>(DefaultRes.ok,Result.OK).setBody(userWithNameList); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 7952791..6d3ad9e 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -31,4 +31,8 @@ activity: page-size: 6 # 前端一行显示数量 row-size: 3 +#留言 +leave-word: + # 分页大小 + page-size: 3 diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml index 2256263..12ff86e 100644 --- a/src/main/resources/mapping/UserMapper.xml +++ b/src/main/resources/mapping/UserMapper.xml @@ -13,6 +13,47 @@ + + + + + + + + update user @@ -52,4 +93,17 @@ where user_id=#{userId} + + + \ No newline at end of file diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 7d633bd..487b0b3 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -2,14 +2,13 @@ package com.share.help; import com.share.help.dao.ActivityHistoryMapper; import com.share.help.dao.ActivityMapper; +import com.share.help.dao.LeaveWordMapper; import com.share.help.dao.UserMapper; import com.share.help.entity.ActivityEntity; import com.share.help.entity.UserEntity; -import com.share.help.entity.custorm.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.entity.custorm.*; import com.share.help.form.ActivityStatus; +import com.share.help.res.Page; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,6 +50,9 @@ class HelpApplicationTests { @Autowired private ActivityHistoryMapper activityHistoryMapper; + @Autowired + private LeaveWordMapper leaveWordMapper; + private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); @BeforeEach @@ -130,6 +132,8 @@ class HelpApplicationTests { }}; FindUserRes findUserRes=userMapper.count(10,list,null,null); + Assertions.assertNotNull(findUserRes); + List userEntities=userMapper.getPage(0,10,list,null,null); Assertions.assertFalse(userEntities.isEmpty()); @@ -182,4 +186,23 @@ class HelpApplicationTests { List userWithNames=activityHistoryMapper.queryUser(ActivityStatus.join.name(),47L); Assertions.assertFalse(userWithNames.isEmpty()); } + + //查询用户列表 + @Test + public void queryUser(){ + List userWithNames =userMapper.queryUser("6",null); + Assertions.assertFalse(userWithNames.isEmpty()); + + userWithNames =userMapper.queryUser("6","2"); + Assertions.assertFalse(userWithNames.isEmpty()); + } + + //留言列表 + @Test + public void queryLeaveWord(){ + Page> listPage=leaveWordMapper.count(10,"222"); + Assertions.assertNotNull(listPage); + List leaveWordRes=leaveWordMapper.select(0,3,"222"); + Assertions.assertFalse(leaveWordRes.isEmpty()); + } }