完成笔记评论

This commit is contained in:
wangxulei 2024-12-25 17:43:13 +08:00
parent f965fdaee3
commit fe5db963b5
22 changed files with 906 additions and 171 deletions

View File

@ -58,62 +58,21 @@ public class ApiController {
@GetMapping("/api/notes") @GetMapping("/api/notes")
@OperLog(operModule = "获取所有笔记", operType = OperType.QUERY, operDesc = "获取所有笔记") @OperLog(operModule = "获取所有笔记", operType = OperType.QUERY, operDesc = "获取所有笔记")
public ResultBean<IPage<NoteVo>> page(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> page(NoteDto noteDto) {
// 1. 通过noteService根据传入的NoteDto参数查询笔记的分页信息获取包含笔记数据的分页对象
IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
// 2. 创建一个用于存储当前用户点赞笔记信息的列表初始化为空
List<UpNotesVo> upNotesVos = new ArrayList<>();
// 3. 从请求头中获取名为"token"的token字符串用于后续解析获取用户ID // 3. 从请求头中获取名为"token"的token字符串用于后续解析获取用户ID
String token = request.getHeader("token"); String token = request.getHeader("token");
String authorId = ""; String followId = "";
try { try {
// 4. 尝试使用jwtTokenUtil工具类从获取到的token中解析出用户名这里假设用户名就是用户ID如果解析成功则赋值给authorId变量 // 4. 尝试使用jwtTokenUtil工具类从获取到的token中解析出用户名这里假设用户名就是用户ID如果解析成功则赋值给authorId变量
authorId = jwtTokenUtil.getUsernameFromToken(token); followId = jwtTokenUtil.getUsernameFromToken(token);
} catch (Exception e) { } catch (Exception e) {
// 5. 如果在解析token过程中出现异常此处捕获异常但不做任何处理authorId仍为空字符串后续可根据此情况决定是否继续相关业务逻辑 // 5. 如果在解析token过程中出现异常此处捕获异常但不做任何处理authorId仍为空字符串后续可根据此情况决定是否继续相关业务逻辑
} }
if(StringUtil.isNotEmpty(followId)){
// 6. 判断解析出的用户ID是否不为空即是否成功获取到了用户ID noteDto.setFollowId(followId);
if (StringUtil.isNotEmpty(authorId)) {
// 7. 如果获取到了用户ID创建一个UpNotesDto对象用于设置查询条件
UpNotesDto upNotesDto = new UpNotesDto();
// 8. 将获取到的用户ID设置到UpNotesDto对象中作为查询当前用户点赞笔记的条件表示要查询该用户点赞的笔记
upNotesDto.setFollowId(authorId);
// 9. 通过upNotesService根据设置好的查询条件查询当前用户点赞的笔记列表并将结果赋值给upNotesVos列表
upNotesVos = upNotesService.selectUpNotesList(upNotesDto);
} }
// 10. 通过upNotesService查询所有笔记的点赞数量统计信息获取一个包含各笔记点赞数量相关信息的列表 // 1. 通过noteService根据传入的NoteDto参数查询笔记的分页信息获取包含笔记数据的分页对象
List<UpNotesVo> selectAllUpCount = upNotesService.selectAllUpCount(); IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
// 11. 获取前面查询到的笔记分页信息中的具体笔记记录列表后续要对这些笔记记录进行相关属性的设置操作
List<NoteVo> records = pageInfo.getRecords();
// 12. 为了能在下面的lambda表达式中使用upNotesVos变量创建一个final修饰的变量来引用它因为lambda表达式中访问的外部变量需要是final或者事实上的final不可重新赋值
List<UpNotesVo> finalUpNotesVos = upNotesVos;
// 13. 同样为了在lambda表达式中使用authorId变量创建一个final修饰的变量来引用它
String finalAuthorId = authorId;
// 14. 使用Java 8的Stream API对每条笔记记录进行遍历处理
records.stream().forEach(noteVo -> {
// 15. 判断当前用户ID是否不为空即是否获取到了用户ID且有效如果为空则不进行当前用户对该笔记点赞状态的判断设置操作
if (StringUtil.isNotEmpty(finalAuthorId)) {
// 16. 在当前用户点赞笔记列表finalUpNotesVos通过Stream的filter操作筛选出与当前遍历的笔记noteVo的ID相等的点赞笔记记录然后获取第一个匹配的记录如果有的话否则返回null
UpNotesVo upNote = finalUpNotesVos.stream().filter(upNotesVo -> noteVo.getNoteId().equals(upNotesVo.getNoteId())).findFirst().orElse(null);
// 17. 如果找到了对应的点赞笔记记录即upNote不为null说明当前用户点赞了这条笔记将笔记的IsUp属性设置为true表示已点赞状态
if (upNote!= null) {
noteVo.setIsUp(Boolean.TRUE);
}
}
// 18. 在所有笔记的点赞数量统计信息列表selectAllUpCount通过Stream的filter操作筛选出与当前遍历的笔记noteVo的ID相等的记录然后获取第一个匹配的记录如果有的话否则返回null
UpNotesVo noteCount = selectAllUpCount.stream().filter(upNotesVo -> upNotesVo.getNoteId().equals(noteVo.getNoteId())).findFirst().orElse(null);
// 19. 如果找到了对应的点赞数量统计记录即noteCount不为null将笔记的UpCount属性设置为该记录中的点赞数量从而为每条笔记设置对应的点赞数量信息
if (noteCount!= null) {
noteVo.setUpCount(noteCount.getUpCount());
}
});
// 20. 将处理好的包含笔记信息已设置点赞状态和点赞数量的分页对象包装在ResultBean中返回以便前端或其他调用方获取处理后的结果数据 // 20. 将处理好的包含笔记信息已设置点赞状态和点赞数量的分页对象包装在ResultBean中返回以便前端或其他调用方获取处理后的结果数据
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
} }
@ -133,12 +92,22 @@ public class ApiController {
@GetMapping("/api/getNote") @GetMapping("/api/getNote")
@OperLog(operModule = "获取单个笔记",operType = OperType.QUERY,operDesc = "获取单个笔记") @OperLog(operModule = "获取单个笔记",operType = OperType.QUERY,operDesc = "获取单个笔记")
public ResultBean<NoteVo> getNoteById(NoteDto noteDto) { public ResultBean<NoteVo> getNoteById(NoteDto noteDto) {
Note note = noteService.getById(noteDto.getNoteId()); // 3. 从请求头中获取名为"token"的token字符串用于后续解析获取用户ID
NoteVo noteVo = BeanUtil.copyProperties(note, NoteVo.class); String token = request.getHeader("token");
noteVo.setCreateTimeStr(noteVo.getCreateTime()); String followId = "";
try {
// 4. 尝试使用jwtTokenUtil工具类从获取到的token中解析出用户名这里假设用户名就是用户ID如果解析成功则赋值给authorId变量
followId = jwtTokenUtil.getUsernameFromToken(token);
} catch (Exception e) {
// 5. 如果在解析token过程中出现异常此处捕获异常但不做任何处理authorId仍为空字符串后续可根据此情况决定是否继续相关业务逻辑
}
if(StringUtil.isNotEmpty(followId)){
noteDto.setFollowId(followId);
}
NoteVo noteVo = noteService.selectNoteDetail(noteDto);
NoteImgDto noteImgDto = new NoteImgDto(); NoteImgDto noteImgDto = new NoteImgDto();
noteImgDto.setNoteId(note.getNoteId()); noteImgDto.setNoteId(noteVo.getNoteId());
List<NoteImgVo> noteImgVos = noteImgService.selectNoteImgList(noteImgDto); List<NoteImgVo> noteImgVos = noteImgService.selectNoteImgList(noteImgDto);
List<String> imageList = noteImgVos.stream().map(NoteImgVo::getImgUrl).collect(Collectors.toList()); List<String> imageList = noteImgVos.stream().map(NoteImgVo::getImgUrl).collect(Collectors.toList());
noteVo.setImgList(imageList); noteVo.setImgList(imageList);

View File

@ -16,6 +16,10 @@ import com.dd.admin.business.note.entity.Note;
import com.dd.admin.business.note.service.NoteService; import com.dd.admin.business.note.service.NoteService;
import com.dd.admin.business.noteImg.entity.NoteImg; import com.dd.admin.business.noteImg.entity.NoteImg;
import com.dd.admin.business.noteImg.service.NoteImgService; import com.dd.admin.business.noteImg.service.NoteImgService;
import com.dd.admin.business.reply.domain.ReplyDto;
import com.dd.admin.business.reply.domain.ReplyVo;
import com.dd.admin.business.reply.entity.Reply;
import com.dd.admin.business.reply.service.ReplyService;
import com.dd.admin.business.starNotes.domain.StarNotesDto; import com.dd.admin.business.starNotes.domain.StarNotesDto;
import com.dd.admin.business.starNotes.domain.StarNotesVo; import com.dd.admin.business.starNotes.domain.StarNotesVo;
import com.dd.admin.business.starNotes.entity.StarNotes; import com.dd.admin.business.starNotes.entity.StarNotes;
@ -42,7 +46,12 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.dd.admin.common.consts.XhsConst.TRUE;
@RestController @RestController
public class AuthApi { public class AuthApi {
@ -64,43 +73,29 @@ public class AuthApi {
StarNotesService starNotesService; StarNotesService starNotesService;
@Autowired @Autowired
FollowService followService; FollowService followService;
@Autowired
ReplyService replyService;
@ApiOperation(value = "获取所有笔记") @ApiOperation(value = "获取所有笔记")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/notes") @GetMapping("/api/auth/notes")
@OperLog(operModule = "获取所有笔记",operType = OperType.QUERY,operDesc = "获取所有笔记") @OperLog(operModule = "获取所有笔记",operType = OperType.QUERY,operDesc = "获取所有笔记")
public ResultBean<IPage<NoteVo>> page(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> page(NoteDto noteDto) {
String authorId = String.valueOf(request.getAttribute("authorId")); String followId = String.valueOf(request.getAttribute("authorId"));
noteDto.setFollowId(followId);
IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto); IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
List<NoteVo> records = pageInfo.getRecords();
UpNotesDto upNotesDto = new UpNotesDto();
upNotesDto.setFollowId(authorId);
List<UpNotesVo> upNotesVos = upNotesService.selectUpNotesList(upNotesDto);
List<UpNotesVo> selectAllUpCount = upNotesService.selectAllUpCount();
records.stream().forEach(noteVo->{
UpNotesVo upNote = upNotesVos.stream().filter(upNotesVo -> noteVo.getNoteId().equals(upNotesVo.getNoteId())).findFirst().orElse(null);
if(upNote!=null){
noteVo.setIsUp(Boolean.TRUE);
}
UpNotesVo noteCount = selectAllUpCount.stream().filter(upNotesVo -> upNotesVo.getNoteId().equals(noteVo.getNoteId())).findFirst().orElse(null);
if(noteCount!=null){
noteVo.setUpCount(noteCount.getUpCount());
}
});
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
} }
@ApiOperation(value = "获取所有笔记") @ApiOperation(value = "获取所有关注笔记")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getFollowNotes") @GetMapping("/api/auth/getFollowNotes")
@OperLog(operModule = "获取所有笔记",operType = OperType.QUERY,operDesc = "获取所有笔记") @OperLog(operModule = "获取所有关注笔记",operType = OperType.QUERY,operDesc = "获取所有关注笔记")
public ResultBean<IPage<NoteVo>> getFollowNotes(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> getFollowNotes() {
String followId = String.valueOf(request.getAttribute("authorId")); String followId = String.valueOf(request.getAttribute("authorId"));
NoteDto noteDto = new NoteDto();
noteDto.setFollowId(followId);
List<Follow> follows = followService.selectFollowListByFollowId(followId); List<Follow> follows = followService.selectFollowListByFollowId(followId);
IPage<NoteVo> pageInfo = new IPage<NoteVo>() { IPage<NoteVo> pageInfo = new IPage<NoteVo>() {
@ -153,24 +148,7 @@ public class AuthApi {
String authorIds = CommonUtil.getIds(follows, "authorId"); String authorIds = CommonUtil.getIds(follows, "authorId");
noteDto.setAuthorIds(authorIds); noteDto.setAuthorIds(authorIds);
pageInfo = noteService.selectNotePage(noteDto); pageInfo = noteService.selectNotePage(noteDto);
List<NoteVo> records = pageInfo.getRecords();
UpNotesDto upNotesDto = new UpNotesDto();
upNotesDto.setFollowId(followId);
List<UpNotesVo> upNotesVos = upNotesService.selectUpNotesList(upNotesDto);
List<UpNotesVo> selectAllUpCount = upNotesService.selectAllUpCount();
records.stream().forEach(noteVo->{
UpNotesVo upNote = upNotesVos.stream().filter(upNotesVo -> noteVo.getNoteId().equals(upNotesVo.getNoteId())).findFirst().orElse(null);
if(upNote!=null){
noteVo.setIsUp(Boolean.TRUE);
} }
UpNotesVo noteCount = selectAllUpCount.stream().filter(upNotesVo -> upNotesVo.getNoteId().equals(noteVo.getNoteId())).findFirst().orElse(null);
if(noteCount!=null){
noteVo.setUpCount(noteCount.getUpCount());
}
});
}
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
} }
@ -180,27 +158,12 @@ public class AuthApi {
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getUpNotes") @GetMapping("/api/auth/getUpNotes")
@OperLog(operModule = "获取所有点赞笔记",operType = OperType.QUERY,operDesc = "获取所有点赞笔记") @OperLog(operModule = "获取所有点赞笔记",operType = OperType.QUERY,operDesc = "获取所有点赞笔记")
public ResultBean<IPage<NoteVo>> getUpNotes(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> getUpNotes() {
String authorId = String.valueOf(request.getAttribute("authorId")); String followId = String.valueOf(request.getAttribute("authorId"));
NoteDto noteDto = new NoteDto();
IPage<NoteVo> pageInfo = noteService.selectMineUpNotes(authorId); noteDto.setFollowId(followId);
List<NoteVo> records = pageInfo.getRecords(); noteDto.setMyUpById(followId);
UpNotesDto upNotesDto = new UpNotesDto(); IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
upNotesDto.setFollowId(authorId);
List<UpNotesVo> upNotesVos = upNotesService.selectUpNotesList(upNotesDto);
List<UpNotesVo> selectAllUpCount = upNotesService.selectAllUpCount();
records.stream().forEach(noteVo->{
UpNotesVo upNote = upNotesVos.stream().filter(upNotesVo -> noteVo.getNoteId().equals(upNotesVo.getNoteId())).findFirst().orElse(null);
if(upNote!=null){
noteVo.setIsUp(Boolean.TRUE);
}
UpNotesVo noteCount = selectAllUpCount.stream().filter(upNotesVo -> upNotesVo.getNoteId().equals(noteVo.getNoteId())).findFirst().orElse(null);
if(noteCount!=null){
noteVo.setUpCount(noteCount.getUpCount());
}
});
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
} }
@ -209,28 +172,12 @@ public class AuthApi {
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getStarNotes") @GetMapping("/api/auth/getStarNotes")
@OperLog(operModule = "获取所有收藏笔记",operType = OperType.QUERY,operDesc = "获取所有收藏笔记") @OperLog(operModule = "获取所有收藏笔记",operType = OperType.QUERY,operDesc = "获取所有收藏笔记")
public ResultBean<IPage<NoteVo>> getStarNotes(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> getStarNotes() {
String authorId = String.valueOf(request.getAttribute("authorId")); String followId = String.valueOf(request.getAttribute("authorId"));
NoteDto noteDto = new NoteDto();
IPage<NoteVo> pageInfo = noteService.selectMineStarNotes(authorId); noteDto.setFollowId(followId);
List<NoteVo> records = pageInfo.getRecords(); noteDto.setMyStarById(followId);
IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
UpNotesDto upNotesDto = new UpNotesDto();
upNotesDto.setFollowId(authorId);
List<UpNotesVo> upNotesVos = upNotesService.selectUpNotesList(upNotesDto);
List<UpNotesVo> selectAllUpCount = upNotesService.selectAllUpCount();
records.stream().forEach(noteVo->{
UpNotesVo upNote = upNotesVos.stream().filter(upNotesVo -> noteVo.getNoteId().equals(upNotesVo.getNoteId())).findFirst().orElse(null);
if(upNote!=null){
noteVo.setIsUp(Boolean.TRUE);
}
UpNotesVo noteCount = selectAllUpCount.stream().filter(upNotesVo -> upNotesVo.getNoteId().equals(noteVo.getNoteId())).findFirst().orElse(null);
if(noteCount!=null){
noteVo.setUpCount(noteCount.getUpCount());
}
});
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
} }
@ -238,7 +185,7 @@ public class AuthApi {
@ApiOperation(value = "获取博主信息") @ApiOperation(value = "获取博主信息")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getMine") @GetMapping("/api/auth/getMine")
@OperLog(operModule = "获取博主信息",operType = OperType.QUERY,operDesc = "获取博主信息") @OperLog(operModule = "获取当前博主信息",operType = OperType.QUERY,operDesc = "获取当前博主信息")
public ResultBean<Author> getMine() { public ResultBean<Author> getMine() {
String authorId = String.valueOf(request.getAttribute("authorId")); String authorId = String.valueOf(request.getAttribute("authorId"));
Author author = authorService.getById(authorId); Author author = authorService.getById(authorId);
@ -246,12 +193,14 @@ public class AuthApi {
} }
@ApiOperation(value = "获取博主笔记") @ApiOperation(value = "获取当前博主笔记")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getMineNotes") @GetMapping("/api/auth/getMineNotes")
@OperLog(operModule = "获取博主笔记",operType = OperType.QUERY,operDesc = "获取博主笔记") @OperLog(operModule = "获取当前博主笔记",operType = OperType.QUERY,operDesc = "获取当前博主笔记")
public ResultBean<IPage<NoteVo>> getMineNotes(NoteDto noteDto) { public ResultBean<IPage<NoteVo>> getMineNotes() {
String authorId = String.valueOf(request.getAttribute("authorId")); String authorId = String.valueOf(request.getAttribute("authorId"));
NoteDto noteDto = new NoteDto();
noteDto.setFollowId(authorId);
noteDto.setAuthorId(authorId); noteDto.setAuthorId(authorId);
IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto); IPage<NoteVo> pageInfo = noteService.selectNotePage(noteDto);
return ResultBean.success(pageInfo); return ResultBean.success(pageInfo);
@ -265,7 +214,7 @@ public class AuthApi {
public ResultBean upNote(@RequestBody NoteDto noteDto) { public ResultBean upNote(@RequestBody NoteDto noteDto) {
String followId = String.valueOf(request.getAttribute("authorId")); String followId = String.valueOf(request.getAttribute("authorId"));
Author follow = authorService.getById(followId); Author follow = authorService.getById(followId);
Boolean upNote = Boolean.FALSE; Boolean isUp = Boolean.FALSE;
//查看在不在点赞列表 //查看在不在点赞列表
UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId); UpNotes upNotes = upNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId);
//不在证明是点赞 //不在证明是点赞
@ -277,16 +226,42 @@ public class AuthApi {
upNotes.setFollowName(follow.getAuthorName()); upNotes.setFollowName(follow.getAuthorName());
upNotes.setNoteId(noteDto.getNoteId()); upNotes.setNoteId(noteDto.getNoteId());
upNotes.setNoteTitle(noteDto.getNoteTitle()); upNotes.setNoteTitle(noteDto.getNoteTitle());
upNote = Boolean.TRUE; isUp = Boolean.TRUE;
upNotesService.save(upNotes); upNotesService.save(upNotes);
}else{ }else{
//在则表示取消赞删除数据 //在则表示取消赞删除数据
upNotesService.removeById(upNotes); upNotesService.removeById(upNotes);
} }
return ResultBean.success(upNote); return ResultBean.success(isUp);
}; };
@ApiOperation(value = "收藏笔记")
@ApiOperationSupport(order = 1)
@PostMapping("/api/auth/starNote")
@OperLog(operModule = "收藏笔记",operType = OperType.ADD,operDesc = "收藏笔记")
public ResultBean starNote(@RequestBody NoteDto noteDto) {
String followId = String.valueOf(request.getAttribute("authorId"));
Author follow = authorService.getById(followId);
Boolean isStar = Boolean.FALSE;
//查看在不在点赞列表
StarNotes starNotes = starNotesService.selectOneByFollowId(noteDto.getNoteId(),noteDto.getAuthorId(), followId);
//不在证明是点赞
if(starNotes==null){
starNotes = new StarNotes();
starNotes.setAuthorId(noteDto.getAuthorId());
starNotes.setAuthorName(noteDto.getAuthorName());
starNotes.setFollowId(follow.getAuthorId());
starNotes.setFollowName(follow.getAuthorName());
starNotes.setNoteId(noteDto.getNoteId());
starNotes.setNoteTitle(noteDto.getNoteTitle());
isStar = Boolean.TRUE;
starNotesService.save(starNotes);
}else{
//在则表示取消赞删除数据
starNotesService.removeById(starNotes);
}
return ResultBean.success(isStar);
};
@ApiOperation(value = "创建笔记") @ApiOperation(value = "创建笔记")
@ -325,4 +300,124 @@ public class AuthApi {
noteService.updateById(updateNote); noteService.updateById(updateNote);
return ResultBean.success(); return ResultBean.success();
} }
//外层倒叙 回复正序
@ApiOperation(value = "获取笔记评论")
@ApiOperationSupport(order = 1)
@GetMapping("/api/auth/getNoteReply")
@OperLog(operModule = "获取笔记评论",operType = OperType.QUERY,operDesc = "获取笔记评论")
public ResultBean<Author> getNoteReply( ReplyDto replyDto) {
String noteId = replyDto.getNoteId();
List<ReplyVo> replyList = replyService.selectReplyList(new ReplyDto().setNoteId(noteId));
// 先构建一个以回复ID为键回复对象为值的Map方便后续快速查找回复对象
// 构建以replyId为键ReplyVo对象为值的Map方便后续快速查找回复对象
Map<String, ReplyVo> replyMap = replyList.stream()
.collect(Collectors.toMap(ReplyVo::getReplyId, reply -> reply));
List<ReplyVo> secondLevelReplies = replyList
.stream()
.filter(reply ->
(StringUtil.isNotEmpty(reply.getParentId())||StringUtil.isNotEmpty(reply.getTopParentId()))
).sorted(Comparator.comparing(ReplyVo::getCreateTime)).collect(Collectors.toList());
secondLevelReplies.forEach(replyVo -> {
if(StringUtil.isNotEmpty(replyVo.getParentId())){
replyVo.setParentAuthorId(replyMap.get(replyVo.getParentId()).getAuthorId());
replyVo.setParentAuthorName(replyMap.get(replyVo.getParentId()).getAuthorName());
}
});
// 获取第一层回复topId为空且parentId也为空
List<ReplyVo> firstLevelReplies = replyList.stream()
.filter(reply -> reply.getTopParentId() == null && reply.getParentId() == null)
.collect(Collectors.toList());
// 将第二层回复添加到对应的第一层回复下通过topId与replyId关联
firstLevelReplies.forEach(firstLevelReply -> {
String firstLevelReplyId = firstLevelReply.getReplyId();
List<ReplyVo> relatedSecondLevelReplies = secondLevelReplies.stream()
.filter(secondLevelReply -> firstLevelReplyId.equals(secondLevelReply.getTopParentId()))
.collect(Collectors.toList());
if (firstLevelReply.getReply() == null) {
firstLevelReply.setReply(new ArrayList<>());
}
firstLevelReply.getReply().addAll(relatedSecondLevelReplies);
});
return ResultBean.success(firstLevelReplies);
}
// // 先按照parentId进行分组用于后续查找子回复
// Map<String, List<ReplyVo>> groupedByParentId = replyList.stream()
// .filter(reply -> reply.getParentId()!= null &&!reply.getParentId().isEmpty())
// .collect(Collectors.groupingBy(ReplyVo::getParentId));
//
// // 处理每一个顶级回复parentId为null的回复递归构建树形结构
// List<ReplyVo> resultList = replyList.stream()
// .filter(reply -> reply.getParentId() == null || reply.getParentId().isEmpty())
// .peek(parentReply -> {
// // 递归设置子回复列表
// setChildrenReplies(parentReply, groupedByParentId);
// })
// .collect(Collectors.toList());
// // 第一步将回复列表按照parentId进行分组key是parentIdvalue是对应的回复列表
// Map<String, List<ReplyVo>> groupedByParentId = replyList.stream()
// .filter(reply -> reply.getParentId()!= null &&!reply.getParentId().isEmpty())
// .collect(Collectors.groupingBy(ReplyVo::getParentId));
//
// // 第二步创建一个新的列表用于存放最终处理后的回复列表先将没有parentId的元素添加进去
// List<ReplyVo> resultList = replyList.stream()
// .filter(reply -> reply.getParentId() == null || reply.getParentId().isEmpty())
// .collect(Collectors.toList());
//
// // 第三步遍历没有parentId的元素将其对应的子回复列表通过parentId从分组中获取设置到Reply属性下
// resultList.forEach(parentReply -> {
// String parentId = parentReply.getReplyId();
// List<ReplyVo> childrenReplies = groupedByParentId.getOrDefault(parentId, new ArrayList<>());
// parentReply.setReply(childrenReplies);
// });
//不再无限极调用 因为前端页面我不会写 采用和官方一样的@形式
private static void setChildrenReplies(ReplyVo parentReply, Map<String, List<ReplyVo>> groupedByParentId) {
String parentId = parentReply.getReplyId();
List<ReplyVo> childrenReplies = groupedByParentId.getOrDefault(parentId, new ArrayList<>());
// 遍历当前层级的子回复递归设置它们的子回复
childrenReplies.forEach(childReply -> {
setChildrenReplies(childReply, groupedByParentId);
});
parentReply.setReply(childrenReplies);
}
@ApiOperation(value = "回复笔记")
@ApiOperationSupport(order = 1)
@PostMapping("/api/auth/replyNote")
@OperLog(operModule = "回复笔记",operType = OperType.ADD,operDesc = "回复笔记")
public ResultBean replyNote(@RequestBody ReplyDto replyDto) {
String authorId = String.valueOf(request.getAttribute("authorId"));
Author author = authorService.getById(authorId);
Note note = noteService.getById(replyDto.getNoteId());
if (authorId.equals(note.getAuthorId())) {
replyDto.setAuthorReplay(TRUE);
}
List<ReplyVo> replyList = replyService.selectReplyList(new ReplyDto().setNoteId(replyDto.getNoteId()));
if (CollectionUtil.isEmpty(replyList)) {
replyDto.setFirstReplay(TRUE);
}
replyDto.setNoteId(note.getNoteId());
replyDto.setNoteTitile(note.getNoteTitle());
replyDto.setAuthorId(authorId);
replyDto.setAuthorName(author.getAuthorName());
replyDto.setAvatarUrl(author.getAvatarUrl());
replyDto.setIpAddress(IPUtils.getIpAddr(request)); // 请求IP
replyDto.setIpRealAddress(AddressUtils.getRealAddress(replyDto.getIpAddress()));
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
replyService.save(reply);
return ResultBean.success();
}
} }

View File

@ -48,15 +48,6 @@ public class LoginApi {
return ResultBean.success(code); return ResultBean.success(code);
} }
@ApiOperation(value = "获取验证码")
@ApiOperationSupport(order = 1)
@GetMapping("/api/getMine")
@OperLog(operModule = "获取验证码",operType = OperType.QUERY,operDesc = "获取验证码")
public ResultBean<String> getMine() {
String token = request.getHeader("token");
return ResultBean.success(token);
}
@ApiOperation(value = "验证码登陆") @ApiOperation(value = "验证码登陆")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@PostMapping("/api/checkCode") @PostMapping("/api/checkCode")

View File

@ -30,7 +30,11 @@ import com.dd.admin.common.model.UpdateGroup;
@Data @Data
@ApiModel(value="笔记表接收对象") @ApiModel(value="笔记表接收对象")
public class NoteDto { public class NoteDto {
@ApiModelProperty(value = "查询我收藏的字段")
private String myStarById;
@ApiModelProperty(value = "查询我点赞的字段")
private String myUpById;
@ApiModelProperty(value = "笔记id") @ApiModelProperty(value = "笔记id")
@NotBlank(message = "笔记表id不能为空",groups = UpdateGroup.class) @NotBlank(message = "笔记表id不能为空",groups = UpdateGroup.class)
@ -91,4 +95,10 @@ public class NoteDto {
@ApiModelProperty(value = "图片列表") @ApiModelProperty(value = "图片列表")
private List<String> imgs; private List<String> imgs;
@ApiModelProperty(value = "作者ID")
//传入此参数 如果你点赞了会显示相应状态
private String followId;
} }

View File

@ -51,6 +51,8 @@ public class NoteVo {
@ApiModelProperty(value = "作者ID") @ApiModelProperty(value = "作者ID")
private String authorId; private String authorId;
@ApiModelProperty(value = "作者头像") @ApiModelProperty(value = "作者头像")
private String authorAvatar; private String authorAvatar;
@ -91,6 +93,9 @@ public class NoteVo {
@ApiModelProperty(value = "收藏数") @ApiModelProperty(value = "收藏数")
private Long starCount; private Long starCount;
@ApiModelProperty(value = "被当前达人点赞")
private Boolean isStar = Boolean.FALSE;
@ApiModelProperty(value = "图片集合") @ApiModelProperty(value = "图片集合")
private List<String> imgList; private List<String> imgList;

View File

@ -27,6 +27,8 @@ public interface NoteMapper extends BaseMapper<Note> {
List<NoteVo> selectNoteList(@Param("noteDto") NoteDto noteDto); List<NoteVo> selectNoteList(@Param("noteDto") NoteDto noteDto);
NoteVo selectNoteDetail( @Param("noteDto") NoteDto noteDto);
IPage<NoteVo> selectMineUpNotes(Page<NoteVo> page, @Param("followId")String followId); IPage<NoteVo> selectMineUpNotes(Page<NoteVo> page, @Param("followId")String followId);
IPage<NoteVo> selectMineStarNotes(Page<NoteVo> page, @Param("followId")String followId); IPage<NoteVo> selectMineStarNotes(Page<NoteVo> page, @Param("followId")String followId);
} }

View File

@ -30,19 +30,50 @@
</sql> </sql>
<select id="selectNotePage" resultType="com.dd.admin.business.note.domain.NoteVo"> <select id="selectNotePage" resultType="com.dd.admin.business.note.domain.NoteVo">
select SELECT
*,CREATE_TIME AS createTimeStr a.*,
from business_note where deleted = 0 COALESCE(COUNT(b.note_id), 0) AS starCount,
<if test="noteDto.authorId != null and noteDto.authorId != ''"> COALESCE(COUNT(c.note_id), 0) AS upCount,
and AUTHOR_ID = #{noteDto.authorId} a.CREATE_TIME AS createTimeStr
<if test="noteDto.followId != null and noteDto.followId != ''">
,CASE WHEN EXISTS (
SELECT 1
FROM business_star_notes sub_b
WHERE sub_b.note_id = a.note_id
AND sub_b.follow_id = #{noteDto.followId}
) THEN true ELSE false END AS isStar
,CASE WHEN EXISTS (
SELECT 1
FROM business_up_notes sub_c
WHERE sub_c.note_id = a.note_id
AND sub_c.follow_id = #{noteDto.followId}
) THEN true ELSE false END AS isUp
</if> </if>
<if test="noteDto.authorIds != null and noteDto.authorId != ''"> FROM
and AUTHOR_ID in ${noteDto.authorIds} business_note a
LEFT JOIN
business_star_notes b ON a.note_id = b.note_id
LEFT JOIN
business_up_notes c ON a.note_id = c.note_id where a.deleted = 0
<if test="noteDto.authorId != null and noteDto.authorId != ''">
and a.AUTHOR_ID = #{noteDto.authorId}
</if>
<if test="noteDto.authorIds != null and noteDto.authorIds != ''">
and a.AUTHOR_ID in ${noteDto.authorIds}
</if> </if>
<if test="noteDto.ipRealAddress != null and noteDto.ipRealAddress != ''"> <if test="noteDto.ipRealAddress != null and noteDto.ipRealAddress != ''">
and IP_REAL_ADDRESS = #{noteDto.ipRealAddress} and a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress}
</if> </if>
order by CREATE_TIME desc <if test="noteDto.myStarById != null and noteDto.myStarById != ''">
and b.follow_id = #{noteDto.myStarById}
</if>
<if test="noteDto.myUpById != null and noteDto.myUpById != ''">
and c.follow_id = #{noteDto.myUpById}
</if>
GROUP BY
a.note_id
ORDER BY
a.create_time DESC
</select> </select>
<select id="selectNoteList" resultType="com.dd.admin.business.note.domain.NoteVo"> <select id="selectNoteList" resultType="com.dd.admin.business.note.domain.NoteVo">
@ -61,4 +92,50 @@
where b.follow_id = #{followId} where b.follow_id = #{followId}
order by b.create_time desc order by b.create_time desc
</select> </select>
<select id="selectNoteDetail" resultType="com.dd.admin.business.note.domain.NoteVo"
parameterType="java.lang.String">
SELECT
a.*,
COALESCE(COUNT(b.note_id), 0) AS starCount,
COALESCE(COUNT(c.note_id), 0) AS upCount,
a.CREATE_TIME AS createTimeStr
-- 使用 CASE WHEN 语句判断是否存在当前用户(通过传入的 followId对笔记的收藏记录有则为 true否则为 false
<if test="noteDto.followId != null and noteDto.followId != ''">
,CASE WHEN EXISTS (
SELECT 1
FROM business_star_notes sub_b
WHERE sub_b.note_id = a.note_id
AND sub_b.follow_id = #{noteDto.followId}
) THEN true ELSE false END AS isStar
,CASE WHEN EXISTS (
SELECT 1
FROM business_up_notes sub_c
WHERE sub_c.note_id = a.note_id
AND sub_c.follow_id = #{noteDto.followId}
) THEN true ELSE false END AS isUp
</if>
FROM
business_note a
LEFT JOIN
business_star_notes b ON a.note_id = b.note_id
LEFT JOIN
business_up_notes c ON a.note_id = c.note_id where a.deleted = 0
<if test="noteDto.authorId != null and noteDto.authorId != ''">
and a.AUTHOR_ID = #{noteDto.authorId}
</if>
<if test="noteDto.noteId != null and noteDto.noteId != ''">
and a.NOTE_ID = #{noteDto.noteId}
</if>
<if test="noteDto.authorIds != null and noteDto.authorIds != ''">
and a.AUTHOR_ID in ${noteDto.authorIds}
</if>
<if test="noteDto.ipRealAddress != null and noteDto.ipRealAddress != ''">
and a.IP_REAL_ADDRESS = #{noteDto.ipRealAddress}
</if>
GROUP BY
a.note_id
ORDER BY
a.create_time DESC limit 1
</select>
</mapper> </mapper>

View File

@ -22,10 +22,11 @@ public interface NoteService extends IService<Note> {
//笔记表-分页列表 //笔记表-分页列表
IPage<NoteVo> selectNotePage(NoteDto noteDto); IPage<NoteVo> selectNotePage(NoteDto noteDto);
//笔记表-列表 //笔记表-列表
List<NoteVo> selectNoteList(NoteDto noteDto); List<NoteVo> selectNoteList(NoteDto noteDto);
NoteVo selectNoteDetail(NoteDto noteDto);
IPage<NoteVo> selectMineUpNotes( String followId); IPage<NoteVo> selectMineUpNotes( String followId);
IPage<NoteVo> selectMineStarNotes( String followId); IPage<NoteVo> selectMineStarNotes( String followId);

View File

@ -34,6 +34,11 @@ public class NoteServiceImpl extends ServiceImpl<NoteMapper, Note> implements No
return baseMapper.selectNoteList(noteDto); return baseMapper.selectNoteList(noteDto);
} }
@Override
public NoteVo selectNoteDetail(NoteDto noteDto) {
return baseMapper.selectNoteDetail(noteDto);
}
@Override @Override
public IPage<NoteVo> selectMineUpNotes(String followId) { public IPage<NoteVo> selectMineUpNotes(String followId) {
Page page = PageFactory.defaultPage(); Page page = PageFactory.defaultPage();

View File

@ -0,0 +1,88 @@
package com.dd.admin.business.reply.controller;
import cn.hutool.core.bean.BeanUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dd.admin.common.model.UpdateGroup;
import com.dd.admin.common.model.result.ResultBean;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import com.dd.admin.business.reply.entity.Reply;
import com.dd.admin.business.reply.domain.ReplyVo;
import com.dd.admin.business.reply.domain.ReplyDto;
import com.dd.admin.business.reply.service.ReplyService;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 回复表 前端控制器
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Api(tags = "回复表")
@RestController
public class ReplyController {
@Autowired
ReplyService replyService;
@ApiOperation(value = "回复表-分页列表")
@ApiOperationSupport(order = 1)
@GetMapping("/admin/reply/page")
public ResultBean<IPage<ReplyVo>> page(ReplyDto replyDto) {
IPage<ReplyVo> pageInfo = replyService.selectReplyPage(replyDto);
return ResultBean.success(pageInfo);
}
@ApiOperation(value = "回复表-列表")
@ApiOperationSupport(order = 2)
@GetMapping("/admin/reply/list")
public ResultBean<List<ReplyVo>> list(ReplyDto replyDto) {
List<ReplyVo> list = replyService.selectReplyList(replyDto);
return ResultBean.success(list);
}
@ApiOperation(value = "回复表-添加")
@ApiOperationSupport(order = 3)
@PostMapping("/admin/reply/add")
public ResultBean<Reply> add(@RequestBody @Validated ReplyDto replyDto) {
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
replyService.save(reply);
return ResultBean.success(reply);
}
@ApiOperation(value = "回复表-查询")
@ApiOperationSupport(order = 4)
@GetMapping("/admin/reply/{replyId}")
public ResultBean<ReplyVo> get(@PathVariable @NotBlank String replyId) {
Reply reply = replyService.getById(replyId);
ReplyVo replyVo = BeanUtil.copyProperties(reply,ReplyVo.class);
return ResultBean.success(replyVo);
}
@ApiOperation(value = "回复表-修改")
@ApiOperationSupport(order = 5)
@PostMapping("/admin/reply/update")
public ResultBean<Reply> update(@RequestBody @Validated(UpdateGroup.class) ReplyDto replyDto) {
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
replyService.updateById(reply);
return ResultBean.success(reply);
}
@ApiOperation(value = "回复表-删除")
@ApiOperationSupport(order = 6)
@GetMapping("/admin/reply/delete/{replyId}")
public ResultBean<Reply> delete(@PathVariable @NotBlank String replyId) {
Boolean b = replyService.removeById(replyId);
return ResultBean.success(b);
}
}

View File

@ -0,0 +1,103 @@
package com.dd.admin.business.reply.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import com.dd.admin.common.model.UpdateGroup;
import lombok.experimental.Accessors;
/**
* <p>
* 回复表返回对象
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Data
@ApiModel(value="回复表接收对象")
@Accessors(chain = true)
public class ReplyDto {
@ApiModelProperty(value = "回复id")
@NotBlank(message = "回复表id不能为空",groups = UpdateGroup.class)
private String replyId;
@ApiModelProperty(value = "笔记id")
private String noteId;
@ApiModelProperty(value = "笔记标题")
private String noteTitile;
@ApiModelProperty(value = "作者id")
private String authorId;
@ApiModelProperty(value = "作者名")
private String authorName;
@ApiModelProperty(value = "作者id")
private String parentAuthorId;
@ApiModelProperty(value = "作者名")
private String parentAuthorName;
@ApiModelProperty(value = "第一层回复id")
private String topParentId;
@ApiModelProperty(value = "上级id")
private String parentId;
@ApiModelProperty(value = "回复内容")
private String replayContent;
@ApiModelProperty(value = "回复图片id")
private String replayImgId;
@ApiModelProperty(value = "回复图片Url")
private String replayImgUrl;
@ApiModelProperty(value = "0正常 1删除")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "ip地址")
private String ipAddress;
@ApiModelProperty(value = "真实ip地址")
private String ipRealAddress;
@ApiModelProperty(value = "是首评 0不是 1是")
private Integer firstReplay;
@ApiModelProperty(value = "是作者 0不是 1是")
private Integer authorReplay;
@ApiModelProperty(value = "0正常 1折叠")
private Integer replayStatus;
@ApiModelProperty(value = "0文字 1图片")
private Integer replayType;
@ApiModelProperty(value = "点赞数")
private Long upCount;
@ApiModelProperty(value = "头像地址")
private String avatarUrl;
}

View File

@ -0,0 +1,106 @@
package com.dd.admin.business.reply.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.ArrayList;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 回复表返回对象
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Data
@ApiModel(value="回复表返回对象")
public class ReplyVo {
@ApiModelProperty(value = "回复id")
private String replyId;
@ApiModelProperty(value = "笔记id")
private String noteId;
@ApiModelProperty(value = "笔记标题")
private String noteTitile;
@ApiModelProperty(value = "作者id")
private String authorId;
@ApiModelProperty(value = "作者名")
private String authorName;
@ApiModelProperty(value = "作者id")
private String parentAuthorId;
@ApiModelProperty(value = "作者名")
private String parentAuthorName;
@ApiModelProperty(value = "第一层回复的id")
private String topParentId;
@ApiModelProperty(value = "上级id")
private String parentId;
@ApiModelProperty(value = "回复内容")
private String replayContent;
@ApiModelProperty(value = "回复图片id")
private String replayImgId;
@ApiModelProperty(value = "回复图片Url")
private String replayImgUrl;
@ApiModelProperty(value = "0正常 1删除")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建时间")
@JsonFormat(pattern="MM-dd", timezone = "GMT+8")
private Date createTimeStr;
@ApiModelProperty(value = "ip地址")
private String ipAddress;
@ApiModelProperty(value = "真实ip地址")
private String ipRealAddress;
@ApiModelProperty(value = "是首评 0不是 1是")
private Integer firstReplay;
@ApiModelProperty(value = "是作者 0不是 1是")
private Integer authorReplay;
@ApiModelProperty(value = "0正常 1折叠")
private Integer replayStatus;
@ApiModelProperty(value = "0文字 1图片")
private Integer replayType;
@ApiModelProperty(value = "点赞数")
private Long upCount;
@ApiModelProperty(value = "头像地址")
private String avatarUrl;
private List<ReplyVo> Reply = new ArrayList<>();
}

View File

@ -0,0 +1,121 @@
package com.dd.admin.business.reply.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 回复表
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("business_reply")
@ApiModel(value="Reply对象", description="回复表")
public class Reply implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "回复id")
@TableId(value = "REPLY_ID", type = IdType.ASSIGN_UUID)
private String replyId;
@ApiModelProperty(value = "笔记id")
@TableField("NOTE_ID")
private String noteId;
@ApiModelProperty(value = "笔记标题")
@TableField("NOTE_TITILE")
private String noteTitile;
@ApiModelProperty(value = "作者id")
@TableField("AUTHOR_ID")
private String authorId;
@ApiModelProperty(value = "作者名")
@TableField("AUTHOR_NAME")
private String authorName;
@ApiModelProperty(value = "上级id")
@TableField("PARENT_ID")
private String parentId;
@ApiModelProperty(value = "作者id")
private String parentAuthorId;
@ApiModelProperty(value = "作者名")
private String parentAuthorName;
@ApiModelProperty(value = "第一层回复的id")
private String topParentId;
@ApiModelProperty(value = "回复内容")
@TableField("REPLAY_CONTENT")
private String replayContent;
@ApiModelProperty(value = "回复图片id")
@TableField("REPLAY_IMG_ID")
private String replayImgId;
@ApiModelProperty(value = "回复图片Url")
@TableField("REPLAY_IMG_URL")
private String replayImgUrl;
@ApiModelProperty(value = "0正常 1删除")
@TableField("DELETED")
@TableLogic
private Integer deleted;
@ApiModelProperty(value = "创建时间")
@TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "ip地址")
@TableField("IP_ADDRESS")
private String ipAddress;
@ApiModelProperty(value = "真实ip地址")
@TableField("IP_REAL_ADDRESS")
private String ipRealAddress;
@ApiModelProperty(value = "是首评 0不是 1是")
@TableField("FIRST_REPLAY")
private Integer firstReplay;
@ApiModelProperty(value = "是作者 0不是 1是")
@TableField("AUTHOR_REPLAY")
private Integer authorReplay;
@ApiModelProperty(value = "0正常 1折叠")
@TableField("REPLAY_STATUS")
private Integer replayStatus;
@ApiModelProperty(value = "0文字 1图片")
@TableField("REPLAY_TYPE")
private Integer replayType;
@ApiModelProperty(value = "点赞数")
@TableField("UP_COUNT")
private Long upCount;
@ApiModelProperty(value = "头像地址")
@TableField("AVATAR_URL")
private String avatarUrl;
}

View File

@ -0,0 +1,28 @@
package com.dd.admin.business.reply.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.admin.business.reply.entity.Reply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dd.admin.business.reply.domain.ReplyVo;
import com.dd.admin.business.reply.domain.ReplyDto;
import java.util.List;
/**
* <p>
* 回复表 Mapper 接口
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Mapper
public interface ReplyMapper extends BaseMapper<Reply> {
IPage<ReplyVo> selectReplyPage(Page<ReplyVo> page, @Param("replyDto") ReplyDto replyDto);
List<ReplyVo> selectReplyList(@Param("replyDto") ReplyDto replyDto);
}

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dd.admin.business.reply.mapper.ReplyMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.dd.admin.business.reply.entity.Reply">
<id column="REPLY_ID" property="replyId" />
<result column="NOTE_ID" property="noteId" />
<result column="NOTE_TITILE" property="noteTitile" />
<result column="AUTHOR_ID" property="authorId" />
<result column="AUTHOR_NAME" property="authorName" />
<result column="PARENT_ID" property="parentId" />
<result column="REPLAY_CONTENT" property="replayContent" />
<result column="REPLAY_IMG_ID" property="replayImgId" />
<result column="REPLAY_IMG_URL" property="replayImgUrl" />
<result column="DELETED" property="deleted" />
<result column="CREATE_TIME" property="createTime" />
<result column="IP_ADDRESS" property="ipAddress" />
<result column="IP_REAL_ADDRESS" property="ipRealAddress" />
<result column="FIRST_REPLAY" property="firstReplay" />
<result column="AUTHOR_REPLAY" property="authorReplay" />
<result column="REPLAY_STATUS" property="replayStatus" />
<result column="REPLAY_TYPE" property="replayType" />
<result column="UP_COUNT" property="upCount" />
<result column="AVATAR_URL" property="avatarUrl" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
REPLY_ID, NOTE_ID, NOTE_TITILE, AUTHOR_ID, AUTHOR_NAME, PARENT_ID, REPLAY_CONTENT, REPLAY_IMG_ID, REPLAY_IMG_URL, DELETED, CREATE_TIME, IP_ADDRESS, IP_REAL_ADDRESS, FIRST_REPLAY, AUTHOR_REPLAY, REPLAY_STATUS, REPLAY_TYPE, UP_COUNT, AVATAR_URL
</sql>
<select id="selectReplyPage" resultType="com.dd.admin.business.reply.domain.ReplyVo">
select
*
from business_reply where 1 = 1
</select>
<select id="selectReplyList" resultType="com.dd.admin.business.reply.domain.ReplyVo">
select
*,CREATE_TIME AS createTimeStr
from business_reply where DELETED = 0
<if test="replyDto.noteId != null and replyDto.noteId != ''">
and NOTE_ID = #{replyDto.noteId}
</if>
order by up_count asc,create_time desc
</select>
</mapper>

View File

@ -0,0 +1,26 @@
package com.dd.admin.business.reply.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dd.admin.business.reply.entity.Reply;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dd.admin.business.reply.domain.ReplyVo;
import com.dd.admin.business.reply.domain.ReplyDto;
import java.util.List;
/**
* <p>
* 回复表 服务类
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
public interface ReplyService extends IService<Reply> {
//回复表-分页列表
IPage<ReplyVo> selectReplyPage(ReplyDto replyDto);
//回复表-列表
List<ReplyVo> selectReplyList(ReplyDto replyDto);
}

View File

@ -0,0 +1,36 @@
package com.dd.admin.business.reply.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.admin.common.model.PageFactory;
import com.dd.admin.business.reply.entity.Reply;
import com.dd.admin.business.reply.mapper.ReplyMapper;
import com.dd.admin.business.reply.service.ReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.dd.admin.business.reply.domain.ReplyVo;
import com.dd.admin.business.reply.domain.ReplyDto;
import java.util.List;
/**
* <p>
* 回复表 服务实现类
* </p>
*
* @author 727869402@qq.com
* @since 2024-12-25
*/
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements ReplyService {
@Override
public IPage<ReplyVo> selectReplyPage(ReplyDto replyDto) {
Page page = PageFactory.defaultPage();
return baseMapper.selectReplyPage(page,replyDto);
}
@Override
public List<ReplyVo> selectReplyList(ReplyDto replyDto) {
return baseMapper.selectReplyList(replyDto);
}
}

View File

@ -7,6 +7,7 @@ import com.dd.admin.business.starNotes.domain.StarNotesVo;
import com.dd.admin.business.starNotes.domain.StarNotesDto; import com.dd.admin.business.starNotes.domain.StarNotesDto;
import com.dd.admin.business.upNotes.domain.UpNotesDto; import com.dd.admin.business.upNotes.domain.UpNotesDto;
import com.dd.admin.business.upNotes.domain.UpNotesVo; import com.dd.admin.business.upNotes.domain.UpNotesVo;
import com.dd.admin.business.upNotes.entity.UpNotes;
import java.util.List; import java.util.List;
@ -26,4 +27,7 @@ public interface StarNotesService extends IService<StarNotes> {
//收藏笔记列表-列表 //收藏笔记列表-列表
List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto); List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto);
StarNotes selectOneByFollowId(String noteId, String authorId, String followId);
} }

View File

@ -1,7 +1,9 @@
package com.dd.admin.business.starNotes.service.impl; package com.dd.admin.business.starNotes.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.admin.business.upNotes.entity.UpNotes;
import com.dd.admin.common.model.PageFactory; import com.dd.admin.common.model.PageFactory;
import com.dd.admin.business.starNotes.entity.StarNotes; import com.dd.admin.business.starNotes.entity.StarNotes;
import com.dd.admin.business.starNotes.mapper.StarNotesMapper; import com.dd.admin.business.starNotes.mapper.StarNotesMapper;
@ -33,4 +35,14 @@ public class StarNotesServiceImpl extends ServiceImpl<StarNotesMapper, StarNotes
public List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto) { public List<StarNotesVo> selectStarNotesList(StarNotesDto starNotesDto) {
return baseMapper.selectStarNotesList(starNotesDto); return baseMapper.selectStarNotesList(starNotesDto);
} }
@Override
public StarNotes selectOneByFollowId(String noteId, String authorId, String followId) {
LambdaQueryWrapper<StarNotes> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(StarNotes::getNoteId,noteId);
queryWrapper.eq(StarNotes::getAuthorId,authorId);
queryWrapper.eq(StarNotes::getFollowId,followId);
return this.getOne(queryWrapper);
}
} }

View File

@ -20,6 +20,16 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
public class GolbalConfig implements WebMvcConfigurer { public class GolbalConfig implements WebMvcConfigurer {
@Autowired
private ApiInterceptor apiInterceptor;
// 注册拦截器的方法
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(apiInterceptor)
.addPathPatterns("/api/auth/**"); // 拦截/api下所有请求路径
}
@Value("${dd.uploadPath}") @Value("${dd.uploadPath}")
private String uploadPath; private String uploadPath;
@ -53,15 +63,7 @@ public class GolbalConfig implements WebMvcConfigurer {
} }
@Autowired
private ApiInterceptor apiInterceptor;
// 注册拦截器的方法
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(apiInterceptor)
.addPathPatterns("/api/auth/**"); // 拦截/api下所有请求路径
}
// @Bean // @Bean

View File

@ -0,0 +1,8 @@
package com.dd.admin.common.consts;
public class XhsConst {
/**
* 肯定
*/
public final static Integer TRUE = 1;
}

View File

@ -43,8 +43,6 @@ public class ApiInterceptor implements HandlerInterceptor {
if (StrUtil.isBlank(token)) { if (StrUtil.isBlank(token)) {
throw new ApiException("请登录后访问"); throw new ApiException("请登录后访问");
} }
//解析token //解析token
System.out.println(token); System.out.println(token);
String authorId = jwtTokenUtil.getUsernameFromToken(token); String authorId = jwtTokenUtil.getUsernameFromToken(token);