Compare commits

..

1 Commits

@ -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,113 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-03 13:01
*/
@Table(name = "message") // 指定该实体类对应的数据库表名为"message"
public class Message extends BaseEntity {
// 发送者的ID
@JSONField(name = "sender_id")
private BigInteger senderId;
// 聊天室的ID
@JSONField(name = "chat_id")
private BigInteger chatId;
// 消息内容
private String content;
// 消息类型(如文本、图片、视频等)
private String type;
// 消息发送的时间
private Timestamp time;
/**
*
* @return
*/
public String getType() {
return type;
}
/**
*
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
*
* @return
*/
public Timestamp getTime() {
return time;
}
/**
*
* @param time
*/
public void setTime(Timestamp time) {
this.time = time;
}
/**
* ID
* @return ID
*/
public BigInteger getSenderId() {
return senderId;
}
/**
* ID
* @param senderId ID
*/
public void setSenderId(BigInteger senderId) {
this.senderId = senderId;
}
/**
* ID
* @return ID
*/
public BigInteger getChatId() {
return chatId;
}
/**
* ID
* @param chatId ID
*/
public void setChatId(BigInteger chatId) {
this.chatId = chatId;
}
/**
*
* @return
*/
public String getContent() {
return content;
}
/**
*
* @param content
*/
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,188 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 11:36
*/
@Table(name = "moment") // 指定该实体类对应的数据库表名为"moment"
public class Moment extends BaseEntity {
// 朋友圈所有者的用户ID
@JSONField(name = "owner_id")
private BigInteger ownerId;
// 朋友圈的内容文本
private String content;
// 朋友圈的照片URL
private String photo;
// 朋友圈发布的时间
private Timestamp time;
// 朋友圈获得点赞的数量
private Long love;
// 朋友圈的评论数量
private Long remark;
// 朋友圈被分享的次数
private Long share;
// 朋友圈被查看的次数
private Long view;
// 朋友圈被收藏的次数
private Long collect;
/**
*
* @return
*/
public Timestamp getTime() {
return time;
}
/**
*
* @param time
*/
public void setTime(Timestamp time) {
this.time = time;
}
/**
* URL
* @return URL
*/
public String getPhoto() {
return photo;
}
/**
* URL
* @param photo URL
*/
public void setPhoto(String photo) {
this.photo = photo;
}
/**
* ID
* @return ID
*/
public BigInteger getOwnerId() {
return ownerId;
}
/**
* ID
* @param ownerId ID
*/
public void setOwnerId(BigInteger ownerId) {
this.ownerId = ownerId;
}
/**
*
* @return
*/
public String getContent() {
return content;
}
/**
*
* @param content
*/
public void setContent(String content) {
this.content = content;
}
/**
*
* @return
*/
public Long getLove() {
return love;
}
/**
*
* @param love
*/
public void setLove(Long love) {
this.love = love;
}
/**
*
* @return
*/
public Long getRemark() {
return remark;
}
/**
*
* @param remark
*/
public void setRemark(Long remark) {
this.remark = remark;
}
/**
*
* @return
*/
public Long getShare() {
return share;
}
/**
*
* @param share
*/
public void setShare(Long share) {
this.share = share;
}
/**
*
* @return
*/
public Long getView() {
return view;
}
/**
*
* @param view
*/
public void setView(Long view) {
this.view = view;
}
/**
*
* @return
*/
public Long getCollect() {
return collect;
}
/**
*
* @param collect
*/
public void setCollect(Long collect) {
this.collect = collect;
}
}

@ -0,0 +1,131 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 18:44
*/
@Table(name = "news") // 指定该实体类对应的数据库表名为"news"
public class News extends BaseEntity {
// 用户ID表示进行互动的用户
@JSONField(name = "user_id")
private BigInteger userId;
// 动态ID表示互动的特定朋友圈动态
@JSONField(name = "moment_Id")
private BigInteger momentId;
// 表示用户是否对该动态点赞
private Boolean loved;
// 表示用户是否分享该动态
private Boolean shared;
// 表示用户是否查看该动态
private Boolean viewed;
// 表示用户是否收藏该动态
private Boolean collected;
/**
* ID
* @return ID
*/
public BigInteger getUserId() {
return userId;
}
/**
* ID
* @param userId ID
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* ID
* @return ID
*/
public BigInteger getMomentId() {
return momentId;
}
/**
* ID
* @param momentId ID
*/
public void setMomentId(BigInteger momentId) {
this.momentId = momentId;
}
/**
*
* @return truefalse
*/
public Boolean getLoved() {
return loved;
}
/**
*
* @param loved truefalse
*/
public void setLoved(Boolean loved) {
this.loved = loved;
}
/**
*
* @return truefalse
*/
public Boolean getShared() {
return shared;
}
/**
*
* @param shared truefalse
*/
public void setShared(Boolean shared) {
this.shared = shared;
}
/**
*
* @return truefalse
*/
public Boolean getViewed() {
return viewed;
}
/**
*
* @param viewed truefalse
*/
public void setViewed(Boolean viewed) {
this.viewed = viewed;
}
/**
*
* @return truefalse
*/
public Boolean getCollected() {
return collected;
}
/**
*
* @param collected truefalse
*/
public void setCollected(Boolean collected) {
this.collected = collected;
}
}

@ -0,0 +1,53 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.JSONObject;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-06 21:29
*/
@Table(name = "record") // 指定该实体类对应的数据库表名为"record"
public class Record extends BaseEntity {
// 用户ID表示消息记录对应的用户
private BigInteger userId;
// 消息ID表示特定的消息记录
private BigInteger messageId;
/**
* ID
* @return ID
*/
public BigInteger getUserId() {
return userId;
}
/**
* ID
* @param userId ID
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* ID
* @return ID
*/
public BigInteger getMessageId() {
return messageId;
}
/**
* ID
* @param messageId ID
*/
public void setMessageId(BigInteger messageId) {
this.messageId = messageId;
}
}

@ -0,0 +1,150 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @description
*/
@Table(name = "remark") // 指定该实体类对应的数据库表名为"remark"
public class Remark extends BaseEntity {
// 用户ID表示评论者
@JSONField(name = "user_id") // 指定JSON序列化时的字段名
private BigInteger userId;
// 朋友圈ID表示评论所属的朋友圈
@JSONField(name = "moment_id") // 指定JSON序列化时的字段名
private BigInteger momentId;
// 评论内容
private String content;
// 评论时间
private Timestamp time;
// 点赞数
private Long love;
// 收藏数
private Long collect;
// 回复数
private Long reply;
/**
*
* @return
*/
public Timestamp getTime() {
return time;
}
/**
*
* @param time
*/
public void setTime(Timestamp time) {
this.time = time;
}
/**
* ID
* @return ID
*/
public BigInteger getUserId() {
return userId;
}
/**
* ID
* @param userId ID
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* ID
* @return ID
*/
public BigInteger getMomentId() {
return momentId;
}
/**
* ID
* @param momentId ID
*/
public void setMomentId(BigInteger momentId) {
this.momentId = momentId;
}
/**
*
* @return
*/
public String getContent() {
return content;
}
/**
*
* @param content
*/
public void setContent(String content) {
this.content = content;
}
/**
*
* @return
*/
public Long getLove() {
return love;
}
/**
*
* @param love
*/
public void setLove(Long love) {
this.love = love;
}
/**
*
* @return
*/
public Long getCollect() {
return collect;
}
/**
*
* @param collect
*/
public void setCollect(Long collect) {
this.collect = collect;
}
/**
*
* @return
*/
public Long getReply() {
return reply;
}
/**
*
* @param reply
*/
public void setReply(Long reply) {
this.reply = reply;
}
}

@ -0,0 +1,151 @@
package com.hyc.wechat.model.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @description
*/
@Table(name = "reply") // 指定该实体类对应的数据库表名为"reply"
public class Reply extends BaseEntity {
// 回复者的用户ID
@JSONField(name = "user_id") // 指定JSON序列化时的字段名
private BigInteger userId;
// 被回复的用户ID
@JSONField(name = "to_uid") // 指定JSON序列化时的字段名
private BigInteger toUid;
// 所属评论的ID
@JSONField(name = "remark_id") // 指定JSON序列化时的字段名
private BigInteger remarkId;
// 回复时间
private Timestamp time;
// 回复内容
private String content;
// 回复的点赞数
private long love;
// 回复的收藏数
private long collect;
/**
*
* @return
*/
public Timestamp getTime() {
return time;
}
/**
*
* @param time
*/
public void setTime(Timestamp time) {
this.time = time;
}
/**
* ID
* @return ID
*/
public BigInteger getUserId() {
return userId;
}
/**
* ID
* @param userId ID
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* ID
* @return ID
*/
public BigInteger getToUid() {
return toUid;
}
/**
* ID
* @param toUid ID
*/
public void setToUid(BigInteger toUid) {
this.toUid = toUid;
}
/**
* ID
* @return ID
*/
public BigInteger getRemarkId() {
return remarkId;
}
/**
* ID
* @param remarkId ID
*/
public void setRemarkId(BigInteger remarkId) {
this.remarkId = remarkId;
}
/**
*
* @return
*/
public String getContent() {
return content;
}
/**
*
* @param content
*/
public void setContent(String content) {
this.content = content;
}
/**
*
* @return
*/
public long getLove() {
return love;
}
/**
*
* @param love
*/
public void setLove(long love) {
this.love = love;
}
/**
*
* @return
*/
public long getCollect() {
return collect;
}
/**
*
* @param collect
*/
public void setCollect(long collect) {
this.collect = collect;
}
}

@ -0,0 +1,172 @@
package com.hyc.wechat.model.po;
import com.hyc.wechat.dao.annotation.Field;
import com.hyc.wechat.dao.annotation.Table;
import com.hyc.wechat.model.po.abs.BaseEntity;
/**
*
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 23:27
*/
@Table(name = "user") // 指定该实体类对应的数据库表名为"user"
public class User extends BaseEntity {
/**
*
*/
@Field(name = "email")
private String email;
/**
* ID
*/
@Field(name = "wechat_id")
private String wechatId;
/**
*
*/
@Field(name = "phone")
private String phone;
/**
*
*/
@Field(name = "password")
private String password;
/**
*
*/
@Field(name = "gender")
private String gender;
/**
*
*/
@Field(name = "signature")
private String signature;
/**
*
*/
@Field(name = "name")
private String name;
/**
* URL
*/
@Field(name = "photo")
private String photo;
/**
* URL
*/
@Field(name = "chat_background")
private String chatBackground;
/**
*
*/
@Field(name = "location")
private String location;
/**
* 线
*/
@Field(name = "online_status")
private String onlineStatus;
// 以下是属性的getter和setter方法
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWechatId() {
return wechatId;
}
public void setWechatId(String wechatId) {
this.wechatId = wechatId;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getChatBackground() {
return chatBackground;
}
public void setChatBackground(String chatBackground) {
this.chatBackground = chatBackground;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getOnlineStatus() {
return onlineStatus;
}
public void setOnlineStatus(String onlineStatus) {
this.onlineStatus = onlineStatus;
}
}

@ -0,0 +1,219 @@
/*
* 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.Chat;
import com.hyc.wechat.model.po.Member;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.server.ChatServer;
import com.hyc.wechat.service.ChatService;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.constants.Status;
import com.hyc.wechat.service.impl.ChatServiceImpl;
import com.hyc.wechat.service.impl.MessageServiceImpl;
import com.hyc.wechat.util.BeanUtils;
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-03 15:04
*/
@ActionProvider(path = "/chat")
public class ChatProvider extends Provider {
private final ChatService chatService = (ChatService) new ServiceProxyFactory().getProxyInstance(new ChatServiceImpl());
private final MessageService messageService = (MessageService) new ServiceProxyFactory().getProxyInstance(new MessageServiceImpl());
/**
*
*
* @param req
* @param resp
* @throws ServletException Servlet
* @throws IOException IO
* @name createGroupChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.ADD_DO)
public void createGroupChat(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 从请求中解析出Chat对象
Chat chat = (Chat) jsonToJavaObject(req.getInputStream(), Chat.class);
ServiceResult result;
// 调用服务创建群聊
result = chatService.createChat(chat, true);
if (Status.ERROR.equals(result.getStatus())) {
// 如果创建失败,返回错误信息
returnJsonObject(resp, result);
return;
}
// 从服务中获取创建后的Chat对象
chat = (Chat) result.getData();
// 创建Member对象用于将创建者加入群聊
Member member = new Member();
member.setUserId(chat.getOwnerId());
member.setChatId(chat.getId());
// 调用服务将创建者加入群聊
result = chatService.joinChat(new Member[]{member});
if (Status.ERROR.equals(result.getStatus())) {
// 如果加入失败,返回错误信息
returnJsonObject(resp, result);
return;
}
// 如果创建群聊和加入群聊都成功,返回成功信息,并包含群号
result.setMessage(ServiceMessage.CREATE_GROUP_CHAT_SUCCESS.message + chat.getNumber() + ServiceMessage.PLEASE_JOIN_CHAT.message);
returnJsonObject(resp, result);
}
}
/**
*
*
* @name joinChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.JOIN_DO)
public void joinGroupChat(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String number = req.getParameter("number");
String userId = req.getParameter("user_id");
String apply = req.getParameter("apply");
ServiceResult result;
result = chatService.joinChatByNumber(new BigInteger(userId), number, apply);
if (Status.ERROR.equals(result.getStatus())) {
returnJsonObject(resp, result);
return;
}
//加群成功后通知群里所有在线用户
Member member = (Member) result.getData();
//生成打招呼消息
Message message = chatService.getHelloMessage(member);
messageService.insertMessage(message);
ChatServer.addMember(member, message);
returnJsonObject(resp, result);
}
/**
* 退
*
* @name quitChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.QUIT_DO)
public void quitChat(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Member member = (Member) jsonToJavaObject(req.getInputStream(), Member.class);
ServiceResult result;
result = chatService.quitChat(member);
returnJsonObject(resp, result);
}
/**
*
*
* @name remove
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Action(method = RequestMethod.REMOVE_DO)
public void remove(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String memberId = req.getParameter("member_id");
ServiceResult result;
//检查操作用户
User user = (User) req.getSession().getAttribute("login");
if (chatService.isOwner(new BigInteger(memberId), user.getId())) {
result = chatService.removeFromChat(new BigInteger(memberId));
}else{
result = new ServiceResult(Status.ERROR,ServiceMessage.NOT_OWNER.message,null);
}
returnJsonObject(resp, result);
}
/**
*
*
* @name listChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LIST_DO)
public void listChat(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
User user = (User) BeanUtils.toObject(req.getParameterMap(), User.class);
ServiceResult result;
result = chatService.listChat(user);
returnJsonObject(resp, result);
}
/**
*
*
* @name getChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.GET_DO)
public void getChat(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String number = req.getParameter("number");
String userId = req.getParameter("user_id");
ServiceResult result;
result = chatService.getChat(number, new BigInteger(userId));
returnJsonObject(resp, result);
}
/**
*
*
* @name listMember
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
@Action(method = RequestMethod.MEMBER_DO)
public void listMember(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String chatId = req.getParameter("chat_id");
ServiceResult result;
result = chatService.listMember(new BigInteger(chatId));
returnJsonObject(resp, result);
}
}

@ -0,0 +1,181 @@
/*
* 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.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.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.server.ChatServer;
import com.hyc.wechat.service.ChatService;
import com.hyc.wechat.service.FriendService;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.MomentService;
import com.hyc.wechat.service.constants.MessageType;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.impl.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigInteger;
import java.sql.Timestamp;
import static com.hyc.wechat.service.constants.ServiceMessage.CANNOT_DELETE_HYC;
import static com.hyc.wechat.service.constants.Status.ERROR;
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-06 07:11
*/
@ActionProvider(path = "/friend")
public class FriendProvider extends Provider {
private final FriendService friendService = (FriendService) new ServiceProxyFactory().getProxyInstance(new FriendServiceImpl());
private final ChatService chatService = (ChatService) new ServiceProxyFactory().getProxyInstance(new ChatServiceImpl());
private final MessageService messageService = (MessageService) new ServiceProxyFactory().getProxyInstance(new MessageServiceImpl());
private final MomentService momentService = (MomentService)new ServiceProxyFactory().getProxyInstance(new MomentServiceImpl());
/**
*
*
* @name addFriend
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.ADD_DO)
synchronized public void addFriend(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Friend friend = (Friend) jsonToJavaObject(req.getInputStream(), Friend.class);
ServiceResult result;
// //已经是好友不可重复添加
// if (friendService.isFriend(friend)) {
// result = new ServiceResult(Status.ERROR, ALREADY_ADD_FRIEND.message, friend);
// returnJsonObject(resp, result);
// return;
// }
//加好友
result = friendService.addFriend(friend);
if (ERROR.equals(result.getStatus())) {
returnJsonObject(resp, result);
return;
}
//添加好友后判断是否对方也将自己添加为好友,如果双向添加,则建立聊天关系,否则发送好友通知
if (friendService.isFriend(friend)) {
Chat chat = (Chat) chatService.createFriendChat(friend).getData();
//发送打招呼消息
Message message = new Message();
message.setChatId(chat.getId());
message.setSenderId(friend.getUserId());
message.setContent(ServiceMessage.AGREE_FRIEND.message);
message.setTime(new Timestamp(System.currentTimeMillis()));
message.setType(MessageType.USER.toString());
messageService.insertMessage(message);
//初始化朋友圈
momentService.initNews(friend);
} else {
//生成的加好友通知,发送实时通知并存到数据库
Message message = (Message) result.getData();
ChatServer.sendNotify(message, friend.getFriendId());
messageService.insertMessage(message);
}
returnJsonObject(resp, result);
}
/**
*
*
* @name listFriend
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LIST_DO)
public void listFriend(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
ServiceResult result;
result = friendService.listFriend(new BigInteger(userId));
returnJsonObject(resp, result);
}
/**
*
*
* @name listFriend
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.UPDATE_DO)
public void updateFriend(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Friend friend = (Friend) jsonToJavaObject(req.getInputStream(), Friend.class);
ServiceResult result;
result = friendService.updateFriend(friend);
returnJsonObject(resp, result);
}
/**
*
*
* @name deleteFriend
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.DELETE_DO)
synchronized public void deleteFriend(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String friendId = req.getParameter("friend_id");
String userId = req.getParameter("user_id");
ServiceResult result;
//系统账号不可删除
//删除好友之前将聊天关系移除,请求中的好友对象只含有userId和friendId所以需要重新获取
Friend friend = friendService.getByUidAndFriendId(new BigInteger(userId), new BigInteger(friendId));
if (friend == null) {
result = new ServiceResult();
result.setMessage(ServiceMessage.FRIEND_NOT_EXIST.message);
result.setStatus(ERROR);
returnJsonObject(resp, result);
return;
}
if (UserServiceImpl.systemId.equals(friend.getFriendId())) {
returnJsonObject(resp, new ServiceResult(ERROR, ServiceMessage.CANNOT_DELETE_SYSTEM.message, null));
return;
}
if (UserServiceImpl.hycId.equals(friend.getFriendId())) {
returnJsonObject(resp, new ServiceResult(ERROR, CANNOT_DELETE_HYC.message, null));
return;
}
//调用聊天服务将聊天关系解除
Chat chat = new Chat();
chat.setId(friend.getChatId());
chatService.removeChat(chat);
//解除好友关系
result = friendService.removeFriend(friend);
returnJsonObject(resp, result);
}
}

@ -0,0 +1,142 @@
/*
* 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.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.impl.MessageServiceImpl;
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.ControllerUtils.returnJsonObject;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-08 02:32
*/
@ActionProvider(path = "/message")
public class MessageProvider extends Provider {
private final MessageService messageService = (MessageService) new ServiceProxyFactory().getProxyInstance(new MessageServiceImpl());
/**
*
*
* @name listMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LIST_DO)
public void listMessage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
String chatId = req.getParameter("chat_id");
String page = req.getParameter("page");
ServiceResult result = null;
result = messageService.listAllMessage(new BigInteger(userId), new BigInteger(chatId), new Integer(page));
returnJsonObject(resp, result);
}
/**
*
*
* @name listUnreadMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.UNREAD_DO)
public void listUnreadMessage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
String page = req.getParameter("page");
String chatId = req.getParameter("chat_id");
ServiceResult result;
//如果没有写chatId则加载所有未读消息
if (chatId == null) {
result = messageService.listAllUnreadMessage(new BigInteger(userId), new Integer(page));
} else {
result = messageService.listUnreadMessage(new BigInteger(userId), new BigInteger(chatId), new Integer(page));
}
returnJsonObject(resp, result);
}
/**
*
*
* @name read
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.READ_DO)
public void read(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
String chatId = req.getParameter("chat_id");
ServiceResult result = new ServiceResult();
result.setMessage(ServiceMessage.ALREADY_READ.message);
messageService.setAlreadyRead(new BigInteger(userId), new BigInteger(chatId));
returnJsonObject(resp, result);
}
/**
*
*
* @name clear
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.CLEAR_DO)
public void clear(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
String chatId = req.getParameter("chat_id");
ServiceResult result;
result = messageService.removeAllMessage(new BigInteger(userId), new BigInteger(chatId));
returnJsonObject(resp, result);
}
/**
*
*
* @name export
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.EXPORT_DO)
public void export(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userId = req.getParameter("user_id");
String chatId = req.getParameter("chat_id");
ServiceResult result;
result = messageService.exportMessage(new BigInteger(userId), new BigInteger(chatId));
returnJsonObject(resp, result);
}
}

@ -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,134 @@
/*
* 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.controller.constant.WebPage;
import com.hyc.wechat.exception.ServiceException;
import com.hyc.wechat.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.util.ControllerUtils;
import org.apache.log4j.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import static com.hyc.wechat.controller.constant.ControllerMessage.REQUEST_INVALID;
import static com.hyc.wechat.controller.constant.ControllerMessage.SYSTEM_EXECEPTION;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description ActionProviderdoAction
* @date 2019-05-02 11:39
*/
public class Provider {
/**
* Action
*
* @param req
* @param resp
* @name doAction
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
public void doAction(HttpServletRequest req, HttpServletResponse resp) {
//获取请求中的method参数转换成对应的枚举类型
try {
RequestMethod requestMethod = ControllerUtils.valueOf(req.getParameter("method"));
if (RequestMethod.INVALID_REQUEST.equals(requestMethod)) {
toErrorPage("无效的访问链接,系统无法识别您的请求指向的服务内容:" + req.getRequestURI(), req, resp);
return;
} else {
boolean isMacth =false;
//根据方法上的注解找到对应的Action方法并执行
Method[] methods = this.getClass().getMethods();
for (Method m : methods) {
Action action = m.getAnnotation(Action.class);
if (action != null && action.method().equals(requestMethod)) {
try {
m.invoke(this, req, resp);
isMacth=true;
} catch (ServiceException e) {
//服务层抛出的异常信息与用户的操作有关,不包含底层细节,可以向用户输出
e.printStackTrace();
toErrorPage(e.getMessage(), req, resp);
return;
}
}
}
if(!isMacth){
Logger logger = Logger.getLogger(Provider.class);
logger.error("请求的方法没有对应的action方法");
toErrorPage("无效的访问链接,系统无法识别您的请求指向的服务内容"+ req.getRequestURI(), req, resp);
}
}
} catch (ExceptionInInitializerError e) {
e.printStackTrace();
Logger logger = Logger.getLogger(Provider.class);
logger.error(e.getStackTrace());
//此处的异常包含细节信息,对客户端隐藏
toErrorPage(SYSTEM_EXECEPTION.message, req, resp);
} catch (Exception e) {
e.printStackTrace();
Logger logger = Logger.getLogger(Provider.class);
logger.debug(e.getStackTrace());
//此处的异常包含细节信息,对客户端隐藏
toErrorPage(REQUEST_INVALID.message, req, resp);
}
}
/**
*
*
* @param message
* @name toErrorPage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
public static void toErrorPage(String message, HttpServletRequest req, HttpServletResponse resp) {
req.setAttribute("message", message);
try {
req.getRequestDispatcher(WebPage.ERROR_JSP.toString()).forward(req, resp);
} catch (ServletException | IOException e) {
e.printStackTrace();
try {
resp.getWriter().write("服务器异常");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* Providerurl
*
* @name getPath
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
public String getPath() {
return this.getClass().getAnnotation(ActionProvider.class).path();
}
}

@ -0,0 +1,112 @@
/*
* 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.model.po.Remark;
import com.hyc.wechat.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.service.RemarkService;
import com.hyc.wechat.service.impl.RemarkServiceImpl;
import com.sun.org.apache.bcel.internal.generic.BIPUSH;
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-14 01:38
*/
@ActionProvider(path = "/remark")
public class RemarkProvider extends Provider {
// 注入评论服务层的代理实例
RemarkService remarkService = (RemarkService) new ServiceProxyFactory().getProxyInstance(new RemarkServiceImpl());
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws ServletException Servlet
* @throws IOException IO
* @name postRemark
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Action(method = RequestMethod.ADD_DO)
public void postRemark(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 将请求体中的JSON转换为Remark对象
Remark remark = (Remark) jsonToJavaObject(req.getInputStream(), Remark.class);
ServiceResult result;
// 调用服务层添加评论
result = remarkService.addRemark(remark);
// 将结果以JSON格式返回给客户端
returnJsonObject(resp, result);
}
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws ServletException Servlet
* @throws IOException IO
* @name listRemark
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Action(method = RequestMethod.LIST_DO)
public void listRemark(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 从请求参数中获取朋友圈ID和页码
String momentId = req.getParameter("moment_id");
String page = req.getParameter("page");
ServiceResult result;
// 调用服务层获取评论列表
result = remarkService.listRemark(new BigInteger(momentId), Integer.parseInt(page));
// 将结果以JSON格式返回给客户端
returnJsonObject(resp, result);
}
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws IOException IO
* @name deleteRemark
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Action(method = RequestMethod.DELETE_DO)
public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// 从请求参数中获取评论ID
String remarkId = req.getParameter("remark_id");
ServiceResult

@ -0,0 +1,113 @@
/*
* 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.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.service.UploadService;
import com.hyc.wechat.service.impl.UploadServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import static com.hyc.wechat.util.ControllerUtils.returnJsonObject;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-06 02:38
*/
@ActionProvider(path = "/upload")
public class UploadProvider extends Provider {
// 注入上传服务层的代理实例
private final UploadService uploadService = (UploadService) new ServiceProxyFactory().getProxyInstance(new UploadServiceImpl());
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws IOException IO
* @throws ServletException Servlet
* @name uploadPhoto
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019-05-06
*/
@Action(method = RequestMethod.UPLOADPHOTO_DO)
public void uploadPhoto(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// 从请求中获取照片部分
Part part = req.getPart("photo");
// 从请求中获取关联ID
Object id = req.getParameter("id");
// 从请求中获取表名
String tableName = req.getParameter("table");
ServiceResult result;
// 调用服务层上传照片
result = uploadService.uploadPhoto(part, id, tableName);
// 将结果以JSON格式返回给客户端
returnJsonObject(resp, result);
}
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws IOException IO
* @throws ServletException Servlet
* @name uploadBackground
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019-05-06
*/
@Action(method = RequestMethod.BACKGROUND_DO)
public void uploadBackground(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// 从请求中获取照片部分
Part part = req.getPart("photo");
// 从请求中获取关联ID
Object id = req.getParameter("id");
ServiceResult result;
// 调用服务层上传背景图片
result = uploadService.uploadBackground(part, id);
// 将结果以JSON格式返回给客户端
returnJsonObject(resp, result);
}
/**
*
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @throws IOException IO
* @throws ServletException Servlet
* @name uploadfile
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019-05-06
*/
@Action(method = RequestMethod.UPLOADFILE_DO)
public void uploadfile(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// 从请求中获取文件部分
Part part = req.getPart("file");
ServiceResult result;
// 调用服务层上传文件
result = uploadService.uploadFile(part);
// 将结果以JSON格式

@ -0,0 +1,404 @@
/*
* 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.controller.constant.WebPage;
import com.hyc.wechat.factory.ServiceProxyFactory;
import com.hyc.wechat.model.dto.ServiceResult;
import com.hyc.wechat.model.po.Friend;
import com.hyc.wechat.model.po.Member;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.provider.annotation.Action;
import com.hyc.wechat.provider.annotation.ActionProvider;
import com.hyc.wechat.service.ChatService;
import com.hyc.wechat.service.FriendService;
import com.hyc.wechat.service.MomentService;
import com.hyc.wechat.service.UserService;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.constants.Status;
import com.hyc.wechat.service.impl.ChatServiceImpl;
import com.hyc.wechat.service.impl.FriendServiceImpl;
import com.hyc.wechat.service.impl.MomentServiceImpl;
import com.hyc.wechat.service.impl.UserServiceImpl;
import com.hyc.wechat.util.BeanUtils;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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>
* @program wechat
* @description
* @date 2019-05-02 10:07
*/
@ActionProvider(path = "/user")
public class UserProvider extends Provider {
private final int AUTO_LOGIN_AGE = 60 * 60 * 24 *30;
private final String AUTO_LOGIN_PATH = "/";
private final UserService userService = (UserService) new ServiceProxyFactory().getProxyInstance(new UserServiceImpl());
private final ChatService chatService = (ChatService) new ServiceProxyFactory().getProxyInstance(new ChatServiceImpl());
private final FriendService friendService = (FriendService) new ServiceProxyFactory().getProxyInstance(new FriendServiceImpl());
private final MomentService momentService = (MomentService)new ServiceProxyFactory().getProxyInstance(new MomentServiceImpl());
/**
*
*
* @name register
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.REGISTER_DO)
public void register(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
User user = (User) BeanUtils.toObject(req.getParameterMap(), User.class);
ServiceResult result;
//检查用户注册信息
result = userService.checkRegister(user);
if (Status.ERROR.equals(result.getStatus())) {
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.REGISTER_JSP.toString()).forward(req,resp);
return;
}
//插入用户
result = userService.insertUser(user);
if (Status.ERROR.equals(result.getStatus())) {
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.REGISTER_JSP.toString()).forward(req,resp);
} else {
//注册成功后将用户添加到聊天总群中
user = (User) result.getData();
addToDefaultChat(user);
//与系统账号加好友
addToSystemChat(user);
//加hyc
addToHYCChat(user);
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req,resp);
}
}
/**
*
*
* @name login
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LOGIN_DO)
public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
User user = (User) BeanUtils.toObject(req.getParameterMap(), User.class);
ServiceResult result;
if (user == null) {
result = new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req,resp);
return;
}
HttpSession session = req.getSession(false);
//检查用户是否已经建立会话并且已经具有登陆信息
if (session == null || session.getAttribute("login") == null) {
//检查是不是游客登陆,游客登陆的话先创建个游客账号然后登陆
if ("visitor".equals(user.getEmail())) {
result = userService.visitorLogin();
if (Status.ERROR.equals(result.getStatus())) {
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req,resp);
return;
}
User visitor = (User) result.getData();
//把游客加入聊天总群
addToDefaultChat(visitor);
//与系统账号加好友
addToSystemChat(visitor);
//添加hyc
// addToHYCChat(visitor);
} else {
//如果是用户登陆,校验密码是否正确
result = userService.checkPassword(user);
if (Status.ERROR.equals(result.getStatus())) {
req.setAttribute("message",result.getMessage());
req.setAttribute("data",result.getData());
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req,resp);
return;
} else {
//校验密码成功时,给会话中添加用户信息
result = userService.getUser(user.getId());
user = (User) result.getData();
//如果设置自动登陆则添加cookie
if (req.getParameter("auto_login")!=null) {
setAutoLoginCookie(resp,req, String.valueOf(user.getId()));
}
}
}
} else {
//先从session获取用户信息再更新用户信息到会话中
user = (User) session.getAttribute("login");
result = userService.getUser(user.getId());
}
req.getSession(true).setAttribute("login", result.getData());
req.getRequestDispatcher(WebPage.INDEX_JSP.toString()).forward(req,resp);
}
/**
*
*
* @name get
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.GET_DO)
public void get(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
User user = (User) BeanUtils.toObject(req.getParameterMap(), User.class);
ServiceResult result;
//获取用户数据
result = userService.getUser(user.getId());
if (Status.ERROR.equals(result.getStatus())) {
returnJsonObject(resp, result);
} else {
//获取数据成功时的处理
resp.getWriter().write(result.getMessage());
}
}
/**
*
*
* @name logout
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LOGOUT_DO)
public void logout(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession();
if (session != null) {
session.invalidate();
}
returnJsonObject(resp, new ServiceResult(Status.SUCCESS, ServiceMessage.LOGOUT_SUCCESS.message, null));
}
/**
*
*
* @name update
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.UPDATE_DO)
public void update(HttpServletRequest req, HttpServletResponse resp) throws IOException {
User user = (User) jsonToJavaObject(req.getInputStream(), User.class);
ServiceResult result;
if (user != null && user.getWechatId() != null) {
User oldUser = (User) userService.getUser(user.getId()).getData();
if (!oldUser.getWechatId().equals(user.getWechatId())) {
//如果请求要求修改微信名,先检查用户名(微信号)是否合法
result = userService.checkWechatId(user.getWechatId());
if (Status.ERROR.equals(result.getStatus())) {
returnJsonObject(resp, result);
return;
}
}
}
//更新用户数据
result = userService.updateUser(user);
returnJsonObject(resp, result);
}
/**
*
*
* @name updatePwd
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.UPDATEPASSWORD_DO)
public void updatePwd(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String oldPwd = req.getParameter("old_password");
String newPwd = req.getParameter("new_password");
String userId = req.getParameter("user_id");
ServiceResult result;
//更新用户数据
result = userService.updatePwd(oldPwd, newPwd, new BigInteger(userId));
returnJsonObject(resp, result);
}
/**
*
*
* @name list
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Action(method = RequestMethod.LIST_DO)
public void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
User user = (User) BeanUtils.toObject(req.getParameterMap(), User.class);
ServiceResult result;
result = userService.listUserLikeName(user.getName());
if (Status.ERROR.equals(result.getStatus())) {
returnJsonObject(resp, result);
return;
}
returnJsonObject(resp, result);
}
/**
*
*
* @name list
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
public void autoLogin(HttpServletRequest req) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if ("user_id".equalsIgnoreCase(cookie.getName())) {
ServiceResult result = userService.getUser(cookie.getValue());
if (Status.SUCCESS.equals(result.getStatus())) {
// addToDefaultChat((User) result.getData());
//如果获取用户信息成功则设置login属性
HttpSession session = req.getSession();
session.setAttribute("login", result.getData());
return;
}
}
}
}
}
/**
* cookie
*
* @param userId id
* @name setAutoLoginCookie
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
private void setAutoLoginCookie(HttpServletResponse resp,HttpServletRequest req, String userId) {
Cookie cookie = new Cookie("user_id", userId);
cookie.setMaxAge(AUTO_LOGIN_AGE);
cookie.setPath(req.getContextPath());
resp.addCookie(cookie);
}
/**
* (id=0)
*
* @param user
* @name addToDefaultChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
private void addToDefaultChat(User user) {
Member member = new Member();
member.setChatId(BigInteger.valueOf(0));
member.setUserId(user.getId());
chatService.joinChat(new Member[]{member});
}
/**
*
*
* @param user
* @name addToSystemChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
private void addToSystemChat(User user) {
Friend friend = new Friend();
//系统添加用户账号为好友
friend.setUserId(UserServiceImpl.systemId);
friend.setFriendId(user.getId());
friendService.addFriend(friend);
//用户添加系统账号为好友
friend.setAlias(null);
friend.setUserId(user.getId());
friend.setFriendId(UserServiceImpl.systemId);
friendService.addFriend(friend);
//将用户和系统账号id=0添加到同一个聊天中
chatService.createFriendChat(friend);
//插入一条消息
Message message = new Message();
message.setContent("欢迎使用wechat在线聊天系统我是本系统的开发者如果程序在使用的过程中发现一些问题请刷新一下浏览器如果问题依然没有解决可以发邮件向我反馈。" +
"开发者信息\n" +
"开发者:黄钰朝\n" +
"联系邮箱:<a href=\"mailto:kobe524348@gmail.com\">kobe524348@gmail.com</a>\n" +
"项目启动时间2019-05-01\n" +
"版本号1.0\n" +
"发布时间2019-05-15\n" +
"开源许可:<a href=\"http://www.apache.org/licenses/LICENSE-2.0\">Apache License 2.0 Copyright 黄钰朝</a></pre>");
}
/**
*
*
* @param user
* @name addToHYCChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
private void addToHYCChat(User user) {
Friend friend = new Friend();
//hyc添加用户账号为好友
friend.setUserId(BigInteger.valueOf(1));
friend.setFriendId(user.getId());
friendService.addFriend(friend);
friend.setAlias(null);
//用户添加hyc账号为好友
friend.setUserId(user.getId());
friend.setFriendId(BigInteger.valueOf(1));
friendService.addFriend(friend);
//将用户和hyc账号id=1添加到同一个聊天中
chatService.createFriendChat(friend);
//初始朋友圈
momentService.initNews(friend);
}
}

@ -0,0 +1,44 @@
/*
* 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.annotation;
import com.hyc.wechat.controller.constant.RequestMethod;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description 访HTTP
* @date 2019-05-02 09:42
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Action {
/**
* 访
* @return
*/
String path() default "";
/**
* 访HTTP
* @return RequestMethodHTTP
*/
RequestMethod method();
}

@ -0,0 +1,36 @@
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description ActionProviderURL
* @date 2019-05-02 11:28
*/
@Documented
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.TYPE)
public @interface ActionProvider {
/**
* ActionProviderURL
* @return
*/
String path() default "";
}

@ -0,0 +1,334 @@
/*
* 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.server;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hyc.wechat.dao.*;
import com.hyc.wechat.factory.DaoProxyFactory;
import com.hyc.wechat.factory.ServiceProxyFactory;
import com.hyc.wechat.model.builder.MessageVOBuilder;
import com.hyc.wechat.model.po.Chat;
import com.hyc.wechat.model.po.Member;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.model.vo.MessageVO;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.impl.MessageServiceImpl;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.*;
import static com.hyc.wechat.service.constants.MessageType.FILE;
import static com.hyc.wechat.service.constants.MessageType.IMG;
import static com.hyc.wechat.util.StringUtils.toLegalText;
import static com.hyc.wechat.util.StringUtils.toLegalTextIgnoreTag;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-04 00:28
*/
@ServerEndpoint("/server/chat/{user}")
public class ChatServer {
/*
**************************************************************
*
**************************************************************
*/
private static final MessageService MESSAGE_SERVICE = (MessageService) new ServiceProxyFactory().getProxyInstance(new MessageServiceImpl());
private static final UserDao USER_DAO = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
private static final ChatDao CHAT_DAO = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
private static final MessageDao MESSAGE_DAO = (MessageDao) DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
private static final MemberDao MEMBER_DAO = (MemberDao) DaoProxyFactory.getInstance().getProxyInstance(MemberDao.class);
private static final RecordDao RECORD_DAO = (RecordDao) DaoProxyFactory.getInstance().getProxyInstance(RecordDao.class);
/**
* 线server
*/
private static final ConcurrentHashMap<String, ChatServer> SERVER_MAP = new ConcurrentHashMap<>();
/**
*
*/
private static final ScheduledExecutorService SERVICE = new ScheduledThreadPoolExecutor(10);
/**
* 线
*/
private static int onlineCount = 0;
private final String ALREADY_ONLINE = "您已经在一个新的浏览器上登陆,系统将自动断开与本页面的连接,页面将不可用";
/**
* ()
*/
private final Long SAVE_PERIOD_SECOND = 1L;
/**
*
*/
private final Long INIT_DELAY = 0L;
/*
**************************************************************
*
**************************************************************
*/
private Session session;
private User user;
/**
* onOpen
*/
private Map<BigInteger, Member> memberMap = new HashMap<>();
/**
*
*/
private MessageTask messageTask = new MessageTask();
@OnOpen
public void onOpen(Session session, @PathParam("user") String userId) throws IOException {
//检查是否已经建立过连接
ChatServer server = SERVER_MAP.get(userId);
if (server != null && server.session != null && server.session.isOpen()) {
server.session.getBasicRemote().sendText(ALREADY_ONLINE);
server.session.close();
}
server = new ChatServer();
//装载用户数据,作为缓存
server.session = session;
server.user = USER_DAO.getUserById(userId);
if (server.user == null) {
try {
server.session.getBasicRemote().sendText("当前用户不存在");
} catch (IOException e) {
e.printStackTrace();
}
}
//启动消息队列的定时器,定时将消息存入数据库
SERVICE.scheduleAtFixedRate(server.messageTask, INIT_DELAY, SAVE_PERIOD_SECOND, TimeUnit.SECONDS);
//加载用户所在的所有聊天中的所有成员
List<Chat> chatList = CHAT_DAO.listByUserId(userId);
for (Chat chat : chatList) {
List<Member> list = MEMBER_DAO.listMemberByChatId(chat.getId());
for (Member member : list) {
if (!String.valueOf(member.getUserId()).equals(userId)) {
//将除了自己的所有成员加入容器
server.memberMap.put(member.getId(), member);
}
}
}
//将用户id对应的对象装载到Map容器
SERVER_MAP.put(userId, server);
onlineCount++;
System.out.println("有新连接加入!当前在线人数为" + onlineCount);
System.out.println("当前系统用户:" + userId);
}
@OnMessage
public void onMessage(String msg, Session session, @PathParam("user") String userId) throws IOException {
System.out.println("来自客户端的消息:" + msg + " 客户端请求参数 :" + userId + " 客户端session :" + session.toString());
//从容器中获取server
ChatServer server = SERVER_MAP.get(userId);
//客户段上传到服务器是Message,服务器发送到客户端是MessageVo
Message message = JSON.toJavaObject(JSON.parseObject(msg), Message.class);
//先过滤消息内容,如果是文件和图片则不过滤标签
if (FILE.toString().equalsIgnoreCase(message.getType()) || IMG.toString().equalsIgnoreCase(message.getType())) {
message.setContent(toLegalTextIgnoreTag(message.getContent()));
} else {
message.setContent(toLegalText(message.getContent()));
}
if (message.getContent().trim().isEmpty()) {
return;
}
//向消息的接收者和自己发送消息
sendMessage(message, userId);
//将po对象加入消息存储队列
server.messageTask.enQueue(message);
}
@OnClose
public void onClose(@PathParam("user") String userId) {
onlineCount--;
System.out.println(SERVER_MAP.get(userId));
System.out.println("有一连接关闭!当前在线人数为" + onlineCount);
}
@OnError
public void onError(Throwable error) {
System.out.println("发生错误");
error.printStackTrace();
}
/**
* 线
*
* @param message
* @param userId id
* @return
* @name sendNotify
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/13
*/
public static void sendNotify(Message message, BigInteger userId) {
//从容器中获取server
ChatServer server = SERVER_MAP.get(String.valueOf(userId));
//发送给对应用户
if (server != null && server.session != null && server.session.isOpen()) {
//创建vo对象(使用建造者模式的链式调用)
User sender = USER_DAO.getUserById(message.getSenderId());
MessageVO messageVo = new MessageVOBuilder().setSenderId(sender.getId())
.setSenderName(sender.getName()).setChatId(message.getChatId())
.setContent(message.getContent()).setSenderPhoto(sender.getPhoto())
.setTime(message.getTime()).setType(message.getType()).build();
String jsonString = JSONObject.toJSONString(messageVo);
try {
server.session.getBasicRemote().sendText(jsonString);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 线map
*
* @param newMember
* @param message
* @name addMember
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/13
*/
public static void addMember(Member newMember, Message message) {
List<Member> memberList = MEMBER_DAO.listMemberByChatId(newMember.getChatId());
for (Member oldMember : memberList) {
//除开自己
if(newMember.getUserId().equals(oldMember.getUserId())){
continue;
}
//从容器中获取该新成员的server
ChatServer server = SERVER_MAP.get(String.valueOf(newMember.getUserId()));
//把一个旧成员加入这个新成员的memberMap
if (server != null && server.session != null && server.session.isOpen()) {
server.memberMap.put(oldMember.getId(), oldMember);
}
//把新成员自己加入到旧成员对方的memberMap
server = SERVER_MAP.get(String.valueOf(oldMember.getUserId()));
if (server != null && server.session != null && server.session.isOpen()) {
server.memberMap.put(newMember.getId(), newMember);
}
}
//使用该成员的server在这个聊天中向该群成员发送打招呼消息
ChatServer server = SERVER_MAP.get(String.valueOf(newMember.getUserId()));
if (server != null && server.session != null && server.session.isOpen()) {
try {
server.sendMessage(message, String.valueOf(newMember.getUserId()));
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @notice none
* @date 2019/5/7
*/
private class MessageTask extends TimerTask {
/**
*
*/
private Queue<Message> messageQueue = new LinkedBlockingQueue<>();
/**
*
*
* @param message
* @name enQueue
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
private void enQueue(Message message) {
this.messageQueue.add(message);
}
@Override
public void run() {
for (Message message : this.messageQueue) {
//将消息插入数据库,并从队列移除
MESSAGE_SERVICE.insertMessage(message);
this.messageQueue.remove();
}
}
}
/**
*
*
* @param message
* @name sendMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
synchronized private void sendMessage(Message message, String userId) throws IOException {
//从容器中获取server
ChatServer server = SERVER_MAP.get(userId);
//创建vo对象(使用建造者模式的链式调用)
MessageVO messageVo = new MessageVOBuilder().setSenderId(server.user.getId())
.setSenderName(server.user.getName()).setChatId(message.getChatId())
.setContent(message.getContent()).setSenderPhoto(server.user.getPhoto())
.setTime(message.getTime()).setType(message.getType()).build();
String jsonString = JSONObject.toJSONString(messageVo);
//发送给自己
if (server.session.isOpen()) {
server.session.getBasicRemote().sendText(jsonString);
}
//遍历与用户具有聊天关系的集合,将消息发给指定用户,如果在线则发送消息
Set<BigInteger> keys = server.memberMap.keySet();
for (BigInteger key : keys) {
Member member = server.memberMap.get(key);
//获取接收者server
ChatServer receiver = SERVER_MAP.get(String.valueOf(member.getUserId()));
//当该成员处于消息对应的聊天中,并且在线时时给他发送消息
if (member.getChatId().equals(message.getChatId()) && receiver != null && receiver.session != null && receiver.session.isOpen()) {
try {
receiver.session.getBasicRemote().sendText(jsonString);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

@ -0,0 +1,185 @@
/*
* 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.*;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe5243 48@gmail.com"></a>
* @description
* @date 2019-05-03 13:26
*/
public interface ChatService {
/**
* ,使uuid
*
* @param isGroupChat
* @param chat
* @return
* @name createChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
ServiceResult createChat(Chat chat, boolean isGroupChat);
/**
* id
*
* @param friend
* @name createFriendChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/13
*/
ServiceResult createFriendChat(Friend friend);
/**
*
*
* @param members
* @return
* @name joinChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
ServiceResult joinChat(Member[] members);
/**
*
*
* @param userId id
* @param number
* @param apply
* @name joinChatByNumber
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
ServiceResult joinChatByNumber(BigInteger userId, String number, String apply);
/**
* </br>
*
*
* @param members
* @return
* @name quitChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
ServiceResult quitChat(Member members);
/**
*
*
* @param memberId id
* @name removeFromChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
ServiceResult removeFromChat(BigInteger memberId);
/**
*
*
* @param user
* @return
* @name listChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
ServiceResult listChat(User user);
/**
* id
*
* @param userId id
* @param number id
* @name getChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
ServiceResult getChat(String number, BigInteger userId);
/**
*
*
* @param chat
* @return
* @name removeChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
void removeChat(Chat chat);
/**
*
*
* @param number
* @name getChatByNumber
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
void getChatByNumber(Object number);
/**
*
*
* @param chatId id
* @name listMember
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
ServiceResult listMember(BigInteger chatId);
/**
*
*
* @param member
* @name getHelloMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
Message getHelloMessage(Member member);
/**
*
* @name isOwner
* @param memberId
* @param userId id
* @return
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/15
*/
boolean isOwner(BigInteger memberId, BigInteger userId);
}

@ -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);
/**
* idid
*
* @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,143 @@
/*
* 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.Message;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 11:15
*/
public interface MessageService {
/**
*
*
* @param message
* @name insertMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
void insertMessage(Message message);
/**
*
*
* @param userId id
* @param chatId id
* @param page
* @return
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult listAllMessage(Object userId, Object chatId, int page);
/**
*
*
* @param userId id
* @param chatId id
* @param page
* @name listUnreadMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult listUnreadMessage(Object userId, Object chatId, int page);
/**
*
*
* @param userId id
* @param page
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult listAllUnreadMessage(Object userId, int page);
/**
*
*
* @param userId id
* @param messageId id
* @name removeMessage
* @notice </br>
* 访
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult removeMessage(BigInteger userId, BigInteger messageId);
/**
*
*
* @param userId id
* @param chatId id
* @name removeAllMessage
* @notice </br>
* 访
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult removeAllMessage(BigInteger userId, BigInteger chatId);
/**
*
*
* @param userId id
* @param chatId id
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult exportMessage(Object userId, Object chatId);
/**
*
*
* @param userId id
* @param messageId id
* @name drawMessage
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult drawBackMessage(BigInteger userId, BigInteger messageId);
/**
*
*
* @param userId id
* @param chatId id
* @name setAlreadyRead
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
void setAlreadyRead(Object userId, Object chatId);
}

@ -0,0 +1,126 @@
/*
* 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;
import com.hyc.wechat.model.po.Moment;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 13:13
*/
public interface MomentService {
/**
*
*
* @param moment
* @name insertMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult insertMoment(Moment moment);
/**
*
*
* @param friend
* @return
* @name initNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/18
*/
ServiceResult initNews(Friend friend);
/**
*
*
* @param momentId id
* @name removeMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult removeMoment(BigInteger momentId);
/**
*
*
* @param moment
* @name updateMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult updateMoment(Moment moment);
/**
*
*
* @param page
* @param userId id
* @name listNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult listMyMoment(BigInteger userId, int page);
/**
*
*
* @param userId id
* @param page
* @name listNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
ServiceResult listNews(BigInteger userId, int page);
/**
*
*
* @param userId id
* @param momentId id
* @name love
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/8
*/
ServiceResult love(BigInteger userId, BigInteger momentId);
/**
*
*
* @param userId id
* @param page
* @name loadPhoto
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
ServiceResult listPhoto(BigInteger userId, int page);
}

@ -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,70 @@
/*
* 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 javax.servlet.http.Part;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-06 02:23
*/
public interface UploadService {
/**
* photo
*
* @param part
* @param id id
* @param tableName
* @return
* @name uploadPhoto
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
ServiceResult uploadPhoto(Part part, Object id, String tableName);
/**
*
*
* @param part
* @param id id
* @return
* @name uploadBackground
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
ServiceResult uploadBackground(Part part, Object id);
/**
*
*
* @param part
* @name uploadFile
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
ServiceResult uploadFile(Part part);
}

@ -0,0 +1,114 @@
/*
* 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.User;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-02 02:18
*/
public interface UserService {
/**
*
*
* @param user
* @return
*/
ServiceResult checkRegister(User user);
/**
*
*
* @param user
* @return
*/
ServiceResult insertUser(User user);
/**
*
*
* @param user
* @return
*/
ServiceResult checkPassword(User user);
/**
*
*
* @param wechatId
* @return
*/
ServiceResult checkWechatId(String wechatId);
/**
* id
*
* @param id id
* @return
*/
ServiceResult getUser(Object id);
/**
* ,
*
* @param user
* @return /
*/
ServiceResult updateUser(User user);
/**
*
*
* @param oldPwd
* @param newPwd
* @param userId id
* @return /
*/
ServiceResult updatePwd(String oldPwd, String newPwd , BigInteger userId);
/**
*
*
* @param name
* @return
* @name listUserLikeName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
ServiceResult listUserLikeName(String name);
/**
*
*
* @name visitorLogin
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
ServiceResult visitorLogin();
}

@ -0,0 +1,44 @@
/*
* 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.constants;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-14 17:20
*/
public enum ChatType {
/**
*
*/
GROUP,
/**
*
*/
FRIEND;
/**
* toString
*
* @return
*/
@Override
public String toString() {
return super.toString().toLowerCase();
}
}

@ -0,0 +1,52 @@
/*
* 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.constants;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-13 11:29
*/
public enum MessageType {
/**
*
*/
USER,
/**
*
*/
IMG,
/**
*
*/
FILE,
/**
*
*/
FRIEND;
/**
* toString
*
* @return
*/
@Override
public String toString() {
return super.toString().toLowerCase();
}
}

@ -0,0 +1,405 @@
/*
* 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.constants;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-02 22:27
*/
public enum ServiceMessage {
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
EMAIL_FORMAT_INCORRECT("您输入的邮箱格式不正确,邮箱只能由英文字母/数字组成,且域名符合规则"),
/**
*
*/
EMAIL_ALREADY_USED("该邮箱已被注册!"),
/**
*
*/
PASSWORD_INCORRECT("您输入的密码不正确,请重新输入或尝试找回密码"),
/**
*
*/
ACCOUNT_NOT_FOUND("该微信账号不存在,请检查您的输入是否正确"),
/**
*
*/
WECHAT_ID_USED("您输入的微信号已被占用,请重新输入"),
/**
*
*/
WECHAT_ID_INVALID("您输入的微信号不符合要求,请重新输入"),
/**
*
*/
INVALID_PASSWORD("您的密码不符合要求密码必须是6~20位英文字母/数字/下划线组成"),
/**
*
*/
NO_USER_INFO("找不到该用户的信息,请检查该用户是否登陆"),
/**
*
*/
UPDATE_USER_FAILED("更新用户信息失败,请重试"),
/**
*
*/
NO_SUCH_USER("找不到相关用户,试着换一个关键词吧"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
REGISTER_INFO_VALID("您的注册信息符合要求,可以继续注册"),
/**
*
*/
REGISTER_SUCCESS("您已经注册成功,请记住您的密码,使用邮箱号进行登陆"),
/**
*
*/
LOGIN_SUCCESS("登陆成功欢迎进入wechat在线聊天系统"),
/**
* 退
*/
LOGOUT_SUCCESS("您已成功退出账号,请重新登陆"),
/**
*
*/
WECHAT_ID_VALID("该微信号有效且未被占用"),
/**
*
*/
GET_INFO_SUCCESS("获取个人信息成功"),
/**
*
*/
UPDATE_INFO_SUCCESS("更新个人信息成功,请刷新页面查看"),
/**
*
*/
UPDATE_PASSWORD_SUCCESS("您已成功更新登陆密码,新的登陆密码为 "),
/**
*
*/
UPDATE_BACKGROUND_SUCCESS("更新聊天背景成功,打开一个聊天窗口即可看到效果"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
CREATE_CHAT_FAILED("发起聊天失败,您无法与对方进行聊天"),
/**
*
*/
JOIN_CHAT_FAILED("加入聊天失败"),
/**
*
*/
MEMBER_ALREADY_EXIST("该成员已经在此聊天中,不可重复添加"),
/**
*
*/
MEMBER_NOT_FOUND("此聊天中没有该成员"),
/**
* 退
*/
QUIT_CHAT_FAILED("退出聊天失败,请重试"),
/**
*
*/
NOT_OWNER("您并不是该群的群主或管理员,没有权限进行此操作"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
CREATE_CHAT_SUCCESS("创建聊天成功"),
/**
*
*/
CREATE_GROUP_CHAT_SUCCESS("你成功创建了一个群聊,群号为 :"),
/**
*
*/
PLEASE_JOIN_CHAT(" 使用群号即可加入群聊,快去邀请好友加群吧"),
/**
*
*/
JOIN_CHAT_SUCCESS("加入聊天成功"),
/**
* 退
*/
QUIT_CHAT_SUCCESS("退出聊天成功,以后你将收不到该聊天的任何信息"),
/**
*
*/
REMOVE_MEMBER_SUCCESS("移除聊天成员成功"),
/**
*
*/
REMOVE_MEMBER_FAILED("移除聊天成员失败"),
/**
*
*/
CANNOT_REMOVE_FRIEND("该成员所处的聊天是好友私聊,不可移除,您可以选择删除该好友"),
/**
*
*/
NO_CHAT_NOW("您当前没有加入任何聊天,请先添加好友或者加入群聊吧"),
/**
*
*/
LIST_CHAT_SUCCESS("成功加载聊天列表"),
/**
*
*/
CHAT_NUMBER_INVALID("您输入的群号不符合要求群号必须只由数字组成并且长度在6-20位之间"),
/**
*
*/
CHAT_NUMBER_ALREADT_EXIST("您输入的群号已经被占用,请重新输入"),
/**
*
*/
JOIN_GROUP_CHAT_SUCCESS("加入群聊成功,请在聊天列表查看"),
/**
*
*/
CHAT_NOT_FOUND("该聊天不存在,请检查您的输入"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
UPLOAD_FAILED("上传文件失败,请重试"),
/**
*
*/
UPLOAD_SUCCESS("上传文件成功"),
/**
*
*/
UNSUPPROT_TABLE("系统尚未提供这张数据库表的上传服务"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
ADD_FRIEND_SUCCESS("发送好友申请成功,当对方同意好友申请时,就可以和对方开始聊天了"),
/**
*
*/
ALREADY_ADD_FRIEND("您已经发出了好友申请,不可重复添加好友,没有看到聊天窗口的话,可以刷新浏览器试一试哦"),
/**
*
*/
NO_FRIEND_NOW("您现在还没有好友呢,快去添加好友吧"),
/**
*
*/
DELETE_FRIEND_SUCCESS("对方已从您的好友中移除,将不再接收对方的消息"),
/**
*
*/
FRIEND_NOT_EXIST("系统找不到该好友的账号"),
/**
*
*/
UPDATE_FRIEND_SUCCESS("更新好友信息成功"),
/**
*
*/
ALREADY_FRIEND("该用户已经是你的好友了,不可重复添加,去你的好友列表里找他吧"),
/**
*
*/
CANNOT_ADD_YOURSELF("不可以添加自己为好友哦"),
/**
*
*/
AGREE_FRIEND("我通过了你的好友验证请求,现在我们可以开始聊天了"),
/**
*
*/
CANNOT_DELETE_SYSTEM("这是系统账号,负责提供消息推送功能,不可以被删除"),
/**
*
*/
CANNOT_DELETE_HYC("这是开发者账号,他掌握着本系统的后台数据库,所以你是删不掉的哈哈哈"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
DELETE_FAILED("无法将该聊天记录删除,请重试"),
/**
*
*/
NO_RECORD("当前没有聊天记录"),
/**
*
*/
ALREADY_READ("您打开了一个窗口系统已将其中已将其中的消息设置为已读如果没有新消息下次加载时一个聊天最多只加载20条已读消息"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
CONTENT_ILLEGAL("系统检测到您输入的内容中包含非法字符,已自动将其过滤 "),
/**
*
*/
CONTENT_TOO_LONG("您输入的内容过长,请重新输入"),
/**
*
*/
POST_MOMENT_SUCCESS("成功发布一条朋友圈,你的朋友将可以在朋友圈中看到这条动态"),
/**
*
*/
NO_NEWS("你的朋友一条朋友圈也没有,快去多加一些好友吧"),
/**
*
*/
NO_MORE("没有更多数据了"),
/**
*
*/
NO_REMARK("当前朋友圈暂时没有评论,快去发表评论吧"),
/**
*
*/
NO_MOMENT("你现在没有已发布的朋友圈,快去发布你的朋友圈吧"),
/**
*
*/
MISSING_TIME("该消息中缺少了发送时间参数,无法存入数据库"),
/**
*
*/
MISSING_TYPE("该消息中缺少了类型参数,无法存入数据库"),
/**
*
*/
POST_SUCCESS("发布成功"),
/**
*
*/
POST_FAILED("发布失败"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
NOT_NULL("内容不能为空"),
/**
*
*/
NOT_FOUND("该记录不存在"),
/**
* 0
*/
PAGE_INVALID("无法查询页数小于1的记录,该查询无效"),
/*
**************************************************************
*
**************************************************************
*/
/**
*
*/
PARAMETER_NOT_ENOUGHT("请求参数不足,无法执行服务"),
/**
*
*/
PLEASE_REDO("执行失败,请重试"),
/**
*
*/
OPERATE_SUCCESS("执行操作成功"),
/**
*
*/
DATABASE_ERROR("系统数据库发生了故障,无法正常提供服务");
public String message;
ServiceMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
private void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,83 @@
/*
* 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.constants;
/**
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01
*/
public enum Status {
// 注册状态
/**
*
*/
ACCOUNT_ALREADY_EXIST,
/**
*
*/
DATA_ILLEGAL,
/**
*
*/
DATA_TOO_MUCH,
// 登陆状态
/**
*
*/
PASSWORD_INCORRECT,
// 修改信息状态
/**
*
*/
PERMISSION_DENY,
// 管理房间状态
/**
*
*/
ROOM_ALREADY_EXIST,
// 订单状态
/**
*
*/
ALREADY_BOOKED,
// 操作状态
/**
*
*/
NOT_FOUNT,
/**
*
*/
NO_RESULT,
/**
*
*/
SUCCESS,
/**
*
*/
ERROR;
}

@ -0,0 +1,538 @@
/*
* 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.*;
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.*;
import com.hyc.wechat.model.vo.MemberVO;
import com.hyc.wechat.service.ChatService;
import com.hyc.wechat.service.constants.ChatType;
import com.hyc.wechat.service.constants.MessageType;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.constants.Status;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.LinkedList;
import java.util.List;
import static com.hyc.wechat.util.StringUtils.toLegalText;
import static com.hyc.wechat.util.UUIDUtils.getUUID;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-03 13:52
*/
public class ChatServiceImpl implements ChatService {
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
private final ChatDao chatDao = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
private final MemberDao memberDao = (MemberDao) DaoProxyFactory.getInstance().getProxyInstance(MemberDao.class);
private final MessageDao messageDao = (MessageDao) DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
private final FriendDao friendDao = (FriendDao) DaoProxyFactory.getInstance().getProxyInstance(FriendDao.class);
/**
* ,使uuid
*
* @param isGroupChat
* @param chat
* @return
* @name createChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
@Override
public ServiceResult createChat(Chat chat, boolean isGroupChat) {
//检查参数
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, chat);
}
//阻止插入id
chat.setId(null);
//检查创建用户是否存在
if (userDao.getUserById(chat.getOwnerId()) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, chat);
}
//判断聊天类型
if (isGroupChat) {
//检查群号是否合法
if (!isValidChatNumber(chat.getNumber())) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NUMBER_INVALID.message, chat);
}
//群名
chat.setName(toLegalText(chat.getName()));
//检查群号是否已存在
if (chatDao.getByChatNumber(chat.getNumber()) != null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NUMBER_ALREADT_EXIST.message, chat);
}
//设置聊天类型为群聊
chat.setType(ChatType.GROUP.toString());
} else {
//使用uuid作为外部标识
if (chat.getNumber() == null) {
chat.setNumber(getUUID());
}
}
try {
//将该聊天插入数据库
if (chatDao.insert(chat) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.CREATE_CHAT_FAILED.message, chat);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, chat);
}
//插入成功将其从数据库查出以便返回id
chat = chatDao.getByChatNumber(chat.getNumber());
return new ServiceResult(Status.SUCCESS, ServiceMessage.CREATE_CHAT_SUCCESS.message, chat);
}
/**
* id
*
* @param friend
* @name createFriendChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/13
*/
@Override
public ServiceResult createFriendChat(Friend friend) {
if (friend == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
//不与自己建立聊天
if (friend.getFriendId().equals(friend.getUserId())) {
return new ServiceResult(Status.ERROR, ServiceMessage.CANNOT_ADD_YOURSELF.message, null);
}
Chat chat = new Chat();
//这里查到双向添加好友说明对方先加我为好友,聊天所有者为对方
chat.setOwnerId(friend.getFriendId());
chat = (Chat) createChat(chat, false).getData();
//创建两个成员,将双方加入聊天中
Member member1 = new Member();
member1.setUserId(friend.getUserId());
member1.setChatId(chat.getId());
Member member2 = new Member();
member2.setUserId(friend.getFriendId());
member2.setChatId(chat.getId());
joinChat(new Member[]{member1, member2});
//添加成功后将聊天id更新到朋友信息中
try {
//更新好友信息
friend = friendDao.getFriendByUIDAndFriendId(friend.getUserId(), friend.getFriendId());
if (friend == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, chat);
}
friend.setChatId(chat.getId());
friendDao.update(friend);
friend = friendDao.getFriendByUIDAndFriendId(friend.getFriendId(), friend.getUserId());
if (friend == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, chat);
}
friend.setChatId(chat.getId());
friendDao.update(friend);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, chat);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.CREATE_CHAT_SUCCESS.message, chat);
}
/**
*
*
* @param userId id
* @param number
* @name joinChatByNumber
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Override
public ServiceResult joinChatByNumber(BigInteger userId, String number, String apply) {
if (userId == null | number == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
//通过群号获取群id
Chat chat = chatDao.getByChatNumber(number);
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NOT_FOUND.message, number);
}
//通过群id和用户id创建一个成员
Member member = new Member();
member.setChatId(chat.getId());
member.setUserId(userId);
member.setApply(apply);
ServiceResult result = joinChat(new Member[]{member});
if (Status.ERROR.equals(result.getStatus())) {
return result;
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.JOIN_GROUP_CHAT_SUCCESS.message, member);
}
/**
*
*
* @param chatId id
* @name listMember
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
@Override
public ServiceResult listMember(BigInteger chatId) {
if (chatId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, chatId);
}
List<MemberVO> memberVOList;
try {
//检查聊天是否存在
if (chatDao.getChatById(chatId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NOT_FOUND.message, chatId);
}
memberVOList = new LinkedList<>();
List<Member> memberList = memberDao.listMemberByChatId(chatId);
//对每个成员将其用户信息查出来构建memberVO
for (Member member : memberList) {
User user = userDao.getUserById(member.getUserId());
MemberVO memberVO = new MemberVO();
memberVO.setName(user.getName());
memberVO.setPhoto(user.getPhoto());
memberVO.setSignature(user.getSignature());
memberVO.setChatId(chatId);
memberVO.setUserId(member.getUserId());
memberVO.setBackground(member.getBackground());
memberVO.setLevel(member.getLevel());
memberVO.setId(member.getId());
memberVOList.add(memberVO);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, chatId);
}
return new ServiceResult(Status.SUCCESS, null, memberVOList);
}
/**
*
*
* @param members
* @return
* @name joinChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
@Override
synchronized public ServiceResult joinChat(Member[] members) {
try {
for (Member member : members) {
//阻止插入id
member.setId(null);
Chat chat = chatDao.getChatById(member.getChatId());
User user = userDao.getUserById(member.getUserId());
//检查聊天是否存在
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NOT_FOUND.message, members);
}
//检查用户是否存在
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, members);
}
//检查该用户是否已在此聊天
if (memberDao.getMemberByUIdAndChatId(member.getUserId(), member.getChatId()) != null) {
return new ServiceResult(Status.ERROR, ServiceMessage.MEMBER_ALREADY_EXIST.message, members);
}
//将群成员昵称设置为用户的昵称
if (member.getGroupAlias() == null) {
member.setGroupAlias(user.getName());
}
//将该成员插入到此聊天
if (memberDao.insert(member) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.JOIN_CHAT_FAILED.message, members);
}
//将该聊天的成员加一
chat.setMember(chat.getMember() + 1);
chatDao.update(chat);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, members);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.JOIN_CHAT_SUCCESS.message, members);
}
/**
* 退</br>
*
* @param member
* @return
* @name quitChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
@Override
synchronized public ServiceResult quitChat(Member member) {
if (member == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, member);
}
try {
member = memberDao.getMemberByUIdAndChatId(member.getUserId(), member.getChatId());
ServiceResult result;
result = removeFromChat(member.getId());
if (Status.ERROR.equals(result.getStatus())) {
return result;
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, member);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.QUIT_CHAT_SUCCESS.message, member);
}
/**
*
*
* @param memberId id
* @name removeFromChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult removeFromChat(BigInteger memberId) {
if(memberId==null){
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
try {
//检查成员是否存在
if (memberDao.getMemberById(memberId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.MEMBER_NOT_FOUND.message, null);
}
Member member = memberDao.getMemberById(memberId);
Chat chat = chatDao.getChatById(member.getChatId());
//不可移除好友
if(ChatType.FRIEND.toString().equalsIgnoreCase(chat.getType())){
return new ServiceResult(Status.ERROR, ServiceMessage.CANNOT_REMOVE_FRIEND.message, memberId);
}
//将该成员从聊天中移除
if (memberDao.delete(member) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.REMOVE_MEMBER_FAILED.message, memberId);
}
//将该聊天的成员减一
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NOT_FOUND.message, memberId);
}
chat.setMember(chat.getMember() - 1);
chatDao.update(chat);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, memberId);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.REMOVE_MEMBER_SUCCESS.message, memberId);
}
/**
*
*
* @param user
* @return
* @name listChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
@Override
public ServiceResult listChat(User user) {
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, user);
}
//检查用户是否存在
if (userDao.getUserById(user.getId()) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, user);
}
List<Chat> chatVOList = new LinkedList<>();
try {
List<Chat> chatList = chatDao.listByUserId(user.getId());
if (chatList == null || chatList.size() == 0) {
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_CHAT_NOW.message, chatList);
}
for (Chat chat : chatList) {
//在私聊中将聊天头像设置未对方头像
if (ChatType.FRIEND.toString().equalsIgnoreCase(chat.getType())) {
chat = chatDao.toFriendChat(chat.getId(), user.getId());
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, chatList);
}
}
chatVOList.add(chat);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, null, chatVOList);
}
/**
* id
*
* @param number id
* @param userId id
* @name getChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult getChat(String number, BigInteger userId) {
if (number == null || userId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, number);
}
Chat chat;
try {
chat = chatDao.getByChatNumber(number);
//检查聊天是否存在
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, chat);
}
//检查用户是否存在
User user = userDao.getUserById(userId);
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, chat);
}
//检查是否是私聊
if (ChatType.FRIEND.toString().equalsIgnoreCase(chat.getType())) {
chat = chatDao.toFriendChat(chat.getId(), user.getId());
if (chat == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, number);
}
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, number);
}
return new ServiceResult(Status.SUCCESS, null, chat);
}
/**
*
*
* @param chat
* @return
* @name removeChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Override
public void removeChat(Chat chat) {
try {
chatDao.delete(chat);
} catch (DaoException e) {
e.printStackTrace();
}
}
/**
*
*
* @param number
* @return
* @name getChatByNumber
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Override
public void getChatByNumber(Object number) {
try {
chatDao.getByChatNumber(number);
} catch (DaoException e) {
e.printStackTrace();
}
}
/**
*
*
* @param member
* @name getHelloMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public Message getHelloMessage(Member member) {
//生成打招呼消息
Message message = new Message();
message.setChatId(member.getChatId());
message.setSenderId(member.getUserId());
message.setTime(new Timestamp(System.currentTimeMillis()));
message.setType(MessageType.USER.toString());
message.setContent(member.getApply());
return message;
}
/**
*
* @name isOwner
* @param memberId
* @param userId id
* @return
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/15
*/
@Override
public boolean isOwner(BigInteger memberId, BigInteger userId) {
if (memberId == null || userId == null) {
return false;
}
Member member = memberDao.getMemberById(memberId);
Chat chat = chatDao.getChatById(member.getChatId());
if (userId.equals(chat.getOwnerId())) {
return true;
} else {
return false;
}
}
private boolean isValidChatNumber(String chatNumber) {
if (chatNumber == null || chatNumber.trim().isEmpty()) {
return false;
}
String regex = "[0-9]{6,20}$";
return chatNumber.matches(regex);
}
}

@ -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;
}
/**
* idid
*
* @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,393 @@
/*
* 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.*;
import com.hyc.wechat.exception.DaoException;
import com.hyc.wechat.exception.ServiceException;
import com.hyc.wechat.factory.DaoProxyFactory;
import com.hyc.wechat.model.builder.MessageVOBuilder;
import com.hyc.wechat.model.dto.ServiceResult;
import com.hyc.wechat.model.po.Member;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.Record;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.model.vo.MessageVO;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.constants.ServiceMessage;
import com.hyc.wechat.service.constants.Status;
import java.io.File;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
import static com.hyc.wechat.service.constants.ServiceMessage.*;
import static com.hyc.wechat.util.UUIDUtils.getUUID;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 14:35
*/
public class MessageServiceImpl implements MessageService {
private final ChatDao chatDao = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
private final MessageDao messageDao = (MessageDao) DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
private final RecordDao recordDao = (RecordDao) DaoProxyFactory.getInstance().getProxyInstance(RecordDao.class);
private final MemberDao memberDao = (MemberDao) DaoProxyFactory.getInstance().getProxyInstance(MemberDao.class);
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
/**
*
*
* @param message
* @name insertMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public void insertMessage(Message message) {
try {
//将消息插入数据库
if (messageDao.insert(message) != 1) {
throw new ServiceException(DATABASE_ERROR.message + message.toString());
}
//检查是否有时间参数
if(message.getTime()==null){
throw new ServiceException(MISSING_TIME.message + message.toString());
}
if(message.getType()==null){
throw new ServiceException(MISSING_TYPE.message + message.toString());
}
message = messageDao.getMessageBySenderIdAndChatIdAndTime(message.getSenderId(), message.getChatId(), message.getTime());
//对每条消息给聊天中所有成员产生消息记录
//加载用户所在的所有聊天中的所有成员,给所有成员插入记录
List<Member> memberList = memberDao.listMemberByChatId(message.getChatId());
if (memberList != null && memberList.size() > 0) {
for (Member member : memberList) {
Record record = new Record();
record.setMessageId(message.getId());
record.setUserId(member.getUserId());
if (recordDao.insert(record) != 1) {
throw new ServiceException(DATABASE_ERROR.message + record.toString());
}
}
}
} catch (DaoException e) {
e.printStackTrace();
throw new ServiceException(e);
}
}
/**
*
*
* @param userId id
* @param chatId id
* @param page
* @return
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult listAllMessage(Object userId, Object chatId, int page) {
int limit = 200;
int offset = (page - 1) * limit;
//检查页数
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
List<MessageVO> messageVOList = new LinkedList<>();
//数据判空
if (userId == null || chatId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
try {
User user = userDao.getUserById(userId);
//检查用户是否存在
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, null);
}
//查询数据库
List<Message> messageList = messageDao.listMessageByUserIdAndChatIdDesc(userId, chatId, limit, offset);
//检查数据是否存在
if (messageList == null || messageList.size() == 0) {
return new ServiceResult(Status.SUCCESS, null, messageList);
}
toMessageVOObject(messageVOList, messageList);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, chatId);
}
return new ServiceResult(Status.SUCCESS, null, messageVOList);
}
/**
*
*
* @param userId id
* @param chatId id
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult exportMessage(Object userId, Object chatId) {
//数据判空
if (userId == null || chatId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
File file;
try {
file = new File("/upload/file/" + getUUID() + ".txt");
messageDao.messageToFile(userId, chatId, file.getPath());
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, chatId);
}
return new ServiceResult(Status.SUCCESS, null, file.getName());
}
/**
*
*
* @param userId id
* @param page
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult listAllUnreadMessage(Object userId, int page) {
if (userId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
List<MessageVO> messageVOList = new LinkedList<>();
//一次最多获取2000条未读消息
int limit = 2000;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
try {
User user = userDao.getUserById(userId);
//检查用户是否存在
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, null);
}
List<Message> messageList = messageDao.listUnreadMessageByUserId(userId, limit, offset);
//检查数据是否存在
if (messageList == null || messageList.size() == 0) {
return new ServiceResult(Status.SUCCESS, null, messageList);
}
//使用记录和用户信息建造视图层消息实体
toMessageVOObject(messageVOList, messageList);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, null);
}
return new ServiceResult(Status.SUCCESS, null, messageVOList);
}
/**
*
*
* @param userId id
* @param chatId id
* @param page
* @name listUnreadMessage
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult listUnreadMessage(Object userId, Object chatId, int page) {
if (userId == null || chatId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
List<MessageVO> messageVOList = new LinkedList<>();
List<Message> list = null;
int limit = 1000;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
try {
User user = userDao.getUserById(userId);
//检查用户是否存在
if (user == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, null);
}
List<Message> messageList = messageDao.listUnreadMessage(userId, chatId, limit, offset);
//检查数据是否存在
if (messageList == null || messageList.size() == 0) {
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_RECORD.message, messageList);
}
//使用记录和用户信息建造视图层消息实体
toMessageVOObject(messageVOList, messageList);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, null);
}
return new ServiceResult(Status.SUCCESS, null, messageVOList);
}
/**
*
*
* @param userId id
* @param messageId id
* @name removeMessage
* @notice </br>
* 访
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult removeMessage(BigInteger userId, BigInteger messageId) {
if (userId == null | messageId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
Record record = null;
try {
record = new Record();
record.setUserId(userId);
record.setMessageId(messageId);
//将该记录移除
if (recordDao.delete(record) != 1) {
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, record);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, record);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, record);
}
/**
*
*
* @param userId id
* @param chatId id
* @name removeAllMessage
* @notice </br>
* 访
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult removeAllMessage(BigInteger userId, BigInteger chatId) {
if (userId == null | chatId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
try {
if (chatDao.getChatById(chatId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.CHAT_NOT_FOUND.message, null);
}
if (userDao.getUserById(userId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.ACCOUNT_NOT_FOUND.message, null);
}
//将记录移除
recordDao.deleteAllRecordInChat(userId, chatId);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, chatId);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, chatId);
}
/**
*
*
* @param userId id
* @param messageId id
* @name drawMessage
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult drawBackMessage(BigInteger userId, BigInteger messageId) {
if (userId == null | messageId == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
try {
Message message = new Message();
message.setId(messageId);
//将该消息移除
if (messageDao.delete(message) != 1) {
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, messageId);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, messageId);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, messageId);
}
/**
*
*
* @param userId id
* @param chatId id
* @name setAlreadyRead
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public void setAlreadyRead(Object userId, Object chatId) {
try {
recordDao.updateStatusInChat(1, userId, chatId);
} catch (DaoException e) {
e.printStackTrace();
}
}
/**
*
*
* @param messageVOList
* @param messageList
* @name toMessageVOObject
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/8
*/
public void toMessageVOObject(List<MessageVO> messageVOList, List<Message> messageList) {
//使用记录和用户信息建造视图层消息实体
for (Message message : messageList) {
User sender = userDao.getUserById(message.getSenderId());
if (sender == null) {
throw new ServiceException("消息的发送者不存在");
}
MessageVO messageVo = new MessageVOBuilder().setSenderId(message.getSenderId())
.setSenderName(sender.getName()).setChatId(message.getChatId())
.setContent(message.getContent()).setSenderPhoto(sender.getPhoto())
.setTime(message.getTime()).setType(message.getType()).build();
messageVOList.add(messageVo);
}
}
}

@ -0,0 +1,439 @@
/*
* 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.FriendDao;
import com.hyc.wechat.dao.MomentDao;
import com.hyc.wechat.dao.NewsDao;
import com.hyc.wechat.dao.UserDao;
import com.hyc.wechat.exception.DaoException;
import com.hyc.wechat.exception.ServiceException;
import com.hyc.wechat.factory.DaoProxyFactory;
import com.hyc.wechat.model.builder.MomentVOBuilder;
import com.hyc.wechat.model.dto.ServiceResult;
import com.hyc.wechat.model.po.Friend;
import com.hyc.wechat.model.po.Moment;
import com.hyc.wechat.model.po.News;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.model.vo.MomentVO;
import com.hyc.wechat.service.MomentService;
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;
import static com.hyc.wechat.util.StringUtils.toLegalText;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 19:19
*/
public class MomentServiceImpl implements MomentService {
private final MomentDao momentDao = (MomentDao) DaoProxyFactory.getInstance().getProxyInstance(MomentDao.class);
private final NewsDao newsDao = (NewsDao) DaoProxyFactory.getInstance().getProxyInstance(NewsDao.class);
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
private final FriendDao friendDao = (FriendDao) DaoProxyFactory.getInstance().getProxyInstance(FriendDao.class);
/**
*
*
* @param moment
* @name insertMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult insertMoment(Moment moment) {
StringBuilder message = new StringBuilder();
try {
//判空
if (moment == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
//检查长度
if(moment.getContent().length()>800){
return new ServiceResult(Status.ERROR, ServiceMessage.CONTENT_TOO_LONG.message, moment);
}
//检查内容
if (!isValidContent(moment.getContent())) {
message.append(ServiceMessage.CONTENT_ILLEGAL.message);
}
//过滤非法字符
moment.setContent(toLegalText(moment.getContent()));
//插入数据库
//先把状态值设置为1插入后查出状态为1的返回给前端并且对News表插入动态记录之后再更新状态为0
moment.setStatus(1);
if (momentDao.insert(moment) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.PLEASE_REDO.message, moment);
}
//获取朋友圈记录返回id值,
moment = momentDao.getMomentByOwnerIdAndStatus(moment.getOwnerId(), 1);
//查找用户的所有朋友给他们插入news记录
List<Friend> friendList = friendDao.listByUserId(moment.getOwnerId());
for (Friend friend : friendList) {
News news = new News();
news.setMomentId(moment.getId());
news.setUserId(friend.getFriendId());
newsDao.insert(news);
}
//给用户自己插入news记录
News news = new News();
news.setMomentId(moment.getId());
news.setUserId(moment.getOwnerId());
newsDao.insert(news);
//创建一个新对象用于更新状态为0表示该朋友圈处理完毕
Moment updateStatus = new Moment();
updateStatus.setId(moment.getId());
updateStatus.setStatus(0);
momentDao.update(updateStatus);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, moment);
}
return new ServiceResult(Status.SUCCESS, message.append(ServiceMessage.POST_MOMENT_SUCCESS.message).toString(), moment);
}
/**
*
*
* @param friend
* @return
* @name initNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/18
*/
@Override
public ServiceResult initNews(Friend friend) {
if(friend==null|friend.getFriendId()==null||friend.getUserId()==null){
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
try{
List<Moment> momentList = momentDao.listMyMomentByOwnerIdDesc(friend.getUserId(), 1000, 0);
for (Moment moment : momentList) {
News news = new News();
news.setMomentId(moment.getId());
news.setUserId(friend.getFriendId());
newsDao.insert(news);
}
momentList =momentDao.listMyMomentByOwnerIdDesc(friend.getFriendId(), 1000, 0);
for (Moment moment : momentList) {
News news = new News();
news.setMomentId(moment.getId());
news.setUserId(friend.getUserId());
newsDao.insert(news);
}}catch (DaoException e){
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, null);
}
return new ServiceResult(Status.SUCCESS,null,null);
}
/**
*
*
* @param momentId id
* @name removeMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult removeMoment(BigInteger momentId) {
try {
//判空
if (momentId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
//检查是否存在
if (momentDao.getMomentById(momentId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, momentId);
}
//删除
Moment moment = new Moment();
moment.setId(momentId);
if (momentDao.delete(moment) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.PLEASE_REDO.message, moment);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, momentId);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, momentId);
}
/**
*
*
* @param moment
* @name updateMoment
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult updateMoment(Moment moment) {
try {
//判空
if (moment == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
//检查是否存在
if (momentDao.getMomentById(moment.getId()) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, moment);
}
//删除
if (momentDao.update(moment) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.PLEASE_REDO.message, moment);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, moment);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, moment);
}
/**
*
*
* @param userId id
* @param page
* @name listNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult listMyMoment(BigInteger userId, int page) {
//判空
if (userId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
List<MomentVO> momentVOList = new LinkedList<>();
//根据页数信息生成查询参数
int limit = 10;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
try {
List<Moment> momentList = momentDao.listMyMomentByOwnerIdDesc(userId, limit, offset);
if (momentList == null || momentList.size() == 0) {
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_MOMENT.message, momentList);
}
User user = userDao.getUserById(userId);
//将朋友圈和用户信息转化成朋友圈视图层对象
for (Moment moment : momentList) {
News news = null;
try {
news = newsDao.getNewsByMomentIdAndUserId(moment.getId(), userId);
} catch (DaoException e) {
e.printStackTrace();
}
if (news == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, null);
}
toMomentVOObject(momentVOList, news, moment, user);
}
} catch (DaoException e) {
e.printStackTrace();
}
return new ServiceResult(Status.SUCCESS,null, momentVOList);
}
/**
*
*
* @param userId id
* @param page
* @name listNews
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Override
public ServiceResult listNews(BigInteger userId, int page) {
//判空
if (userId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
//根据页数信息生成查询参数
int limit = 10;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
List<MomentVO> momentVOList = new LinkedList<>();
try {
List<News> newsList;
newsList = newsDao.listNewsByUserId(userId, limit, offset);
//查找朋友圈动态
if (newsList == null || newsList.size() == 0) {
if(page==1){
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_NEWS.message, momentVOList);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_MORE.message, momentVOList);
}
//根据动态中的朋友圈id获取朋友圈数据
for (News news : newsList) {
Moment moment = momentDao.getMomentById(news.getMomentId());
//获取朋友圈的发布者的用户信息
User user = userDao.getUserById(moment.getOwnerId());
if(user==null){
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, momentVOList);
}
//将朋友圈和动态信息转化成朋友圈视图层对象
toMomentVOObject(momentVOList, news, moment, user);
//统计浏览量
if(!news.getViewed()){
moment.setView(moment.getView()+1L);
momentDao.update(moment);
news.setViewed(true);
newsDao.update(news);
}
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, momentVOList);
}
return new ServiceResult(Status.SUCCESS,null, momentVOList);
}
/**
*
*
* @param userId id
* @param momentId id
* @name love
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/8
*/
@Override
synchronized public ServiceResult love(BigInteger userId, BigInteger momentId) {
if (userId == null || momentId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
News news;
try {
news = newsDao.getNewsByMomentIdAndUserId(momentId, userId);
//检查news是否存在
if (news == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, null);
}
Moment moment = momentDao.getMomentById(news.getMomentId());
if (moment == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, null);
}
//从非点赞到点赞状态,该朋友圈点赞数加一,否则减一
moment.setLove(!news.getLoved() ? moment.getLove() + 1 : moment.getLove() - 1);
momentDao.update(moment);
//修改状态,如果是ture则改为false,是false则改为ture
news.setLoved(!news.getLoved());
newsDao.update(news);
} catch (DaoException e) {
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, null);
}
return new ServiceResult(Status.SUCCESS,null, news.getLoved());
}
/**
*
*
* @param userId id
* @param page
* @name loadPhoto
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
@Override
public ServiceResult listPhoto(BigInteger userId, int page) {
//根据页数信息生成查询参数
int limit = 10;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
//判空
if (userId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
List<String> photoList = new LinkedList<>();
try {
List<Moment> momentList = momentDao.listPhoto(userId,limit,offset);
if(momentList==null||momentList.size()==0){
return new ServiceResult(Status.ERROR, ServiceMessage.NO_MOMENT.message, null);
}
for (Moment moment:momentList) {
photoList.add(moment.getPhoto());
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, photoList);
}
return new ServiceResult(Status.SUCCESS, null, photoList);
}
/**
*
*
* @param momentVOList
* @param news
* @param moment
* @param user
* @name toMomentVOObject
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/8
*/
private void toMomentVOObject(List<MomentVO> momentVOList, News news, Moment moment, User user) {
MomentVO momentVO = new MomentVOBuilder().setContent(moment.getContent()).setUserId(moment.getOwnerId())
.setId(moment.getId()).setRemark(moment.getRemark()).setShare(moment.getShare()).setUserName(user.getName())
.setView(moment.getView()).setCollect(moment.getCollect()).setLove(moment.getLove()).setUserPhoto(user.getPhoto())
.setShared(news.getShared()).setViewed(news.getViewed()).setCollected(news.getCollected()).setPhoto(moment.getPhoto())
.setLoved(news.getLoved()).setTime(moment.getTime()).build();
momentVOList.add(momentVO);
}
/**
*
*
* @param content
*/
private boolean isValidContent(String content) {
if (content == null || content.trim().isEmpty()) {
return false;
}
//如果内容经过过滤后与原来不一样,说明含有非法内容
String legalText = toLegalText(content);
if (content.equals(legalText)) {
return true;
}
return false;
}
}

@ -0,0 +1,221 @@
/*
* 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.MomentDao;
import com.hyc.wechat.dao.RemarkDao;
import com.hyc.wechat.dao.UserDao;
import com.hyc.wechat.exception.DaoException;
import com.hyc.wechat.exception.ServiceException;
import com.hyc.wechat.factory.DaoProxyFactory;
import com.hyc.wechat.model.dto.ServiceResult;
import com.hyc.wechat.model.po.Moment;
import com.hyc.wechat.model.po.Remark;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.model.vo.RemarkVO;
import com.hyc.wechat.service.RemarkService;
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;
import static com.hyc.wechat.util.StringUtils.toLegalText;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-14 01:16
*/
public class RemarkServiceImpl implements RemarkService {
private final RemarkDao remarkDao = (RemarkDao) DaoProxyFactory.getInstance().getProxyInstance(RemarkDao.class);
private final MomentDao momentDao = (MomentDao) DaoProxyFactory.getInstance().getProxyInstance(MomentDao.class);
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
/**
*
*
* @param remark
* @name addRemark
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult addRemark(Remark remark) {
if (remark == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
StringBuilder message = new StringBuilder();
//检查长度
if (remark.getContent().length() > 200) {
return new ServiceResult(Status.ERROR, ServiceMessage.CONTENT_TOO_LONG.message, remark);
}
//检查内容
if (!isValidContent(remark.getContent())) {
message.append(ServiceMessage.CONTENT_ILLEGAL.message);
}
//过滤非法字符
remark.setContent(toLegalText(remark.getContent()));
try {
//检查是否存在
Moment moment = momentDao.getMomentById(remark.getMomentId());
if (moment == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, remark);
}
//阻止插入id
remark.setId(null);
if (remarkDao.insert(remark) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.POST_FAILED.message, remark);
}
//评论成功后该朋友圈评论数加一
moment.setRemark(moment.getRemark() + 1L);
if (momentDao.update(moment) != 1) {
throw new ServiceException("无法更新该朋友圈的评论数" + moment.toString());
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, remark);
}
return new ServiceResult(Status.SUCCESS, message.append(ServiceMessage.POST_SUCCESS.message).toString(), remark);
}
/**
*
*
* @param momentId id
* @param page
* @name listRemark
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult listRemark(BigInteger momentId, int page) {
//判空
if (momentId == null) {
return new ServiceResult(Status.SUCCESS, ServiceMessage.PARAMETER_NOT_ENOUGHT.message, null);
}
//根据页数信息生成查询参数
int limit = 30;
int offset = (page - 1) * limit;
if (offset < 0) {
return new ServiceResult(Status.ERROR, ServiceMessage.PAGE_INVALID.message, null);
}
List<RemarkVO> remarkVOList = new LinkedList<>();
try {
List<Remark> remarkList;
remarkList = remarkDao.listRemarkDesc(momentId, limit, offset);
//查找评论
if (remarkList == null || remarkList.size() == 0) {
return new ServiceResult(Status.SUCCESS, ServiceMessage.NO_REMARK.message, remarkVOList);
}
//添加评论者的头像,昵称
for (Remark remark : remarkList) {
User user = userDao.getUserById(remark.getUserId());
remarkVOList.add(toRemarkVOObject(remark, user));
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, remarkVOList);
}
return new ServiceResult(Status.SUCCESS, null, remarkVOList);
}
/**
*
*
* @param remarkId id
* @name removeRemark
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult removeRemark(BigInteger remarkId) {
try {
//判空
if (remarkId == null) {
throw new ServiceException(ServiceMessage.NOT_NULL.message);
}
//检查是否存在
if (remarkDao.getRemarkById(remarkId) == null) {
return new ServiceResult(Status.ERROR, ServiceMessage.NOT_FOUND.message, remarkId);
}
//删除
Remark remark = remarkDao.getRemarkById(remarkId);
if (remarkDao.delete(remark) != 1) {
return new ServiceResult(Status.ERROR, ServiceMessage.PLEASE_REDO.message, remark);
}
//将评论数减一
Moment moment = momentDao.getMomentById(remark.getMomentId());
moment.setRemark(moment.getRemark() - 1L);
if (momentDao.update(moment) != 1) {
throw new ServiceException("无法更新该朋友圈的评论数" + moment.toString());
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, ServiceMessage.DATABASE_ERROR.message, remarkId);
}
return new ServiceResult(Status.SUCCESS, ServiceMessage.OPERATE_SUCCESS.message, remarkId);
}
/**
*
*
* @param content
*/
private boolean isValidContent(String content) {
if (content == null || content.trim().isEmpty()) {
return false;
}
//如果内容经过过滤后与原来不一样,说明含有非法内容
String legalText = toLegalText(content);
if (content.equals(legalText)) {
return true;
}
return false;
}
/**
*
*
* @param remark
* @param user
* @name toRemarkVOObject
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
private RemarkVO toRemarkVOObject(Remark remark, User user) {
RemarkVO remarkVO = new RemarkVO();
remarkVO.setContent(remark.getContent());
remarkVO.setUserId(remark.getUserId());
remarkVO.setId(remark.getId());
remarkVO.setUserName(user.getName());
remarkVO.setUserPhoto(user.getPhoto());
remarkVO.setLove(remark.getLove());
remarkVO.setReply(remark.getReply());
remarkVO.setTime(remark.getTime());
remarkVO.setMomentId(remark.getMomentId());
return remarkVO;
}
}

@ -0,0 +1,145 @@
/*
* 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.MomentDao;
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.Moment;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.service.UploadService;
import com.hyc.wechat.service.constants.Status;
import javax.servlet.http.Part;
import java.io.IOException;
import java.math.BigInteger;
import static com.hyc.wechat.service.constants.ServiceMessage.*;
import static com.hyc.wechat.util.UploadUtils.toFileName;
import static com.hyc.wechat.util.UploadUtils.toPhotoName;
/**
*
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-06 02:28
*/
public class UploadServiceImpl implements UploadService {
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
private final MomentDao momentDao = (MomentDao) DaoProxyFactory.getInstance().getProxyInstance(MomentDao.class);
/**
* photo
*
* @param part
* @param id id
* @param tableName
* @return
* @name uploadPhoto
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Override
public ServiceResult uploadPhoto(Part part, Object id, String tableName) {
String fileName;
try {
fileName = toPhotoName(part);
if ("user".equalsIgnoreCase(tableName)) {
User user = new User();
user.setId(new BigInteger(String.valueOf(id)));
user.setPhoto(fileName);
if (userDao.update(user) != 1) {
return new ServiceResult(Status.ERROR, UPDATE_USER_FAILED.message, user);
}
} else if ("moment".equalsIgnoreCase(tableName)) {
Moment moment = new Moment();
moment.setId(new BigInteger(String.valueOf(id)));
moment.setPhoto(fileName);
if (momentDao.update(moment) != 1) {
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, moment);
}
} else {
return new ServiceResult(Status.ERROR, UNSUPPROT_TABLE.message, tableName);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, id);
} catch (IOException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, UPLOAD_FAILED.message, id);
}
return new ServiceResult(Status.SUCCESS, UPDATE_INFO_SUCCESS.message, fileName);
}
/**
*
*
* @param part
* @param id id
* @return
* @name uploadBackground
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Override
public ServiceResult uploadBackground(Part part, Object id) {
String fileName;
try {
fileName = toPhotoName(part);
User user = new User();
user.setId(new BigInteger(String.valueOf(id)));
user.setChatBackground(fileName);
if (userDao.update(user) != 1) {
return new ServiceResult(Status.ERROR, UPDATE_USER_FAILED.message, user);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, id);
} catch (IOException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, UPLOAD_FAILED.message, id);
}
return new ServiceResult(Status.SUCCESS, UPDATE_BACKGROUND_SUCCESS.message, fileName);
}
/**
*
*
* @param part
* @name uploadFile
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Override
public ServiceResult uploadFile(Part part) {
String fileName;
try {
fileName = toFileName(part);
} catch (IOException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, UPLOAD_FAILED.message, part);
}
return new ServiceResult(Status.SUCCESS, UPLOAD_SUCCESS.message, fileName);
}
}

@ -0,0 +1,393 @@
/*
* 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.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.User;
import com.hyc.wechat.service.UserService;
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;
import static com.hyc.wechat.service.constants.ServiceMessage.*;
import static com.hyc.wechat.util.Md5Utils.getDigest;
import static com.hyc.wechat.util.StringUtils.toLikeSql;
import static com.hyc.wechat.util.UUIDUtils.getUUID;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-02 03:19
*/
public class UserServiceImpl implements UserService {
/**
* 使
*/
public static final String VISITOR_EMAIL = "visitor@wechat.com";
private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
/**
* id
*/
public static final BigInteger systemId = BigInteger.valueOf(0);
/**
*
*/
public static final BigInteger hycId = BigInteger.valueOf(1);
/**
*
*
* @param user
* @return
*/
@Override
public ServiceResult checkRegister(User user) {
if(user==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
try {
//防止插入id
user.setId(null);
//检查邮箱格式
if (!isValidEmail(user.getEmail())) {
return new ServiceResult(Status.ERROR, EMAIL_FORMAT_INCORRECT.message, user);
}
//检查邮箱是否已被注册
if (userDao.getUserByEmail(user.getEmail()) != null) {
return new ServiceResult(Status.ERROR, EMAIL_ALREADY_USED.message, user);
}
//检查密码是否合法
if (!isValidPassword(user.getPassword())) {
return new ServiceResult(Status.ERROR, INVALID_PASSWORD.message, user);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, REGISTER_INFO_VALID.message, user);
}
/**
*
*
* @param user
* @return
*/
@Override
public ServiceResult insertUser(User user) {
if (user == null) {
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message, null);
}
try {
//插入前对用户的密码进行加密
user.setPassword(getDigest(user.getPassword()));
//给用户设置默认昵称(邮箱号)
if (user.getName() == null) {
user.setName(user.getEmail().trim());
}
if (userDao.insert(user) != 1) {
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
user = userDao.getUserByEmail(user.getEmail());
//插入后销毁用户对象中的密码数据
user.setPassword(null);
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, REGISTER_SUCCESS.message, user);
}
/**
*
*
* @param user
* @return
*/
@Override
public ServiceResult checkPassword(User user) {
if(user==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
User realUser;
try {
realUser = userDao.getUserByEmail(user.getEmail());
//检查账号是否存在
if (realUser == null) {
return new ServiceResult(Status.ERROR, ACCOUNT_NOT_FOUND.message, user);
}
//检查密码是否正确
if (user.getPassword() == null || !realUser.getPassword().equals(getDigest(user.getPassword()))) {
return new ServiceResult(Status.ERROR, PASSWORD_INCORRECT.message, user);
}
//成功后返回该用户的id信息
user.setId(realUser.getId());
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, LOGIN_SUCCESS.message, user);
}
/**
*
*
* @param wechatId
* @return
*/
@Override
public ServiceResult checkWechatId(String wechatId) {
if(wechatId==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
try {
//检查是否合法
if (!isValidWechatId(wechatId)) {
return new ServiceResult(Status.ERROR, WECHAT_ID_INVALID.message, wechatId);
}
//检查是否重复
if (userDao.getUserByWechatId(wechatId) != null) {
return new ServiceResult(Status.ERROR, WECHAT_ID_USED.message, wechatId);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, wechatId);
}
return new ServiceResult(Status.SUCCESS, WECHAT_ID_VALID.message, wechatId);
}
/**
*
*
* @param oldPwd
* @param newPwd
* @param userId id
* @return /
*/
@Override
public ServiceResult updatePwd(String oldPwd, String newPwd, BigInteger userId) {
if(oldPwd==null||newPwd==null||userId==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
try {
User user = userDao.getUserById(userId);
//检查账号是否存在
if (user == null) {
return new ServiceResult(Status.ERROR, ACCOUNT_NOT_FOUND.message, userId);
}
//检查旧密码是否正确
if (!user.getPassword().equals(getDigest(oldPwd))) {
return new ServiceResult(Status.ERROR, PASSWORD_INCORRECT.message, user);
}
//检查新密码是否合法
if(!isValidPassword(newPwd)){
return new ServiceResult(Status.ERROR, INVALID_PASSWORD.message, user);
}
//更新密码
user.setPassword(getDigest(newPwd));
if(userDao.update(user)!=1){
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
}catch (DaoException e){
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message,userId);
}
return new ServiceResult(Status.SUCCESS,UPDATE_PASSWORD_SUCCESS.message+newPwd,userId);
}
/**
* id
*
* @param id id
* @return
*/
@Override
public ServiceResult getUser(Object id) {
if(id==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
User user = null;
try {
user = userDao.getUserById(id);
if (user == null) {
return new ServiceResult(Status.ERROR, NO_USER_INFO.message, user);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, GET_INFO_SUCCESS.message, user);
}
/**
* ,
*
* @param user
* @return /
*/
@Override
public ServiceResult updateUser(User user) {
if(user==null){
return new ServiceResult(Status.ERROR, PARAMETER_NOT_ENOUGHT.message,null);
}
try {
//阻止更新用户密码
user.setPassword(null);
//阻止更新邮箱
user.setEmail(null);
if (userDao.update(user) != 1) {
return new ServiceResult(Status.ERROR, UPDATE_USER_FAILED.message, user);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, user);
}
return new ServiceResult(Status.SUCCESS, UPDATE_INFO_SUCCESS.message, user);
}
/**
*
*
* @param name
* @return
* @name listUserLikeName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Override
public ServiceResult listUserLikeName(String name) {
List<User> list = new LinkedList<>();
try {
//查找内容判空
if (name == null || name.trim().isEmpty()) {
return new ServiceResult(Status.ERROR, "关键词" + NOT_NULL.message, list);
}
//将关键词转换成模糊查询
String[] likeSql = toLikeSql(name);
for (String sql : likeSql) {
list.addAll(userDao.listLikeName(sql));
}
if (list.size() == 0) {
return new ServiceResult(Status.ERROR, NO_SUCH_USER.message, list);
}
} catch (DaoException e) {
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message, list);
}
return new ServiceResult(Status.SUCCESS, OPERATE_SUCCESS.message, list);
}
/**
*
*
* @name visitorLogin
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/9
*/
@Override
public ServiceResult visitorLogin() {
User visitor = new User();
//游客统一使用此邮箱,便于将来批量删除游客数据
visitor.setEmail(VISITOR_EMAIL);
visitor.setName("游客");
visitor.setWechatId(getUUID());
try {
if(userDao.insert(visitor)!=1){
return new ServiceResult(Status.ERROR,DATABASE_ERROR.message,visitor);
}
visitor = userDao.getUserByWechatId(visitor.getWechatId());
if(visitor==null){
return new ServiceResult(Status.ERROR,DATABASE_ERROR.message,null);
}
}catch (DaoException e){
e.printStackTrace();
return new ServiceResult(Status.ERROR, DATABASE_ERROR.message,visitor);
}
return new ServiceResult(Status.SUCCESS, LOGIN_SUCCESS.message,visitor);
}
/*
**************************************************************
*
**************************************************************
*/
private boolean isValidEmail(String email) {
if (email == null || email.trim().isEmpty()) {
return false;
}
String regex = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
return email.matches(regex);
}
private boolean isValidWechatId(String wechatId) {
if (wechatId == null || wechatId.trim().isEmpty()) {
return false;
}
String regex = "[\\w_]{6,20}$";
return wechatId.matches(regex);
}
private boolean isValidPassword(String password) {
if (password == null || password.trim().isEmpty()) {
return false;
}
String regex = "[\\w_]{6,20}$";
return password.matches(regex);
}
private boolean isValidPhoneNum(String number) {
if (number == null || number.trim().isEmpty()) {
return false;
}
String regex = "0?(13|14|15|17|18|19)[0-9]{9}";
return number.matches(regex);
}
private boolean isValidIdNumber(String number) {
if (number == null || number.trim().isEmpty()) {
return false;
}
String regex = "\\d{17}[\\d|x]|\\d{15}";
return number.matches(regex);
}
private boolean isValidNickName(String name) {
if (name == null || name.trim().isEmpty() || name.length() > 20) {
return false;
}
return true;
}
}

@ -0,0 +1,70 @@
/*
* 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.test;
import com.hyc.wechat.dao.MessageDao;
import com.hyc.wechat.dao.UserDao;
import com.hyc.wechat.factory.DaoProxyFactory;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.User;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description SQLHandler
* @date 2019-05-01 17:50
*/
public class TestDao {
public static void main(String[] args) {
// 通过DaoProxyFactory获取MessageDao的代理实例
MessageDao messageDao = (MessageDao) DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
// 以下是注释掉的代码,可能用于之前的测试或示例
// 通过DaoProxyFactory获取RecordDao的代理实例
// RecordDao recordDao = (RecordDao) DaoProxyFactory.getInstance().getProxyInstance(RecordDao.class);
// 删除聊天中的所有记录
// recordDao.deleteAllRecordInChat(210,59);
// 创建一个新用户并插入到数据库
// User user = new User();
// user.setName("testasdf中文");
// userDao.insert(user);
// 打印最后插入的用户ID
// System.out.println(userDao.getLastInsert().getId());
// 通过ID获取用户
// user = userDao.getUserById("50");
// 模糊查询用户名并打印查询到的记录数
// List list = userDao.listLikeName("%昵称%");
// System.out.println("查询到记录:" + list.size() + "条");
// 通过DaoProxyFactory获取ChatDao的代理实例
// ChatDao chatDao = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
// 将聊天转换为好友聊天
// chatDao.toFriendChat("4", "123");
// 创建一条朋友圈动态并插入到数据库
// Moment moment = new Moment();
// moment.setOwnerId(BigInteger.valueOf(0));
// moment.setContent("一条朋友圈");
// moment.setLove(10L);
// 通过DaoProxyFactory获取MomentDao的代理实例
// MomentDao momentDao = (MomentDao) DaoProxyFactory.getInstance().getProxyInstance(MomentDao.class);
// momentDao.insert(moment);
// 查询用户在聊天中的消息
// messageDao.listMessageByUserIdAndChatId("0","0",10,1000);
// 创建一个News对象但未使用
// News news = new News();
}
}

@ -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.test;
import com.hyc.wechat.dao.DataSource;
import com.hyc.wechat.dao.impl.DataSourceImpl;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.model.po.abs.BaseEntity;
import com.hyc.wechat.util.JdbcUtils;
import com.mysql.cj.x.protobuf.MysqlxDatatypes;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 16:49
*/
public class TestDataSource {
public static void main(String[] args) throws SQLException {
// 输出测试开始信息
System.out.println("测试直接从数据源获取连接");
// 获取数据源的单例实例
DataSource dataSource = DataSourceImpl.getInstance();
// 从数据源获取一个数据库连接
Connection conn = dataSource.getConnection();
// 输出获取到的连接信息
System.out.println("获取一个连接\n");
System.out.println(conn);
// 输出当前已创建的连接数
System.out.println("当前已创建连接数 = " + dataSource.getCurrentCount());
// 输出当前空闲的连接数
System.out.println("当前空闲连接数 = " + dataSource.getfreeCount());
// 释放刚才获取的连接
System.out.println("释放一个连接");
dataSource.freeConnection(conn);
// 循环获取和释放连接10次
for (int i = 0; i < 10; i++) {
conn = dataSource.getConnection();
System.out.println(conn);
// 使用工具类关闭连接
JdbcUtils.close(conn);
}
// 注意这里再次释放连接可能会导致空指针异常因为conn在循环中已经被关闭
System.out.println("释放一个连接");
dataSource.freeConnection(conn);
// 输出当前已创建的连接数
System.out.println("当前已创建连接数 = " + dataSource.getCurrentCount());
// 输出当前空闲的连接数
System.out.println("当前空闲连接数 = " + dataSource.getfreeCount());
}
}

@ -0,0 +1,50 @@
/*
* 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.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.User;
import java.util.Date;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description JSONJSONUser
* @date 2019-05-04 01:02
*/
public class TestJson {
public static void main(String[] args) {
// 解析JSON字符串为JSONObject对象
JSON json = JSONObject.parseObject(
"{\"id\":\"2\", " +
"\"wechat_id\":\"s\"}" // 注意这里wechat_id应该是User类中定义的字段名
);
// 将JSONObject对象转换为User类的实例
User user = JSONObject.toJavaObject(json,User.class);
// 打印User对象的id属性
System.out.println(user.getId());
// 打印User对象的wechat_id属性
System.out.println(user.getWechatId());
// 打印一个基于给定时间戳的日期字符串
System.out.println(new Date(1309237).toString());
// 打印User对象的字符串表示形式
System.out.println(user.toString());
}
}

@ -0,0 +1,48 @@
/*
* 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.test;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description 使log4j
* @date 2019-05-02 17:12
*/
public class TestLog {
public static void main(String[] args) {
// 调用log方法打印日志信息
log("日志信息");
}
/**
*
* @param logInfo
*/
public static void log(String logInfo){
// 1. 创建Logger实例传入当前类的Class对象
Logger log = Logger.getLogger(TestLog.class);
// 2. 配置Logger通常需要读取log4j.properties文件来设置日志级别和输出目的地
// 这里的配置方式是通过PropertyConfigurator类来加载log4j.properties文件
// PropertyConfigurator.configure("path/to/log4j.properties");
// 3. 使用debug级别打印日志信息
log.debug(logInfo);
}
}

@ -0,0 +1,66 @@
/*
* 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.test;
import com.hyc.wechat.model.po.Message;
import com.hyc.wechat.model.po.Moment;
import com.hyc.wechat.service.MessageService;
import com.hyc.wechat.service.MomentService;
import com.hyc.wechat.service.UserService;
import com.hyc.wechat.service.impl.MessageServiceImpl;
import com.hyc.wechat.service.impl.MomentServiceImpl;
import com.hyc.wechat.service.impl.UserServiceImpl;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-06 06:43
*/
public class TestService {
public static void main(String[] args) {
// 创建UserService实例并测试查询用户列表的方法
UserService userService = new UserServiceImpl();
List list = (List) userService.listUserLikeName("昵称").getData();
System.out.println("查询到:" + list.size() + "个用户");
// 创建MessageService实例并测试消息相关的服务方法
MessageService messageService = new MessageServiceImpl();
Message message = new Message();
message.setChatId(BigInteger.valueOf(44));
message.setSenderId(BigInteger.valueOf(0));
message.setContent("测试");
message.setTime(new Timestamp(1111111111L)); // 注意时间戳应该是long类型
messageService.insertMessage(message);
messageService.listAllMessage(0, 40, 1);
messageService.listUnreadMessage(0, 40, 1);
messageService.setAlreadyRead(0, 40);
// 创建MomentService实例并测试朋友圈相关的服务方法
MomentService momentService = new MomentServiceImpl();
Moment moment = new Moment();
moment.setOwnerId(BigInteger.valueOf(0));
moment.setContent("第一条朋友圈");
momentService.insertMoment(moment);
momentService.removeMoment(BigInteger.valueOf(8));
momentService.listMyMoment(BigInteger.valueOf(0), 1);
momentService.listNews(BigInteger.valueOf(184), 1);
}
}

@ -0,0 +1,154 @@
/*
* 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 com.alibaba.fastjson.JSONObject;
import com.hyc.wechat.dao.impl.SQLRunnerImpl;
import com.hyc.wechat.model.po.User;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.Map;
import static com.hyc.wechat.util.ReflectUtils.getFields;
import static com.hyc.wechat.util.ReflectUtils.getMethods;
import static com.hyc.wechat.util.StringUtils.toLegalText;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description Javabean
* @date 2019-04-15 00:47
*/
public class BeanUtils {
/**
* requestparameterMap
*
* @param map requestgetParameterMapMap
* @param clazz
* @return java.lang.Object
* @name toObject
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/15
*/
public static Object toObject(Map<String, String[]> map, Class clazz) {
/**
* request<br>
*
*/
LinkedList<Method> methods = null;
LinkedList<Field> fields = null;
Object obj;
try {
obj = clazz.newInstance();
methods = getMethods(obj);
fields = getFields(obj);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException("无法实例化类:" + clazz.getName());
}
for (Field f : fields) {
/**
* String
*/
Constructor cons = null;
try {
cons = f.getType().getConstructor(String.class);
} catch (Exception e) {
/**
*
*/
Logger logger = Logger.getLogger(BeanUtils.class);
logger.debug("从请求参数转化成对象时缺少String类型的构造器 " +f.getName() );
}
/**
*
*/
String[] param = map.get(f.getName());
if (param != null && param[0] != null) {
Object value = null;
try {
if (cons != null) {
/**
*
*/
param[0] = new String(param[0].getBytes(), StandardCharsets.UTF_8);
/**
*
*/
param[0] = toLegalText(param[0]);
value = cons.newInstance(param[0]);
}
for (Method m : methods) {
if (m.getName().equalsIgnoreCase(StringUtils.field2SetMethod(f.getName()))) {
m.invoke(obj, value);
}
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
/**
*
*/
Logger logger = Logger.getLogger(BeanUtils.class);
logger.debug("从请求参数转化成对象时无法初始化[属性] " +f.getName()+ " [属性值]" + param[0] );
}
}
}
return obj;
}
public static Object jsonToJavaObject(InputStream inputStream,Class targetClass) {
/**
* jsonjava
* @name jsonToJavaObject
* @param inputStream json
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/5
*/ JSONObject jsonObject = null;
try {
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder builder = new StringBuilder();
String jsonData;
while ((jsonData = streamReader.readLine()) != null) {
builder.append(jsonData);
}
jsonObject = JSONObject.parseObject(builder.toString());
Logger logger = Logger.getLogger(BeanUtils.class);
logger.info("从请求中获得json数据"+jsonObject.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return JSONObject.toJavaObject(jsonObject, targetClass);
}
}

@ -0,0 +1,60 @@
package com.hyc.wechat.util;
import com.alibaba.fastjson.JSON;
import com.hyc.wechat.controller.constant.RequestMethod;
import com.hyc.wechat.model.dto.ServiceResult;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description JSON
* @date 2019-05-02 17:35
*/
public class ControllerUtils {
/**
* methodRequestMethod
*
* @param name methodGETPOSTHTTP
* @return RequestMethodRequestMethod.INVALID_REQUEST
* @name valueOf
* @notice nullnamenullNullPointerException
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/20
* @see RequestMethod
*/
public static RequestMethod valueOf(String name) {
try {
name = name.toUpperCase().replaceAll("\\.", "_");
return RequestMethod.valueOf(name);
} catch (IllegalArgumentException | NullPointerException e) {
// 如果捕获到异常,说明请求参数没有匹配到任何服务,为无效请求
e.printStackTrace();
return RequestMethod.INVALID_REQUEST;
}
}
/**
* JSONHTTP
*
* @param resp HTTP
* @param result
* @throws IOException I/O
* @name returnJsonObject
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
public static void returnJsonObject(HttpServletResponse resp, ServiceResult result) throws IOException {
JSON json = (JSON) JSON.toJSON(result);
resp.getWriter().write(json.toJSONString());
Logger logger = Logger.getLogger(ControllerUtils.class);
logger.info(json.toJSONString());
}
}

@ -0,0 +1,223 @@
/*
* 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 com.hyc.wechat.dao.DataSource;
import com.hyc.wechat.dao.impl.DataSourceImpl;
import com.hyc.wechat.exception.DaoException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description
* @date 2019-04-08 03:00
*/
public class JdbcUtils {
private static DataSource dataSrc = DataSourceImpl.getInstance();
private final static String PROP_PATH = "db_config.properties";
private JdbcUtils() {
}
/**
*
*
* @return java.sql.Connection
* @name getConnection
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static Connection getConnection() {
return dataSrc.getConnection();
}
/**
* ,StatementResultSet
*
* @param conn
* @name close
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static void close(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
close(conn);
}
/**
*
*
* @param conn
* @name close
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
*
*
* @return int
* @name getfreeCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static int getfreeCount() {
return dataSrc.getfreeCount();
}
/**
*
*
* @return int
* @name getCurrentCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static int getCurrentCount() {
return dataSrc.getCurrentCount();
}
/**
* PreparedStatement
*
* @param ps sql
* @param params
* @name setParams
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/8
*/
public static void setParams(PreparedStatement ps, Object[] params) {
for (int i = 0; i < params.length; i++) {
}
if (params != null) {
for (int i = 0; i < params.length; i++) {
try {
ps.setObject(i + 1, params[i]);
} catch (SQLException e) {
e.printStackTrace();
throw new DaoException("预编译参数异常:" + ps.toString(), e);
}
}
}
}
/**
*
*
* @param obj
* @return java.lang.String
* @name getTableName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
public static String getTableName(Object obj) {
return obj == null ? null : getConfig(obj.getClass().getSimpleName());
}
/**
*
*
* @param clazz
* @return java.lang.String
* @name getTableName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
public static String getTableName(Class clazz) {
return clazz == null ? null : getConfig(clazz.getSimpleName());
}
/**
*
*
* @param tableName
* @return java.lang.Class
* @name getClass
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
public static Class getClass(String tableName) {
try {
return tableName == null ? null : Class.forName(getConfig(tableName));
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new DaoException("无法加载表名对应的类:" + tableName, e);
}
}
/**
* Dao
*
* @param key
* @return java.lang.String
* @name getConfig
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
public static String getConfig(String key) {
try {
Properties prop = new Properties();
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PROP_PATH));
return key == null ? null : prop.getProperty(key);
} catch (IOException e) {
e.printStackTrace();
throw new DaoException("无法加载配置文件:" + PROP_PATH, e);
}
}
}

@ -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);
}
}

@ -0,0 +1,79 @@
/*
* 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.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.LinkedList;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description
* @date 2019-04-20 02:28
*/
public class ReflectUtils {
/**
*
*
* @param obj
* @return LinkedList
*/
public static LinkedList<Method> getMethods(Object obj) {
return getMethods(obj.getClass());
}
/**
*
*
* @param clazz
* @return LinkedList
*/
public static LinkedList<Method> getMethods(Class clazz) {
LinkedList<Method> methods = new LinkedList<>();
for (Class cla = clazz; cla != Object.class; cla = cla.getSuperclass()) {
methods.addAll(Arrays.asList(cla.getDeclaredMethods()));
}
return methods;
}
/**
*
*
* @param obj
* @return LinkedList
*/
public static LinkedList<Field> getFields(Object obj) {
return getFields(obj.getClass());
}
/**
*
*
* @param clazz
* @return LinkedList
*/
public static LinkedList<Field> getFields(Class clazz) {
LinkedList<Field> fields = new LinkedList<>();
for (Class cla = clazz; cla != Object.class; cla = cla.getSuperclass()) {
fields.addAll(Arrays.asList(cla.getDeclaredFields()));
}
return fields;
}
}

@ -0,0 +1,135 @@
/*
* 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.util.ArrayList;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-04-15 17:28
*/
public class StringUtils {
/**
*
*
* @param keyWord
* @return
* @name toLikeSql
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
public static String[] toLikeSql(String keyWord) {
//TODO 添加每个字符的模糊搜索
ArrayList<String> list = new ArrayList<>();
String sql = "%" + keyWord + "%";
list.add(sql);
String[] strings = new String[list.size()];
return list.toArray(strings);
}
/**
* get
*
* @param field
* @return
* @name field2GetMethod
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
public static String field2GetMethod(String field) {
StringBuilder method = new StringBuilder("get" + field);
method.setCharAt(3, (char) (method.charAt(3) - 32));
return method.toString();
}
/**
* javamysql'_'
*
* @param field java
* @return mysql
* @name field2SqlField
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
public static String field2SqlField(String field) {
byte[] bytes = field.getBytes();
StringBuilder name = new StringBuilder();
for (byte aByte : bytes) {
if (aByte >= 'A' && aByte <= 'Z') {
name.append('_');
}
name.append((char) aByte);
}
return name.toString();
}
public static String field2SetMethod(String field) {
StringBuilder method = new StringBuilder("set" + field);
method.setCharAt(3, (char) (method.charAt(3) - 32));
return method.toString();
}
/**
*
*
* @param str
* @return
* @name
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/23
*/
public static String toLegalText(String str) {
if (str == null || str.trim().isEmpty()) {
return "";
}
str = toLegalTextIgnoreTag(str);
String htmlLabel = "<[^>]+>";
str = str.replaceAll(htmlLabel, "");
str = str.replace("\"", "");
str = str.replaceAll("\t|\r|\n", "");
return str;
}
/**
* html
*
* @param str
* @return
* @name
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/23
*/
public static String toLegalTextIgnoreTag(String str) {
if (str == null || str.trim().isEmpty()) {
return "";
}
String styleLabel = "<style[^>]*?>[\\s\\S]*?<\\/style>";
String scriptLabel = "<script[^>]*?>[\\s\\S]*?<\\/script>";
str = str.replaceAll(styleLabel, "");
str = str.replaceAll(scriptLabel, "");
return str;
}
}

@ -0,0 +1,32 @@
/*
* 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.util.UUID;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description uuid线
* @date 2019-04-16 20:51
*/
public class UUIDUtils {
public static String getUUID(){
String uuid = UUID.randomUUID().toString();
return uuid.replace("-","");
}
}

@ -0,0 +1,70 @@
/*
* 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 com.hyc.wechat.exception.ServiceException;
import com.hyc.wechat.model.po.Chat;
import com.hyc.wechat.model.po.User;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.io.IOException;
import static com.hyc.wechat.util.UUIDUtils.getUUID;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-04-19 13:31
*/
public class UploadUtils {
/**
* (photo)
*
* @return String
* @name toPhotoName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/19
*/
public static String toPhotoName(Part part) throws IOException {
String head = part.getHeader("Content-Disposition");
String filename = getUUID() + head.substring(head.lastIndexOf("."), head.lastIndexOf("\""));
part.write("photo/"+filename);
return filename;
}
/**
* (file)
*
* @return String
* @name toFileName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
public static String toFileName(Part part) throws IOException {
String head = part.getHeader("Content-Disposition");
String filename = getUUID() + head.substring(head.lastIndexOf("."), head.lastIndexOf("\""));
part.write("file/"+filename);
return filename;
}
}

@ -0,0 +1,83 @@
/*
* 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.model.vo;
import com.hyc.wechat.model.po.Member;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-10 05:22
*/
public class MemberVO extends Member {
// 群成员的昵称
private String name;
// 群成员的个性签名
private String signature;
// 群成员的头像URL
private String photo;
/**
*
* @return
*/
public String getSignature() {
return signature;
}
/**
*
* @return
*/
public String getName() {
return name;
}
/**
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @param signature
*/
public void setSignature(String signature) {
this.signature = signature;
}
/**
* URL
* @return URL
*/
public String getPhoto() {
return photo;
}
/**
* URL
* @param photo URL
*/
public void setPhoto(String photo) {
this.photo = photo;
}
}

@ -0,0 +1,70 @@
/*
* 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.model.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.model.po.Message;
import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 01:53
*/
public class MessageVO extends Message {
// 发送者的昵称
@JSONField(name = "sender_name")
private String senderName;
// 发送者的头像URL
@JSONField(name = "sender_photo")
private String senderPhoto;
/**
*
* @return
*/
public String getSenderName() {
return senderName;
}
/**
*
* @param senderName
*/
public void setSenderName(String senderName) {
this.senderName = senderName;
}
/**
* URL
* @return URL
*/
public String getSenderPhoto() {
return senderPhoto;
}
/**
* URL
* @param senderPhoto URL
*/
public void setSenderPhoto(String senderPhoto) {
this.senderPhoto = senderPhoto;
}
}

@ -0,0 +1,146 @@
/*
* 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.model.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.model.po.Moment;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 20:12
*/
public class MomentVO extends Moment {
// 朋友圈动态发布者的昵称
@JSONField(name = "user_name")
private String userName;
// 标记该动态是否被点赞
private Boolean loved;
// 标记该动态是否被分享
private Boolean shared;
// 标记该动态是否被查看
private Boolean viewed;
// 标记该动态是否被收藏
private Boolean collected;
// 朋友圈动态发布者的头像URL
@JSONField(name = "user_photo")
private String userPhoto;
/**
* URL
* @return URL
*/
public String getUserPhoto() {
return userPhoto;
}
/**
* URL
* @param userPhoto URL
*/
public void setUserPhoto(String userPhoto) {
this.userPhoto = userPhoto;
}
/**
*
* @return
*/
public String getUserName() {
return userName;
}
/**
*
* @param userName
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
*
* @return truefalse
*/
public boolean getLoved() {
return loved;
}
/**
*
* @param loved truefalse
*/
public void setLoved(boolean loved) {
this.loved = loved;
}
/**
*
* @return truefalse
*/
public boolean getShared() {
return shared;
}
/**
*
* @param shared truefalse
*/
public void setShared(boolean shared) {
this.shared = shared;
}
/**
*
* @return truefalse
*/
public boolean getViewed() {
return viewed;
}
/**
*
* @param viewed truefalse
*/
public void setViewed(boolean viewed) {
this.viewed = viewed;
}
/**
*
* @return truefalse
*/
public boolean getCollected() {
return collected;
}
/**
*
* @param collected truefalse
*/
public void setCollected(boolean collected) {
this.collected = collected;
}
}

@ -0,0 +1,68 @@
/*
* 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.model.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.hyc.wechat.model.po.Remark;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-14 02:09
*/
public class RemarkVO extends Remark {
// 评论发布者的昵称
@JSONField(name = "user_name")
private String userName;
// 评论发布者的头像URL
@JSONField(name = "user_photo")
private String userPhoto;
/**
*
* @return
*/
public String getUserName() {
return userName;
}
/**
*
* @param userName
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* URL
* @return URL
*/
public String getUserPhoto() {
return userPhoto;
}
/**
* URL
* @param userPhoto URL
*/
public void setUserPhoto(String userPhoto) {
this.userPhoto = userPhoto;
}
}

@ -1,17 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/wechat-master/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/wechat-master/web" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">

@ -1,16 +1,31 @@
// test
/*
* 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.controller.annotation;
package com.hyc.wechat.controller.annotation; // 定义注解所在的包名
import java.lang.annotation.*;
import java.lang.annotation.*; // 导入Java标准注解库
// 定义一个名为ControllerConfig的注解
@Retention(value = RetentionPolicy.RUNTIME) // 指定注解的生命周期RUNTIME表示注解将被保留到运行时可以通过反射读取
@Target(value = ElementType.TYPE) // 指定注解可以应用的目标类型TYPE表示注解可以用于类、接口或枚举声明
public @interface ControllerConfig { // 使用@interface关键字定义注解
// 定义一个名为path的属性方法默认值为空字符串
// 该属性用于配置控制器类的路径
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description ActionProviderurl
* @date 2019-05-02 11:28
*/
@Documented
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.TYPE)
public @interface ControllerConfig {
String path() default "";
}

@ -1,11 +1,31 @@
/*
* 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.controller.constant;
// 定义一个名为ControllerMessage的枚举类用于存储控制器相关的消息常量
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-03 13:11
*/
public enum ControllerMessage {
/**
*
*/
//枚举常量,表示用户当前处于游客身份
YOU_ARE_VISITOR("您现在处于游客身份,该服务并未对游客开放,如需使用请先注册一个账号"),
/*
@ -16,24 +36,21 @@ public enum ControllerMessage {
/**
*
*/
// 枚举常量,用于分隔不同类型的消息常量,系统错误码部分
SYSTEM_EXECEPTION("服务器发生了严重异常,无法提供服务"),
/**
*
*/
//// 枚举常量,表示请求参数错误
REQUEST_INVALID("您的请求参数不足或错误,系统无法处理您的请求");
// 枚举成员变量,用于存储消息文本
public String message;
// 枚举的构造方法,用于在创建枚举实例时初始化成员变量
ControllerMessage(String message) {
this.message = message;
}
// 公共方法,用于获取枚举实例中存储的消息文本
public String getMessage() {
return message;
}
// 私有方法,用于设置枚举实例中的消息文本
private void setMessage(String message) {
this.message = message;
}

@ -1,5 +1,30 @@
/*
* 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.controller.constant;
/**
* requestmethod
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description
* @date 2019-04-18 12:45
*/
public enum RequestMethod {
/**

@ -1,8 +1,32 @@
/*
* 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.controller.constant;
// 定义一个名为WebPage的枚举类用于表示不同的网页路径
/**
*
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description
* @date 2019-04-18 12:48
*/
public enum WebPage {
/**
*
*/
@ -45,8 +69,6 @@ public enum WebPage {
PICTRUES_JSP;
@Override
// 重写toString方法以提供枚举常量的字符串表示形式
// 将枚举名称转换为小写,并用点号替换下划线,以符合网页文件的命名习惯
public String toString() {
return "/"+super.toString().toLowerCase().replaceAll("_", ".");
}

@ -1,73 +1,87 @@
package com.hyc.wechat.controller.impl.filter; // 定义过滤器所在的包名
/*
* 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.
*/
import com.hyc.wechat.controller.constant.ControllerMessage; // 导入控制器消息常量类
import com.hyc.wechat.controller.constant.WebPage; // 导入网页常量类
import org.apache.log4j.Logger; // 导入log4j日志记录器
package com.hyc.wechat.controller.impl.filter;
import javax.servlet.*; // 导入Servlet API
import javax.servlet.annotation.WebFilter; // 导入WebFilter注解
import javax.servlet.annotation.WebInitParam; // 导入WebInitParam注解
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest类
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse类
import java.io.IOException; // 导入IOException类
import com.hyc.wechat.controller.constant.ControllerMessage;
import com.hyc.wechat.controller.constant.WebPage;
import org.apache.log4j.Logger;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-02 22:56
*/
// 使用@WebFilter注解定义一个名为"EncodingFilter"的过滤器
// 过滤器将作用于所有的URL模式"/*"
// 并且具有一个初始化参数"ENCODING",其值为"UTF-8"
@WebFilter(
filterName = "EncodingFilter",
urlPatterns = {"/*"},
urlPatterns = {"/*"}, servletNames = {"/*"},
initParams = {
@WebInitParam(name = "ENCODING", value = "UTF-8")
}
)
public class EncodingFilter implements Filter { // 实现Filter接口
public class EncodingFilter implements Filter {
private String ENCODING = null; // 用于存储字符编码的成员变量
private String ENCODING = null;
@Override
public void init(FilterConfig config) { // 过滤器初始化方法
// 从FilterConfig获取初始化参数"ENCODING"
public void init(FilterConfig config) {
this.ENCODING = config.getInitParameter("ENCODING");
}
@Override
public void destroy() { // 过滤器销毁方法
// 在此可以释放资源,但本例中无需实现
public void destroy() {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {
// 类型转换以便使用HttpServletRequest和HttpServletResponse的方法
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse resp = (HttpServletResponse) servletResponse;
try {
// 设置请求和响应的字符编码
req.setCharacterEncoding(ENCODING);
resp.setContentType("text/html;charset=utf-8");
resp.setCharacterEncoding(ENCODING);
// 设置CORS相关响应头允许跨域请求
resp.addHeader("Access-Control-Allow-Origin", "*");
resp.addHeader("Access-Control-Allow-Headers",
"origin, content-type, accept, x-requested-with, sid, mycustom, smuser");
resp.addHeader("Access-Control-Allow-Methods", "*");
resp.addHeader("Access-Control-Max-Age", "100");
resp.addHeader("Access-Control-Allow-Credentials", "false");
// 继续执行过滤链中的下一个过滤器或Servlet
filterChain.doFilter(servletRequest, servletResponse);
} catch (IOException | ServletException e) {
e.printStackTrace(); // 打印异常堆栈信息
e.printStackTrace();
try {
// 设置请求属性,传递系统异常信息
req.setAttribute("message", ControllerMessage.SYSTEM_EXECEPTION.message);
// 转发请求到错误页面
req.getRequestDispatcher(WebPage.ERROR_JSP.toString()).forward(req, resp);
} catch (ServletException | IOException ex) {
ex.printStackTrace(); // 打印转发过程中可能出现的异常堆栈信息
ex.printStackTrace();
}
}
// 获取日志记录器并记录请求信息
Logger logger = Logger.getLogger(EncodingFilter.class);
logger.info("[请求url] : " + req.getRequestURI() + " [请求参数] " + req.getQueryString());
}
}

@ -1,80 +1,100 @@
// 导入必要的库
/*
* 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.controller.impl.filter;
import com.hyc.wechat.controller.constant.ControllerMessage; // 导入控制器消息常量类
import com.hyc.wechat.controller.constant.RequestMethod; // 导入请求方法常量类
import com.hyc.wechat.controller.constant.WebPage; // 导入网页常量类
import com.hyc.wechat.model.dto.ServiceResult; // 导入服务结果数据传输对象
import com.hyc.wechat.model.po.User; // 导入用户持久化对象
import com.hyc.wechat.provider.UserProvider; // 导入用户提供者类
import com.hyc.wechat.service.constants.Status; // 导入状态常量类
import com.hyc.wechat.service.impl.UserServiceImpl; // 导入用户服务实现类
import com.hyc.wechat.controller.constant.ControllerMessage;
import com.hyc.wechat.controller.constant.RequestMethod;
import com.hyc.wechat.controller.constant.WebPage;
import com.hyc.wechat.model.dto.ServiceResult;
import com.hyc.wechat.model.po.User;
import com.hyc.wechat.provider.UserProvider;
import com.hyc.wechat.service.constants.Status;
import com.hyc.wechat.service.impl.UserServiceImpl;
import javax.servlet.*; // 导入Servlet API
import javax.servlet.annotation.WebFilter; // 导入WebFilter注解
import javax.servlet.annotation.WebInitParam; // 导入WebInitParam注解
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest类
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse类
import javax.servlet.http.HttpSession; // 导入HttpSession类
import java.io.IOException; // 导入IOException类
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import static com.hyc.wechat.util.ControllerUtils.returnJsonObject; // 导入返回JSON对象的工具方法
import static com.hyc.wechat.util.ControllerUtils.returnJsonObject;
// 使用@WebFilter注解定义一个名为"LoginFilter"的过滤器
// 过滤器将作用于所有的URL模式"/*"
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-09 15:41
*/
@WebFilter(
filterName = "LoginFilter",
urlPatterns = {"/*"},
urlPatterns = {"/*"}, servletNames = {"/*"},
initParams = {
@WebInitParam(name = "ENCODING", value = "UTF-8")
})
public class LoginFilter implements Filter { // 实现Filter接口
public class LoginFilter implements Filter {
private final UserProvider userProvider = new UserProvider(); // 创建用户提供者实例
private final UserProvider userProvider = new UserProvider();
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest; // 类型转换
HttpServletResponse resp = (HttpServletResponse) servletResponse; // 类型转换
String method = req.getParameter("method"); // 获取请求方法参数
String uri = req.getRequestURI(); // 获取请求URI
String contextPath = req.getContextPath(); // 获取上下文路径
String path = uri.substring(contextPath.length()); // 获取请求路径
HttpSession sess = req.getSession(false); // 获取当前会话如果不存在则返回null
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse resp = (HttpServletResponse) servletResponse;
String method = req.getParameter("method");
String uri = req.getRequestURI();
String contextPath = req.getContextPath();
String path = uri.substring(contextPath.length());
HttpSession sess = req.getSession(false);
// 尝试自动登录
//尝试自动登陆
userProvider.autoLogin(req);
sess = req.getSession(); // 获取或创建会话
// 放行登录和注册相关请求
sess=req.getSession();
//放行登陆注册
if (sess == null || sess.getAttribute("login") == null) {
if (WebPage.LOGIN_JSP.toString().equalsIgnoreCase(path) || // 登录页面
WebPage.REGISTER_JSP.toString().equalsIgnoreCase(path) || // 注册页面
RequestMethod.LOGIN_DO.toString().equalsIgnoreCase(method) || // 登录操作
RequestMethod.REGISTER_DO.toString().equalsIgnoreCase(method) || // 注册操作
path.endsWith("logo.png") || path.endsWith(".js") || path.endsWith("agreement.html")) { // 资源文件
filterChain.doFilter(req, resp); // 继续执行过滤链
if (WebPage.LOGIN_JSP.toString().equalsIgnoreCase(path) ||
(WebPage.REGISTER_JSP.toString()).equalsIgnoreCase(path) ||
(RequestMethod.LOGIN_DO.toString()).equalsIgnoreCase(method) ||
(RequestMethod.REGISTER_DO.toString()).equalsIgnoreCase(method) ||
path.endsWith("logo.png") || path.endsWith(".js") || path.endsWith("agreement.html")) {
filterChain.doFilter(req, resp);
return;
} else {
// 检查会话是否有'login'属性,没有则重定向到登录界面
//检查session是否有'login'属性,没有则重定向到登陆界面
if (sess == null || sess.getAttribute("login") == null) {
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req, resp); // 转发到登录页面
req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req, resp);
return;
}
}
} else {
// 已登录用户检查登录身份
}else {
//已登陆用户检查登陆身份
if (path.startsWith("/wechat/moment") || path.startsWith("/wechat/friend")) {
// 检查登录身份
User user = (User) sess.getAttribute("login"); // 获取登录用户信息
//检查登陆身份
User user = (User) sess.getAttribute("login");
if (user != null && UserServiceImpl.VISITOR_EMAIL.equals(user.getEmail())) {
// 游客不可使用
returnJsonObject(resp, new ServiceResult(Status.ERROR, ControllerMessage.YOU_ARE_VISITOR.message, null)); // 返回错误信息
//游客不可使用
returnJsonObject(resp, new ServiceResult(Status.ERROR, ControllerMessage.YOU_ARE_VISITOR.message, null));
return;
}
}
}
filterChain.doFilter(req, resp); // 继续执行过滤链
filterChain.doFilter(req, resp);
}
}

@ -1,3 +1,18 @@
/*
* 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.controller.impl.listener;
@ -10,20 +25,18 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* ServletWebWeb
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description servlet
* @date 2019-05-01 0844
*/
@WebListener
public class ServletContextListener implements javax.servlet.ServletContextListener {
/**
* 使ConcurrentHashMap线
*/
private static final ConcurrentHashMap<String, Provider> providerMap = new ConcurrentHashMap<>();
/**
* Servlet
* @param sce Servlet
*/
@Override
public void contextInitialized(ServletContextEvent sce) {

@ -1,65 +1,90 @@
// 导入必要的库
/*
* 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.controller.impl.servlet;
import com.hyc.wechat.controller.annotation.ControllerConfig; // 导入自定义的ControllerConfig注解
import com.hyc.wechat.controller.constant.ControllerMessage; // 导入控制器消息常量类
import com.hyc.wechat.provider.Provider; // 导入Provider接口
import com.hyc.wechat.util.ControllerUtils; // 导入控制器工具类
import org.apache.log4j.Logger; // 导入log4j日志记录器
import com.hyc.wechat.controller.annotation.ControllerConfig;
import com.hyc.wechat.controller.constant.ControllerMessage;
import com.hyc.wechat.provider.Provider;
import com.hyc.wechat.util.ControllerUtils;
import org.apache.log4j.Logger;
import javax.servlet.annotation.MultipartConfig; // 导入MultipartConfig注解
import javax.servlet.annotation.WebServlet; // 导入WebServlet注解
import javax.servlet.http.HttpServlet; // 导入HttpServlet类
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest类
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse类
import java.io.IOException; // 导入IOException类
import java.util.Map; // 导入Map接口
import java.util.Set; // 导入Set接口
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import static com.hyc.wechat.provider.Provider.toErrorPage; // 导入Provider类的静态方法toErrorPage
import static com.hyc.wechat.provider.Provider.toErrorPage;
// 使用@MultipartConfig注解配置文件上传的临时存储位置
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description controller
* @date 2019-05-02 03:28
*/
@MultipartConfig(location = "/home/pan/tomcat/webapps/wechat/upload")
//@MultipartConfig(location = "C:\\Users\\Misterchaos\\Documents\\Java Develop Workplaces\\IDEA workspace\\wechat\\out\\artifacts\\wechat_war_exploded\\upload")
@WebServlet("/wechat/*") // 使用@WebServlet注解映射@WebServlet到/wechat/*路径
@WebServlet("/wechat/*")
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
this.doPost(req, resp); // 将GET请求转发到doPost方法处理
this.doPost(req, resp);
}
/**
* urlProvider
*
* @param req
* @param resp
* @param req
* @param resp
* @name doPost
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Map<String, Provider> providerMap = (Map<String, Provider>) getServletContext().getAttribute("providerMap"); // 从ServletContext获取Provider映射
String url = req.getRequestURI(); // 获取请求的URI
Set<String> keys = providerMap.keySet(); // 获取Provider映射的键集合
Logger logger = Logger.getLogger(MyServlet.class); // 获取日志记录器
logger.info("[请求url:] " + url + " [匹配provider]: " + url.substring(14)); // 记录请求的URL和尝试匹配的Provider
boolean isMatch = false; // 标记是否找到匹配的Provider
for (String key : keys) { // 遍历Provider映射的键集合
// 解析注解中的path信息匹配ActionProvider
String path = providerMap.get(key).getPath(); // 获取Provider的路径
if (url.substring(14).equalsIgnoreCase(path)) { // 检查请求的路径是否与Provider的路径匹配
providerMap.get(key).doAction(req, resp); // 执行匹配的Provider的doAction方法
logger.info("provider 分发完毕"); // 记录Provider分发完成
isMatch = true; // 设置匹配标志为true
Map<String, Provider>providerMap = (Map<String, Provider>) getServletContext().getAttribute("providerMap");
String url = req.getRequestURI();
Set<String> keys = providerMap.keySet();
Logger logger = Logger.getLogger(MyServlet.class);
logger.info("[请求url:]"+url+"[匹配provider]:"+url.substring(14));
boolean isMatch=false;
for (String key : keys) {
//解析注解中的path信息匹配ActionProvider
String path =providerMap.get(key).getPath();
if (url.substring(14).equalsIgnoreCase(path)) {
providerMap.get(key).doAction(req, resp);
logger.info("provider 分发完毕");
isMatch=true;
}
}
if (!isMatch) { // 如果没有找到匹配的Provider
toErrorPage(ControllerMessage.REQUEST_INVALID.message, req, resp); // 转发到错误页面
logger.info("该请求没有匹配provider: " + url.substring(14)); // 记录没有匹配的Provider
return; // 结束方法执行
if(!isMatch){
toErrorPage(ControllerMessage.REQUEST_INVALID.message,req,resp);
logger.info("该请求没有匹配provider :"+url.substring(14));
return;
}
// logger.info("响应结果 "+resp.getOutputStream()); // 这行代码被注释掉了,可能是为了调试目的
// logger.info("响应结果 "+resp.getOutputStream());
}
}

@ -1,11 +1,28 @@
/*
* 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;
import com.hyc.wechat.dao.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Dao
* @date 2019-05-01 17:11
*/
public interface BaseDao {
@ -24,6 +41,8 @@ public interface BaseDao {
* @param obj
* @name insert
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Insert()
int insert(Object obj);
@ -37,6 +56,8 @@ public interface BaseDao {
* @name update
* @notice null<br>
* null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Update()
int update(Object obj);
@ -47,6 +68,8 @@ public interface BaseDao {
* @param obj
* @name delete
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Delete()
int delete(Object obj);

@ -1,3 +1,18 @@
/*
* 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;
@ -9,7 +24,9 @@ import com.hyc.wechat.model.po.Chat;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description CRUD
* @date 2019-05-03 02:18
*/
public interface ChatDao extends BaseDao {
@ -23,6 +40,8 @@ public interface ChatDao extends BaseDao {
* @return
* @name getChatById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = Chat.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
@ -35,6 +54,8 @@ public interface ChatDao extends BaseDao {
* @return
* @name listByUserId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/3
*/
@Result(entity = Chat.class, returns = ResultType.LIST)
@Query(value = "select c.id,c.number,c.owner_id,c.name,c.type,c.member,c.photo,c.status,c.gmt_create,c.gmt_modified " +
@ -51,6 +72,8 @@ public interface ChatDao extends BaseDao {
* @return
* @name toFriendChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/5
*/
@Result(entity = Chat.class, returns = ResultType.OBJECT)
@Query(value = "select c.id,c.number,c.owner_id,u.name as name,c.member,u.photo as photo,c.type,c.status,c.gmt_create,c.gmt_modified " +
@ -65,6 +88,8 @@ public interface ChatDao extends BaseDao {
* @return
* @name getByChatNumber
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Result(entity = Chat.class,returns = ResultType.OBJECT)
@Query(value = "select "+ALL_FIELD+" from "+TABLE+" where number = ? ")

@ -1,3 +1,18 @@
/*
* 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;
@ -6,8 +21,10 @@ import com.hyc.wechat.exception.DaoException;
import java.sql.Connection;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Dao
* @date 2019-05-01 16:33
*/
public interface DataSource {
/**
@ -17,6 +34,8 @@ public interface DataSource {
* @throws DaoException
* @name getConnection
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
Connection getConnection() throws DaoException;
@ -26,6 +45,8 @@ public interface DataSource {
*
* @param conn
* @name freeConnection
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
void freeConnection(Connection conn);
@ -35,6 +56,8 @@ public interface DataSource {
* @param conn
* @return java.sql.Connection
* @name createConnection
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
void destroyConnection(Connection conn);
@ -44,6 +67,8 @@ public interface DataSource {
*
* @return int
* @name getCurrentCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
int getCurrentCount();
@ -52,6 +77,8 @@ public interface DataSource {
*
* @return int
* @name getfreeCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
int getfreeCount();
}

@ -1,3 +1,18 @@
/*
* 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;
@ -11,8 +26,10 @@ import java.math.BigInteger;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description CRUD
* @date 2019-05-02 01:59
*/
public interface FriendDao extends BaseDao {
@ -27,6 +44,8 @@ public interface FriendDao extends BaseDao {
* @return
* @name getFriendByUIDAndFriendId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Result(entity = Friend.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where user_id = ? and friend_id = ? ")
@ -40,6 +59,8 @@ public interface FriendDao extends BaseDao {
* @return
* @name listByUserId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Result(entity = Friend.class, returns = ResultType.LIST)
@Query(value = "select f.id,f.user_id,f.friend_id,f.chat_id,f.group_id,f.alias,f.description,u.photo as photo,f.status,f.gmt_create,f.gmt_modified " +
@ -53,6 +74,8 @@ public interface FriendDao extends BaseDao {
* @param id id
* @name getFriendById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Friend.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")

@ -1,3 +1,18 @@
/*
* 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;
@ -10,7 +25,9 @@ import java.math.BigInteger;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description user_chatCRUD
* @date 2019-05-03 13:05
*/
public interface MemberDao extends BaseDao {
String TABLE = "member";
@ -23,6 +40,8 @@ public interface MemberDao extends BaseDao {
* @return
* @name getMemberById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = Member.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
@ -36,6 +55,8 @@ public interface MemberDao extends BaseDao {
* @return
* @name getMemberByUIdAndChatId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = Member.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where user_id = ? and chat_id = ? ")
@ -48,6 +69,8 @@ public interface MemberDao extends BaseDao {
* @param chatId id
* @return
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/5
*/
@Result(entity = Member.class, returns = ResultType.LIST)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where chat_id = ? ")

@ -1,3 +1,18 @@
/*
* 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;
@ -10,7 +25,9 @@ import java.math.BigInteger;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description messageCRUD
* @date 2019-05-03 13:06
*/
public interface MessageDao extends BaseDao {
@ -26,6 +43,8 @@ public interface MessageDao extends BaseDao {
* @param chatId id
* @return
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = Message.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where sender_id = ? and chat_id = ? and time = ? ")
@ -41,6 +60,8 @@ public interface MessageDao extends BaseDao {
* @param offset
* @name listMessageByUserIdAndChatId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Message.class, returns = ResultType.LIST)
@Query(value = "select m.id, m.sender_id, m.chat_id, m.content , m.type , m.time ,m.status , " +
@ -58,6 +79,8 @@ public interface MessageDao extends BaseDao {
* @param offset
* @name listMessageByUserIdAndChatId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Message.class, returns = ResultType.LIST)
@Query(value = "select m.id, m.sender_id, m.chat_id, m.content , m.type , m.time ,m.status , " +
@ -73,6 +96,8 @@ public interface MessageDao extends BaseDao {
* @param chatId id
* @param fileName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Message.class, returns = ResultType.LIST)
@Query(value = "select m.id, m.sender_id, m.chat_id, m.content , m.type , m.time ,m.status , " +
@ -89,6 +114,8 @@ public interface MessageDao extends BaseDao {
* @param limit
* @param offset
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Message.class, returns = ResultType.LIST)
@Query(value = "select m.id, m.sender_id, m.chat_id, m.content , m.type , m.time ,m.status , " +
@ -104,6 +131,8 @@ public interface MessageDao extends BaseDao {
* @param limit
* @param offset
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Message.class, returns = ResultType.LIST)
@Query(value = "select m.id, m.sender_id, m.chat_id, m.content , m.type , m.time ,m.status , " +

@ -25,7 +25,9 @@ import com.hyc.wechat.model.po.Moment;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description CRUD
* @date 2019-05-07 11:55
*/
public interface MomentDao extends BaseDao {
String TABLE = "moment";
@ -37,6 +39,8 @@ public interface MomentDao extends BaseDao {
* @param id id
* @name geMomentById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = Moment.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
@ -48,6 +52,8 @@ public interface MomentDao extends BaseDao {
* @param ownerId id
* @param stauts
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/8
*/
@Result(entity = Moment.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? and status = ? ")
@ -62,6 +68,8 @@ public interface MomentDao extends BaseDao {
* @param offset
* @name listMyMomentByOwnerIdDesc
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Moment.class, returns = ResultType.LIST)
@Query("select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? order by time desc limit ? offset ? ")
@ -75,6 +83,8 @@ public interface MomentDao extends BaseDao {
* @param offset
* @name listMyMomentByOwnerId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = Moment.class, returns = ResultType.LIST)
@Query("select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? order by time limit ? offset ? ")
@ -89,6 +99,8 @@ public interface MomentDao extends BaseDao {
* @param offset
* @name loadPhoto
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
@Result(entity = Moment.class, returns = ResultType.LIST)
@Query("select photo from " + TABLE + " where owner_id = ? order by time desc limit ? offset ? ")

@ -1,3 +1,18 @@
/*
* 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;
@ -9,7 +24,9 @@ import com.hyc.wechat.model.po.News;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description CRUD
* @date 2019-05-07 18:47
*/
public interface NewsDao extends BaseDao {
String TABLE = "news";
@ -23,6 +40,8 @@ public interface NewsDao extends BaseDao {
* @param offset
* @name listNewsByUserId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = News.class, returns = ResultType.LIST)
@Query("select " + ALL_FIELD + " from " + TABLE + " where user_id = ? order by gmt_create desc limit ? offset ? ")
@ -36,6 +55,8 @@ public interface NewsDao extends BaseDao {
* @param userId id
* @name getNewsByMomentId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Result(entity = News.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where moment_id = ? and user_id = ? ")

@ -1,3 +1,18 @@
/*
* 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;
@ -5,7 +20,9 @@ import com.hyc.wechat.dao.annotation.Delete;
import com.hyc.wechat.dao.annotation.Update;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description CRUD
* @date 2019-05-06 21:41
*/
public interface RecordDao extends BaseDao {
String TABLE = "record";
@ -20,6 +37,8 @@ public interface RecordDao extends BaseDao {
* @param chatId id
* @name updateStatusInChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/7
*/
@Update("update " + TABLE + " as r inner join message as m set r.status = ? where r.user_id = ? and r.message_id = m.id and m.chat_id = ?")
void updateStatusInChat(Object status, Object userId ,Object chatId);
@ -32,6 +51,8 @@ public interface RecordDao extends BaseDao {
* @param chatId id
* @name deleteAllRecordInChat
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/10
*/
@Update("delete r from " + TABLE + " r inner join message m on r.message_id = m.id where r.user_id = ? and m.chat_id = ? " )
void deleteAllRecordInChat(Object userId , Object chatId);

@ -1,3 +1,18 @@
/*
* 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;
@ -10,7 +25,9 @@ import com.hyc.wechat.model.po.Remark;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-14 01:12
*/
public interface RemarkDao extends BaseDao{
String TABLE = "remark";
@ -24,6 +41,8 @@ public interface RemarkDao extends BaseDao{
* @param offset
* @name listRemarkDesc
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Result(entity = Remark.class, returns = ResultType.LIST)
@Query("select " + ALL_FIELD + " from " + TABLE + " where moment_id = ? order by time limit ? offset ? ")
@ -35,6 +54,8 @@ public interface RemarkDao extends BaseDao{
* @param id id
* @name geRemarkById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/14
*/
@Result(entity = Remark.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")

@ -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 {
}

@ -1,3 +1,18 @@
/*
* 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;
@ -5,8 +20,10 @@ package com.hyc.wechat.dao;
import java.sql.ResultSet;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program XHotel
* @description
* @date 2019-04-09 15:06
*/
public interface ResultMapper {
/**
@ -15,6 +32,8 @@ public interface ResultMapper {
* @param rs
* @return java.lang.Object
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
Object doMap(ResultSet rs);
}

@ -1,9 +1,26 @@
//t
/*
* 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>
* @program XHotel
* @description sql
* @date 2019-04-11 17:55
*/
public interface SQLMapper {
@ -15,6 +32,8 @@ public interface SQLMapper {
* @return sql
* @name doMap
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/12
*/
String doMap(Object... params);

@ -1,4 +1,19 @@
//导入必要库
/*
* 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;
import com.hyc.wechat.dao.annotation.Insert;
@ -6,8 +21,10 @@ import com.hyc.wechat.dao.annotation.Insert;
import java.util.LinkedList;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description SQL
* @date 2019-05-01 17:34
*/
public interface SQLRunner {
@ -31,6 +48,8 @@ public interface SQLRunner {
* @return java.lang.Object
* @name executeUpdate
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
int executeUpdate(String sql, Object[] params);
@ -44,6 +63,8 @@ public interface SQLRunner {
* @return int sql
* @name executeUpdate
* @notice SqlMapper
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
* @see SQLMapper
*/
int executeUpdate(Object obj, SQLMapper sqlMapper);
@ -55,6 +76,8 @@ public interface SQLRunner {
* @return int
* @name insert
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
@Insert()
int insert(Object obj, String table);
@ -67,6 +90,8 @@ public interface SQLRunner {
* @name update
* @notice null<br>
* null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
int update(Object obj, String table);
@ -77,6 +102,8 @@ public interface SQLRunner {
* @return int
* @name delete
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
int delete(Object id, String table);
@ -98,6 +125,8 @@ public interface SQLRunner {
* @return java.lang.Object
* @name executeQuery
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
Object executeQuery(String sql, Object[] params, ResultMapper mapper);
@ -116,6 +145,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryList
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
LinkedList queryList(String sql, Object[] params, Class clazz);
@ -129,6 +160,8 @@ public interface SQLRunner {
* @return Object
* @name queryList
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
Object queryObject(String sql, Object[] params, Class clazz);
@ -140,6 +173,8 @@ public interface SQLRunner {
* @return
* @name queryValue
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/11
*/
Object queryValue(String sql, Object[] params);
@ -166,6 +201,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryOrderBy
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryOrderBy(String[] selectFields, String orderBy, boolean isDesc, String tableName);
@ -197,6 +234,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryWhere
* @notice not
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryWhere(String[] selectFields, Object obj, String conj, String condition);
@ -212,6 +251,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryWhereAndEquals
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryWhereAndEquals(String[] selectFields, Object obj);
@ -228,6 +269,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryWhereLikeAnd
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryWhereLikeAnd(String[] selectFields, Object obj);
@ -243,6 +286,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryWhereLikeAnd
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryWhereLikeOr(String[] selectFields, Object obj);
@ -262,6 +307,8 @@ public interface SQLRunner {
* @return java.util.LinkedList
* @name queryPages
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
LinkedList queryPages(String[] selectFields, String tableName, String limit, String offset);
@ -279,6 +326,8 @@ public interface SQLRunner {
* @param fieldValues
* @name fieldMapper
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
void fieldMapper(Object obj, LinkedList fieldNames, LinkedList fieldValues);
@ -290,6 +339,8 @@ public interface SQLRunner {
* @return java.lang.String
* @name selectMapper
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String selectMapper(String tableName, Object[] selectFields);
@ -301,6 +352,8 @@ public interface SQLRunner {
* @return java.lang.String where,where id = ? and user_name = ?
* @name whereMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String whereMapper(Object[] whereFields, String conj, String condition);
@ -312,6 +365,8 @@ public interface SQLRunner {
* @return java.lang.String where,where id like ? and user_name like ?
* @name likeMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String likeMapper(Object[] likeFields, String conj);
@ -323,6 +378,8 @@ public interface SQLRunner {
* @return java.lang.String
* @name orderByMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String orderByMapper(String orderBy, boolean isDesc);
@ -334,6 +391,8 @@ public interface SQLRunner {
* @return java.lang.String
* @name pageMapper
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String pageMapper(String limit, String offset);
@ -346,6 +405,8 @@ public interface SQLRunner {
* @return java.lang.String
* @name pageMapper
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
String pageOffsetMapper(String offset);

@ -1,4 +1,19 @@
//导入必要库
/*
* 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;
import com.hyc.wechat.dao.annotation.Query;
@ -9,8 +24,10 @@ import com.hyc.wechat.model.po.User;
import java.util.List;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description UserCRUD
* @date 2019-05-01 23:39
*/
public interface UserDao extends BaseDao {
String TABLE = "user";
@ -25,6 +42,8 @@ public interface UserDao extends BaseDao {
* @return
* @name getUserById
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = User.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
@ -38,6 +57,8 @@ public interface UserDao extends BaseDao {
* @return
* @name getUserByEmail
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = User.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where email = ? ")
@ -51,6 +72,8 @@ public interface UserDao extends BaseDao {
* @return
* @name getUserByWechatId
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/2
*/
@Result(entity = User.class, returns = ResultType.OBJECT)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where wechat_id = ? ")
@ -61,6 +84,8 @@ public interface UserDao extends BaseDao {
* @return
* @name listByName
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/5
*/
@Result(entity = User.class, returns = ResultType.LIST)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where name = ?")
@ -74,6 +99,8 @@ public interface UserDao extends BaseDao {
* @return
* @name listLike
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/6
*/
@Result(entity = User.class, returns = ResultType.LIST)
@Query(value = "select " + ALL_FIELD + " from " + TABLE + " where name like ? ")

@ -1,25 +1,32 @@
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Delete {
/**
* value
* SQL
*
* @return SQL
*/
String value()default "";
}

@ -1,19 +1,32 @@
//导入必要库
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description SQL
* @program wechat
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Field {
/* name
*
* @return
*/
String name ();
}

@ -1,22 +1,32 @@
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Insert {
/**
* value
* SQL
*
* @return SQL
*/
String value()default "";
}

@ -1,11 +1,28 @@
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description SQL
* @program wechat
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)

@ -1,11 +1,28 @@
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)

@ -1,3 +1,18 @@
/*
* 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.annotation;
@ -6,8 +21,10 @@ import com.hyc.wechat.model.po.abs.BaseEntity;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description SQL
* @program wechat
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)

@ -1,9 +1,26 @@
/*
* 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.annotation;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description SQL
* @date 2019-05-01 21:21
*/
public enum ResultType{
/**

@ -1,12 +1,29 @@
//导入必要库
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
* @date 2019-05-01 00:19
*/
@Documented
@Retention(value = RetentionPolicy.RUNTIME)

@ -1,11 +1,28 @@
//导入必要库
/*
* 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.annotation;
import java.lang.annotation.*;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @program wechat
* @date 2019-05-01 13:32
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)

@ -1,3 +1,19 @@
/*
* 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.impl;
import com.hyc.wechat.dao.DataSource;
@ -14,8 +30,10 @@ import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Dao
* @date 2019-05-01 16:40
*/
public class DataSourceImpl implements DataSource {
/*
@ -133,6 +151,8 @@ public class DataSourceImpl implements DataSource {
* @throws DaoException
* @name getConnection
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Override
public Connection getConnection() throws DaoException {
@ -169,6 +189,8 @@ public class DataSourceImpl implements DataSource {
*
* @param conn
* @name freeConnection
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Override
public void freeConnection(Connection conn) {
@ -180,6 +202,8 @@ public class DataSourceImpl implements DataSource {
*
* @return java.sql.Connection
* @name createConnection
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Override
public void destroyConnection(Connection conn) {
@ -197,6 +221,8 @@ public class DataSourceImpl implements DataSource {
*
* @return int
* @name getCurrentCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Override
public int getCurrentCount() {
@ -208,6 +234,8 @@ public class DataSourceImpl implements DataSource {
*
* @return int
* @name getfreeCount
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
@Override
public int getfreeCount() {
@ -226,6 +254,8 @@ public class DataSourceImpl implements DataSource {
*
* @return java.sql.Connection
* @name createConnection
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/5/1
*/
private Connection createConnection() throws DaoException {
currentCount++;

@ -1,3 +1,18 @@
/*
* 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.impl;
@ -19,8 +34,10 @@ import static com.hyc.wechat.util.ReflectUtils.getMethods;
import static com.hyc.wechat.util.StringUtils.field2SqlField;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description sql
* @date 2019-05-01 17:34
*/
public class SQLRunnerImpl implements SQLRunner {
@ -39,6 +56,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.Object
* @name executeUpdate
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
@Override
public int executeUpdate(String sql, Object[] params) {
@ -73,6 +92,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return int sql
* @name executeUpdate
* @notice SqlMapper
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
* @see SQLMapper
*/
@Override
@ -128,6 +149,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return int
* @name insert
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
@Override
public int insert(Object obj, String table) {
@ -162,6 +185,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @name update
* @notice null<br>
* null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
@Override
public int update(Object obj, String table) {
@ -205,6 +230,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return int
* @name delete
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public int delete(Object obj, String table) {
@ -238,6 +265,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.Object
* @name executeQuery
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
@Override
public Object executeQuery(String sql, Object[] params, ResultMapper mapper) {
@ -291,7 +320,9 @@ public class SQLRunnerImpl implements SQLRunner {
* @param clazz
* @return java.util.LinkedList
* @name queryList
* @notice non
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
@Override
public LinkedList queryList(String sql, Object[] params, Class clazz) {
@ -302,8 +333,10 @@ public class SQLRunnerImpl implements SQLRunner {
* ResultMapperList<br>
* 使
*
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @name ListMapper
* @notice
* @date 2019/4/10
* @see com.hyc.www.dao.inter.ResultMapper
*/
LinkedList list = new LinkedList<>();
@ -366,6 +399,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return Object
* @name queryList
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/10
*/
@Override
public Object queryObject(String sql, Object[] params, Class clazz) {
@ -381,6 +416,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return
* @name queryValue
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/11
*/
@Override
public Object queryValue(String sql, Object[] params) {
@ -424,6 +461,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryOrderBy
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryOrderBy(String[] selectFields, String orderBy, boolean isDesc, String tableName) {
@ -465,6 +504,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryWhere
* @notice not
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryWhere(String[] selectFields, Object obj, String conj, String condition) {
@ -507,6 +548,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryWhereAndEquals
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryWhereAndEquals(String[] selectFields, Object obj) {
@ -526,6 +569,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryWhereLikeAnd
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryWhereLikeAnd(String[] selectFields, Object obj) {
@ -544,6 +589,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryWhereLikeAnd
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryWhereLikeOr(String[] selectFields, Object obj) {
@ -566,6 +613,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.util.LinkedList
* @name queryPages
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public LinkedList queryPages(String[] selectFields, String tableName, String limit, String offset) {
@ -588,6 +637,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @param fieldValues
* @name fieldMapper
* @notice null
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/9
*/
@Override
public void fieldMapper(Object obj, LinkedList fieldNames, LinkedList fieldValues) {
@ -637,6 +688,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String
* @name selectMapper
* @notice
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String selectMapper(String tableName, Object[] selectFields) {
@ -657,6 +710,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String where,where id = ? and user_name = ?
* @name whereMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String whereMapper(Object[] whereFields, String conj, String condition) {
@ -682,6 +737,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String where,where id like ? and user_name like ?
* @name likeMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String likeMapper(Object[] likeFields, String conj) {
@ -706,6 +763,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String
* @name orderByMapper
* @notice where
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String orderByMapper(String orderBy, boolean isDesc) {
@ -733,6 +792,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String
* @name pageMapper
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String pageMapper(String limit, String offset) {
@ -748,6 +809,8 @@ public class SQLRunnerImpl implements SQLRunner {
* @return java.lang.String
* @name pageMapper
* @notice none
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @date 2019/4/13
*/
@Override
public String pageOffsetMapper(String offset) {

@ -1,51 +1,44 @@
/*
* 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.exception;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Dao
* @date 2019-05-01 16:36
*/
public class DaoException extends RuntimeException{
/**
*
* DaoException
*/
public DaoException() {
super();
}
/**
*
* DaoException
* @param message
*/
public DaoException(String message) {
super(message);
}
/**
*
* DaoException
* @param message
* @param cause
*/
public DaoException(String message, Throwable cause) {
super(message, cause);
}
/**
*
* DaoException
* @param cause
*/
public DaoException(Throwable cause) {
super(cause);
}
/**
*
* DaoException
* @param message
* @param cause
* @param enableSuppression
* @param writableStackTrace
*/
protected DaoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

@ -1,52 +1,44 @@
/*
* 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.exception;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description service
* @date 2019-05-01 17:41
*/
public class ServiceException extends RuntimeException{
/**
*
* ServiceException
*/
public ServiceException() {
super();
}
/**
*
* ServiceException
* @param message
*/
public ServiceException(String message) {
super(message);
}
/**
*
* ServiceException
* @param message
* @param cause
*/
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
/**
*
* ServiceException
* @param cause
*/
public ServiceException(Throwable cause) {
super(cause);
}
/**
*
* ServiceException
*
* @param message
* @param cause
* @param enableSuppression
* @param writableStackTrace
*/
protected ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

@ -1,3 +1,18 @@
/*
* 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.factory;
@ -10,18 +25,16 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Daosql
* @date 2019-05-01 11:01
*/
public class DaoProxyFactory implements InvocationHandler {
private static SQLRunner executor = new SQLRunnerImpl();
private static DaoProxyFactory instance= new DaoProxyFactory();
/**
* 使Java Proxy API
* @param interfaces DAOClass
* @return
*/
public Object getProxyInstance(Class interfaces) {
return Proxy.newProxyInstance(interfaces.getClassLoader(), new Class[]{interfaces}, this);
}
@ -29,21 +42,11 @@ public class DaoProxyFactory implements InvocationHandler {
private DaoProxyFactory() {
}
/**
* DaoProxyFactory
* @return DaoProxyFactory
*/
public static DaoProxyFactory getInstance(){
return instance;
}
/**
* InvocationHandlerinvoke
* @param proxy
* @param method
* @param args
* @return
* @throws Throwable
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getAnnotation(Insert.class) != null) {
@ -74,22 +77,17 @@ public class DaoProxyFactory implements InvocationHandler {
}
}
if (method.getAnnotation(Query.class) != null) {
// 获取@Result注解指定的返回类型
ResultType type = method.getAnnotation(Result.class).returns();
switch (type) {
case OBJECT:
// 执行查询并返回单个对象
return executor.queryObject(method.getAnnotation(Query.class).value(), args, method.getAnnotation(Result.class).entity());
case LIST:
// 执行查询并返回对象列表
return executor.queryList(method.getAnnotation(Query.class).value(), args, method.getAnnotation(Result.class).entity());
case VALUE:
// 执行查询并返回单个值
return executor.queryValue(method.getAnnotation(Query.class).value(), args);
default:
}
}
// 如果方法没有注解,则直接调用原始方法
return method.invoke(proxy, args);
}

@ -1,4 +1,19 @@
//导入必要库
/*
* 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.factory;
import java.lang.reflect.InvocationHandler;
@ -6,47 +21,31 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description Daosql
* @date 2019-05-01 11:01
*/
public class ServiceProxyFactory implements InvocationHandler {
private Object target;
/**
* 使Java Proxy API
* @param target
* @return
*/
public Object getProxyInstance(Object target) {
this.target =target;
// 创建代理对象,该代理对象实现了目标对象的所有接口
return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
}
/**
* InvocationHandlerinvoke
* @param proxy
* @param method
* @param args
* @return
* @throws Throwable
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(target, args);
}
/**
*
* @return
*/
public Object getTarget() {
return target;
}
/**
*
* @param target
*/
public void setTarget(Object target) {
this.target = target;
}

@ -1,3 +1,19 @@
/*
* 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.factory.proxy;
import com.hyc.wechat.dao.DataSource;
@ -10,92 +26,51 @@ import java.lang.reflect.Proxy;
import java.sql.Connection;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description
*
* @description
* @date 2019-05-01 17:52
*/
public class ConnectionProxy implements InvocationHandler {
// 被代理的Connection对象
private Connection target;
// 数据源对象,用于管理数据库连接
private DataSource dataSource;
/**
*
* @param dataSource
*/
public ConnectionProxy(DataSource dataSource) {
this.dataSource = dataSource;
public Connection getProxyInstance(Connection target){
this.target= target;
return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),new Class[]{Connection.class},this);
}
/**
*
* @param target Connection
* @return Connection
*/
public Connection getProxyInstance(Connection target) {
this.target = target; // 设置被代理的目标对象
// 使用Proxy类创建一个Connection代理实例并将当前对象作为调用处理器
return (Connection) Proxy.newProxyInstance(
Connection.class.getClassLoader(), // 类加载器
new Class[]{Connection.class}, // 代理实现的接口数组
this); // 调用处理器
public ConnectionProxy(DataSource dataSource) {
this.dataSource = dataSource;
}
/**
* InvocationHandlerinvoke
* @param proxy
* @param method
* @param args
* @return
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
// 如果调用的是close方法则将连接放回数据源而不是真正关闭连接
if ("close".equals(method.getName())) {
dataSource.freeConnection(target); // 将连接放回数据源
return null; // close方法没有返回值
//调用代理对象的close方法时将目标对象放回数据库连接池
dataSource.freeConnection(target);
return null;
}
try {
// 对于其他方法调用,直接转发给被代理的目标对象
return method.invoke(target, args);
} catch (IllegalAccessException | InvocationTargetException e) {
// 如果方法调用过程中发生异常则抛出DaoException
throw new DaoException("无法调用目标对象的方法", e);
}
}
// 以下是getter和setter方法用于访问和修改target和dataSource属性
/**
* Connection
* @return Connection
*/
public Connection getTarget() {
return target;
}
/**
* Connection
* @param target Connection
*/
public void setTarget(Connection target) {
this.target = target;
}
/**
*
* @return
*/
public DataSource getDataSource() {
return dataSource;
}
/**
*
* @param dataSource
*/
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

@ -1,4 +1,19 @@
//导入必要库
/*
* 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.model.builder;
import com.hyc.wechat.model.vo.MessageVO;
@ -7,91 +22,49 @@ import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description MessageVO
* @date 2019-05-07 14:58
*/
public class MessageVOBuilder {
private MessageVO messageVo;
/**
* MessageVO
*/
public MessageVOBuilder() {
this.messageVo = new MessageVO();
}
/**
* MessageVO
* @return MessageVO
*/
public MessageVO build(){
return this.messageVo;
}
/**
*
* @param senderName
* @return MessageVOBuilder便
*/
public MessageVOBuilder setSenderName(String senderName) {
this.messageVo.setSenderName(senderName);
return this;
}
/**
* ID
* @param senderId ID
* @return MessageVOBuilder便
*/
public MessageVOBuilder setSenderId(BigInteger senderId){
this.messageVo.setSenderId(senderId);
return this;
}
/**
* URL
* @param senderPhoto URL
* @return MessageVOBuilder便
*/
public MessageVOBuilder setSenderPhoto(String senderPhoto){
this.messageVo.setSenderPhoto(senderPhoto);
return this;
}
/**
* ID
* @param chatId ID
* @return MessageVOBuilder便
*/
public MessageVOBuilder setChatId(BigInteger chatId){
this.messageVo.setChatId(chatId);
return this;
}
/**
*
* @param content
* @return MessageVOBuilder便
*/
public MessageVOBuilder setContent(String content){
this.messageVo.setContent(content);
return this;
}
/**
*
* @param time
* @return MessageVOBuilder便
*/
public MessageVOBuilder setTime(Timestamp time){
this.messageVo.setTime(time);
return this;
}
/**
*
* @param type
* @return MessageVOBuilder便
*/
public MessageVOBuilder setType(String type){
this.messageVo.setType(type);
return this;
}
/**
* ID
* @param id ID
* @return MessageVOBuilder便
*/
public MessageVOBuilder setId(BigInteger id){
this.messageVo.setId(id);
return this;

@ -1,3 +1,18 @@
/*
* 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.model.builder;
@ -7,186 +22,100 @@ import java.math.BigInteger;
import java.sql.Timestamp;
/**
* @description MomentVO
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description
* @date 2019-05-07 20:32
*/
public class MomentVOBuilder {
// MomentVO对象用于存储构建过程中的数据
private MomentVO momentVO;
/**
* MomentVO
*/
public MomentVOBuilder() {
this.momentVO = new MomentVO();
}
/**
* MomentVO
* @return MomentVO
*/
public MomentVO build() {
return this.momentVO;
}
// 以下方法用于设置MomentVO对象的属性并返回当前Builder对象以便链式调用
/**
*
* @param time
* @return Builder
*/
public MomentVOBuilder setTime(Timestamp time){
this.momentVO.setTime(time);
return this;
}
/**
* URL
* @param userPhoto URL
* @return Builder
*/
public MomentVOBuilder setUserPhoto(String userPhoto){
this.momentVO.setUserPhoto(userPhoto);
return this;
}
/**
* URL
* @param photo URL
* @return Builder
*/
public MomentVOBuilder setPhoto(String photo){
this.momentVO.setPhoto(photo);
return this;
}
/**
*
* @param userName
* @return Builder
*/
public MomentVOBuilder setUserName(String userName){
this.momentVO.setUserName(userName);
return this;
}
/**
* ID
* @param id ID
* @return Builder
*/
public MomentVOBuilder setId(BigInteger id) {
this.momentVO.setId(id);
return this;
}
/**
* ID
* @param userId ID
* @return Builder
*/
public MomentVOBuilder setUserId(BigInteger userId) {
this.momentVO.setOwnerId(userId);
return this;
}
/**
*
* @param content
* @return Builder
*/
public MomentVOBuilder setContent(String content) {
this.momentVO.setContent(content);
return this;
}
/**
*
* @param share
* @return Builder
*/
public MomentVOBuilder setShare(Long share) {
this.momentVO.setShare(share);
return this;
}
/**
*
* @param love
* @return Builder
*/
public MomentVOBuilder setLove(Long love) {
this.momentVO.setLove(love);
return this;
}
/**
*
* @param remark
* @return Builder
*/
public MomentVOBuilder setRemark(Long remark) {
this.momentVO.setRemark(remark);
return this;
}
/**
*
* @param view
* @return Builder
*/
public MomentVOBuilder setView(Long view) {
this.momentVO.setView(view);
return this;
}
/**
*
* @param collect
* @return Builder
*/
public MomentVOBuilder setCollect(Long collect) {
this.momentVO.setCollect(collect);
return this;
}
/**
*
* @param loved
* @return Builder
*/
public MomentVOBuilder setLoved(Boolean loved) {
this.momentVO.setLoved(loved);
return this;
}
/**
*
* @param shared
* @return Builder
*/
public MomentVOBuilder setShared(Boolean shared) {
this.momentVO.setShared(shared);
return this;
}
/**
*
* @param viewed
* @return Builder
*/
public MomentVOBuilder setViewed(Boolean viewed) {
this.momentVO.setViewed(viewed);
return this;
}
public MomentVOBuilder setViewed(Boolean viewed) {
this.momentVO.setViewed(viewed);
return this;
/**
*
* @param collected
* @return Builder
*/
}
public MomentVOBuilder setCollected(Boolean collected) {
this.momentVO.setCollected(collected);
return this;
}
}

@ -1,99 +1,73 @@
/*
* 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.model.dto;
import com.hyc.wechat.service.constants.Status;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description serviceDTO
* @description service
* @date 2019-05-02 03:01
*/
public class ServiceResult {
/**
*
*
*/
private Status status;
/**
*
*
*/
private String message;
/**
*
*
*/
private Object data;
/**
* ServiceResult
*/
public ServiceResult() {
}
/**
* ServiceResult
*
* @param status
* @param message
* @param data
*/
public ServiceResult(Status status, String message, Object data) {
this.status = status;
this.message = message;
this.data = data;
}
/**
*
*
* @return
*/
public Status getStatus() {
return status;
}
/**
*
*
* @param status
*/
public void setStatus(Status status) {
this.status = status;
}
/**
*
*
* @return
*/
public String getMessage() {
return message;
}
/**
*
*
* @param message
*/
public void setMessage(String message) {
this.message = message;
}
/**
*
*
* @return
*/
public Object getData() {
return data;
}
/**
*
*
* @param data
*/
public void setData(Object data) {
this.data = data;
}
}

@ -1,4 +1,19 @@
//导入必要库
/*
* 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.model.po;
import com.alibaba.fastjson.annotation.JSONField;
@ -8,135 +23,65 @@ import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
/**
* @description chat
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @description chat
* @date 2019-05-03 01:38
*/
@Table(name = "chat") // 指定该实体类对应的数据库表名为chat
@Table(name = "chat")
public class Chat extends BaseEntity {
// 聊天室的编号
private String number;
// 聊天室所有者的ID
@JSONField(name = "owner_id") // 指定在JSON序列化时的字段名为owner_id
@JSONField(name = "owner_id")
private BigInteger ownerId;
// 聊天室的类型(如群聊、私聊等)
private String type;
// 聊天室的名称
private String name;
// 聊天室的成员数量
private Integer member;
// 聊天室的封面照片URL
private String photo;
/**
*
*
* @return
*/
public String getType() {
return type;
}
/**
*
*
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
*
*
* @return
*/
public String getNumber() {
return number;
}
/**
*
*
* @param number
*/
public void setNumber(String number) {
this.number = number;
}
/**
* URL
*
* @return URL
*/
public String getPhoto() {
return photo;
}
/**
* URL
*
* @param photo URL
*/
public void setPhoto(String photo) {
this.photo = photo;
}
/**
* ID
*
* @return ID
*/
public BigInteger getOwnerId() {
return ownerId;
}
/**
* ID
*
* @param ownerId ID
*/
public void setOwnerId(BigInteger ownerId) {
this.ownerId = ownerId;
}
/**
*
*
* @return
*/
public String getName() {
return name;
}
/**
*
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
*
* @return
*/
public Integer getMember() {
return member;
}
/**
*
*
* @param member
*/
public void setMember(Integer member) {
this.member = member;
}
}

@ -1,4 +1,19 @@
//导入必要库
/*
* 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.model.po;
import com.alibaba.fastjson.annotation.JSONField;
@ -8,158 +23,77 @@ import com.hyc.wechat.model.po.abs.BaseEntity;
import java.math.BigInteger;
/**
* @author <a href="mailto:kobe524348@gmail.com"></a>
* @program wechat
* @description friend
* @description
* @date 2019-05-02 01:56
*/
@Table(name = "friend") // 指定该实体类对应的数据库表名为friend
@Table(name = "friend")
public class Friend extends BaseEntity {
// 用户ID表示朋友的用户标识
@JSONField(name = "user_id") // 指定在JSON序列化时的字段名为user_id
@JSONField(name = "user_id")
private BigInteger userId;
// 朋友ID表示朋友的用户标识
@JSONField(name = "friend_id") // 指定在JSON序列化时的字段名为friend_id
@JSONField(name = "friend_id")
private BigInteger friendId;
// 聊天室ID表示与朋友关联的聊天室标识
@JSONField(name = "chat_id") // 指定在JSON序列化时的字段名为chat_id
@JSONField(name = "chat_id")
private BigInteger chatId;
// 朋友的头像照片URL
private String photo;
// 分组ID表示朋友所属的分组标识
@JSONField(name = "group_id") // 指定在JSON序列化时的字段名为group_id
@JSONField(name = "group_id")
private BigInteger groupId;
// 朋友的别名,用于在好友列表中显示的名称
private String alias;
// 朋友的描述信息
private String description;
/**
* ID
*
* @return ID
*/
public BigInteger getChatId() {
return chatId;
}
/**
* ID
*
* @param chatId ID
*/
public void setChatId(BigInteger chatId) {
this.chatId = chatId;
}
/**
* URL
*
* @return URL
*/
public String getPhoto() {
return photo;
}
/**
* URL
*
* @param photo URL
*/
public void setPhoto(String photo) {
this.photo = photo;
}
/**
* ID
*
* @return ID
*/
public BigInteger getUserId() {
return userId;
}
/**
* ID
*
* @param userId ID
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* ID
*
* @return ID
*/
public BigInteger getFriendId() {
return friendId;
}
/**
* ID
*
* @param friendId ID
*/
public void setFriendId(BigInteger friendId) {
this.friendId = friendId;
}
/**
* ID
*
* @return ID
*/
public BigInteger getGroupId() {
return groupId;
}
/**
* ID
*
* @param groupId ID
*/
public void setGroupId(BigInteger groupId) {
this.groupId = groupId;
}
/**
*
*
* @return
*/
public String getAlias() {
return alias;
}
/**
*
*
* @param alias
*/
public void setAlias(String alias) {
this.alias = alias;
}
/**
*
*
* @return
*/
public String getDescription() {
return description;
}
/**
*
*
* @param description
*/
public void setDescription(String description) {
this.description = description;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save