Terdapat dua peringkat balasan (balas ulasan, balas balasan di bawah ulasan)
Jadual Komen (TFW_Comments), jadual kandungan balas (TFW_UserResponse) dan jadual hubungan balasan ulasan (TFW_MsgRelation)
Nota: Pembaca secara automatik mengabaikan medan ID organisasi perkhidmatan jadual ulasan ini bersamaan dengan siaran ulasan ini (di bawah artikel)
1 ID artikel atau ID siaran Dapatkan ulasan (ID perkhidmatan untuk artikel ini). Tahap pertama (komen)
Untuk mendapatkan balasan peringkat kedua (commentsId), anda perlu membuat pertanyaan dalam jadual perhubungan berdasarkan ID ulasan dan jenis balasan sama dengan 1. Tahap kedua (balas di bawah ulasan)
Mendapatkan maklumat balasan peringkat ketiga dalam jadual perhubungan berdasarkan ID ulasan, jenis balasan 2 dan ID balasan. Tahap ketiga (balas dalam balasan di bawah ulasan) Nota: ID balasan adalah yang unggul
@Override public Map<String, Object> findComments(JSONObject jsonObject) { data.clear(); String userId = jsonObject.getString("userId"); String role = this.role(jsonObject); if (role.equals("-1")){ //没有权限 data.put("error","-1"); data.put("msg","当前用户没有权限"); return data; } List<Map<String, Object>> info = commentsDao.findComment(jsonObject.getString("fWJLID"),null); //查询点赞次数 int countTag = 0; MsgRelationTag msgRelationTag = new MsgRelationTag(); for (Map item : info){ item.put("inputShow",false); int commentsId = (int) item.get("commentsId"); //查询点赞次数 countTag = msgRelationDao.findCountTagByTagId(commentsId,1); item.put("countTag",countTag); //设置点赞状态 msgRelationTag.setTagId(commentsId); msgRelationTag.setTagType(1); msgRelationTag.setTagUserId(Integer.parseInt(userId)); MsgRelationTag msgTag = msgRelationDao.findMsgTag(msgRelationTag); if (msgTag != null) { item.put("tagStatus",msgTag.getStatus()); }else { item.put("tagStatus",""); } //如果有@id if (item.get("atId") != null){ String content = item.get("content").toString(); StringBuffer tmrAtId = findUserName(item.get("atId").toString()); item.put("content",content+'@'+tmrAtId); } //二级回复数据 List<Map<String, Object>> twoReply = new ArrayList<>(); //所有数据 List<Map<String, Object>> userResponse = userResponseDao.findUserResponse(commentsId, null, "","",null); for (Map userResponseInfo :userResponse){ int userResponseIds = Integer.parseInt(userResponseInfo.get("userResponseId").toString()); //查询点赞次数 countTag = msgRelationDao.findCountTagByTagId(userResponseIds,2); //设置点赞状态 msgRelationTag.setTagId(userResponseIds); msgRelationTag.setTagType(2); msgTag = msgRelationDao.findMsgTag(msgRelationTag); if (msgTag != null) {userResponseInfo.put("tagStatus",msgTag.getStatus());}else {userResponseInfo.put("tagStatus","");} userResponseInfo.put("countTag",countTag); userResponseInfo.put("inputShow",false); Integer responseType = (Integer) userResponseInfo.get("responseType"); for (Map stairReplyInfo : userResponse){ Integer userResponseId = (Integer) stairReplyInfo.get("userResponseId"); int msgRelationId = Integer.parseInt(stairReplyInfo.get("msgRelationId").toString()); //接受者id*/ twoReply = userResponseDao.findUserResponse(msgRelationId, userResponseId,"1","",null); //二级回复数据 for (Map twoReplyItem : twoReply){ int twoReplyId = Integer.parseInt(twoReplyItem.get("userResponseId").toString()); twoReplyItem.put("inputShow",false); //查询点赞次数 countTag = msgRelationDao.findCountTagByTagId(twoReplyId,2); twoReplyItem.put("countTag",countTag); //设置点赞状态 msgRelationTag.setTagId(twoReplyId); msgTag = msgRelationDao.findMsgTag(msgRelationTag); if (msgTag != null) {twoReplyItem.put("tagStatus",msgTag.getStatus());}else {twoReplyItem.put("tagStatus","");} String userRepContent = twoReplyItem.get("userRepContent").toString(); if (twoReplyItem.get("tmrAtId") != null){ StringBuffer tmrAtId = findUserName(twoReplyItem.get("tmrAtId").toString()); twoReplyItem.put("userRepContent",userRepContent+'@'+tmrAtId); } } stairReplyInfo.put("twoReply",twoReply); } } item.put("stairReply",userResponse); } data.put("data",info); data.put("error",0); data.put("msg","查询成功"); return data; }
Kod lain boleh diabaikan. Kenyataan utama ialah:
List<Map<String, Object>> info = commentsDao.findComment(jsonObject.getString("fWJLID"),null);
Gambar di atas mendapat ulasan berdasarkan FWJLID. (Ini boleh digunakan sebagai ID siaran untuk mendapatkan ulasan di bawah siaran) Paparan Tahap 1
sepadan dengan pernyataan SQL (OPT ialah jadual pengguna saya)
select tc.content ,tc.commentsId,convert(varchar(19),tc.startTime,120) as startTime,tc.recipientId ,tc.operatorId,zo.NAME as operatorName,tc.atId,zo.HeadImgUrl as operatorHeadImgUrl from TFW_Comments tc left join zd_opt zo on zo.AID = tc.operatorId where tc.FWJLID = 5101
Hasil pertanyaan:
List<Map<String, Object>> userResponse = userResponseDao.findUserResponse(commentsId, null, "","",null);
Gambar di atas mendapat balasan di bawah komen berdasarkan komen. (Dapatkan balasan berdasarkan ID ulasan) Paparan peringkat kedua
sepadan dengan pernyataan sql
select tur.userResponseId,tur.operatorId,tur.recipientId,convert(varchar(19),tur.startTime,120) as startTime,tur.userRepContent,tmr.atId as tmrAtId, tmr.msgRelationId ,tmr.responseType,tmr.replyId, zo.NAME as operatorName, zo1.NAME as recipientName, zo.HeadImgUrl as operatorHeadImgUrl, zo1.HeadImgUrl as recipientHeadImgUrl from TFW_MsgRelation tmr left join TFW_UserResponse tur on tur.userResponseId = tmr.userResponseId left join zd_opt zo on zo.AID = tur.operatorId left join zd_opt zo1 on zo1.AID = tur.recipientId where tmr.commentsId = 47
Hasil pertanyaan
twoReply = userResponseDao.findUserResponse(msgRelationId, userResponseId,"1","",null); //二级回复数据
Gambar di atas adalah untuk mendapatkan balasan kedua berdasarkan ID komen (msgRelationId) dan ID balasan (userResponseId). ID balasan juga merupakan kelas induk. Ia adalah ID balasan. Paparan lapisan ketiga
sepadan dengan sql
select tur.userResponseId,tur.operatorId,tur.recipientId,convert(varchar(19),tur.startTime,120) as startTime,tur.userRepContent,tmr.atId as tmrAtId, tmr.msgRelationId ,tmr.responseType,tmr.replyId, zo.NAME as operatorName, zo1.NAME as recipientName, zo.HeadImgUrl as operatorHeadImgUrl, zo1.HeadImgUrl as recipientHeadImgUrl from TFW_MsgRelation tmr left join TFW_UserResponse tur on tur.userResponseId = tmr.userResponseId left join zd_opt zo on zo.AID = tur.operatorId left join zd_opt zo1 on zo1.AID = tur.recipientId where tmr.commentsId = 136 and tmr.replyId = 155
hasil pertanyaan
kembali paparan halaman dan kembalikan paparan badan
Atas ialah kandungan terperinci Bagaimana untuk melaksanakan fungsi komen dan balasan dalam java. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!