From eaef390b3aea1a359f0e41430c06233c70ce7a7e Mon Sep 17 00:00:00 2001 From: luiju Date: Sun, 11 Aug 2024 22:14:56 +0800 Subject: [PATCH] Fix: Clean and format code --- .../Exception/GlobalExceptionHandler.java | 1 - .../Exception/TooManyRequestException.java | 2 +- .../escserver/config/AuthInterceptor.java | 4 +-- .../cn/luijp/escserver/config/CorsConfig.java | 5 ++-- .../controller/AttachController.java | 2 +- .../escserver/controller/AuthController.java | 2 +- .../controller/CategoriesController.java | 3 +-- .../controller/CommentController.java | 8 +++--- .../controller/LoginFailedController.java | 2 +- .../escserver/controller/PostsController.java | 18 ++++++------- .../escserver/controller/TagsController.java | 3 +-- .../mapper/PostCategoriesMapper.java | 7 ----- .../escserver/mapper/PostTagsMapper.java | 7 ----- .../escserver/model/dto/CategoriesAllDto.java | 6 +---- .../controller/AuthControllerService.java | 4 +-- .../CategoriesControllerService.java | 4 +-- .../controller/TagsControllerService.java | 5 +--- .../impl/AuthControllerServiceImpl.java | 2 +- .../impl/CategoriesControllerServiceImpl.java | 27 +++++++++---------- .../impl/CommentControllerServiceImpl.java | 10 +++---- .../LoginFailedControllerServiceImpl.java | 4 +-- .../impl/PostsControllerServiceImpl.java | 3 --- .../impl/TagsControllerServiceImpl.java | 18 ++++++------- 23 files changed, 57 insertions(+), 90 deletions(-) diff --git a/src/main/java/cn/luijp/escserver/Exception/GlobalExceptionHandler.java b/src/main/java/cn/luijp/escserver/Exception/GlobalExceptionHandler.java index 0372794..bb34018 100644 --- a/src/main/java/cn/luijp/escserver/Exception/GlobalExceptionHandler.java +++ b/src/main/java/cn/luijp/escserver/Exception/GlobalExceptionHandler.java @@ -3,7 +3,6 @@ import cn.luijp.escserver.model.dto.ResponseDto; import lombok.extern.slf4j.Slf4j; import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; diff --git a/src/main/java/cn/luijp/escserver/Exception/TooManyRequestException.java b/src/main/java/cn/luijp/escserver/Exception/TooManyRequestException.java index c7e6025..e6af47b 100644 --- a/src/main/java/cn/luijp/escserver/Exception/TooManyRequestException.java +++ b/src/main/java/cn/luijp/escserver/Exception/TooManyRequestException.java @@ -1,6 +1,6 @@ package cn.luijp.escserver.Exception; -public class TooManyRequestException extends RuntimeException{ +public class TooManyRequestException extends RuntimeException { public TooManyRequestException() { super(); } diff --git a/src/main/java/cn/luijp/escserver/config/AuthInterceptor.java b/src/main/java/cn/luijp/escserver/config/AuthInterceptor.java index 8eca5e5..b3e4f5c 100644 --- a/src/main/java/cn/luijp/escserver/config/AuthInterceptor.java +++ b/src/main/java/cn/luijp/escserver/config/AuthInterceptor.java @@ -22,13 +22,13 @@ public AuthInterceptor(AuthControllerService authControllerService) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (request.getMethod().equals("GET")) { return true; - }else if (request.getMethod().equals("POST")) { + } else if (request.getMethod().equals("POST")) { Login auth = authControllerService.auth(request); if (auth == null) { throw new AuthForbiddenException(); } return true; - }else{ + } else { return false; } diff --git a/src/main/java/cn/luijp/escserver/config/CorsConfig.java b/src/main/java/cn/luijp/escserver/config/CorsConfig.java index aa62064..619b4ef 100644 --- a/src/main/java/cn/luijp/escserver/config/CorsConfig.java +++ b/src/main/java/cn/luijp/escserver/config/CorsConfig.java @@ -5,7 +5,6 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.util.List; import java.util.Objects; @Configuration @@ -17,11 +16,11 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { - if(Objects.equals(corsDomain, "")){ + if (Objects.equals(corsDomain, "")) { registry.addMapping("/**") .allowedMethods("GET", "POST") .allowedHeaders("*"); - }else{ + } else { registry.addMapping("/**") .allowedMethods("GET", "POST") .allowCredentials(true) diff --git a/src/main/java/cn/luijp/escserver/controller/AttachController.java b/src/main/java/cn/luijp/escserver/controller/AttachController.java index de57b39..d49af08 100644 --- a/src/main/java/cn/luijp/escserver/controller/AttachController.java +++ b/src/main/java/cn/luijp/escserver/controller/AttachController.java @@ -52,7 +52,7 @@ public void image(HttpServletResponse response, @PathVariable String uuid) { response.reset(); response.setContentType("image/png"); // response.setHeader("Content-Disposition", "attachment; filename=\"" + attachControllerService.getOriginName(uuid) + "\""); - attachControllerService.get(uuid,response); + attachControllerService.get(uuid, response); } @GetMapping("/download/{uuid}") diff --git a/src/main/java/cn/luijp/escserver/controller/AuthController.java b/src/main/java/cn/luijp/escserver/controller/AuthController.java index b432624..5574fb2 100644 --- a/src/main/java/cn/luijp/escserver/controller/AuthController.java +++ b/src/main/java/cn/luijp/escserver/controller/AuthController.java @@ -41,7 +41,7 @@ public ResponseDto login(@RequestBody Auth auth, HttpServletResponse res if (clientIp == null || clientIp.isEmpty()) { clientIp = request.getRemoteAddr(); } - if(!authControllerService.checkRate(clientIp)){ + if (!authControllerService.checkRate(clientIp)) { throw new TooManyRequestException(); } Login login = authControllerService.login(auth.getUsername(), auth.getPassword()); diff --git a/src/main/java/cn/luijp/escserver/controller/CategoriesController.java b/src/main/java/cn/luijp/escserver/controller/CategoriesController.java index 4462ffd..9e2c025 100644 --- a/src/main/java/cn/luijp/escserver/controller/CategoriesController.java +++ b/src/main/java/cn/luijp/escserver/controller/CategoriesController.java @@ -3,7 +3,6 @@ import cn.luijp.escserver.model.dto.CategoriesAllDto; import cn.luijp.escserver.model.dto.ResponseDto; import cn.luijp.escserver.model.entity.Categories; -import cn.luijp.escserver.model.entity.Tags; import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo; import cn.luijp.escserver.service.controller.CategoriesControllerService; import org.springframework.beans.factory.annotation.Autowired; @@ -35,7 +34,7 @@ public ResponseDto> getCategoriesList() { @GetMapping("/alias/{categoryAlias}") public ResponseDto getCategoriesByTagAlias(@PathVariable String categoryAlias) { Categories categoryIdByAlias = categoriesControllerService.getCategoryIdByAlias(categoryAlias); - if(categoryIdByAlias == null){ + if (categoryIdByAlias == null) { return ResponseDto.error(-404, "Category not exist"); } return ResponseDto.successWithData(categoryIdByAlias); diff --git a/src/main/java/cn/luijp/escserver/controller/CommentController.java b/src/main/java/cn/luijp/escserver/controller/CommentController.java index 9c7e1d4..2994c52 100644 --- a/src/main/java/cn/luijp/escserver/controller/CommentController.java +++ b/src/main/java/cn/luijp/escserver/controller/CommentController.java @@ -20,25 +20,25 @@ public CommentController(CommentControllerService commentControllerService) { @GetMapping("/list/{postId}/{pageNum}/{pageSize}") public ResponseDto listVisible(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) { - CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,true); + CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, true); return ResponseDto.successWithData(comment); } @PostMapping("/listUnVisible/{postId}/{pageNum}/{pageSize}") public ResponseDto listUnVisible(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) { - CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,false); + CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, false); return ResponseDto.successWithData(comment); } @PostMapping("/listAll/{postId}/{pageNum}/{pageSize}") public ResponseDto listAllByPostId(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) { - CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,null); + CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, null); return ResponseDto.successWithData(comment); } @PostMapping("/listAll/{pageNum}/{pageSize}") public ResponseDto listAll(@PathVariable Integer pageNum, @PathVariable Integer pageSize) { - CommentListDto comment = commentControllerService.getComment(null, pageNum, pageSize,null); + CommentListDto comment = commentControllerService.getComment(null, pageNum, pageSize, null); return ResponseDto.successWithData(comment); } diff --git a/src/main/java/cn/luijp/escserver/controller/LoginFailedController.java b/src/main/java/cn/luijp/escserver/controller/LoginFailedController.java index f296419..172a409 100644 --- a/src/main/java/cn/luijp/escserver/controller/LoginFailedController.java +++ b/src/main/java/cn/luijp/escserver/controller/LoginFailedController.java @@ -22,7 +22,7 @@ public LoginFailedController(LoginFailedControllerService loginFailedControllerS } @PostMapping("/list") - public ResponseDto> list(){ + public ResponseDto> list() { return ResponseDto.successWithData(loginFailedControllerService.getLoginFailed()); } } diff --git a/src/main/java/cn/luijp/escserver/controller/PostsController.java b/src/main/java/cn/luijp/escserver/controller/PostsController.java index fb9627a..c2671af 100644 --- a/src/main/java/cn/luijp/escserver/controller/PostsController.java +++ b/src/main/java/cn/luijp/escserver/controller/PostsController.java @@ -105,17 +105,17 @@ public ResponseDto del(@PathVariable Long id) { } @GetMapping("/get/{id}") - public ResponseDto get(@PathVariable Long id,HttpServletRequest request) { + public ResponseDto get(@PathVariable Long id, HttpServletRequest request) { Posts post = postsControllerService.getPost(id); - if(post == null){ + if (post == null) { return ResponseDto.error(-404, "Post not found"); } Login auth = authControllerService.auth(request); if (auth == null) { - if(post.getVisible() != 1){ + if (post.getVisible() != 1) { return ResponseDto.error(-403, "Auth required"); } - if(post.getEncrypt() != null && !post.getEncrypt().isEmpty()){ + if (post.getEncrypt() != null && !post.getEncrypt().isEmpty()) { return ResponseDto.error(-403, "Auth required"); } } @@ -124,18 +124,18 @@ public ResponseDto get(@PathVariable Long id,HttpServletRequest request) @PostMapping("/get/{id}") public ResponseDto getEncrypt(@PathVariable Long id, - @RequestBody String encrypt, - HttpServletRequest request) { + @RequestBody String encrypt, + HttpServletRequest request) { Posts post = postsControllerService.getPost(id); - if(post == null){ + if (post == null) { return ResponseDto.error(-404, "Post not found"); } Login auth = authControllerService.auth(request); if (auth == null) { - if(post.getVisible() != 1){ + if (post.getVisible() != 1) { return ResponseDto.error(-403, "Auth required"); } - if(!Objects.equals(post.getEncrypt(), encrypt)){ + if (!Objects.equals(post.getEncrypt(), encrypt)) { return ResponseDto.error(-403, "Password not match"); } } diff --git a/src/main/java/cn/luijp/escserver/controller/TagsController.java b/src/main/java/cn/luijp/escserver/controller/TagsController.java index 8c297ad..9fb3a79 100644 --- a/src/main/java/cn/luijp/escserver/controller/TagsController.java +++ b/src/main/java/cn/luijp/escserver/controller/TagsController.java @@ -1,7 +1,6 @@ package cn.luijp.escserver.controller; import cn.luijp.escserver.model.dto.ResponseDto; -import cn.luijp.escserver.model.entity.Categories; import cn.luijp.escserver.model.entity.Tags; import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; import cn.luijp.escserver.service.controller.TagsControllerService; @@ -34,7 +33,7 @@ public ResponseDto> getTagsByPostId(@PathVariable Long @GetMapping("/alias/{tagAlias}") public ResponseDto getTagsByTagAlias(@PathVariable String tagAlias) { Tags tagIdByAlias = tagsControllerService.getTagIdByAlias(tagAlias); - if(tagIdByAlias == null){ + if (tagIdByAlias == null) { return ResponseDto.error(-404, "Tag not exist"); } return ResponseDto.successWithData(tagIdByAlias); diff --git a/src/main/java/cn/luijp/escserver/mapper/PostCategoriesMapper.java b/src/main/java/cn/luijp/escserver/mapper/PostCategoriesMapper.java index e4303aa..41ee768 100644 --- a/src/main/java/cn/luijp/escserver/mapper/PostCategoriesMapper.java +++ b/src/main/java/cn/luijp/escserver/mapper/PostCategoriesMapper.java @@ -1,14 +1,7 @@ package cn.luijp.escserver.mapper; import cn.luijp.escserver.model.entity.PostCategories; -import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.toolkit.Constants; import com.github.yulichang.base.MPJBaseMapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.util.List; public interface PostCategoriesMapper extends MPJBaseMapper { } diff --git a/src/main/java/cn/luijp/escserver/mapper/PostTagsMapper.java b/src/main/java/cn/luijp/escserver/mapper/PostTagsMapper.java index e8aa60c..6b895e8 100644 --- a/src/main/java/cn/luijp/escserver/mapper/PostTagsMapper.java +++ b/src/main/java/cn/luijp/escserver/mapper/PostTagsMapper.java @@ -1,14 +1,7 @@ package cn.luijp.escserver.mapper; import cn.luijp.escserver.model.entity.PostTags; -import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.toolkit.Constants; import com.github.yulichang.base.MPJBaseMapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.util.List; public interface PostTagsMapper extends MPJBaseMapper { } diff --git a/src/main/java/cn/luijp/escserver/model/dto/CategoriesAllDto.java b/src/main/java/cn/luijp/escserver/model/dto/CategoriesAllDto.java index 349a8cf..7362d6a 100644 --- a/src/main/java/cn/luijp/escserver/model/dto/CategoriesAllDto.java +++ b/src/main/java/cn/luijp/escserver/model/dto/CategoriesAllDto.java @@ -7,14 +7,10 @@ @Data public class CategoriesAllDto { + List children; private Long id; - private String name; - private String alias; - private Long parentId; - List children; - } diff --git a/src/main/java/cn/luijp/escserver/service/controller/AuthControllerService.java b/src/main/java/cn/luijp/escserver/service/controller/AuthControllerService.java index 2a3eb49..12ab5b9 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/AuthControllerService.java +++ b/src/main/java/cn/luijp/escserver/service/controller/AuthControllerService.java @@ -11,8 +11,8 @@ public interface AuthControllerService { Login auth(HttpServletRequest request); - public void recordFailed(String ip); + void recordFailed(String ip); - public Boolean checkRate(String ip); + Boolean checkRate(String ip); } diff --git a/src/main/java/cn/luijp/escserver/service/controller/CategoriesControllerService.java b/src/main/java/cn/luijp/escserver/service/controller/CategoriesControllerService.java index 6a824ee..dcf5d2c 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/CategoriesControllerService.java +++ b/src/main/java/cn/luijp/escserver/service/controller/CategoriesControllerService.java @@ -18,7 +18,7 @@ public interface CategoriesControllerService { List getCategoriesByPostId(Long postId); - public List getCategoriesList(); + List getCategoriesList(); - public Categories getCategoryIdByAlias(String categoryAlias); + Categories getCategoryIdByAlias(String categoryAlias); } diff --git a/src/main/java/cn/luijp/escserver/service/controller/TagsControllerService.java b/src/main/java/cn/luijp/escserver/service/controller/TagsControllerService.java index b0b0a76..6fc56f5 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/TagsControllerService.java +++ b/src/main/java/cn/luijp/escserver/service/controller/TagsControllerService.java @@ -1,10 +1,7 @@ package cn.luijp.escserver.service.controller; -import cn.luijp.escserver.model.dto.ResponseDto; -import cn.luijp.escserver.model.entity.Categories; import cn.luijp.escserver.model.entity.Tags; import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; -import org.springframework.web.bind.annotation.PathVariable; import java.util.List; @@ -20,5 +17,5 @@ public interface TagsControllerService { List getTagsByPostId(Long postId); - public Tags getTagIdByAlias(String tagAlias); + Tags getTagIdByAlias(String tagAlias); } diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/AuthControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/AuthControllerServiceImpl.java index c565af7..86b35ee 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/AuthControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/AuthControllerServiceImpl.java @@ -97,7 +97,7 @@ public void recordFailed(String ip) { public Boolean checkRate(String ip) { LocalDateTime oneDayBefore = LocalDateTime.now().minus(Duration.ofDays(1)); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.gt(LoginFailed::getCreateTime,oneDayBefore).eq(LoginFailed::getIp, ip); + queryWrapper.gt(LoginFailed::getCreateTime, oneDayBefore).eq(LoginFailed::getIp, ip); List loginFailedList = loginFailedService.list(queryWrapper); return loginFailedList.size() < 30; } diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/CategoriesControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/CategoriesControllerServiceImpl.java index e417a1d..759e9de 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/CategoriesControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/CategoriesControllerServiceImpl.java @@ -4,10 +4,7 @@ import cn.luijp.escserver.model.dto.CategoriesAllDto; import cn.luijp.escserver.model.entity.Categories; import cn.luijp.escserver.model.entity.PostCategories; -import cn.luijp.escserver.model.entity.PostTags; -import cn.luijp.escserver.model.entity.Tags; import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo; -import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; import cn.luijp.escserver.service.controller.CategoriesControllerService; import cn.luijp.escserver.service.db.ICategoriesService; import cn.luijp.escserver.service.db.IPostCategoriesService; @@ -42,7 +39,7 @@ public CategoriesControllerServiceImpl(ICategoriesService categoriesService, public List getAllCategories() { List list = categoriesService.list(); - return getCategories(list,0L); + return getCategories(list, 0L); } public List getCategoriesList() { @@ -51,22 +48,22 @@ public List getCategoriesList() { public Categories getCategoryIdByAlias(String categoryAlias) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Categories::getAlias,categoryAlias); + queryWrapper.eq(Categories::getAlias, categoryAlias); return categoriesService.getOne(queryWrapper); } private List getCategories(List categoriesList, Long parentId) { List categoriesAllDtoList = new ArrayList<>(); - categoriesList.forEach((item)->{ - if(Objects.equals(item.getParentId(), parentId)){ - CategoriesAllDto categoriesAllDto =new CategoriesAllDto(); + categoriesList.forEach((item) -> { + if (Objects.equals(item.getParentId(), parentId)) { + CategoriesAllDto categoriesAllDto = new CategoriesAllDto(); categoriesAllDto.setId(item.getId()); categoriesAllDto.setName(item.getName()); categoriesAllDto.setParentId(item.getParentId()); categoriesAllDto.setAlias(item.getAlias()); categoriesAllDtoList.add(categoriesAllDto); - List childCategories = getCategories(categoriesList,item.getId()); + List childCategories = getCategories(categoriesList, item.getId()); categoriesAllDto.setChildren(childCategories); } }); @@ -83,7 +80,7 @@ public Long updateCategory(Categories category) { } try { boolean status = categoriesService.saveOrUpdate(category); - if(status){ + if (status) { return category.getId(); } return null; @@ -113,12 +110,12 @@ public Boolean delCategory(Long categoryId) { public List getCategoriesByPostId(Long postId) { MPJLambdaWrapper wrapper = JoinWrappers.lambda(PostCategories.class) .selectAs(PostCategories::getId, PostCategoriesWithCategoriesVo::getPostCategoriesId) - .selectAs(PostCategories::getPostId,PostCategoriesWithCategoriesVo::getPostId) - .selectAs(PostCategories::getCategoryId,PostCategoriesWithCategoriesVo::getCategoryId) - .selectAs(Categories::getName,PostCategoriesWithCategoriesVo::getCategoryName) - .selectAs(Categories::getAlias,PostCategoriesWithCategoriesVo::getCategoryAlias) + .selectAs(PostCategories::getPostId, PostCategoriesWithCategoriesVo::getPostId) + .selectAs(PostCategories::getCategoryId, PostCategoriesWithCategoriesVo::getCategoryId) + .selectAs(Categories::getName, PostCategoriesWithCategoriesVo::getCategoryName) + .selectAs(Categories::getAlias, PostCategoriesWithCategoriesVo::getCategoryAlias) .leftJoin(Categories.class, Categories::getId, PostCategories::getCategoryId) .eq(PostCategories::getPostId, postId); - return postCategoriesMapper.selectJoinList(PostCategoriesWithCategoriesVo.class,wrapper); + return postCategoriesMapper.selectJoinList(PostCategoriesWithCategoriesVo.class, wrapper); } } diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/CommentControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/CommentControllerServiceImpl.java index 7b67d7a..5a404e4 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/CommentControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/CommentControllerServiceImpl.java @@ -23,9 +23,9 @@ public CommentControllerServiceImpl(ICommentService commentService) { public Long addComment(Comment comment) { comment.setVisible(false); boolean status = commentService.save(comment); - if(status){ + if (status) { return comment.getId(); - }else{ + } else { return null; } } @@ -36,11 +36,11 @@ public Boolean delComment(Long id) { public CommentListDto getComment(Long postId, Integer pageNum, Integer pageSize, Boolean visible) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if(postId != null){ + if (postId != null) { queryWrapper.eq(Comment::getPostId, postId); } - if (visible != null){ - queryWrapper.eq(Comment::getVisible,visible); + if (visible != null) { + queryWrapper.eq(Comment::getVisible, visible); } Page commentPage = commentService.page(new Page<>(pageNum, pageSize), queryWrapper); CommentListDto commentListDto = new CommentListDto(); diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/LoginFailedControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/LoginFailedControllerServiceImpl.java index a5d46c7..98e5613 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/LoginFailedControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/LoginFailedControllerServiceImpl.java @@ -24,9 +24,9 @@ public LoginFailedControllerServiceImpl(ILoginFailedService loginFailedService) public List getLoginFailed() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.orderByDesc(LoginFailed::getId); - IPage loginFailedPage = loginFailedService.page(new Page<>(1,10),queryWrapper); + IPage loginFailedPage = loginFailedService.page(new Page<>(1, 10), queryWrapper); List records = loginFailedPage.getRecords(); - if(records.isEmpty()) { + if (records.isEmpty()) { return null; } return records; diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/PostsControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/PostsControllerServiceImpl.java index ecb523e..6cc164a 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/PostsControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/PostsControllerServiceImpl.java @@ -6,8 +6,6 @@ import cn.luijp.escserver.model.dto.PostsListDto; import cn.luijp.escserver.model.dto.PostsWithTC; import cn.luijp.escserver.model.entity.*; -import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo; -import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; import cn.luijp.escserver.service.controller.PostsControllerService; import cn.luijp.escserver.service.db.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -104,7 +102,6 @@ private PostsListDto packagePost(Integer pageNum, Integer pageSize, Integer type if (visible == 2) { postsQueryWrapper.in(Posts::getVisible, Arrays.asList(1, 2)); } else if (visible == -1) { - ; } else { postsQueryWrapper.eq(Posts::getVisible, visible); } diff --git a/src/main/java/cn/luijp/escserver/service/controller/impl/TagsControllerServiceImpl.java b/src/main/java/cn/luijp/escserver/service/controller/impl/TagsControllerServiceImpl.java index 188bc71..1414209 100644 --- a/src/main/java/cn/luijp/escserver/service/controller/impl/TagsControllerServiceImpl.java +++ b/src/main/java/cn/luijp/escserver/service/controller/impl/TagsControllerServiceImpl.java @@ -2,7 +2,6 @@ import cn.luijp.escserver.mapper.PostTagsMapper; -import cn.luijp.escserver.model.dto.ResponseDto; import cn.luijp.escserver.model.entity.PostTags; import cn.luijp.escserver.model.entity.Tags; import cn.luijp.escserver.model.vo.PostTagsWithTagsVo; @@ -15,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.swing.text.html.HTML; import java.util.List; import java.util.Objects; @@ -46,7 +44,7 @@ public Long updateTag(Tags tag) { } try { boolean status = tagsService.saveOrUpdate(tag); - if(status){ + if (status) { return tag.getId(); } return null; @@ -75,19 +73,19 @@ public Boolean delTag(Long tagId) { public List getTagsByPostId(Long postId) { MPJLambdaWrapper wrapper = JoinWrappers.lambda(PostTags.class) - .selectAs(PostTags::getId,PostTagsWithTagsVo::getPostTagsId) - .selectAs(PostTags::getPostId,PostTagsWithTagsVo::getPostId) - .selectAs(PostTags::getTagId,PostTagsWithTagsVo::getTagId) - .selectAs(Tags::getName,PostTagsWithTagsVo::getTagName) - .selectAs(Tags::getAlias,PostTagsWithTagsVo::getTagAlias) + .selectAs(PostTags::getId, PostTagsWithTagsVo::getPostTagsId) + .selectAs(PostTags::getPostId, PostTagsWithTagsVo::getPostId) + .selectAs(PostTags::getTagId, PostTagsWithTagsVo::getTagId) + .selectAs(Tags::getName, PostTagsWithTagsVo::getTagName) + .selectAs(Tags::getAlias, PostTagsWithTagsVo::getTagAlias) .leftJoin(Tags.class, Tags::getId, PostTags::getTagId) .eq(PostTags::getPostId, postId); - return postTagsMapper.selectJoinList(PostTagsWithTagsVo.class,wrapper); + return postTagsMapper.selectJoinList(PostTagsWithTagsVo.class, wrapper); } public Tags getTagIdByAlias(String tagAlias) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Tags::getAlias,tagAlias); + wrapper.eq(Tags::getAlias, tagAlias); return tagsService.getOne(wrapper); } }