后端代码优化
This commit is contained in:
parent
197c94fa85
commit
1ef4e7a278
@ -8,7 +8,8 @@
|
|||||||
* Copyright (c) 2021-2023 linfeng all rights reserved.
|
* 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.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -46,6 +46,12 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
|
|||||||
return new PageUtils(page);
|
return new PageUtils(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否点赞
|
||||||
|
* @param uid
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean isThumbs(Integer uid, Long id) {
|
public Boolean isThumbs(Integer uid, Long id) {
|
||||||
CommentThumbsEntity one = baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
CommentThumbsEntity one = baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||||
@ -62,6 +68,11 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
|
|||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞
|
||||||
|
* @param request
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addThumbs(AddThumbsForm request, AppUserEntity user) {
|
public void addThumbs(AddThumbsForm request, AppUserEntity user) {
|
||||||
CommentThumbsEntity one=baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
CommentThumbsEntity one=baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||||
@ -74,9 +85,17 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
|
|||||||
ct.setUid(user.getUid());
|
ct.setUid(user.getUid());
|
||||||
ct.setCId(request.getId());
|
ct.setCId(request.getId());
|
||||||
ct.setCreateTime(DateUtil.nowDateTime());
|
ct.setCreateTime(DateUtil.nowDateTime());
|
||||||
this.save(ct);
|
boolean save = this.save(ct);
|
||||||
|
if(!save){
|
||||||
|
throw new LinfengException("点赞失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消点赞
|
||||||
|
* @param request
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void cancelThumbs(AddThumbsForm request, AppUserEntity user) {
|
public void cancelThumbs(AddThumbsForm request, AppUserEntity user) {
|
||||||
baseMapper.delete(new LambdaQueryWrapper<CommentThumbsEntity>()
|
baseMapper.delete(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||||
|
@ -64,8 +64,7 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
|
|||||||
LambdaQueryWrapper<FollowEntity> queryWrapper= Wrappers.lambdaQuery();
|
LambdaQueryWrapper<FollowEntity> queryWrapper= Wrappers.lambdaQuery();
|
||||||
queryWrapper.eq(FollowEntity::getUid,uid);
|
queryWrapper.eq(FollowEntity::getUid,uid);
|
||||||
queryWrapper.eq(FollowEntity::getFollowUid,id);
|
queryWrapper.eq(FollowEntity::getFollowUid,id);
|
||||||
Integer num = baseMapper.selectCount(queryWrapper);
|
return baseMapper.selectCount(queryWrapper) != 0;
|
||||||
return num!=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,15 +78,13 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
|
|||||||
LambdaQueryWrapper<FollowEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<FollowEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
lambdaQueryWrapper.eq(FollowEntity::getUid, uid);
|
lambdaQueryWrapper.eq(FollowEntity::getUid, uid);
|
||||||
lambdaQueryWrapper.eq(FollowEntity::getFollowUid, followUid);
|
lambdaQueryWrapper.eq(FollowEntity::getFollowUid, followUid);
|
||||||
Integer num = baseMapper.selectCount(lambdaQueryWrapper);
|
if(baseMapper.selectCount(lambdaQueryWrapper) == 0){
|
||||||
if(num == 0){
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LambdaQueryWrapper<FollowEntity> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<FollowEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
lambdaQueryWrapper2.eq(FollowEntity::getUid, followUid);
|
wrapper.eq(FollowEntity::getUid, followUid);
|
||||||
lambdaQueryWrapper2.eq(FollowEntity::getFollowUid, uid);
|
wrapper.eq(FollowEntity::getFollowUid, uid);
|
||||||
Integer num2 = baseMapper.selectCount(lambdaQueryWrapper2);
|
return baseMapper.selectCount(wrapper) == 0 ? 2 : 1;
|
||||||
return num2==0?2:1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,7 +101,9 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getFollowUids(AppUserEntity user) {
|
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());
|
return list.stream().map(FollowEntity::getFollowUid).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +48,9 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
|
|||||||
@Override
|
@Override
|
||||||
public Integer collectCount(Integer postId) {
|
public Integer collectCount(Integer postId) {
|
||||||
|
|
||||||
return baseMapper.selectCount(new LambdaQueryWrapper<PostCollectionEntity>()
|
return this.lambdaQuery()
|
||||||
.eq(PostCollectionEntity::getPostId, postId));
|
.eq(PostCollectionEntity::getPostId,postId)
|
||||||
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user