Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
9b783d7c7a | 1 year ago |
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.provider;
|
||||
|
||||
import com.hyc.wechat.controller.constant.RequestMethod;
|
||||
import com.hyc.wechat.factory.ServiceProxyFactory;
|
||||
import com.hyc.wechat.model.dto.ServiceResult;
|
||||
import com.hyc.wechat.model.po.Moment;
|
||||
import com.hyc.wechat.provider.annotation.Action;
|
||||
import com.hyc.wechat.provider.annotation.ActionProvider;
|
||||
import com.hyc.wechat.service.MomentService;
|
||||
import com.hyc.wechat.service.impl.MomentServiceImpl;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import static com.hyc.wechat.util.BeanUtils.jsonToJavaObject;
|
||||
import static com.hyc.wechat.util.ControllerUtils.returnJsonObject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description 负责朋友圈相关流程
|
||||
* @date 2019-05-07 21:33
|
||||
*/
|
||||
@ActionProvider(path = "/moment")
|
||||
public class MomentProvider extends Provider {
|
||||
private final MomentService momentService = (MomentService) new ServiceProxyFactory().getProxyInstance(new MomentServiceImpl());
|
||||
|
||||
/**
|
||||
* 提供发布朋友圈的业务流程
|
||||
*
|
||||
* @name postMoment
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.ADD_DO)
|
||||
public void postMoment(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
Moment moment = (Moment) jsonToJavaObject(req.getInputStream(), Moment.class);
|
||||
ServiceResult result;
|
||||
result = momentService.insertMoment(moment);
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供删除朋友圈的业务流程
|
||||
*
|
||||
* @name deleteMoment
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.DELETE_DO)
|
||||
public void deleteMoment(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String momentId = req.getParameter("moment_id");
|
||||
ServiceResult result;
|
||||
result = momentService.removeMoment(new BigInteger(momentId));
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供更新朋友圈的业务流程
|
||||
*
|
||||
* @name updateMoment
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.UPDATE_DO)
|
||||
public void updateMoment(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
Moment moment = (Moment) jsonToJavaObject(req.getInputStream(), Moment.class);
|
||||
ServiceResult result;
|
||||
result = momentService.updateMoment(moment);
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供获取个人朋友圈的业务流程
|
||||
*
|
||||
* @name listMoment
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.MOMENT_DO)
|
||||
public void listMoment(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String userId = req.getParameter("user_id");
|
||||
String page = req.getParameter("page");
|
||||
ServiceResult result;
|
||||
result = momentService.listMyMoment(new BigInteger(userId), new Integer(page));
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供获取朋友圈动态的业务流程
|
||||
*
|
||||
* @name listNews
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.NEWS_DO)
|
||||
public void listNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String userId = req.getParameter("user_id");
|
||||
String page = req.getParameter("page");
|
||||
ServiceResult result;
|
||||
result = momentService.listNews(new BigInteger(userId), new Integer(page));
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提供获取朋友圈照片的业务流程
|
||||
*
|
||||
* @name loadPhoto
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/10
|
||||
*/
|
||||
@Action(method = RequestMethod.PHOTO_DO)
|
||||
public void listPhoto(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String userId = req.getParameter("user_id");
|
||||
String page = req.getParameter("page");
|
||||
ServiceResult result;
|
||||
result = momentService.listPhoto(new BigInteger(userId), new Integer(page));
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
/**
|
||||
* 提供朋友圈点赞的服务
|
||||
*
|
||||
* @name love
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/9
|
||||
*/
|
||||
@Action(method = RequestMethod.LOVE_DO)
|
||||
public void love(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String userId = req.getParameter("user_id");
|
||||
String momentId = req.getParameter("moment_id");
|
||||
ServiceResult result;
|
||||
result = momentService.love(new BigInteger(userId), new BigInteger(momentId));
|
||||
returnJsonObject(resp, result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.service;
|
||||
|
||||
import com.hyc.wechat.model.dto.ServiceResult;
|
||||
import com.hyc.wechat.model.po.Friend;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description 负责好友相关服务
|
||||
* @date 2019-05-06 05:57
|
||||
*/
|
||||
public interface FriendService {
|
||||
/**
|
||||
* 添加好友关系
|
||||
*
|
||||
* @param friend 要添加的好友关系
|
||||
* @return
|
||||
* @name addFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
ServiceResult addFriend(Friend friend);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 返回一个用户的好友列表
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
* @name listFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
ServiceResult listFriend(Object userId);
|
||||
|
||||
/**
|
||||
* 更新好友信息
|
||||
*
|
||||
* @param friend 朋友
|
||||
* @name updateFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
ServiceResult updateFriend(Friend friend);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 移除好友
|
||||
*
|
||||
* @param friend 要移除的好友关系
|
||||
* @return
|
||||
* @name removeFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
ServiceResult removeFriend(Friend friend);
|
||||
|
||||
/**
|
||||
* 判断是否存在一条这样的朋友记录
|
||||
*
|
||||
* @param friend 判断该朋友关系是否是双向的
|
||||
* @name isFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
boolean isFriend(Friend friend);
|
||||
|
||||
/**
|
||||
* 通过用户id和朋友id查询朋友关系
|
||||
*
|
||||
* @param uid 用户id
|
||||
* @param friendId 朋友id
|
||||
* @return
|
||||
* @name getByUidAndFriendId
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
Friend getByUidAndFriendId(Object uid, Object friendId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.service;
|
||||
|
||||
import com.hyc.wechat.exception.DaoException;
|
||||
import com.hyc.wechat.exception.ServiceException;
|
||||
import com.hyc.wechat.model.dto.ServiceResult;
|
||||
import com.hyc.wechat.model.po.Moment;
|
||||
import com.hyc.wechat.model.po.News;
|
||||
import com.hyc.wechat.model.po.Remark;
|
||||
import com.hyc.wechat.model.po.User;
|
||||
import com.hyc.wechat.model.vo.MomentVO;
|
||||
import com.hyc.wechat.service.constants.ServiceMessage;
|
||||
import com.hyc.wechat.service.constants.Status;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description 负责评论服务
|
||||
* @date 2019-05-14 01:14
|
||||
*/
|
||||
public interface RemarkService {
|
||||
/**添加一条评论
|
||||
* @name addRemark
|
||||
* @param remark 评论
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/14
|
||||
*/
|
||||
ServiceResult addRemark(Remark remark);
|
||||
/**
|
||||
* 查询一条朋友圈的评论
|
||||
*
|
||||
* @param momentId 朋友圈id
|
||||
* @param page 页数
|
||||
* @name listRemark
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/14
|
||||
*/
|
||||
ServiceResult listRemark(BigInteger momentId, int page);
|
||||
|
||||
/**
|
||||
* 删除一条评论
|
||||
*
|
||||
* @param remarkId 评论id
|
||||
* @name removeRemark
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/14
|
||||
*/
|
||||
ServiceResult removeRemark(BigInteger remarkId);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.service;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description 负责回复服务
|
||||
* @date 2019-05-14 01:14
|
||||
*/
|
||||
public interface ReplyService {
|
||||
}
|
||||
@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.service.impl;
|
||||
|
||||
import com.hyc.wechat.dao.ChatDao;
|
||||
import com.hyc.wechat.dao.FriendDao;
|
||||
import com.hyc.wechat.dao.MessageDao;
|
||||
import com.hyc.wechat.dao.UserDao;
|
||||
import com.hyc.wechat.exception.DaoException;
|
||||
import com.hyc.wechat.factory.DaoProxyFactory;
|
||||
import com.hyc.wechat.model.dto.ServiceResult;
|
||||
import com.hyc.wechat.model.po.Chat;
|
||||
import com.hyc.wechat.model.po.Friend;
|
||||
import com.hyc.wechat.model.po.Message;
|
||||
import com.hyc.wechat.model.po.User;
|
||||
import com.hyc.wechat.service.FriendService;
|
||||
import com.hyc.wechat.service.constants.MessageType;
|
||||
import com.hyc.wechat.service.constants.ServiceMessage;
|
||||
import com.hyc.wechat.service.constants.Status;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.hyc.wechat.service.constants.ServiceMessage.*;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description 负责提供好友相关服务
|
||||
* @date 2019-05-06 07:07
|
||||
*/
|
||||
public class FriendServiceImpl implements FriendService {
|
||||
private final FriendDao friendDao = (FriendDao) DaoProxyFactory.getInstance().getProxyInstance(FriendDao.class);
|
||||
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
|
||||
private final ChatDao chatDao = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
|
||||
private final MessageDao messageDao = (MessageDao)DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
|
||||
|
||||
/**
|
||||
* 添加好友关系
|
||||
*
|
||||
* @param friend 要添加的好友关系
|
||||
* @return
|
||||
* @name addFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
synchronized public ServiceResult addFriend(Friend friend) {
|
||||
if (friend == null) {
|
||||
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message, friend);
|
||||
}
|
||||
//检查是否是2个用户
|
||||
if (friend.getFriendId().equals(friend.getUserId())) {
|
||||
return new ServiceResult(Status.ERROR, CANNOT_ADD_YOURSELF.message, friend);
|
||||
}
|
||||
//检查是否已经是好友
|
||||
if (isFriend(friend)) {
|
||||
return new ServiceResult(Status.ERROR, ALREADY_FRIEND.message, friend);
|
||||
}
|
||||
//用于发送好友通知
|
||||
Message message = new Message();
|
||||
try {
|
||||
//检查是否添加过好友,不可重复添加
|
||||
if (friendDao.getFriendByUIDAndFriendId(friend.getUserId(), friend.getFriendId()) != null) {
|
||||
return new ServiceResult(Status.ERROR, ALREADY_ADD_FRIEND.message, friend);
|
||||
}
|
||||
//检查好友是否存在
|
||||
if (userDao.getUserById(friend.getFriendId()) == null) {
|
||||
return new ServiceResult(Status.ERROR, FRIEND_NOT_EXIST.message, friend);
|
||||
}
|
||||
//检查用户是否存在
|
||||
User user = userDao.getUserById(friend.getUserId());
|
||||
if (user == null) {
|
||||
return new ServiceResult(Status.ERROR, ACCOUNT_NOT_FOUND.message, friend);
|
||||
}
|
||||
//设置好友默认备注为好友昵称
|
||||
if (friend.getAlias() == null) {
|
||||
User friendUser = userDao.getUserById(friend.getFriendId());
|
||||
friend.setAlias(friendUser.getName());
|
||||
}
|
||||
//添加好友
|
||||
if (friendDao.insert(friend) != 1) {
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
//添加好友后如果已经双向加好友,则不用发申请,而是把之前的申请消息删除
|
||||
if(isFriend(friend)){
|
||||
//查询自己与系统建立的聊天,用于查找发送好友申请那条消息并删除
|
||||
message.setSenderId(friend.getFriendId());
|
||||
Friend systemFriend = friendDao.getFriendByUIDAndFriendId(friend.getUserId(),UserServiceImpl.systemId);
|
||||
if(systemFriend==null){
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
message.setChatId(systemFriend.getChatId());
|
||||
messageDao.delete(message);
|
||||
}else {
|
||||
//如果对方是普通用户,需要发送加好友通知
|
||||
if (!UserServiceImpl.systemId.equals(friend.getFriendId()) && !UserServiceImpl.systemId.equals(friend.getUserId())) {
|
||||
//获取好友与系统的聊天,用于推送通知
|
||||
Friend systemFriend = friendDao.getFriendByUIDAndFriendId(UserServiceImpl.systemId, friend.getFriendId());
|
||||
//生成一条加好友通知消息
|
||||
message.setChatId(systemFriend.getChatId());
|
||||
message.setSenderId(user.getId());
|
||||
message.setContent("好友申请:" + friend.getDescription());
|
||||
message.setType(MessageType.FRIEND.toString());
|
||||
message.setTime(new Timestamp(System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
return new ServiceResult(Status.SUCCESS, ADD_FRIEND_SUCCESS.message, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个用户的好友列表
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
* @name listFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
public ServiceResult listFriend(Object userId) {
|
||||
if (userId == null) {
|
||||
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message, null);
|
||||
}
|
||||
List<Friend> friendList = new LinkedList<>();
|
||||
try {
|
||||
List<Friend> list = friendDao.listByUserId(userId);
|
||||
//只返回双向添加为好友的关系
|
||||
for (Friend friend : list) {
|
||||
if (isFriend(friend)) {
|
||||
friendList.add(friend);
|
||||
}
|
||||
}
|
||||
if (friendList.size() == 0) {
|
||||
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_FRIEND_NOW.message, userId);
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, userId);
|
||||
}
|
||||
return new ServiceResult(Status.SUCCESS, null, friendList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新好友信息
|
||||
*
|
||||
* @param friend 朋友
|
||||
* @name updateFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
public ServiceResult updateFriend(Friend friend) {
|
||||
if (friend == null) {
|
||||
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message, null);
|
||||
}
|
||||
try {
|
||||
//检查成员是否存在
|
||||
if (friendDao.getFriendById(friend.getId()) == null) {
|
||||
return new ServiceResult(Status.ERROR, FRIEND_NOT_EXIST.message, friend);
|
||||
}
|
||||
if (friendDao.update(friend) != 1) {
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, friend);
|
||||
}
|
||||
return new ServiceResult(Status.SUCCESS, UPDATE_FRIEND_SUCCESS.message, friend);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除好友
|
||||
*
|
||||
* @param friend 要移除的好友关系
|
||||
* @return
|
||||
* @name removeFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
synchronized public ServiceResult removeFriend(Friend friend) {
|
||||
if (friend == null) {
|
||||
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message, friend);
|
||||
}
|
||||
|
||||
try {
|
||||
//检查成员是否存在
|
||||
if (friendDao.getFriendByUIDAndFriendId(friend.getUserId(), friend.getFriendId()) != null) {
|
||||
//将该成员从聊天中移除
|
||||
if (friendDao.delete(friend) != 1) {
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
//将对方的的朋友记录也删除
|
||||
friend = friendDao.getFriendByUIDAndFriendId(friend.getFriendId(), friend.getUserId());
|
||||
if (friendDao.delete(friend) != 1) {
|
||||
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, friend);
|
||||
}
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, friend);
|
||||
}
|
||||
return new ServiceResult(Status.SUCCESS, ServiceMessage.DELETE_FRIEND_SUCCESS.message, friend);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在一条这样的朋友记录
|
||||
*
|
||||
* @param friend 判断该朋友关系是否是双向的
|
||||
* @name isFriend
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
public boolean isFriend(Friend friend) {
|
||||
|
||||
try {
|
||||
Friend reverseFriend = friendDao.getFriendByUIDAndFriendId(friend.getFriendId(), friend.getUserId());
|
||||
friend = friendDao.getFriendByUIDAndFriendId(friend.getUserId(), friend.getFriendId());
|
||||
if (reverseFriend == null || friend == null) {
|
||||
//反向查询没有结果则是单向的
|
||||
return false;
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户id和朋友id查询朋友关系
|
||||
*
|
||||
* @param uid 用户id
|
||||
* @param friendId 朋友id
|
||||
* @return
|
||||
* @name getByUidAndFriendId
|
||||
* @notice none
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @date 2019/5/6
|
||||
*/
|
||||
@Override
|
||||
public Friend getByUidAndFriendId(Object uid, Object friendId) {
|
||||
Friend friend = null;
|
||||
try {
|
||||
friend = friendDao.getFriendByUIDAndFriendId(uid, friendId);
|
||||
} catch (DaoException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return friend;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @program wechat
|
||||
* @description 用于对用户的密码进行摘要处理
|
||||
* @date 2019-04-16 00:50
|
||||
*/
|
||||
public class Md5Utils {
|
||||
private static final String ENCODING = "UTF-8";
|
||||
|
||||
private Md5Utils() {
|
||||
}
|
||||
|
||||
public static String getDigest(String originText) {
|
||||
MessageDigest md = null;
|
||||
byte[] digest = null;
|
||||
try {
|
||||
md = MessageDigest.getInstance("md5");
|
||||
digest = md.digest(originText.getBytes(ENCODING));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("无法支持md5加密", e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("无法支持UTF-8编码格式", e);
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(digest);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2019. 黄钰朝
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hyc.wechat.dao;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
||||
* @description
|
||||
* @date 2019-05-14 01:12
|
||||
*/
|
||||
public interface ReplyDao extends BaseDao {
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue