use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method getNewsCommentList.
@Override
public PageVO<NewsCommentBO> getNewsCommentList(Integer newsId, Pageable pageable, Integer userId) {
Page<NewsCommentBO> allByNewsIdAndIsDel = newsCommentRepository.findAllByNewsIdAndIsDel(newsId, false, pageable);
List<NewsCommentBO> commentList = allByNewsIdAndIsDel.getContent();
commentList.forEach(li -> {
// 评论中评论的回复只显示未删除的点赞最多的三条
if (li.getReplies().size() > 3) {
li.setReplies(li.getReplies().stream().filter(de -> !de.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()).subList(0, 3));
li.setIsNeedOpen(true);
} else {
li.setIsNeedOpen(false);
}
// 评论字段赋值
UserInfo userInfo = userInfoService.selectById(li.getUserId());
li.setUserName(userInfo.getUsername());
li.setAvatar(userInfo.getPicPath());
if (li.getZan() > 0 && userId != null) {
CommentZanBO zanInfo = commentZanRepository.findOne(li.getId());
if (zanInfo != null && zanInfo.getZanUserList().parallelStream().anyMatch(zan -> zan.equals(userId))) {
li.setIsPraised(true);
} else {
li.setIsPraised(false);
}
} else {
li.setIsPraised(false);
}
// 设置能否删除该评论字段
if (li.getUserId().equals(userId)) {
li.setIsCanDel(true);
} else {
li.setIsCanDel(false);
}
// 回复字段赋值
li.getReplies().forEach(re -> handleReplies(re, userId));
});
return new PageVO(allByNewsIdAndIsDel, pageable.getPageNumber(), commentList);
}
use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.
the class UserInfoApi method updateAvatar.
/**
* 修改用户信息
*
* @param type 要修改的类型有{avatar,name,mobile,description,pwd}
* @param userInfoUpdateVO
* @return
*/
@PostMapping("/updateUserInfo/{type}/v1")
public Result<String> updateAvatar(@PathVariable("type") String type, UserInfoUpdateVO userInfoUpdateVO, HttpServletResponse httpResponse) {
// 设置ajax跨域可访问
httpResponse.addHeader("Access-Control-Allow-Origin", "*");
UserInfoBO loginUser = userComponent.getLoginUser();
if (loginUser.getId() == null) {
return Result.error("unLogin", "请登录后再进行操作");
}
UserInfo userInfo = new UserInfo(loginUser.getId());
userInfo.setPicPath(userInfoBORepository.findOne(loginUser.getId()).getUserInfo().getPicPath());
switch(type) {
case "avatar":
if (userInfoUpdateVO.getFile() == null) {
return Result.error("null", "请选择图片");
}
if (userComponent.updateUserAvatar(loginUser.getId(), userInfoUpdateVO.getFile())) {
return Result.success();
}
return Result.error("error", "头像更改失败");
case "name":
if (StringUtils.isBlank(userInfoUpdateVO.getName())) {
return Result.error("null", "用户名不能为空");
} else if (!userInfoUpdateVO.getName().equals(loginUser.getUserInfo().getUsername()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getName())) {
return Result.error("null", "昵称修改失败该昵称已被占用");
}
userInfo.setUsername(userInfoUpdateVO.getName());
break;
case "description":
if (StringUtils.isBlank(userInfoUpdateVO.getDescription())) {
return Result.error("null", "个性签名不能为空");
}
userInfo.setAutograph(userInfoUpdateVO.getDescription());
break;
case "mobile":
if (StringUtils.isBlank(userInfoUpdateVO.getMobile())) {
return Result.error("null", "请输入要修改的手机号码");
} else if (!userInfoUpdateVO.getMobile().matches(Phone.CK)) {
return Result.error("error", "请输入正确的的电话号码");
} else if (!userInfoUpdateVO.getMobile().equals(loginUser.getUserInfo().getMobile()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getMobile())) {
return Result.error("error", "手机号修改失败该号码已被占用");
}
userInfo.setMobile(userInfoUpdateVO.getMobile());
break;
case "pwd":
if (StringUtils.isBlank(userInfoUpdateVO.getOldPwd())) {
return Result.error("null", "请输入原密码");
} else if (!userInfoService.selectById(loginUser.getId()).getPwd().equals(userInfoUpdateVO.getOldPwd())) {
return Result.error("error", "原密码输入错误,密码修改失败");
} else if (StringUtils.isBlank(userInfoUpdateVO.getNewPwd1()) || StringUtils.isBlank(userInfoUpdateVO.getNewPwd2()) || !userInfoUpdateVO.getNewPwd2().equals(userInfoUpdateVO.getNewPwd1())) {
return Result.error("error", "新密码未输入或两次密码输入不一致,密码修改失败");
}
userInfo.setPwd(userInfoUpdateVO.getNewPwd1());
break;
default:
return Result.error("error", "不支持该类型的修改");
}
// 修改数据库
userInfoService.updateById(userInfo);
UserInfo userInfo1 = userInfoService.selectById(loginUser.getId());
// 修改缓存
UserInfoBO one = userInfoBORepository.findOne(loginUser.getId());
if (one != null) {
one.setUserInfo(userInfo1);
} else {
one = new UserInfoBO(loginUser.getId(), userInfo1);
}
userInfoBORepository.save(one);
return Result.success();
}
use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.
the class UserComponent method userRegister.
/**
* 用户注册
* @param registerVO
* @return
*/
public Integer userRegister(RegisterVO registerVO) {
if (!registerVO.getPwd1().equals(registerVO.getPwd2())) {
return null;
}
UserInfo userInfo = new UserInfo();
userInfo.setUsername(registerVO.getUserName());
userInfo.setMobile(registerVO.getMobile());
userInfo.setPwd(registerVO.getPwd1());
userInfoService.insert(userInfo);
// 注册的时候就给用户一个初始信用积分
UserInfoBO userInfoBO = new UserInfoBO(userInfo.getId(), userInfo);
userInfoBORepository.save(userInfoBO);
return userInfo.getId();
}
use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.
the class UserComponent method getLoginUser.
/**
* 获取当前用户信息
*
* @return
*/
public UserInfoBO getLoginUser() {
Integer userId = getUserId();
if (userId == -1) {
return new UserInfoBO();
} else {
UserInfoBO one = userInfoBORepository.findOne(userId);
if (one == null) {
UserInfo userInfo = userInfoService.selectById(userId);
UserInfoBO userInfoBO = new UserInfoBO(userId, userInfo);
userInfoBORepository.save(userInfoBO);
return userInfo != null ? userInfoBO : new UserInfoBO();
} else {
return one;
}
}
}
use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method getCommentReplies.
@Override
public CommentReplyVO getCommentReplies(String commentId, PageableVo pageable, Integer userId) {
StopWatch stopWatch = new StopWatch("mongo");
stopWatch.start("查询");
CommentReplyVO commentReplyVO = new CommentReplyVO(newsCommentRepository.findOne(commentId), pageable);
stopWatch.stop();
if (commentReplyVO.getNewsCommentAndReply() != null) {
stopWatch.start("评论处理");
UserInfo userInfo = userInfoService.selectById(commentReplyVO.getNewsCommentAndReply().getUserId());
commentReplyVO.getNewsCommentAndReply().setAvatar(userInfo.getPicPath());
commentReplyVO.getNewsCommentAndReply().setUserName(userInfo.getUsername());
if (commentReplyVO.getNewsCommentAndReply().getZan() > 0 && userId != null) {
CommentZanBO one = commentZanRepository.findOne(commentReplyVO.getNewsCommentAndReply().getId());
if (one != null) {
commentReplyVO.getNewsCommentAndReply().setIsPraised(one.getZanUserList().parallelStream().anyMatch(li -> li.equals(userId)));
} else {
commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
}
} else {
commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
}
// 设置能否删除该评论字段
if (commentReplyVO.getNewsCommentAndReply().getUserId().equals(userId)) {
commentReplyVO.getNewsCommentAndReply().setIsCanDel(true);
} else {
commentReplyVO.getNewsCommentAndReply().setIsCanDel(false);
}
stopWatch.stop();
if (CollectionUtils.isNotEmpty(commentReplyVO.getNewsCommentAndReply().getReplies())) {
stopWatch.start("回复分页处理");
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().stream().filter(li -> !li.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()));
Integer replySize = commentReplyVO.getNewsCommentAndReply().getReplies().size();
if (replySize >= pageable.getPage() * pageable.getSize() - pageable.getSize()) {
if (pageable.getPage() == 1) {
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(0, pageable.getSize() > replySize ? replySize : pageable.getSize()));
} else {
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(pageable.getPage() * pageable.getSize() - pageable.getSize(), replySize > pageable.getPage() * pageable.getSize() ? pageable.getPage() * pageable.getSize() : replySize));
}
} else {
commentReplyVO.getNewsCommentAndReply().setReplies(new ArrayList<>());
}
stopWatch.stop();
stopWatch.start("数据库查询操作");
commentReplyVO.getNewsCommentAndReply().getReplies().forEach(li -> handleReplies(li, userId));
stopWatch.stop();
}
}
System.out.println(stopWatch.prettyPrint());
return commentReplyVO;
}
Aggregations