增加同意、拒绝好友邀请接口

master
pan 5 years ago
parent b38510b1db
commit 0a00898ce0
  1. 6
      src/main/java/com/share/help/Constants.java
  2. 37
      src/main/java/com/share/help/controller/UserController.java
  3. 13
      src/main/java/com/share/help/dao/FriendMapper.java
  4. 11
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  5. 10
      src/main/java/com/share/help/entity/custorm/LeaveWordRes.java
  6. 1
      src/main/java/com/share/help/form/ActivityStatus.java
  7. 34
      src/main/java/com/share/help/form/AgreeFriendForm.java
  8. 8
      src/main/java/com/share/help/form/NotActivityStatus.java
  9. 27
      src/main/java/com/share/help/form/SendFriendForm.java
  10. 2
      src/main/java/com/share/help/service/ActivityService.java
  11. 66
      src/main/java/com/share/help/service/LeaveWordService.java

@ -53,4 +53,10 @@ public class Constants {
public static final String ACTIVITY_INTERFACE_HELP = "/help";
//修改分数
public static final String ACTIVITY_INTERFACE_SCORE = "/score";
//发送好友邀请
public static final String USER_INTERFACE_SEND_FRIEND = "/friend";
//拒绝好友邀请
public static final String USER_INTERFACE_REFUSE_FRIEND = "/refuse/{id}";
//同意好友邀请
public static final String USER_INTERFACE_AGREE_FRIEND = "/agree";
}

