Skip to content

Commit

Permalink
修复了留言的一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TreasureJade committed Dec 28, 2019
1 parent 21209a4 commit a918b10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CreatLeaveMsgForm {

@ApiModelProperty("留言内容")
@NotNull(message = "留言内容不能为空")
private String commentMsg;
private String leaveMsg;

@ApiModelProperty("被回复人 ")
private Long replyUserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class LeaveMessageServiceImpl implements LeaveMessageService {
@Override
public ResultVO insertLeaveMsg(CreatLeaveMsgForm form) {
LeaveMessage leaveMessage = new LeaveMessage();
BeanUtils.copyProperties(form,leaveMessage);
if (leaveMessage.getReplyUserId()==null){
BeanUtils.copyProperties(form, leaveMessage);
if (leaveMessage.getReplyUserId() == null) {
leaveMessage.setReplyUserId(0L);
}
User user = userService.getCurrentUser();
Expand All @@ -46,7 +46,7 @@ public ResultVO insertLeaveMsg(CreatLeaveMsgForm form) {
}
leaveMessage.setUserId(user.getUserId());
leaveMessage.setCreatTime(TimeUtil.getNowTime());
if (messageMapper.insert(leaveMessage)==1){
if (messageMapper.insert(leaveMessage) == 1) {
return ResultVOUtil.success();
}
return ResultVOUtil.error(ResultEnum.SERVER_ERROR);
Expand All @@ -56,7 +56,7 @@ public ResultVO insertLeaveMsg(CreatLeaveMsgForm form) {
public ResultVO selectAllLeaveMsg() {
List<LeaveMsgVO> result = new ArrayList<>();
List<Long> leaveMsgIdList = messageMapper.getAllParentLeaveMsg();
for (Long leaveMsgId : leaveMsgIdList){
for (Long leaveMsgId : leaveMsgIdList) {
LeaveMsgVO vo = messageMapper.selectByLeaveMsgId(leaveMsgId);
List<ReplyVO> vos = messageMapper.selectByPid(vo.getLeaveMessageId());
List<ReplyVO> reply = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.swpu.uchain.blog.entity.Visitor;
import com.swpu.uchain.blog.redis.RedisService;
import com.swpu.uchain.blog.redis.key.IpKey;
import com.swpu.uchain.blog.redis.key.UpdateTimeKey;
import com.swpu.uchain.blog.service.VisitorService;
import com.swpu.uchain.blog.util.IpUtil;
import com.swpu.uchain.blog.util.ResultVOUtil;
import com.swpu.uchain.blog.util.TimeUtil;
import com.swpu.uchain.blog.vo.IndexMsgVO;
import com.swpu.uchain.blog.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -35,8 +37,8 @@ public void addVisitorNum(HttpServletRequest request) {
if (visitor == null) {
visitor = visitorMapper.selectByPage("total_page");
visitor.setTotalNum(visitor.getTotalNum() + 1);
if (visitorMapper.updateByPrimaryKey(visitor)==1){
redisService.set(IpKey.ipKey,Ip,visitor);
if (visitorMapper.updateByPrimaryKey(visitor) == 1) {
redisService.set(IpKey.ipKey, Ip, visitor);
}

}
Expand All @@ -49,6 +51,12 @@ public ResultVO getIndexMsg() {
vo.setCommentTotal(visitorMapper.getCommentTotal());
vo.setLeaveMessageTotal(visitorMapper.getLeaveMsgTotal());
vo.setTagTotal(visitorMapper.getTagsTotal());
String updateTime = redisService.get(UpdateTimeKey.timeKey, "updateTime", String.class);
if (updateTime == null || "".equals(updateTime)) {
String time = TimeUtil.getTimeCN();
redisService.set(UpdateTimeKey.timeKey, "updateTime", time);
}
vo.setUpdateTime(redisService.get(UpdateTimeKey.timeKey, "updateTime", String.class));
return ResultVOUtil.success(vo);
}
}
8 changes: 4 additions & 4 deletions src/main/resources/mappers/LeaveMessageMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
<select id="selectByLeaveMsgId" resultType="com.swpu.uchain.blog.vo.LeaveMsgVO">
SELECT u.user_id,u.username,u.head_portrait ,lm.leave_message_id,lm.leave_msg,lm.creat_time
FROM leave_message lm
LEFT JOIN user u on c.user_id = u.user_id
where c.comment_id = #{id}
LEFT JOIN user u on lm.user_id = u.user_id
where lm.leave_message_id = #{id}
</select>
<select id="selectByPid" resultType="com.swpu.uchain.blog.vo.ReplyVO">
SELECT u.user_id,u.username,u.head_portrait ,lm.leave_message_id as comment_id,
lm.leave_msg as comment_msg,lm.creat_time,lm.reply_user_id
FROM
user u,
leave_message lm
WHERE u.user_id = c.user_id
and c.pid = #{pid}
WHERE u.user_id = lm.user_id
and lm.pid = #{pid}
</select>
</mapper>

0 comments on commit a918b10

Please sign in to comment.