package chat.module.friendcircle;
|
|
import chat.server.call.IJSONWriter;
|
import chat.server.call.IJsonProvider;
|
import chat.server.im.DataPool;
|
import chat.user.User;
|
import frame.object.data.Entity;
|
import frame.object.data.ID;
|
import frame.util.MapList;
|
|
|
public class CircleObject implements IJsonProvider {
|
|
private String id;
|
private FriendCircle root;
|
private String ownerId;
|
private String doctorId;
|
private String location;
|
private LabeList labelList;
|
private String content;
|
private String media;
|
private MediaType mediaType;
|
private int cnt_collection;
|
private int cnt_thumbsup;
|
private int cnt_comment;
|
private int cnt_forward;
|
private MapList<User> collectionList;
|
private MapList<User> thumbsupList;
|
private MapList<Comment> commentList;
|
private MapList<Forward> forwardList;
|
|
|
public CircleObject(FriendCircle root) {
|
labelList = new LabeList();
|
collectionList = new MapList<User>();
|
thumbsupList = new MapList<User>();
|
commentList = new MapList<Comment>();
|
forwardList = new MapList<Forward>();
|
this.root = root;
|
}
|
|
public void load(Entity entity) {
|
id = entity.getString("id");
|
|
ownerId = entity.getString("senderId");
|
doctorId = entity.getString("doctorId");
|
location = entity.getString("region");
|
labelList.load(entity.getString("dieaselabel"));
|
content = entity.getString("content");
|
mediaType = MediaType.parse(entity.getInteger("type", 2));
|
media = entity.getString("medias");
|
|
cnt_collection = entity.getInteger("cnt_collection", 0);
|
cnt_thumbsup = entity.getInteger("cnt_thumbsup", 0);
|
cnt_comment = entity.getInteger("cnt_comment", 0);
|
cnt_forward = entity.getInteger("cnt_forward", 0);
|
}
|
|
public void load(DataPool dataPool) {
|
location = dataPool.getString("region");
|
labelList.load(dataPool.getString("dieaselabel"));
|
content = dataPool.getString("content");
|
mediaType = MediaType.parse(dataPool.getString("type"));
|
media = dataPool.getString("media");
|
}
|
|
// 收藏
|
public void addOneCollect(User one) {
|
if (one == null) {
|
return;
|
}
|
|
String key = one.getId();
|
User user = collectionList.get(key);
|
|
if (user == null) {
|
insertOneCollectionToDB(one);
|
collectionList.add(key, one);
|
}
|
}
|
|
// 点赞
|
public void addOneThumbsup(User one) {
|
if (one == null) {
|
return;
|
}
|
|
String key = one.getId();
|
User user = thumbsupList.get(key);
|
|
if (user == null) {
|
insertOneThumbsupToDB(one);
|
thumbsupList.add(key, one);
|
}
|
}
|
|
public String addOneComment(User user, String parentId, String comment) {
|
if (parentId != null) {
|
return addOneLevelComment(user, comment);
|
}
|
|
return addTowLevelComment(user, parentId, comment);
|
}
|
|
// 添加一级评论
|
public String addOneLevelComment(User one, String content) {
|
if (one == null) {
|
return null;
|
}
|
|
String id = ID.newValue();
|
|
Comment comment = new Comment(one);
|
comment.setId(id);
|
comment.setContent(content);
|
|
insertOneCommentToDB(comment);
|
commentList.add(id, comment);
|
|
return id;
|
}
|
|
// 添加二级评论
|
public String addTowLevelComment(User one, String parentId, String content) {
|
if (one == null) {
|
return null;
|
}
|
|
Comment comment = commentList.get(parentId);
|
|
if (comment == null) {
|
return null;
|
}
|
|
insertOneCommentToDB(comment);
|
return comment.addOneSubComment(one, content);
|
}
|
|
// 转发
|
public void addOneForward(User sender, User to) {
|
if (sender == null || to == null) {
|
return;
|
}
|
|
Forward forward = new Forward(sender, to);
|
String key = forward.getKey();
|
|
forward = forwardList.get(key);
|
|
if (forward == null) {
|
insertOneForwardToDB(forward);
|
forwardList.add(key, forward);
|
}
|
}
|
|
public void insertToDB() {
|
// TODO Auto-generated method stub
|
|
}
|
|
private void insertOneCollectionToDB(User one) {
|
// TODO Auto-generated method stub
|
|
}
|
|
private void insertOneThumbsupToDB(User one) {
|
// TODO Auto-generated method stub
|
|
}
|
|
private void insertOneCommentToDB(Comment comment) {
|
// TODO Auto-generated method stub
|
|
}
|
|
private void insertOneForwardToDB(Forward forward) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void writeJSONObject(IJSONWriter writer) {
|
writer.beginObject();
|
writeJSONData(writer);
|
writer.endObject();
|
}
|
|
@Override
|
public void writeJSONData(IJSONWriter writer) {
|
writer.write("contentId", id);
|
writer.write("ownerId", ownerId);
|
writer.write("doctorId", doctorId);
|
writer.write("avatar", "https://yishiwuyou.oss-cn-shanghai.aliyuncs.com/avatar/2020/12/18/6e546ce5fbbc4482ae9e.png");
|
writer.write("mediaType", mediaType.toIntCode());
|
|
if (MediaType.Vedio == mediaType) {
|
writer.write("media", media);
|
writer.writeNull("image");
|
}
|
else if (MediaType.Image == mediaType) {
|
writer.write("image", media);
|
writer.writeNull("media");
|
}
|
|
writer.write("location", location);
|
writer.write("labelList", labelList.getValue());
|
writer.write("isAattention", root.isAttention());
|
writer.write("cnt_collection", cnt_collection + collectionList.size());
|
writer.write("cnt_thumbsup", cnt_thumbsup + thumbsupList.size());
|
writer.write("cnt_comment", cnt_comment + commentList.size());
|
writer.write("cnt_forward", cnt_forward + forwardList.size());
|
writer.write("content", content);
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
public String getOwnerId() {
|
return ownerId;
|
}
|
|
public void setOwnerId(String userId) {
|
this.ownerId = userId;
|
}
|
|
public String getDoctorId() {
|
return doctorId;
|
}
|
|
public void setDoctorId(String doctorId) {
|
this.doctorId = doctorId;
|
}
|
|
}
|