@ -159,4 +159,41 @@ public class UserController {
}
/**
*发送好友邀请
*/
@PostMapping(Constants.USER_INTERFACE_SEND_FRIEND)
public JSONResponse<DefaultRes,Void> sendFriend(SendFriendForm sendFriendForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(sendFriendForm.getTargetUserId(),userId)){
sendFriendForm.setSourceUserId(userId);
return leaveWordService.sendFriend(sendFriendForm);
}else {
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 拒绝好友邀请
* @param id 留言id
* @return 返回拒绝结果
*/
@PostMapping(Constants.USER_INTERFACE_REFUSE_FRIEND)
public JSONResponse<DefaultRes,Void> refuseFriend(@PathVariable Long id){
if(id!=null){
return leaveWordService.refuseFriend(id);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
@PostMapping(Constants.USER_INTERFACE_AGREE_FRIEND)
public JSONResponse<DefaultRes,Void> agreeFriend(AgreeFriendForm agreeFriendForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(agreeFriendForm.getSourceUserId(),userId,agreeFriendForm.getLeaveWordId())){
agreeFriendForm.setTargetUserId(userId);
return leaveWordService.agreeFriend(agreeFriendForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -0,0 +1,13 @@
package com.share.help.dao;
import com.share.help.entity.FriendEntity;
import org.apache.ibatis.annotations.Insert;
/**
* 添加好友
*/
public interface FriendMapper {
@Insert("insert into friend(source_user_id,target_user_id) value(#{sourceUserId},#{targetUserId})")
boolean addFriend(FriendEntity friendEntity);
}

@ -3,6 +3,7 @@ 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.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -20,11 +21,19 @@ public interface LeaveWordMapper {
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" +
@Select("select leave_word.source_user_id as userId,user.name,user.head_img as headImg,user.info,leave_word.type,activity_id as activityId,leave_word_id as leaveWordId 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);
/**
* 删除留言
* @param leaveWordId 留言id
* @return 返回删除结果
*/
@Delete("delete from leave_word where leave_word_id=#{leaveWordId}")
boolean deleteOne(@Param("leaveWordId") Long leaveWordId);
}

@ -8,6 +8,8 @@ import com.share.help.form.LeaveWordType;
public class LeaveWordRes {
// 留言用户id
private String userId;
// 留言id
private Long leaveWordId;
// 留言用户姓名
private String name;
// 留言用户头像
@ -23,6 +25,14 @@ public class LeaveWordRes {
//活动内容
private String content;
public Long getLeaveWordId() {
return leaveWordId;
}
public void setLeaveWordId(Long leaveWordId) {
this.leaveWordId = leaveWordId;
}
public String getTitle() {
return title;
}

@ -11,3 +11,4 @@ public enum ActivityStatus {
// 完成
complete
}

@ -0,0 +1,34 @@
package com.share.help.form;
/**
* 同意好友邀请表单
*/
public class AgreeFriendForm {
private Long leaveWordId;
private String sourceUserId;
private String targetUserId;
public Long getLeaveWordId() {
return leaveWordId;
}
public void setLeaveWordId(Long leaveWordId) {
this.leaveWordId = leaveWordId;
}
public String getSourceUserId() {
return sourceUserId;
}
public void setSourceUserId(String sourceUserId) {
this.sourceUserId = sourceUserId;
}
public String getTargetUserId() {
return targetUserId;
}
public void setTargetUserId(String targetUserId) {
this.targetUserId = targetUserId;
}
}

@ -0,0 +1,8 @@
package com.share.help.form;
public enum NotActivityStatus {
//推荐
recommend,
//好友
friend
}

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 发送好友邀请表单
*/
public class SendFriendForm {
//发送邀请用户
private String sourceUserId;
//添加用户
private String targetUserId;
public String getSourceUserId() {
return sourceUserId;
}
public void setSourceUserId(String sourceUserId) {
this.sourceUserId = sourceUserId;
}
public String getTargetUserId() {
return targetUserId;
}
public void setTargetUserId(String targetUserId) {
this.targetUserId = targetUserId;
}
}

@ -127,7 +127,7 @@ public class ActivityService{
// 给求助用户发送留言
LeaveWordEntity leaveWordEntity=new LeaveWordEntity();
leaveWordEntity.setType(activityForm.getActivityStatus().toString());
leaveWordEntity.setType(activityForm.getActivityStatus().name());
leaveWordEntity.setSourceUserId(activityForm.getUserId());
ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId());
if(activity==null){

@ -1,19 +1,24 @@
package com.share.help.service;
import com.share.help.dao.ActivityMapper;
import com.share.help.dao.FriendMapper;
import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.FriendEntity;
import com.share.help.entity.LeaveWordEntity;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.form.FindLeaveWordForm;
import com.share.help.form.LeaveWordType;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.List;
@Service
@ -28,6 +33,11 @@ public class LeaveWordService {
@Autowired
private ActivityMapper activityMapper;
@Autowired
private FriendMapper friendMapper;
private Logger logger= LoggerFactory.getLogger(LeaveWordService.class);
/**
* 查询留言
* @param findLeaveWordForm 查询条件
@ -46,4 +56,56 @@ public class LeaveWordService {
listPage.setBody(leaveWordRes);
return new JSONResponse<DefaultRes,Page<List<LeaveWordRes>>>(DefaultRes.ok, Result.OK).setBody(listPage);
}
/**
* 发送好友邀请
* @param sendFriendForm 邀请表单
* @return 返回发送结果
*/
public JSONResponse<DefaultRes,Void> sendFriend(SendFriendForm sendFriendForm){
LeaveWordEntity leaveWordEntity=new LeaveWordEntity();
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
leaveWordEntity.setSourceUserId(sendFriendForm.getSourceUserId());
leaveWordEntity.setTargetUserId(sendFriendForm.getTargetUserId());
leaveWordEntity.setType(NotActivityStatus.friend.name());
if(leaveWordMapper.insert(leaveWordEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 拒绝好友邀请
* @param id 留言id
* @return 返回拒绝结果
*/
public JSONResponse<DefaultRes,Void> refuseFriend(Long id){
if(leaveWordMapper.deleteOne(id)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 同意好友邀请
* @param agreeFriendForm 邀请表单
* @return 返回邀请结果
*/
public JSONResponse<DefaultRes, Void> agreeFriend(AgreeFriendForm agreeFriendForm) {
if(!leaveWordMapper.deleteOne(agreeFriendForm.getLeaveWordId())){
logger.error("删除留言失败");
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
FriendEntity friendEntity=new FriendEntity();
friendEntity.setSourceUserId(agreeFriendForm.getSourceUserId());
friendEntity.setTargetUserId(agreeFriendForm.getTargetUserId());
if(friendMapper.addFriend(friendEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

Loading…
Cancel
Save