Skip to content

Commit

Permalink
优化了代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrettluo committed Mar 13, 2023
1 parent 195e68f commit 918b017
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

Expand All @@ -27,16 +28,16 @@
@RequestMapping("/collect")
public class CollectController {

@Autowired
@Resource
CollectServiceImpl collectServiceImpl;

@ApiOperation(value = "2.3 新增一个收藏文档", notes = "新增单个收藏文档")
@ApiOperation(value = "新增一个收藏文档", notes = "新增单个收藏文档")
@PostMapping(value = "/auth/insert")
public BaseApiResult insert(@RequestBody CollectDTO collect, HttpServletRequest request) {
return collectServiceImpl.insert(setRelationshipValue(collect, request));
}

@ApiOperation(value = "2.4 根据id移除某个收藏文档", notes = "根据id移除某个文档")
@ApiOperation(value = "根据id移除某个收藏文档", notes = "根据id移除某个文档")
@DeleteMapping(value = "/auth/remove")
public BaseApiResult remove(@RequestBody CollectDTO collect, HttpServletRequest request) {
return collectServiceImpl.remove(setRelationshipValue(collect, request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
Expand All @@ -38,7 +39,7 @@
@RequestMapping("/comment")
public class CommentController {

@Autowired
@Resource
ICommentService commentService;

@ApiOperation(value = "查询评论列表", notes = "更新评论")
Expand Down Expand Up @@ -74,7 +75,7 @@ public BaseApiResult remove(@RequestBody Comment comment, HttpServletRequest req

@ApiOperation(value = "根据id列表移除批量评论", notes = "根据id移除批量评论")
@DeleteMapping(value = "/auth/removeBatch")
public BaseApiResult removeBatch(@RequestBody BatchIdDTO batchIdDTO, HttpServletRequest request) {
public BaseApiResult removeBatch(@RequestBody BatchIdDTO batchIdDTO) {
List<String> commentIdList = batchIdDTO.getIds();
if (CollectionUtils.isEmpty(commentIdList)) {
return BaseApiResult.error(MessageConstant.PARAMS_ERROR_CODE, MessageConstant.PARAMS_FORMAT_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

Expand All @@ -34,7 +33,7 @@
@RequestMapping("/docReview")
public class DocReviewController {

@Autowired
@Resource
private DocReviewService docReviewService;

@Resource
Expand Down Expand Up @@ -126,8 +125,7 @@ public BaseApiResult approve(@RequestBody @Valid BatchIdDTO batchIdDTO) {
@Permission({PermissionEnum.ADMIN})
@ApiOperation(value = "管理员和普通用户分别查询数据", notes = "查询文档审批的列表")
@GetMapping("queryReviewResultList")
public BaseApiResult queryReviewResultList(@ModelAttribute("pageParams") @Valid BasePageDTO pageParams,
HttpServletRequest request) {
public BaseApiResult queryReviewResultList(@ModelAttribute("pageParams") @Valid BasePageDTO pageParams) {
return docReviewService.queryReviewLog(pageParams, null, true);
}

Expand Down
35 changes: 0 additions & 35 deletions src/main/java/com/jiaruiblog/controller/IndexController.java

This file was deleted.

20 changes: 12 additions & 8 deletions src/main/java/com/jiaruiblog/controller/StatisticsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -43,28 +43,28 @@
@RequestMapping("/statistics")
public class StatisticsController {

@Autowired
@Resource
StatisticsService statisticsService;

@Autowired
@Resource
RedisService redisService;

@Autowired
@Resource
IFileService fileService;

@Autowired
@Resource
FileServiceImpl fileServiceImpl;

@Autowired
@Resource
TagService tagService;

@ApiOperation(value = "4.1 查询热度榜", notes = "查询列表")
@ApiOperation(value = "查询热度榜", notes = "查询列表")
@GetMapping(value = "/trend")
public BaseApiResult trend() {
return statisticsService.trend();
}

@ApiOperation(value = "4.2 查询统计数据", notes = "查询列表")
@ApiOperation(value = "查询统计数据", notes = "查询列表")
@GetMapping(value = "/all")
public BaseApiResult all() {
return statisticsService.all();
Expand All @@ -77,6 +77,7 @@ public BaseApiResult all() {
* @Date 15:46 2022/9/11
* @Param []
**/
@ApiOperation(value = "查询搜索结果", notes = "查询列表")
@GetMapping("getSearchResult")
public BaseApiResult getSearchResult(@RequestHeader HttpHeaders headers) {
List<String> userSearchList = Lists.newArrayList();
Expand All @@ -95,6 +96,7 @@ public BaseApiResult getSearchResult(@RequestHeader HttpHeaders headers) {
return BaseApiResult.success(result);
}

@ApiOperation(value = "删除用户的搜索关键词", notes = "删除key")
@PutMapping(value = "removeKey")
public BaseApiResult removeKey(@RequestBody SearchKeyDTO searchKeyDTO) {
redisService.delSearchHistoryByUserId(searchKeyDTO.getUserId(), searchKeyDTO.getSearchWord());
Expand All @@ -117,6 +119,7 @@ public BaseApiResult removeKey(@RequestBody SearchKeyDTO searchKeyDTO) {
* @Date 15:51 2022/9/11
* @Param []
**/
@ApiOperation(value = "查询十条热门榜单", notes = "查询列表")
@GetMapping("getHotTrend")
public BaseApiResult getHotTrend() {
List<String> docIdList = redisService.getHotList(null, RedisServiceImpl.DOC_KEY);
Expand Down Expand Up @@ -177,6 +180,7 @@ public BaseApiResult getHotTrend() {
* @Date 21:58 2022/9/17
* @Param []
**/
@ApiOperation(value = "查询最新数据", notes = "查询列表展示1、最近新提交的12篇文章;2、获取最近新连接关系的文档")
@GetMapping("/recentDocs")
public BaseApiResult getRecentDocs() {
List<Map<String, Object>> result = Lists.newArrayList();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/jiaruiblog/entity/dto/CategoryDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.jiaruiblog.common.MessageConstant;
import com.jiaruiblog.enums.FilterTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

Expand All @@ -15,18 +17,20 @@
* @Date 2022/6/19 5:32 下午
* @Version 1.0
**/

@ApiModel("分类的对象")
@Data
public class CategoryDTO {

@ApiModelProperty(value = "分类的名称", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
@Length(max = 64, message = MessageConstant.PARAMS_LENGTH_REQUIRED)
private String name;

@ApiModelProperty(value = "分类的类型", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private FilterTypeEnum type;


@ApiModelProperty("分类的id")
private String id;

}
19 changes: 9 additions & 10 deletions src/main/java/com/jiaruiblog/entity/dto/DocumentDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.jiaruiblog.common.MessageConstant;
import com.jiaruiblog.enums.FilterTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
Expand All @@ -14,28 +15,26 @@
* @Date 2022/6/19 5:15 下午
* @Version 1.0
**/
@ApiModel("文档查询对象")
@Data
public class DocumentDTO {
public class DocumentDTO extends BasePageDTO{

@ApiModelProperty(value = "过滤类型")
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private FilterTypeEnum type;

@ApiModelProperty(value = "过滤词")
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private String filterWord;

@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
@Min(value = 1, message = MessageConstant.PARAMS_LENGTH_REQUIRED)
private Integer page;

@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
@Min(value = 1, message = MessageConstant.PARAMS_LENGTH_REQUIRED)
private Integer rows;

@ApiModelProperty(value = "分类id")
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private String categoryId;

@ApiModelProperty(value = "标签id")
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private String tagId;

@ApiModelProperty(value = "用户id")
private String userId;
}
5 changes: 5 additions & 0 deletions src/main/java/com/jiaruiblog/entity/dto/RegistryUserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.jiaruiblog.common.MessageConstant;
import com.jiaruiblog.common.RegexConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
Expand All @@ -17,6 +19,7 @@
* @Date 2023/2/14 22:12
* @Version 1.0
**/
@ApiModel("用户注册对象")
@Data
public class RegistryUserDTO {

Expand All @@ -26,11 +29,13 @@ public class RegistryUserDTO {
但是SHA仍然是公认的安全加密算法,较之MD5更为安全*/
public static final String KEY_SHA = "SHA";

@ApiModelProperty(value = "用户名", notes = "最小3个字符, 最长32个字符", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
@Size(min = 3, max = 32, message = MessageConstant.PARAMS_LENGTH_REQUIRED)
@Pattern(regexp = RegexConstant.NUM_WORD_REG, message = MessageConstant.PARAMS_FORMAT_ERROR)
String username;

@ApiModelProperty(value = "用户密码", notes = "最小3个字符, 最长32个字符", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
@Size(min = 3, max = 32, message = MessageConstant.PARAMS_LENGTH_REQUIRED)
@Pattern(regexp = RegexConstant.NUM_WORD_REG, message = MessageConstant.PARAMS_FORMAT_ERROR)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/jiaruiblog/entity/dto/RelationDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.jiaruiblog.common.MessageConstant;
import com.jiaruiblog.enums.FilterTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
Expand All @@ -13,15 +15,19 @@
* @Date 2022/6/19 5:35 下午
* @Version 1.0
**/
@ApiModel(value = "文档与标签/分类的关系")
@Data
public class RelationDTO {

@ApiModelProperty(value = "文档主键", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private String docId;

@ApiModelProperty(value = "筛选的类型", notes = "可选的参数是ALL, FILTER, CATEGORY, TAG", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private FilterTypeEnum type;

@ApiModelProperty(value = "关系的主键id")
private String id;


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jiaruiblog/entity/dto/UserRoleDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.jiaruiblog.auth.PermissionEnum;
import com.jiaruiblog.common.MessageConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
Expand All @@ -13,12 +15,15 @@
* @Date 2023/2/20 21:48
* @Version 1.0
**/
@ApiModel("用户角色对象")
@Data
public class UserRoleDTO {

@ApiModelProperty(value = "用户主键", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private String userId;

@ApiModelProperty(value = "用户角色", notes = "可选的参数有 USER, ADMIN, NO", required = true)
@NotNull(message = MessageConstant.PARAMS_IS_NOT_NULL)
private PermissionEnum role;
}
7 changes: 1 addition & 6 deletions src/main/java/com/jiaruiblog/service/ElasticService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ public interface ElasticService {
* search
* @param keyword String
* @return result
*/
/**
* search
* @param keyword String
* @return result
* @throws IOException
* @throws IOException exception
*/
List<FileDocument> search(String keyword) throws IOException;

Expand Down
Loading

0 comments on commit 918b017

Please sign in to comment.