后端代码优化

This commit is contained in:
linfeng 2022-12-14 10:22:35 +08:00
parent 197c94fa85
commit 1ef4e7a278
4 changed files with 34 additions and 14 deletions

View File

@ -8,7 +8,8 @@
* Copyright (c) 2021-2023 linfeng all rights reserved.
* 版权所有 侵权必究
* -----------------------------------
*/package io.linfeng.modules.admin.controller;
*/
package io.linfeng.modules.admin.controller;
import java.util.Arrays;
import java.util.Map;

View File

@ -46,6 +46,12 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
return new PageUtils(page);
}
/**
* 是否点赞
* @param uid
* @param id
* @return
*/
@Override
public Boolean isThumbs(Integer uid, Long id) {
CommentThumbsEntity one = baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
@ -62,6 +68,11 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
.count();
}
/**
* 点赞
* @param request
* @param user
*/
@Override
public void addThumbs(AddThumbsForm request, AppUserEntity user) {
CommentThumbsEntity one=baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
@ -74,9 +85,17 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
ct.setUid(user.getUid());
ct.setCId(request.getId());
ct.setCreateTime(DateUtil.nowDateTime());
this.save(ct);
boolean save = this.save(ct);
if(!save){
throw new LinfengException("点赞失败");
}
}
/**
* 取消点赞
* @param request
* @param user
*/
@Override
public void cancelThumbs(AddThumbsForm request, AppUserEntity user) {
baseMapper.delete(new LambdaQueryWrapper<CommentThumbsEntity>()

View File

@ -64,8 +64,7 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
LambdaQueryWrapper<FollowEntity> queryWrapper= Wrappers.lambdaQuery();
queryWrapper.eq(FollowEntity::getUid,uid);
queryWrapper.eq(FollowEntity::getFollowUid,id);
Integer num = baseMapper.selectCount(queryWrapper);
return num!=0;
return baseMapper.selectCount(queryWrapper) != 0;
}
@Override
@ -79,15 +78,13 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
LambdaQueryWrapper<FollowEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(FollowEntity::getUid, uid);
lambdaQueryWrapper.eq(FollowEntity::getFollowUid, followUid);
Integer num = baseMapper.selectCount(lambdaQueryWrapper);
if(num == 0){
if(baseMapper.selectCount(lambdaQueryWrapper) == 0){
return 0;
}
LambdaQueryWrapper<FollowEntity> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
lambdaQueryWrapper2.eq(FollowEntity::getUid, followUid);
lambdaQueryWrapper2.eq(FollowEntity::getFollowUid, uid);
Integer num2 = baseMapper.selectCount(lambdaQueryWrapper2);
return num2==0?2:1;
LambdaQueryWrapper<FollowEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(FollowEntity::getUid, followUid);
wrapper.eq(FollowEntity::getFollowUid, uid);
return baseMapper.selectCount(wrapper) == 0 ? 2 : 1;
}
@Override
@ -104,7 +101,9 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
@Override
public List<Integer> getFollowUids(AppUserEntity user) {
List<FollowEntity> list = this.lambdaQuery().eq(FollowEntity::getUid, user.getUid()).list();
List<FollowEntity> list = this.lambdaQuery()
.eq(FollowEntity::getUid, user.getUid())
.list();
return list.stream().map(FollowEntity::getFollowUid).collect(Collectors.toList());
}

View File

@ -48,8 +48,9 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
@Override
public Integer collectCount(Integer postId) {
return baseMapper.selectCount(new LambdaQueryWrapper<PostCollectionEntity>()
.eq(PostCollectionEntity::getPostId, postId));
return this.lambdaQuery()
.eq(PostCollectionEntity::getPostId,postId)
.count();
}
@Override