From ae54661dbfbfe0713c1f6e80deebbc9d9672663a Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Sat, 23 Mar 2024 21:20:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9DTO=E3=80=81BO=E3=80=81VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafage/basic/assets/bo/CategoryBO.java | 56 ++++++ .../CommentBO.java} | 55 +++--- .../io/leafage/basic/assets/bo/PostBO.java | 89 +++++++++ .../assets/constants/StatisticsEnum.java | 38 ++++ .../controller/PostStatisticsController.java | 67 ------- .../basic/assets/domain/PostContent.java | 11 +- .../leafage/basic/assets/dto/CategoryDTO.java | 29 +-- .../leafage/basic/assets/dto/CommentDTO.java | 42 +--- .../io/leafage/basic/assets/dto/PostDTO.java | 63 +----- .../repository/PostStatisticsRepository.java | 20 +- .../assets/service/PostStatisticsService.java | 18 +- .../basic/assets/service/PostsService.java | 3 +- .../service/impl/CommentServiceImpl.java | 7 +- .../impl/PostStatisticsServiceImpl.java | 40 +--- .../assets/service/impl/PostsServiceImpl.java | 24 +-- .../leafage/basic/assets/vo/CategoryVO.java | 34 ++-- .../io/leafage/basic/assets/vo/CommentVO.java | 43 +++-- .../basic/assets/vo/PostContentVO.java | 63 ------ .../basic/assets/vo/PostStatisticsVO.java | 118 ------------ .../io/leafage/basic/assets/vo/PostVO.java | 82 ++------ .../controller/CategoryControllerTest.java | 20 +- .../controller/CommentControllerTest.java | 28 +-- .../assets/controller/PostControllerTest.java | 43 ++--- .../PostPostStatisticsControllerTest.java | 92 --------- .../service/impl/CategoryServiceImplTest.java | 22 +-- .../service/impl/CommentServiceImplTest.java | 19 +- .../PostPostStatisticsServiceImplTest.java | 96 --------- .../service/impl/PostServiceImplTest.java | 59 +++--- .../impl/PostStatisticsServiceImplTest.java | 62 ++++++ hypervisor/pom.xml | 8 +- .../basic/hypervisor/bo/AccessLogBO.java | 182 ++++++++++++++++++ .../basic/hypervisor/bo/DictionaryBO.java | 56 ++++++ .../leafage/basic/hypervisor/bo/GroupBO.java | 68 +++++++ .../basic/hypervisor/bo/MessageBO.java | 71 +++++++ .../basic/hypervisor/bo/PrivilegeBO.java | 100 ++++++++++ .../leafage/basic/hypervisor/bo/RegionBO.java | 82 ++++++++ .../leafage/basic/hypervisor/bo/RoleBO.java | 55 ++++++ .../leafage/basic/hypervisor/bo/UserBO.java | 110 +++++++++++ .../AuthorizationServerConfiguration.java | 31 ++- .../basic/hypervisor/dto/AccessLogDTO.java | 160 +-------------- .../basic/hypervisor/dto/DictionaryDTO.java | 47 +---- .../basic/hypervisor/dto/GroupDTO.java | 51 +---- .../basic/hypervisor/dto/MessageDTO.java | 44 +---- .../basic/hypervisor/dto/PrivilegeDTO.java | 70 +------ .../basic/hypervisor/dto/RegionDTO.java | 58 +----- .../leafage/basic/hypervisor/dto/RoleDTO.java | 50 +---- .../leafage/basic/hypervisor/dto/UserDTO.java | 58 +----- .../service/impl/GroupServiceImpl.java | 7 +- .../service/impl/RoleServiceImpl.java | 7 +- .../basic/hypervisor/vo/AccessLogVO.java | 160 ++------------- .../basic/hypervisor/vo/DictionaryVO.java | 56 ++---- .../leafage/basic/hypervisor/vo/GroupVO.java | 79 ++------ .../basic/hypervisor/vo/MessageVO.java | 42 ++-- .../basic/hypervisor/vo/PrivilegeVO.java | 103 ++-------- .../leafage/basic/hypervisor/vo/RegionVO.java | 68 ++----- .../leafage/basic/hypervisor/vo/RoleVO.java | 67 +++---- .../leafage/basic/hypervisor/vo/UserVO.java | 55 ++---- .../controller/DictionaryControllerTest.java | 2 - .../controller/GroupControllerTest.java | 4 +- .../controller/MessageControllerTest.java | 6 +- .../controller/PrivilegeControllerTest.java | 1 - .../controller/RegionControllerTest.java | 1 - .../controller/RoleControllerTest.java | 2 - .../controller/UserControllerTest.java | 2 - .../service/impl/GroupServiceImplTest.java | 10 - .../service/impl/RoleServiceImplTest.java | 14 -- .../service/impl/UserServiceImplTest.java | 1 - pom.xml | 2 +- 68 files changed, 1383 insertions(+), 1950 deletions(-) create mode 100644 assets/src/main/java/io/leafage/basic/assets/bo/CategoryBO.java rename assets/src/main/java/io/leafage/basic/assets/{dto/PostStatisticsDTO.java => bo/CommentBO.java} (55%) create mode 100644 assets/src/main/java/io/leafage/basic/assets/bo/PostBO.java create mode 100644 assets/src/main/java/io/leafage/basic/assets/constants/StatisticsEnum.java delete mode 100644 assets/src/main/java/io/leafage/basic/assets/controller/PostStatisticsController.java delete mode 100644 assets/src/main/java/io/leafage/basic/assets/vo/PostContentVO.java delete mode 100644 assets/src/main/java/io/leafage/basic/assets/vo/PostStatisticsVO.java delete mode 100644 assets/src/test/java/io/leafage/basic/assets/controller/PostPostStatisticsControllerTest.java delete mode 100644 assets/src/test/java/io/leafage/basic/assets/service/impl/PostPostStatisticsServiceImplTest.java create mode 100644 assets/src/test/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImplTest.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/AccessLogBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/DictionaryBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/GroupBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/MessageBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/PrivilegeBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RegionBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RoleBO.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/UserBO.java diff --git a/assets/src/main/java/io/leafage/basic/assets/bo/CategoryBO.java b/assets/src/main/java/io/leafage/basic/assets/bo/CategoryBO.java new file mode 100644 index 00000000..f1d20dd5 --- /dev/null +++ b/assets/src/main/java/io/leafage/basic/assets/bo/CategoryBO.java @@ -0,0 +1,56 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.assets.bo; + + +import jakarta.validation.constraints.NotBlank; + +/** + * bo class for category + * + * @author wilsonli 2022-12-10 22:28 + **/ +public abstract class CategoryBO { + + /** + * 名称 + */ + @NotBlank(message = "category name is blank.") + private String name; + + /** + * 描述 + */ + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/assets/src/main/java/io/leafage/basic/assets/dto/PostStatisticsDTO.java b/assets/src/main/java/io/leafage/basic/assets/bo/CommentBO.java similarity index 55% rename from assets/src/main/java/io/leafage/basic/assets/dto/PostStatisticsDTO.java rename to assets/src/main/java/io/leafage/basic/assets/bo/CommentBO.java index 210fd061..9e745e1e 100644 --- a/assets/src/main/java/io/leafage/basic/assets/dto/PostStatisticsDTO.java +++ b/assets/src/main/java/io/leafage/basic/assets/bo/CommentBO.java @@ -15,34 +15,35 @@ * */ -package io.leafage.basic.assets.dto; +package io.leafage.basic.assets.bo; + + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; /** - * dto class for posts statistics. + * bo class for comment * - * @author wq li 2024-02-02 14:30 - **/ -public class PostStatisticsDTO { + * @author liwenqiang 2023-03-26 14:30 + */ +public abstract class CommentBO { /** - * 帖子ID + * 帖子 */ + @NotNull(message = "postId must not be null.") private Long postId; /** - * 浏览量 - */ - private int viewed; - - /** - * 点赞量 + * 内容 */ - private int likes; + @NotBlank(message = "context must not be blank.") + private String context; /** - * 评论量 + * 回复者 */ - private int comments; + private Long replier; public Long getPostId() { @@ -53,27 +54,19 @@ public void setPostId(Long postId) { this.postId = postId; } - public int getViewed() { - return viewed; - } - - public void setViewed(int viewed) { - this.viewed = viewed; - } - - public int getLikes() { - return likes; + public String getContext() { + return context; } - public void setLikes(int likes) { - this.likes = likes; + public void setContext(String context) { + this.context = context; } - public int getComments() { - return comments; + public Long getReplier() { + return replier; } - public void setComments(int comments) { - this.comments = comments; + public void setReplier(Long replier) { + this.replier = replier; } } diff --git a/assets/src/main/java/io/leafage/basic/assets/bo/PostBO.java b/assets/src/main/java/io/leafage/basic/assets/bo/PostBO.java new file mode 100644 index 00000000..8f2b9258 --- /dev/null +++ b/assets/src/main/java/io/leafage/basic/assets/bo/PostBO.java @@ -0,0 +1,89 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.assets.bo; + + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; + +import java.util.Set; + +/** + * bo class for post + * + * @author liwenqiang 2022-12-10 22:09 + */ +public abstract class PostBO { + + /** + * 标题 + */ + @NotBlank(message = "title must not be blank.") + private String title; + + /** + * 封面 + */ + private String cover; + + /** + * 内容 + */ + @NotBlank(message = "context must not be blank.") + private String context; + + /** + * 标签 + */ + @NotEmpty(message = "tags must not be empty.") + private Set tags; + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getCover() { + return cover; + } + + public void setCover(String cover) { + this.cover = cover; + } + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } + + public Set getTags() { + return tags; + } + + public void setTags(Set tags) { + this.tags = tags; + } + +} diff --git a/assets/src/main/java/io/leafage/basic/assets/constants/StatisticsEnum.java b/assets/src/main/java/io/leafage/basic/assets/constants/StatisticsEnum.java new file mode 100644 index 00000000..4aa1d6a4 --- /dev/null +++ b/assets/src/main/java/io/leafage/basic/assets/constants/StatisticsEnum.java @@ -0,0 +1,38 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.assets.constants; + +/** + * statistics type enum + * + * @author liwenqiang 2022-05-31 09:03 + **/ +public enum StatisticsEnum { + + VIEWED("viewed"), + + LIKES("likes"), + + COMMENTS("comments"); + + public final String value; + + StatisticsEnum(String value) { + this.value = value; + } +} diff --git a/assets/src/main/java/io/leafage/basic/assets/controller/PostStatisticsController.java b/assets/src/main/java/io/leafage/basic/assets/controller/PostStatisticsController.java deleted file mode 100644 index 61cadda1..00000000 --- a/assets/src/main/java/io/leafage/basic/assets/controller/PostStatisticsController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.assets.controller; - -import io.leafage.basic.assets.service.PostStatisticsService; -import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.domain.Page; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * resource controller. - * - * @author wq li 2018/12/20 9:54 - **/ -@RestController -@RequestMapping("/statistics") -public class PostStatisticsController { - - private final Logger logger = LoggerFactory.getLogger(PostStatisticsController.class); - - private final PostStatisticsService postStatisticsService; - - public PostStatisticsController(PostStatisticsService postStatisticsService) { - this.postStatisticsService = postStatisticsService; - } - - /** - * 分页查询浏览量统计 - * - * @param page 页码 - * @param size 大小 - * @return 查询到数据,异常时返回204 - */ - @GetMapping - public ResponseEntity> retrieve(@RequestParam int page, @RequestParam int size) { - Page voFlux; - try { - voFlux = postStatisticsService.retrieve(page, size); - } catch (Exception e) { - logger.error("Statistics viewed occurred an error: ", e); - return ResponseEntity.noContent().build(); - } - return ResponseEntity.ok(voFlux); - } - -} diff --git a/assets/src/main/java/io/leafage/basic/assets/domain/PostContent.java b/assets/src/main/java/io/leafage/basic/assets/domain/PostContent.java index a2859401..5b00d0d4 100644 --- a/assets/src/main/java/io/leafage/basic/assets/domain/PostContent.java +++ b/assets/src/main/java/io/leafage/basic/assets/domain/PostContent.java @@ -40,7 +40,7 @@ public class PostContent extends AuditMetadata { /** * 内容 */ - private String content; + private String context; public Long getPostId() { return postId; @@ -50,12 +50,11 @@ public void setPostId(Long postId) { this.postId = postId; } - public String getContent() { - return content; + public String getContext() { + return context; } - public void setContent(String content) { - this.content = content; + public void setContext(String context) { + this.context = context; } - } diff --git a/assets/src/main/java/io/leafage/basic/assets/dto/CategoryDTO.java b/assets/src/main/java/io/leafage/basic/assets/dto/CategoryDTO.java index b611ef3b..8cb073ff 100644 --- a/assets/src/main/java/io/leafage/basic/assets/dto/CategoryDTO.java +++ b/assets/src/main/java/io/leafage/basic/assets/dto/CategoryDTO.java @@ -16,38 +16,13 @@ */ package io.leafage.basic.assets.dto; -import jakarta.validation.constraints.NotBlank; +import io.leafage.basic.assets.bo.CategoryBO; /** * dto class for category. * * @author wq li 2020-12-03 22:59 */ -public class CategoryDTO { +public class CategoryDTO extends CategoryBO { - /** - * 名称 - */ - @NotBlank - private String name; - /** - * 描述 - */ - private String description; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/assets/src/main/java/io/leafage/basic/assets/dto/CommentDTO.java b/assets/src/main/java/io/leafage/basic/assets/dto/CommentDTO.java index 9fb316f8..cc939c8b 100644 --- a/assets/src/main/java/io/leafage/basic/assets/dto/CommentDTO.java +++ b/assets/src/main/java/io/leafage/basic/assets/dto/CommentDTO.java @@ -17,51 +17,13 @@ package io.leafage.basic.assets.dto; -import jakarta.validation.constraints.NotBlank; +import io.leafage.basic.assets.bo.CommentBO; /** * dto class for comment. * * @author wq li 2021-09-29 13:51 */ -public class CommentDTO { +public class CommentDTO extends CommentBO { - /** - * 帖子 - */ - @NotBlank - private String post; - /** - * 内容 - */ - @NotBlank - private String content; - /** - * 回复人 - */ - private String replier; - - public String getPost() { - return post; - } - - public void setPost(String post) { - this.post = post; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getReplier() { - return replier; - } - - public void setReplier(String replier) { - this.replier = replier; - } } diff --git a/assets/src/main/java/io/leafage/basic/assets/dto/PostDTO.java b/assets/src/main/java/io/leafage/basic/assets/dto/PostDTO.java index a586b889..7a8cdbd6 100644 --- a/assets/src/main/java/io/leafage/basic/assets/dto/PostDTO.java +++ b/assets/src/main/java/io/leafage/basic/assets/dto/PostDTO.java @@ -16,54 +16,21 @@ */ package io.leafage.basic.assets.dto; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; +import io.leafage.basic.assets.bo.PostBO; import jakarta.validation.constraints.NotNull; -import java.util.Set; - /** * dto class for posts. * * @author wq li 2019-03-03 22:59 **/ -public class PostDTO { +public class PostDTO extends PostBO { /** - * 标题 - */ - @NotBlank - private String title; - /** - * /** * 分类 */ - @NotNull + @NotNull(message = "categoryId must not be null.") private Long categoryId; - /** - * 标签 - */ - @NotEmpty - private Set tags; - /** - * 封面 - */ - @NotBlank - private String cover; - /** - * 内容 - */ - @NotBlank - private String content; - - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } public Long getCategoryId() { return categoryId; @@ -73,28 +40,4 @@ public void setCategoryId(Long categoryId) { this.categoryId = categoryId; } - public String getCover() { - return cover; - } - - public void setCover(String cover) { - this.cover = cover; - } - - public Set getTags() { - return tags; - } - - public void setTags(Set tags) { - this.tags = tags; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - } diff --git a/assets/src/main/java/io/leafage/basic/assets/repository/PostStatisticsRepository.java b/assets/src/main/java/io/leafage/basic/assets/repository/PostStatisticsRepository.java index 4966f3e7..4abc79e1 100644 --- a/assets/src/main/java/io/leafage/basic/assets/repository/PostStatisticsRepository.java +++ b/assets/src/main/java/io/leafage/basic/assets/repository/PostStatisticsRepository.java @@ -19,8 +19,6 @@ import io.leafage.basic.assets.domain.PostStatistics; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; /** @@ -32,20 +30,10 @@ public interface PostStatisticsRepository extends JpaRepository { /** - * 增加viewed + * 查询帖子数据 * - * @param id 主键 + * @param postId 帖子ID + * @return 统计数据 */ - @Modifying - @Query("update #{#entityName} set viewed = viewed + 1 where id = ?1") - void increaseViewed(Long id); - - /** - * 增加comment - * - * @param id 主键 - */ - @Modifying - @Query("update #{#entityName} set comments = comments + 1 where id = ?1") - void increaseComment(Long id); + PostStatistics getByPostId(Long postId); } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/PostStatisticsService.java b/assets/src/main/java/io/leafage/basic/assets/service/PostStatisticsService.java index efe5a905..df7be79c 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/PostStatisticsService.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/PostStatisticsService.java @@ -17,25 +17,23 @@ package io.leafage.basic.assets.service; -import io.leafage.basic.assets.dto.PostStatisticsDTO; -import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.springframework.data.domain.Page; -import top.leafage.common.servlet.ServletBasicService; +import io.leafage.basic.assets.constants.StatisticsEnum; +import io.leafage.basic.assets.domain.PostStatistics; /** * statistics service. * * @author wq li 2021/09/29 14:32 **/ -public interface PostStatisticsService extends ServletBasicService { +public interface PostStatisticsService { /** - * 分页查询 + * 记录统计量 * - * @param page 分页 - * @param size 大小 - * @return 结果集 + * @param postId 帖子ID + * @param statisticsEnum 统计枚举 + * @return 浏览量 */ - Page retrieve(int page, int size); + PostStatistics increase(Long postId, StatisticsEnum statisticsEnum); } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/PostsService.java b/assets/src/main/java/io/leafage/basic/assets/service/PostsService.java index 0bafed05..82aa5959 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/PostsService.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/PostsService.java @@ -17,7 +17,6 @@ package io.leafage.basic.assets.service; import io.leafage.basic.assets.dto.PostDTO; -import io.leafage.basic.assets.vo.PostContentVO; import io.leafage.basic.assets.vo.PostVO; import org.springframework.data.domain.Page; import top.leafage.common.servlet.ServletBasicService; @@ -45,7 +44,7 @@ public interface PostsService extends ServletBasicService { * @param id 主键 * @return 查询结果 */ - PostContentVO details(Long id); + PostVO details(Long id); /** * 下一篇 diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java index c3f088f3..f366455b 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java @@ -20,7 +20,6 @@ import io.leafage.basic.assets.domain.Comment; import io.leafage.basic.assets.dto.CommentDTO; import io.leafage.basic.assets.repository.CommentRepository; -import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.service.CommentService; import io.leafage.basic.assets.vo.CommentVO; import org.springframework.cglib.beans.BeanCopier; @@ -41,11 +40,9 @@ public class CommentServiceImpl implements CommentService { private final CommentRepository commentRepository; - private final PostStatisticsRepository postStatisticsRepository; - public CommentServiceImpl(CommentRepository commentRepository, PostStatisticsRepository postStatisticsRepository) { + public CommentServiceImpl(CommentRepository commentRepository) { this.commentRepository = commentRepository; - this.postStatisticsRepository = postStatisticsRepository; } @Override @@ -74,8 +71,6 @@ public CommentVO create(CommentDTO dto) { copier.copy(dto, comment, null); comment = commentRepository.saveAndFlush(comment); - // 添加关联帖子的评论数 - this.postStatisticsRepository.increaseComment(comment.getPostId()); return this.convertOuter(comment); } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java index bb2ac459..284ed716 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java @@ -17,14 +17,10 @@ package io.leafage.basic.assets.service.impl; +import io.leafage.basic.assets.constants.StatisticsEnum; import io.leafage.basic.assets.domain.PostStatistics; -import io.leafage.basic.assets.dto.PostStatisticsDTO; import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.service.PostStatisticsService; -import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.springframework.cglib.beans.BeanCopier; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; /** @@ -42,31 +38,13 @@ public PostStatisticsServiceImpl(PostStatisticsRepository postStatisticsReposito } @Override - public Page retrieve(int page, int size) { - return postStatisticsRepository.findAll(PageRequest.of(page, size)).map(this::convertOuter); + public PostStatistics increase(Long postId, StatisticsEnum statisticsEnum) { + PostStatistics postStatistics = postStatisticsRepository.getByPostId(postId); + switch (statisticsEnum) { + case LIKES -> postStatistics.setLikes(postStatistics.getLikes() + 1); + case COMMENTS -> postStatistics.setComments(postStatistics.getComments() + 1); + case VIEWED -> postStatistics.setViewed(postStatistics.getViewed() + 1); + } + return postStatisticsRepository.save(postStatistics); } - - @Override - public PostStatisticsVO create(PostStatisticsDTO dto) { - PostStatistics postStatistics = new PostStatistics(); - BeanCopier copier = BeanCopier.create(PostStatisticsDTO.class, PostStatistics.class, false); - copier.copy(dto, postStatistics, null); - - postStatistics = postStatisticsRepository.saveAndFlush(postStatistics); - return this.convertOuter(postStatistics); - } - - /** - * 对象转换为输出结果对象 - * - * @param postStatistics 信息 - * @return 输出转换后的vo对象 - */ - private PostStatisticsVO convertOuter(PostStatistics postStatistics) { - PostStatisticsVO vo = new PostStatisticsVO(); - BeanCopier copier = BeanCopier.create(PostStatistics.class, PostStatisticsVO.class, false); - copier.copy(postStatistics, vo, null); - return vo; - } - } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java index a753d292..82b12ac3 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java @@ -23,9 +23,7 @@ import io.leafage.basic.assets.repository.CategoryRepository; import io.leafage.basic.assets.repository.PostContentRepository; import io.leafage.basic.assets.repository.PostRepository; -import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.service.PostsService; -import io.leafage.basic.assets.vo.PostContentVO; import io.leafage.basic.assets.vo.PostVO; import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; @@ -51,13 +49,11 @@ public class PostsServiceImpl implements PostsService { private final PostRepository postRepository; private final PostContentRepository postContentRepository; private final CategoryRepository categoryRepository; - private final PostStatisticsRepository postStatisticsRepository; - public PostsServiceImpl(PostRepository postRepository, PostContentRepository postContentRepository, CategoryRepository categoryRepository, PostStatisticsRepository postStatisticsRepository) { + public PostsServiceImpl(PostRepository postRepository, PostContentRepository postContentRepository, CategoryRepository categoryRepository) { this.postRepository = postRepository; this.postContentRepository = postContentRepository; this.categoryRepository = categoryRepository; - this.postStatisticsRepository = postStatisticsRepository; } @Override @@ -79,27 +75,19 @@ public PostVO fetch(Long id) { @Transactional(rollbackFor = Exception.class) @Override - public PostContentVO details(Long id) { + public PostVO details(Long id) { Assert.notNull(id, "post id must not be null."); Post post = postRepository.findById(id).orElse(null); if (post == null) { return null; } - // viewed自增一,异步执行 - this.postStatisticsRepository.increaseViewed(id); - PostVO vo = this.convertOuter(post); - PostContentVO postsContentVO = new PostContentVO(); - BeanCopier copier = BeanCopier.create(PostVO.class, PostContentVO.class, false); - copier.copy(vo, postsContentVO, null); - - postsContentVO.setPostsId(post.getId()); // 获取内容详情 PostContent postContent = postContentRepository.getByPostId(id); if (postContent != null) { - postsContentVO.setContent(postContent.getContent()); + vo.setContext(postContent.getContext()); } - return postsContentVO; + return vo; } @Override @@ -137,7 +125,7 @@ public PostVO create(PostDTO dto) { postContent = new PostContent(); } postContent.setPostId(post.getId()); - postContent.setContent(dto.getContent()); + postContent.setContext(dto.getContext()); postContentRepository.saveAndFlush(postContent); //转换结果 return this.convertOuter(post); @@ -162,7 +150,7 @@ public PostVO modify(Long id, PostDTO dto) { if (postContent == null) { postContent = new PostContent(); } - postContent.setContent(dto.getContent()); + postContent.setContext(dto.getContext()); postContentRepository.save(postContent); //转换结果 return this.convertOuter(post); diff --git a/assets/src/main/java/io/leafage/basic/assets/vo/CategoryVO.java b/assets/src/main/java/io/leafage/basic/assets/vo/CategoryVO.java index e43ef0f5..2e29ae31 100644 --- a/assets/src/main/java/io/leafage/basic/assets/vo/CategoryVO.java +++ b/assets/src/main/java/io/leafage/basic/assets/vo/CategoryVO.java @@ -16,33 +16,39 @@ */ package io.leafage.basic.assets.vo; +import io.leafage.basic.assets.bo.CategoryBO; + +import java.time.Instant; + /** * vo class for category. * * @author wq li 2020-12-03 22:59 */ -public class CategoryVO { +public class CategoryVO extends CategoryBO { /** - * 名称 + * 主键 */ - private String name; + private Long id; + /** - * 统计数 + * 贴子数 */ private long count; + /** - * 描述 + * 最后更新时间 */ - private String description; + private Instant lastModifiedDate; - public String getName() { - return name; + public Long getId() { + return id; } - public void setName(String name) { - this.name = name; + public void setId(Long id) { + this.id = id; } public long getCount() { @@ -53,11 +59,11 @@ public void setCount(long count) { this.count = count; } - public String getDescription() { - return description; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setDescription(String description) { - this.description = description; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/assets/src/main/java/io/leafage/basic/assets/vo/CommentVO.java b/assets/src/main/java/io/leafage/basic/assets/vo/CommentVO.java index 2c3a45bf..0f6e1f76 100644 --- a/assets/src/main/java/io/leafage/basic/assets/vo/CommentVO.java +++ b/assets/src/main/java/io/leafage/basic/assets/vo/CommentVO.java @@ -17,48 +17,49 @@ package io.leafage.basic.assets.vo; +import io.leafage.basic.assets.bo.CommentBO; + +import java.time.Instant; + /** * vo class for comment. * * @author wq li 2021-08-03 22:59 **/ -public class CommentVO { +public class CommentVO extends CommentBO { /** - * 帖子 - */ - private String post; - /** - * 内容 + * 主键 */ - private String content; + private Long id; + /** * 国家 */ private String country; + /** * 位置 */ private String location; + /** * 回复数 */ private Long count; - public String getPost() { - return post; - } + /** + * 最后更新时间 + */ + private Instant lastModifiedDate; - public void setPost(String post) { - this.post = post; - } - public String getContent() { - return content; + public Long getId() { + return id; } - public void setContent(String content) { - this.content = content; + public void setId(Long id) { + this.id = id; } public String getCountry() { @@ -84,4 +85,12 @@ public Long getCount() { public void setCount(Long count) { this.count = count; } + + public Instant getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } } diff --git a/assets/src/main/java/io/leafage/basic/assets/vo/PostContentVO.java b/assets/src/main/java/io/leafage/basic/assets/vo/PostContentVO.java deleted file mode 100644 index 8df6aace..00000000 --- a/assets/src/main/java/io/leafage/basic/assets/vo/PostContentVO.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package io.leafage.basic.assets.vo; - -/** - * vo class for posts content. - * - * @author wq li 2019-03-03 22:59 - **/ -public class PostContentVO extends PostVO { - - /** - * 帖子ID - */ - private Long postsId; - /** - * 目录 - */ - private String catalog; - /** - * 内容 - */ - private String content; - - - public Long getPostsId() { - return postsId; - } - - public void setPostsId(Long postsId) { - this.postsId = postsId; - } - - public String getCatalog() { - return catalog; - } - - public void setCatalog(String catalog) { - this.catalog = catalog; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } -} diff --git a/assets/src/main/java/io/leafage/basic/assets/vo/PostStatisticsVO.java b/assets/src/main/java/io/leafage/basic/assets/vo/PostStatisticsVO.java deleted file mode 100644 index 12057edf..00000000 --- a/assets/src/main/java/io/leafage/basic/assets/vo/PostStatisticsVO.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.assets.vo; - -/** - * vo class for statistics. - * - * @author wq li 2021-09-03 22:59 - **/ -public class PostStatisticsVO { - - /** - * 帖子ID - */ - private Long postId; - - /** - * 浏览量 - */ - private int viewed; - - /** - * 浏览量环比 - */ - private double overViewed; - - /** - * 点赞量 - */ - private int likes; - - /** - * 浏览量点赞量 - */ - private double overLikes; - - /** - * 评论量 - */ - private int comments; - - /** - * 浏览量评论量 - */ - private double overComments; - - - public Long getPostId() { - return postId; - } - - public void setPostId(Long postId) { - this.postId = postId; - } - - public int getViewed() { - return viewed; - } - - public void setViewed(int viewed) { - this.viewed = viewed; - } - - public double getOverViewed() { - return overViewed; - } - - public void setOverViewed(double overViewed) { - this.overViewed = overViewed; - } - - public int getLikes() { - return likes; - } - - public void setLikes(int likes) { - this.likes = likes; - } - - public double getOverLikes() { - return overLikes; - } - - public void setOverLikes(double overLikes) { - this.overLikes = overLikes; - } - - public int getComments() { - return comments; - } - - public void setComments(int comments) { - this.comments = comments; - } - - public double getOverComments() { - return overComments; - } - - public void setOverComments(double overComments) { - this.overComments = overComments; - } -} diff --git a/assets/src/main/java/io/leafage/basic/assets/vo/PostVO.java b/assets/src/main/java/io/leafage/basic/assets/vo/PostVO.java index 5f454035..0cc61271 100644 --- a/assets/src/main/java/io/leafage/basic/assets/vo/PostVO.java +++ b/assets/src/main/java/io/leafage/basic/assets/vo/PostVO.java @@ -16,67 +16,39 @@ */ package io.leafage.basic.assets.vo; -import java.util.Set; +import io.leafage.basic.assets.bo.PostBO; + +import java.time.Instant; /** * vo class for posts. * * @author wq li 2019-03-03 22:59 **/ -public class PostVO { +public class PostVO extends PostBO { /** - * 标题 - */ - private String title; - /** - * 封面 + * 主键 */ - private String cover; - /** - * 标签 - */ - private Set tags; + private Long id; + /** - * 分类 + * category */ private String category; + /** - * 点赞 - */ - private int likes; - /** - * 查看 - */ - private int viewed; - /** - * 评论 + * 最后更新时间 */ - private int comments; + private Instant lastModifiedDate; - public String getTitle() { - return title; + public Long getId() { + return id; } - public void setTitle(String title) { - this.title = title; - } - - public String getCover() { - return cover; - } - - public void setCover(String cover) { - this.cover = cover; - } - - public Set getTags() { - return tags; - } - - public void setTags(Set tags) { - this.tags = tags; + public void setId(Long id) { + this.id = id; } public String getCategory() { @@ -87,27 +59,11 @@ public void setCategory(String category) { this.category = category; } - public int getLikes() { - return likes; - } - - public void setLikes(int likes) { - this.likes = likes; - } - - public int getViewed() { - return viewed; - } - - public void setViewed(int viewed) { - this.viewed = viewed; - } - - public int getComments() { - return comments; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setComments(int comments) { - this.comments = comments; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/assets/src/test/java/io/leafage/basic/assets/controller/CategoryControllerTest.java b/assets/src/test/java/io/leafage/basic/assets/controller/CategoryControllerTest.java index 2ba42bb8..ea93eb20 100644 --- a/assets/src/test/java/io/leafage/basic/assets/controller/CategoryControllerTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/controller/CategoryControllerTest.java @@ -85,7 +85,7 @@ void init() { void retrieve() throws Exception { Pageable pageable = PageRequest.of(0,2); Page page = new PageImpl<>(List.of(categoryVO), pageable, 2L); - given(this.categoryService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willReturn(page); + given(categoryService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willReturn(page); mvc.perform(get("/category").queryParam("page", "0") .queryParam("size", "2").queryParam("sort", "id")) @@ -94,7 +94,7 @@ void retrieve() throws Exception { @Test void retrieve_error() throws Exception { - given(this.categoryService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willThrow(new NoSuchElementException()); + given(categoryService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willThrow(new NoSuchElementException()); mvc.perform(get("/category").queryParam("page", "0") .queryParam("size", "2").queryParam("sort", "id")).andExpect(status().isNoContent()) @@ -103,7 +103,7 @@ void retrieve_error() throws Exception { @Test void fetch() throws Exception { - given(this.categoryService.fetch(Mockito.anyLong())).willReturn(categoryVO); + given(categoryService.fetch(Mockito.anyLong())).willReturn(categoryVO); mvc.perform(get("/category/{id}", 1L)).andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("test")).andDo(print()).andReturn(); @@ -111,7 +111,7 @@ void fetch() throws Exception { @Test void fetch_error() throws Exception { - given(this.categoryService.fetch(Mockito.anyLong())).willThrow(new RuntimeException()); + given(categoryService.fetch(Mockito.anyLong())).willThrow(new RuntimeException()); mvc.perform(get("/category/{id}", 1L)).andExpect(status().isNoContent()) .andDo(print()).andReturn(); @@ -119,7 +119,7 @@ void fetch_error() throws Exception { @Test void create() throws Exception { - given(this.categoryService.create(Mockito.any(CategoryDTO.class))).willReturn(categoryVO); + given(categoryService.create(Mockito.any(CategoryDTO.class))).willReturn(categoryVO); mvc.perform(post("/category").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(categoryDTO)).with(csrf().asHeader())).andExpect(status().isCreated()) @@ -128,7 +128,7 @@ void create() throws Exception { @Test void create_error() throws Exception { - given(this.categoryService.create(Mockito.any(CategoryDTO.class))).willThrow(new RuntimeException()); + given(categoryService.create(Mockito.any(CategoryDTO.class))).willThrow(new RuntimeException()); mvc.perform(post("/category").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(categoryDTO)).with(csrf().asHeader())).andExpect(status().isExpectationFailed()) @@ -137,7 +137,7 @@ void create_error() throws Exception { @Test void modify() throws Exception { - given(this.categoryService.modify(Mockito.anyLong(), Mockito.any(CategoryDTO.class))).willReturn(categoryVO); + given(categoryService.modify(Mockito.anyLong(), Mockito.any(CategoryDTO.class))).willReturn(categoryVO); mvc.perform(put("/category/{id}", 1L).contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(categoryDTO)).with(csrf().asHeader())) @@ -147,7 +147,7 @@ void modify() throws Exception { @Test void modify_error() throws Exception { - given(this.categoryService.modify(Mockito.anyLong(), Mockito.any(CategoryDTO.class))).willThrow(new RuntimeException()); + given(categoryService.modify(Mockito.anyLong(), Mockito.any(CategoryDTO.class))).willThrow(new RuntimeException()); mvc.perform(put("/category/{id}", Mockito.anyLong()).contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(categoryDTO)).with(csrf().asHeader())) @@ -157,7 +157,7 @@ void modify_error() throws Exception { @Test void remove() throws Exception { - this.categoryService.remove(Mockito.anyLong()); + categoryService.remove(Mockito.anyLong()); mvc.perform(delete("/category/{id}", Mockito.anyLong()).with(csrf().asHeader())).andExpect(status().isOk()) .andDo(print()).andReturn(); @@ -165,7 +165,7 @@ void remove() throws Exception { @Test void remove_error() throws Exception { - doThrow(new RuntimeException()).when(this.categoryService).remove(Mockito.anyLong()); + doThrow(new RuntimeException()).when(categoryService).remove(Mockito.anyLong()); mvc.perform(delete("/category/{id}", Mockito.anyLong()).with(csrf().asHeader())).andExpect(status().isExpectationFailed()) .andDo(print()).andReturn(); diff --git a/assets/src/test/java/io/leafage/basic/assets/controller/CommentControllerTest.java b/assets/src/test/java/io/leafage/basic/assets/controller/CommentControllerTest.java index 0a9baaec..2e034b15 100644 --- a/assets/src/test/java/io/leafage/basic/assets/controller/CommentControllerTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/controller/CommentControllerTest.java @@ -74,20 +74,20 @@ class CommentControllerTest { @BeforeEach void init() { commentVO = new CommentVO(); - commentVO.setContent("content"); - commentVO.setPost("post"); + commentVO.setContext("content"); + commentVO.setPostId(1L); commentDTO = new CommentDTO(); - commentDTO.setPost("post"); - commentDTO.setContent("content"); - commentDTO.setReplier("test"); + commentDTO.setPostId(1L); + commentDTO.setContext("content"); + commentDTO.setReplier(1L); } @Test void retrieve() throws Exception { Pageable pageable = PageRequest.of(0, 2); Page page = new PageImpl<>(List.of(commentVO), pageable, 2L); - given(this.commentService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willReturn(page); + given(commentService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willReturn(page); mvc.perform(get("/comment").queryParam("page", "0").queryParam("size", "2")) .andExpect(status().isOk()).andDo(print()).andReturn(); @@ -95,7 +95,7 @@ void retrieve() throws Exception { @Test void retrieve_error() throws Exception { - given(this.commentService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willThrow(new NoSuchElementException()); + given(commentService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willThrow(new NoSuchElementException()); mvc.perform(get("/comment").queryParam("page", "0").queryParam("size", "2")) .andExpect(status().isNoContent()).andDo(print()).andReturn(); @@ -103,44 +103,44 @@ void retrieve_error() throws Exception { @Test void relation() throws Exception { - given(this.commentService.relation(Mockito.anyLong())).willReturn(List.of(commentVO)); + given(commentService.relation(Mockito.anyLong())).willReturn(List.of(commentVO)); mvc.perform(get("/comment/{id}", Mockito.anyLong())).andExpect(status().isOk()).andDo(print()).andReturn(); } @Test void relation_error() throws Exception { - given(this.commentService.relation(Mockito.anyLong())).willThrow(new NoSuchElementException()); + given(commentService.relation(Mockito.anyLong())).willThrow(new NoSuchElementException()); mvc.perform(get("/comment/{id}", Mockito.anyLong())).andExpect(status().isNoContent()).andDo(print()).andReturn(); } @Test void replies() throws Exception { - given(this.commentService.replies(Mockito.anyLong())).willReturn(List.of(commentVO)); + given(commentService.replies(Mockito.anyLong())).willReturn(List.of(commentVO)); mvc.perform(get("/comment/{id}/replies", 1L)).andExpect(status().isOk()).andDo(print()).andReturn(); } @Test void replies_error() throws Exception { - given(this.commentService.replies(Mockito.anyLong())).willThrow(new NoSuchElementException()); + given(commentService.replies(Mockito.anyLong())).willThrow(new NoSuchElementException()); mvc.perform(get("/comment/{id}/replies", 1L)).andExpect(status().isNoContent()).andDo(print()).andReturn(); } @Test void create() throws Exception { - given(this.commentService.create(Mockito.any(CommentDTO.class))).willReturn(commentVO); + given(commentService.create(Mockito.any(CommentDTO.class))).willReturn(commentVO); mvc.perform(post("/comment").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(commentDTO)).with(csrf().asHeader())).andExpect(status().isCreated()) - .andExpect(jsonPath("$.content").value("content")).andDo(print()).andReturn(); + .andExpect(jsonPath("$.context").value("content")).andDo(print()).andReturn(); } @Test void create_error() throws Exception { - given(this.commentService.create(Mockito.any(CommentDTO.class))).willThrow(new NoSuchElementException()); + given(commentService.create(Mockito.any(CommentDTO.class))).willThrow(new NoSuchElementException()); mvc.perform(post("/comment").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(commentDTO)).with(csrf().asHeader())).andExpect(status() diff --git a/assets/src/test/java/io/leafage/basic/assets/controller/PostControllerTest.java b/assets/src/test/java/io/leafage/basic/assets/controller/PostControllerTest.java index 3d67ebfc..668932c1 100644 --- a/assets/src/test/java/io/leafage/basic/assets/controller/PostControllerTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/controller/PostControllerTest.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.leafage.basic.assets.dto.PostDTO; import io.leafage.basic.assets.service.PostsService; -import io.leafage.basic.assets.vo.PostContentVO; import io.leafage.basic.assets.vo.PostVO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -70,7 +69,6 @@ class PostControllerTest { private PostDTO postDTO; private PostVO postVO; - PostContentVO contentVO; @BeforeEach void init() { @@ -80,23 +78,20 @@ void init() { postDTO.setCategoryId(1L); postDTO.setCover("../test.jpg"); postDTO.setTags(Collections.singleton("java")); - postDTO.setContent("content"); + postDTO.setContext("content"); postVO = new PostVO(); postVO.setTitle(postDTO.getTitle()); postVO.setTags(postDTO.getTags()); postVO.setCover(postDTO.getCover()); - contentVO = new PostContentVO(); - contentVO.setTitle("test"); - contentVO.setCatalog("category"); } @Test void retrieve() throws Exception { Pageable pageable = PageRequest.of(0, 2); Page page = new PageImpl<>(List.of(postVO), pageable, 2L); - given(this.postsService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willReturn(page); + given(postsService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willReturn(page); mvc.perform(get("/posts").queryParam("page", "0") .queryParam("size", "2").queryParam("sort", "id")).andExpect(status().isOk()) @@ -105,7 +100,7 @@ void retrieve() throws Exception { @Test void retrieve_error() throws Exception { - given(this.postsService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willThrow(new NoSuchElementException()); + given(postsService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willThrow(new NoSuchElementException()); mvc.perform(get("/posts").queryParam("page", "0") .queryParam("size", "2").queryParam("sort", "id")).andExpect(status().isNoContent()) @@ -114,7 +109,7 @@ void retrieve_error() throws Exception { @Test void fetch() throws Exception { - given(this.postsService.fetch(Mockito.anyLong())).willReturn(postVO); + given(postsService.fetch(Mockito.anyLong())).willReturn(postVO); mvc.perform(get("/posts/{id}", Mockito.anyLong())).andExpect(status().isOk()) .andExpect(jsonPath("$.title").value("test")).andDo(print()).andReturn(); @@ -122,7 +117,7 @@ void fetch() throws Exception { @Test void fetch_error() throws Exception { - given(this.postsService.fetch(Mockito.anyLong())).willThrow(new RuntimeException()); + given(postsService.fetch(Mockito.anyLong())).willThrow(new RuntimeException()); mvc.perform(get("/posts/{id}", Mockito.anyLong())).andExpect(status().isNoContent()) .andDo(print()).andReturn(); } @@ -130,7 +125,7 @@ void fetch_error() throws Exception { @Test void next() throws Exception { - given(this.postsService.next(Mockito.anyLong())).willReturn(postVO); + given(postsService.next(Mockito.anyLong())).willReturn(postVO); mvc.perform(get("/posts/{id}/next", 1L)).andExpect(status().isOk()) .andExpect(jsonPath("$.title").value("test")).andDo(print()).andReturn(); @@ -138,7 +133,7 @@ void next() throws Exception { @Test void next_error() throws Exception { - given(this.postsService.next(Mockito.anyLong())).willThrow(new RuntimeException()); + given(postsService.next(Mockito.anyLong())).willThrow(new RuntimeException()); mvc.perform(get("/posts/{id}/next", 1L)).andExpect(status().isNoContent()) .andDo(print()).andReturn(); } @@ -146,7 +141,7 @@ void next_error() throws Exception { @Test void previous() throws Exception { - given(this.postsService.previous(Mockito.anyLong())).willReturn(postVO); + given(postsService.previous(Mockito.anyLong())).willReturn(postVO); mvc.perform(get("/posts/{id}/previous", 1L)).andExpect(status().isOk()) .andExpect(jsonPath("$.title").value("test")).andDo(print()).andReturn(); @@ -154,14 +149,14 @@ void previous() throws Exception { @Test void previous_error() throws Exception { - given(this.postsService.previous(Mockito.anyLong())).willThrow(new RuntimeException()); + given(postsService.previous(Mockito.anyLong())).willThrow(new RuntimeException()); mvc.perform(get("/posts/{id}/previous", 1L)).andExpect(status().isNoContent()) .andDo(print()).andReturn(); } @Test void details() throws Exception { - given(this.postsService.details(Mockito.anyLong())).willReturn(contentVO); + given(postsService.details(Mockito.anyLong())).willReturn(postVO); mvc.perform(get("/posts/{id}/details", 1L)).andExpect(status().isOk()) .andExpect(jsonPath("$.title").value("test")).andDo(print()).andReturn(); @@ -169,7 +164,7 @@ void details() throws Exception { @Test void details_error() throws Exception { - given(this.postsService.details(Mockito.anyLong())).willThrow(new RuntimeException()); + given(postsService.details(Mockito.anyLong())).willThrow(new RuntimeException()); mvc.perform(get("/posts/{id}/details", 1L)).andExpect(status().isNoContent()) .andDo(print()).andReturn(); @@ -177,7 +172,7 @@ void details_error() throws Exception { @Test void exist() throws Exception { - given(this.postsService.exist(Mockito.anyString())).willReturn(true); + given(postsService.exist(Mockito.anyString())).willReturn(true); mvc.perform(get("/posts/exist").queryParam("title", "test")).andExpect(status().isOk()) .andDo(print()).andReturn(); @@ -185,7 +180,7 @@ void exist() throws Exception { @Test void exist_error() throws Exception { - given(this.postsService.exist(Mockito.anyString())).willThrow(new RuntimeException()); + given(postsService.exist(Mockito.anyString())).willThrow(new RuntimeException()); mvc.perform(get("/posts/exist").queryParam("title", "test")).andExpect(status().isExpectationFailed()) .andDo(print()).andReturn(); @@ -193,7 +188,7 @@ void exist_error() throws Exception { @Test void create() throws Exception { - given(this.postsService.create(Mockito.any(PostDTO.class))).willReturn(postVO); + given(postsService.create(Mockito.any(PostDTO.class))).willReturn(postVO); mvc.perform(post("/posts").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(postDTO)).with(csrf().asHeader())).andExpect(status().isCreated()) @@ -203,7 +198,7 @@ void create() throws Exception { @Test void create_error() throws Exception { - given(this.postsService.create(Mockito.any(PostDTO.class))).willThrow(new RuntimeException()); + given(postsService.create(Mockito.any(PostDTO.class))).willThrow(new RuntimeException()); mvc.perform(post("/posts").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(postDTO)).with(csrf().asHeader())).andExpect(status().isExpectationFailed()) @@ -212,7 +207,7 @@ void create_error() throws Exception { @Test void modify() throws Exception { - given(this.postsService.modify(Mockito.anyLong(), Mockito.any(PostDTO.class))).willReturn(postVO); + given(postsService.modify(Mockito.anyLong(), Mockito.any(PostDTO.class))).willReturn(postVO); mvc.perform(put("/posts/{id}", 1L).contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(postDTO)).with(csrf().asHeader())) @@ -222,7 +217,7 @@ void modify() throws Exception { @Test void modify_error() throws Exception { - given(this.postsService.modify(Mockito.anyLong(), Mockito.any(PostDTO.class))).willThrow(new RuntimeException()); + given(postsService.modify(Mockito.anyLong(), Mockito.any(PostDTO.class))).willThrow(new RuntimeException()); mvc.perform(put("/posts/{id}", 1L).contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(postDTO)).with(csrf().asHeader())) @@ -232,14 +227,14 @@ void modify_error() throws Exception { @Test void remove() throws Exception { - this.postsService.remove(Mockito.anyLong()); + postsService.remove(Mockito.anyLong()); mvc.perform(delete("/posts/{id}", 1L).with(csrf().asHeader())).andExpect(status().isOk()) .andDo(print()).andReturn(); } @Test void remove_error() throws Exception { - doThrow(new RuntimeException()).when(this.postsService).remove(Mockito.anyLong()); + doThrow(new RuntimeException()).when(postsService).remove(Mockito.anyLong()); mvc.perform(delete("/posts/{id}", 1L).with(csrf().asHeader())).andExpect(status().isExpectationFailed()) .andDo(print()).andReturn(); } diff --git a/assets/src/test/java/io/leafage/basic/assets/controller/PostPostStatisticsControllerTest.java b/assets/src/test/java/io/leafage/basic/assets/controller/PostPostStatisticsControllerTest.java deleted file mode 100644 index 0501ee53..00000000 --- a/assets/src/test/java/io/leafage/basic/assets/controller/PostPostStatisticsControllerTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.assets.controller; - -import io.leafage.basic.assets.service.PostStatisticsService; -import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.List; -import java.util.NoSuchElementException; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * post statistics 接口测试 - * - * @author wq li 2021/12/7 17:54 - **/ -@WithMockUser -@ExtendWith(SpringExtension.class) -@WebMvcTest(PostStatisticsController.class) -class PostPostStatisticsControllerTest { - - @Autowired - private MockMvc mvc; - - @MockBean - private PostStatisticsService postStatisticsService; - - private PostStatisticsVO postStatisticsVO; - - @BeforeEach - void init() { - postStatisticsVO = new PostStatisticsVO(); - postStatisticsVO.setPostId(1L); - postStatisticsVO.setComments(12); - postStatisticsVO.setOverComments(23.23); - postStatisticsVO.setLikes(23); - postStatisticsVO.setOverLikes(23.2); - postStatisticsVO.setViewed(23); - postStatisticsVO.setOverViewed(0.23); - } - - @Test - void retrieve() throws Exception { - Pageable pageable = PageRequest.of(0, 2); - Page page = new PageImpl<>(List.of(postStatisticsVO), pageable, 2L); - given(this.postStatisticsService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willReturn(page); - - mvc.perform(get("/statistics").queryParam("page", "0").queryParam("size", "2")) - .andExpect(status().isOk()).andDo(print()).andReturn(); - } - - @Test - void retrieve_error() throws Exception { - given(this.postStatisticsService.retrieve(Mockito.anyInt(), Mockito.anyInt())).willThrow(new NoSuchElementException()); - - mvc.perform(get("/statistics").queryParam("page", "0").queryParam("size", "2")) - .andExpect(status().isNoContent()).andDo(print()).andReturn(); - } -} \ No newline at end of file diff --git a/assets/src/test/java/io/leafage/basic/assets/service/impl/CategoryServiceImplTest.java b/assets/src/test/java/io/leafage/basic/assets/service/impl/CategoryServiceImplTest.java index a73e6d10..a89bcf30 100644 --- a/assets/src/test/java/io/leafage/basic/assets/service/impl/CategoryServiceImplTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/service/impl/CategoryServiceImplTest.java @@ -71,9 +71,9 @@ void init() { void retrieve() { Pageable pageable = PageRequest.of(0, 2); Page page = new PageImpl<>(List.of(Mockito.mock(Category.class)), pageable, 2L); - given(this.categoryRepository.findAll(Mockito.any(PageRequest.class))).willReturn(page); + given(categoryRepository.findAll(Mockito.any(PageRequest.class))).willReturn(page); - given(this.postRepository.countByCategoryId(Mockito.anyLong())).willReturn(Mockito.anyLong()); + given(postRepository.countByCategoryId(Mockito.anyLong())).willReturn(Mockito.anyLong()); Page voPage = categoryService.retrieve(0, 2, "id"); @@ -82,7 +82,7 @@ void retrieve() { @Test void fetch() { - given(this.categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Category.class))); + given(categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Category.class))); CategoryVO categoryVO = categoryService.fetch(Mockito.anyLong()); @@ -92,27 +92,27 @@ void fetch() { @Test void create() { - given(this.categoryRepository.saveAndFlush(Mockito.any(Category.class))).willReturn(Mockito.mock(Category.class)); + given(categoryRepository.saveAndFlush(Mockito.any(Category.class))).willReturn(Mockito.mock(Category.class)); - given(this.postRepository.countByCategoryId(Mockito.anyLong())).willReturn(2L); + given(postRepository.countByCategoryId(Mockito.anyLong())).willReturn(2L); CategoryVO categoryVO = categoryService.create(Mockito.mock(CategoryDTO.class)); - verify(this.categoryRepository, times(1)).saveAndFlush(Mockito.any(Category.class)); + verify(categoryRepository, times(1)).saveAndFlush(Mockito.any(Category.class)); Assertions.assertNotNull(categoryVO); } @Test void modify() { - given(this.categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Category.class))); + given(categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Category.class))); - given(this.categoryRepository.save(Mockito.any(Category.class))).willReturn(Mockito.mock(Category.class)); + given(categoryRepository.save(Mockito.any(Category.class))).willReturn(Mockito.mock(Category.class)); - given(this.postRepository.countByCategoryId(Mockito.anyLong())).willReturn(Mockito.anyLong()); + given(postRepository.countByCategoryId(Mockito.anyLong())).willReturn(Mockito.anyLong()); CategoryVO categoryVO = categoryService.modify(1L, categoryDTO); - verify(this.categoryRepository, times(1)).save(Mockito.any(Category.class)); + verify(categoryRepository, times(1)).save(Mockito.any(Category.class)); Assertions.assertNotNull(categoryVO); } @@ -120,6 +120,6 @@ void modify() { void remove() { categoryService.remove(Mockito.anyLong()); - verify(this.categoryRepository, times(1)).deleteById(Mockito.anyLong()); + verify(categoryRepository, times(1)).deleteById(Mockito.anyLong()); } } \ No newline at end of file diff --git a/assets/src/test/java/io/leafage/basic/assets/service/impl/CommentServiceImplTest.java b/assets/src/test/java/io/leafage/basic/assets/service/impl/CommentServiceImplTest.java index f77e62df..788da563 100644 --- a/assets/src/test/java/io/leafage/basic/assets/service/impl/CommentServiceImplTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/service/impl/CommentServiceImplTest.java @@ -20,7 +20,6 @@ import io.leafage.basic.assets.domain.Comment; import io.leafage.basic.assets.dto.CommentDTO; import io.leafage.basic.assets.repository.CommentRepository; -import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.vo.CommentVO; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -38,7 +37,6 @@ import java.util.List; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doNothing; /** * comment 接口测试 @@ -51,9 +49,6 @@ class CommentServiceImplTest { @Mock private CommentRepository commentRepository; - @Mock - private PostStatisticsRepository postStatisticsRepository; - @InjectMocks private CommentServiceImpl commentService; @@ -61,7 +56,7 @@ class CommentServiceImplTest { void retrieve() { Pageable pageable = PageRequest.of(0, 2); Page page = new PageImpl<>(List.of(Mockito.mock(Comment.class)), pageable, 2L); - given(this.commentRepository.findAll(PageRequest.of(0, 2))).willReturn(page); + given(commentRepository.findAll(PageRequest.of(0, 2))).willReturn(page); Page voPage = commentService.retrieve(0, 2); Assertions.assertNotNull(voPage.getContent()); @@ -69,7 +64,7 @@ void retrieve() { @Test void relation() { - given(this.commentRepository.findByPostIdAndReplierIsNull(Mockito.anyLong())).willReturn(Mockito.anyList()); + given(commentRepository.findByPostIdAndReplierIsNull(Mockito.anyLong())).willReturn(Mockito.anyList()); List voList = commentService.relation(1L); Assertions.assertNotNull(voList); @@ -77,7 +72,7 @@ void relation() { @Test void relation_empty() { - given(this.commentRepository.findByPostIdAndReplierIsNull(Mockito.anyLong())).willReturn(Collections.emptyList()); + given(commentRepository.findByPostIdAndReplierIsNull(Mockito.anyLong())).willReturn(Collections.emptyList()); List voList = commentService.relation(Mockito.anyLong()); Assertions.assertTrue(voList.isEmpty()); @@ -93,7 +88,7 @@ void replies() { comm.setContent("评论信息2222"); comm.setPostId(1L); comm.setReplier(comment.getReplier()); - given(this.commentRepository.findByReplier(Mockito.anyLong())).willReturn(List.of(comment, comm)); + given(commentRepository.findByReplier(Mockito.anyLong())).willReturn(List.of(comment, comm)); List voList = commentService.replies(Mockito.anyLong()); Assertions.assertNotNull(voList); @@ -107,11 +102,9 @@ void replies_empty() { @Test void create() { - given(this.commentRepository.saveAndFlush(Mockito.any(Comment.class))).willReturn(Mockito.mock(Comment.class)); - - doNothing().when(this.postStatisticsRepository).increaseComment(Mockito.anyLong()); + given(commentRepository.saveAndFlush(Mockito.any(Comment.class))).willReturn(Mockito.mock(Comment.class)); - given(this.commentRepository.countByReplier(Mockito.anyLong())).willReturn(2L); + given(commentRepository.countByReplier(Mockito.anyLong())).willReturn(2L); CommentVO commentVO = commentService.create(Mockito.mock(CommentDTO.class)); Assertions.assertNotNull(commentVO); diff --git a/assets/src/test/java/io/leafage/basic/assets/service/impl/PostPostStatisticsServiceImplTest.java b/assets/src/test/java/io/leafage/basic/assets/service/impl/PostPostStatisticsServiceImplTest.java deleted file mode 100644 index 3579f677..00000000 --- a/assets/src/test/java/io/leafage/basic/assets/service/impl/PostPostStatisticsServiceImplTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.assets.service.impl; - -import io.leafage.basic.assets.domain.PostStatistics; -import io.leafage.basic.assets.dto.PostStatisticsDTO; -import io.leafage.basic.assets.repository.PostStatisticsRepository; -import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * statistics 接口测试 - * - * @author wq li 2021/12/7 17:55 - **/ -@ExtendWith(MockitoExtension.class) -class PostPostStatisticsServiceImplTest { - - @Mock - private PostStatisticsRepository postStatisticsRepository; - - @InjectMocks - private PostStatisticsServiceImpl statisticsService; - - private PostStatisticsDTO postStatisticsDTO; - - @BeforeEach - void init() { - postStatisticsDTO = new PostStatisticsDTO(); - postStatisticsDTO.setPostId(1L); - postStatisticsDTO.setComments(23); - postStatisticsDTO.setLikes(213); - postStatisticsDTO.setViewed(2542); - } - - - @Test - void retrieve() { - Pageable pageable = PageRequest.of(0, 2); - Page page = new PageImpl<>(List.of(Mockito.mock(PostStatistics.class)), pageable, 2L); - given(this.postStatisticsRepository.findAll(PageRequest.of(0, 2))).willReturn(page); - - Page voPage = statisticsService.retrieve(0, 2); - Assertions.assertNotNull(voPage.getContent()); - } - - @Test - void create() { - given(this.postStatisticsRepository.saveAndFlush(Mockito.any(PostStatistics.class))).willReturn(Mockito.mock(PostStatistics.class)); - - PostStatisticsVO vo = statisticsService.create(postStatisticsDTO); - - verify(this.postStatisticsRepository, times(1)).saveAndFlush(Mockito.any(PostStatistics.class)); - Assertions.assertNotNull(vo); - } - - @Test - void create_zero() { - given(this.postStatisticsRepository.saveAndFlush(Mockito.any(PostStatistics.class))).willReturn(Mockito.mock(PostStatistics.class)); - - PostStatisticsVO vo = statisticsService.create(postStatisticsDTO); - Assertions.assertNotNull(vo); - } -} \ No newline at end of file diff --git a/assets/src/test/java/io/leafage/basic/assets/service/impl/PostServiceImplTest.java b/assets/src/test/java/io/leafage/basic/assets/service/impl/PostServiceImplTest.java index 2a9a1e7c..40f27131 100644 --- a/assets/src/test/java/io/leafage/basic/assets/service/impl/PostServiceImplTest.java +++ b/assets/src/test/java/io/leafage/basic/assets/service/impl/PostServiceImplTest.java @@ -24,7 +24,6 @@ import io.leafage.basic.assets.repository.CategoryRepository; import io.leafage.basic.assets.repository.PostContentRepository; import io.leafage.basic.assets.repository.PostRepository; -import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.vo.PostVO; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -41,7 +40,8 @@ import java.util.Set; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; /** * 帖子接口测试 @@ -60,9 +60,6 @@ class PostServiceImplTest { @Mock private CategoryRepository categoryRepository; - @Mock - private PostStatisticsRepository postStatisticsRepository; - @InjectMocks private PostsServiceImpl postsService; @@ -72,7 +69,7 @@ class PostServiceImplTest { void init() { postDTO = new PostDTO(); postDTO.setTitle("title"); - postDTO.setContent("content"); + postDTO.setContext("content"); postDTO.setCover("cover"); postDTO.setTags(Set.of("tag")); postDTO.setCategoryId(1L); @@ -82,7 +79,7 @@ void init() { void retrieve() { Pageable pageable = PageRequest.of(0, 2); Page postsPage = new PageImpl<>(List.of(Mockito.mock(Post.class)), pageable, 2L); - given(this.postRepository.findAll(PageRequest.of(0, 2, Sort.by("id")))).willReturn(postsPage); + given(postRepository.findAll(PageRequest.of(0, 2, Sort.by("id")))).willReturn(postsPage); Page voPage = postsService.retrieve(0, 2, "id"); @@ -91,7 +88,7 @@ void retrieve() { @Test void fetch() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); PostVO postVO = postsService.fetch(Mockito.anyLong()); @@ -100,7 +97,7 @@ void fetch() { @Test void fetch_posts_null() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.empty()); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.empty()); PostVO postVO = postsService.fetch(Mockito.anyLong()); @@ -109,7 +106,7 @@ void fetch_posts_null() { @Test void next() { - given(this.postRepository.getFirstByIdGreaterThanAndEnabledTrueOrderByIdAsc(Mockito.anyLong())).willReturn(Mockito.mock(Post.class)); + given(postRepository.getFirstByIdGreaterThanAndEnabledTrueOrderByIdAsc(Mockito.anyLong())).willReturn(Mockito.mock(Post.class)); PostVO postVO = postsService.next(Mockito.anyLong()); @@ -119,7 +116,7 @@ void next() { @Test void previous() { - given(this.postRepository.getFirstByIdLessThanAndEnabledTrueOrderByIdDesc(Mockito.anyLong())).willReturn(Mockito.mock(Post.class)); + given(postRepository.getFirstByIdLessThanAndEnabledTrueOrderByIdDesc(Mockito.anyLong())).willReturn(Mockito.mock(Post.class)); PostVO postVO = postsService.previous(Mockito.anyLong()); @@ -128,13 +125,11 @@ void previous() { @Test void details() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); - - given(this.categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.of(Mockito.mock(Category.class))); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); - doNothing().when(this.postStatisticsRepository).increaseViewed(Mockito.anyLong()); + given(categoryRepository.findById(Mockito.anyLong())).willReturn(Optional.of(Mockito.mock(Category.class))); - given(this.postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); + given(postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); PostVO postVO = postsService.details(Mockito.anyLong()); @@ -143,7 +138,7 @@ void details() { @Test void details_posts_null() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.empty()); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.empty()); PostVO postVO = postsService.details(Mockito.anyLong()); @@ -152,7 +147,7 @@ void details_posts_null() { @Test void exist() { - given(this.postRepository.existsByTitle(Mockito.anyString())).willReturn(true); + given(postRepository.existsByTitle(Mockito.anyString())).willReturn(true); boolean exist = postsService.exist("test"); @@ -161,42 +156,42 @@ void exist() { @Test void create() { - given(this.postRepository.saveAndFlush(Mockito.any(Post.class))).willReturn(Mockito.mock(Post.class)); + given(postRepository.saveAndFlush(Mockito.any(Post.class))).willReturn(Mockito.mock(Post.class)); - given(this.postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); + given(postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); - given(this.postContentRepository.saveAndFlush(Mockito.any(PostContent.class))).willReturn(Mockito.mock(PostContent.class)); + given(postContentRepository.saveAndFlush(Mockito.any(PostContent.class))).willReturn(Mockito.mock(PostContent.class)); PostVO postVO = postsService.create(postDTO); - verify(this.postRepository, times(1)).saveAndFlush(Mockito.any(Post.class)); - verify(this.postContentRepository, times(1)).saveAndFlush(Mockito.any(PostContent.class)); + verify(postRepository, times(1)).saveAndFlush(Mockito.any(Post.class)); + verify(postContentRepository, times(1)).saveAndFlush(Mockito.any(PostContent.class)); Assertions.assertNotNull(postVO); } @Test void modify() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); - given(this.postRepository.save(Mockito.any(Post.class))).willReturn(Mockito.mock(Post.class)); + given(postRepository.save(Mockito.any(Post.class))).willReturn(Mockito.mock(Post.class)); - given(this.postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); + given(postContentRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostContent.class)); - given(this.postContentRepository.save(Mockito.any(PostContent.class))).willReturn(Mockito.mock(PostContent.class)); + given(postContentRepository.save(Mockito.any(PostContent.class))).willReturn(Mockito.mock(PostContent.class)); PostVO postVO = postsService.modify(1L, postDTO); - verify(this.postRepository, times(1)).save(Mockito.any(Post.class)); - verify(this.postContentRepository, times(1)).save(Mockito.any(PostContent.class)); + verify(postRepository, times(1)).save(Mockito.any(Post.class)); + verify(postContentRepository, times(1)).save(Mockito.any(PostContent.class)); Assertions.assertNotNull(postVO); } @Test void modify_error() { - given(this.postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); + given(postRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Post.class))); - given(this.postRepository.save(Mockito.any(Post.class))).willThrow(new RuntimeException()); + given(postRepository.save(Mockito.any(Post.class))).willThrow(new RuntimeException()); Assertions.assertThrows(RuntimeException.class, () -> postsService.modify(1L, postDTO)); } @@ -205,7 +200,7 @@ void modify_error() { void remove() { postsService.remove(Mockito.anyLong()); - verify(this.postRepository, times(1)).deleteById(Mockito.anyLong()); + verify(postRepository, times(1)).deleteById(Mockito.anyLong()); } } diff --git a/assets/src/test/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImplTest.java b/assets/src/test/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImplTest.java new file mode 100644 index 00000000..579fd01e --- /dev/null +++ b/assets/src/test/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImplTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.assets.service.impl; + +import io.leafage.basic.assets.constants.StatisticsEnum; +import io.leafage.basic.assets.domain.PostStatistics; +import io.leafage.basic.assets.repository.PostStatisticsRepository; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * statistics 接口测试 + * + * @author wq li 2021/12/7 17:55 + **/ +@ExtendWith(MockitoExtension.class) +class PostStatisticsServiceImplTest { + + @Mock + private PostStatisticsRepository postStatisticsRepository; + + @InjectMocks + private PostStatisticsServiceImpl postStatisticsService; + + + @Test + void increase() { + given(postStatisticsRepository.getByPostId(Mockito.anyLong())).willReturn(Mockito.mock(PostStatistics.class)); + + given(postStatisticsRepository.save(Mockito.any(PostStatistics.class))).willReturn(Mockito.mock(PostStatistics.class)); + + PostStatistics postStatistics = postStatisticsService.increase(Mockito.anyLong(), StatisticsEnum.COMMENTS); + + verify(postStatisticsRepository, times(1)).save(Mockito.any(PostStatistics.class)); + Assertions.assertNotNull(postStatistics); + } + +} \ No newline at end of file diff --git a/hypervisor/pom.xml b/hypervisor/pom.xml index a083c8df..675c7460 100644 --- a/hypervisor/pom.xml +++ b/hypervisor/pom.xml @@ -50,10 +50,10 @@ org.springframework.cloud spring-cloud-starter-consul-discovery - - org.springframework.boot - spring-boot-starter-oauth2-resource-server - + + + + org.postgresql postgresql diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/AccessLogBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/AccessLogBO.java new file mode 100644 index 00000000..ee274b4a --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/AccessLogBO.java @@ -0,0 +1,182 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +/** + * bo class for access log + * + * @author liwenqiang 2022-03-18 21:09 + */ +public abstract class AccessLogBO { + + /** + * IP地址 + */ + private String ip; + + /** + * 地理位置 + */ + private String location; + + /** + * 用户代理信息 + */ + private String userAgent; + + /** + * HTTP方法 + */ + private String httpMethod; + + /** + * 请求URL + */ + private String url; + + /** + * HTTP状态码 + */ + private Integer statusCode; + + /** + * 响应时间 + */ + private Long responseTime; + + /** + * 来源页面 + */ + private String referer; + + /** + * 会话标识符 + */ + private String sessionId; + + /** + * 设备类型 + */ + private String deviceType; + + /** + * 操作系统 + */ + private String os; + + /** + * 浏览器 + */ + private String browser; + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public String getHttpMethod() { + return httpMethod; + } + + public void setHttpMethod(String httpMethod) { + this.httpMethod = httpMethod; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Integer getStatusCode() { + return statusCode; + } + + public void setStatusCode(Integer statusCode) { + this.statusCode = statusCode; + } + + public Long getResponseTime() { + return responseTime; + } + + public void setResponseTime(Long responseTime) { + this.responseTime = responseTime; + } + + public String getReferer() { + return referer; + } + + public void setReferer(String referer) { + this.referer = referer; + } + + public String getSessionId() { + return sessionId; + } + + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getOs() { + return os; + } + + public void setOs(String os) { + this.os = os; + } + + public String getBrowser() { + return browser; + } + + public void setBrowser(String browser) { + this.browser = browser; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/DictionaryBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/DictionaryBO.java new file mode 100644 index 00000000..1c83a17f --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/DictionaryBO.java @@ -0,0 +1,56 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +/** + * bo class for dictionary + * + * @author wilsonli 2022-03-26 12:21 + **/ +public abstract class DictionaryBO { + + /** + * 名称 + */ + @NotBlank(message = "dictionary name must not be blank.") + private String name; + + /** + * 描述 + */ + private String description; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/GroupBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/GroupBO.java new file mode 100644 index 00000000..d9b074ce --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/GroupBO.java @@ -0,0 +1,68 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +/** + * bo class for group + * + * @author wilsonli 2022-03-26 15:21 + **/ +public abstract class GroupBO { + + /** + * 名称 + */ + @NotBlank(message = "group name must not be blank.") + private String name; + + /** + * 负责人 + */ + private String principal; + + /** + * 描述 + */ + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrincipal() { + return principal; + } + + public void setPrincipal(String principal) { + this.principal = principal; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} \ No newline at end of file diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/MessageBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/MessageBO.java new file mode 100644 index 00000000..33527609 --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/MessageBO.java @@ -0,0 +1,71 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +/** + * dto class for Notification + * + * @author liwenqiang 2022-12-10 13:49 + */ +public abstract class MessageBO { + + /** + * 标题 + */ + @NotBlank(message = "title must not be blank.") + private String title; + + /** + * 内容 + */ + @NotBlank(message = "context must not be blank.") + private String context; + + /** + * 接收人 + */ + @NotBlank(message = "receiver must not be blank.") + private String receiver; + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } + + public String getReceiver() { + return receiver; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/PrivilegeBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/PrivilegeBO.java new file mode 100644 index 00000000..6df77441 --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/PrivilegeBO.java @@ -0,0 +1,100 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; + +/** + * bo class for privilege + * + * @author liwenqiang 2022-12-10 22:09 + */ +public abstract class PrivilegeBO { + + /** + * 名称 + */ + @NotBlank(message = "privilege name must not be blank.") + @Size(max = 32, message = "privilege name max length is 32.") + private String name; + + /** + * 类型 + */ + @NotNull(message = "type must not be null.") + private Character type; + + /** + * 图标 + */ + @NotBlank(message = "icon must not be blank.") + private String icon; + + /** + * 路径 + */ + private String path; + + /** + * 描述 + */ + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Character getType() { + return type; + } + + public void setType(Character type) { + this.type = type; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} \ No newline at end of file diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RegionBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RegionBO.java new file mode 100644 index 00000000..f2c52519 --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RegionBO.java @@ -0,0 +1,82 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +/** + * desc + * + * @author wilsonli 2022-03-26 18:16 + **/ +public abstract class RegionBO { + + /** + * 名称 + */ + @NotBlank(message = "region name must not be blank.") + private String name; + + /** + * 邮编 + */ + private Integer postalCode; + + /** + * 区号 + */ + private String areaCode; + + /** + * 描述 + */ + private String description; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getPostalCode() { + return postalCode; + } + + public void setPostalCode(Integer postalCode) { + this.postalCode = postalCode; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RoleBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RoleBO.java new file mode 100644 index 00000000..41e37f95 --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/RoleBO.java @@ -0,0 +1,55 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +/** + * bo class for role + * + * @author wilsonli 2022-03-26 15:21 + **/ +public abstract class RoleBO { + + /** + * 名称 + */ + @NotBlank(message = "role name must not be blank.") + private String name; + + /** + * 描述 + */ + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/UserBO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/UserBO.java new file mode 100644 index 00000000..efc1559b --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/bo/UserBO.java @@ -0,0 +1,110 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.bo; + +import jakarta.validation.constraints.NotBlank; + +import java.time.Instant; + +/** + * bo class for User + * + * @author liwenqiang 2022-12-10 22:27 + */ +public abstract class UserBO { + + /** + * 用户名 + */ + @NotBlank(message = "username is blank.") + private String username; + + /** + * 名 + */ + private String firstname; + + /** + * 姓 + */ + private String lastname; + + /** + * 头像 + */ + private String avatar; + + /** + * 账号有效期 + */ + private Instant accountExpiresAt; + + /** + * 密码有效期 + */ + private Instant credentialsExpiresAt; + + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public Instant getAccountExpiresAt() { + return accountExpiresAt; + } + + public void setAccountExpiresAt(Instant accountExpiresAt) { + this.accountExpiresAt = accountExpiresAt; + } + + public Instant getCredentialsExpiresAt() { + return credentialsExpiresAt; + } + + public void setCredentialsExpiresAt(Instant credentialsExpiresAt) { + this.credentialsExpiresAt = credentialsExpiresAt; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java index e8511bf1..9347d67b 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java @@ -17,24 +17,21 @@ package io.leafage.basic.hypervisor.config; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.web.SecurityFilterChain; +//import org.springframework.security.config.Customizer; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.web.SecurityFilterChain; -@Configuration -@EnableWebSecurity +//@Configuration +//@EnableWebSecurity public class AuthorizationServerConfiguration { - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.authorizeHttpRequests((authorize) -> authorize - .requestMatchers(HttpMethod.GET).permitAll() - .anyRequest().authenticated()) - .oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults())); - return http.build(); - } +// @Bean +// public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { +// http.authorizeHttpRequests((authorize) -> authorize +// .requestMatchers(HttpMethod.GET).permitAll() +// .anyRequest().authenticated()) +// .oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults())); +// return http.build(); +// } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/AccessLogDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/AccessLogDTO.java index 344c7b47..1ad4b52c 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/AccessLogDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/AccessLogDTO.java @@ -17,169 +17,13 @@ package io.leafage.basic.hypervisor.dto; -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.AccessLogBO; /** * dto class for access log. * * @author liwenqinag 2022/4/15 13:39 **/ -public class AccessLogDTO implements Serializable { +public class AccessLogDTO extends AccessLogBO { - /** - * IP地址 - */ - private String ip; - - /** - * 地理位置 - */ - private String location; - - /** - * 用户代理信息 - */ - private String userAgent; - - /** - * HTTP方法 - */ - private String httpMethod; - - /** - * 请求URL - */ - private String url; - - /** - * HTTP状态码 - */ - private Integer statusCode; - - /** - * 响应时间 - */ - private Long responseTime; - - /** - * 来源页面 - */ - private String referer; - - /** - * 会话标识符 - */ - private String sessionId; - - /** - * 设备类型 - */ - private String deviceType; - - /** - * 操作系统 - */ - private String os; - - /** - * 浏览器 - */ - private String browser; - - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } - - public String getHttpMethod() { - return httpMethod; - } - - public void setHttpMethod(String httpMethod) { - this.httpMethod = httpMethod; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Integer getStatusCode() { - return statusCode; - } - - public void setStatusCode(Integer statusCode) { - this.statusCode = statusCode; - } - - public Long getResponseTime() { - return responseTime; - } - - public void setResponseTime(Long responseTime) { - this.responseTime = responseTime; - } - - public String getReferer() { - return referer; - } - - public void setReferer(String referer) { - this.referer = referer; - } - - public String getSessionId() { - return sessionId; - } - - public void setSessionId(String sessionId) { - this.sessionId = sessionId; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getOs() { - return os; - } - - public void setOs(String os) { - this.os = os; - } - - public String getBrowser() { - return browser; - } - - public void setBrowser(String browser) { - this.browser = browser; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/DictionaryDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/DictionaryDTO.java index 42c73324..b998ba4b 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/DictionaryDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/DictionaryDTO.java @@ -17,52 +17,19 @@ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; - -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.DictionaryBO; /** * dto class for dictionary. * * @author wq li 2022-04-06 17:33 */ -public class DictionaryDTO implements Serializable { +public class DictionaryDTO extends DictionaryBO { /** - * 名称 - */ - @NotBlank - private String name; - /** - * 简称 - */ - @NotBlank - private String alias; - /** - * 上级 + * superior */ private Long superiorId; - /** - * 描述 - */ - private String description; - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAlias() { - return alias; - } - - public void setAlias(String alias) { - this.alias = alias; - } public Long getSuperiorId() { return superiorId; @@ -71,12 +38,4 @@ public Long getSuperiorId() { public void setSuperiorId(Long superiorId) { this.superiorId = superiorId; } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/GroupDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/GroupDTO.java index 0a106e49..721d8fe0 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/GroupDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/GroupDTO.java @@ -16,49 +16,20 @@ */ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; - -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.GroupBO; /** * dto class for group. * * @author wq li 2019/8/31 15:50 */ -public class GroupDTO implements Serializable { - - /** - * 名称 - */ - @NotBlank - @Size(max = 16) - private String name; +public class GroupDTO extends GroupBO { /** - * 负责人 - */ - private String principal; - - /** - * 上级 + * superior */ private Long superiorId; - /** - * 描述 - */ - @Size(max = 64) - private String description; - - public String getPrincipal() { - return principal; - } - - public void setPrincipal(String principal) { - this.principal = principal; - } - public Long getSuperiorId() { return superiorId; } @@ -66,20 +37,4 @@ public Long getSuperiorId() { public void setSuperiorId(Long superiorId) { this.superiorId = superiorId; } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/MessageDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/MessageDTO.java index 6a66cb9a..be4c41c5 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/MessageDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/MessageDTO.java @@ -17,53 +17,13 @@ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; - -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.MessageBO; /** * dto class for message. * * @author wq li 2022/1/29 17:20 **/ -public class MessageDTO implements Serializable { - - /** - * 内容 - */ - @NotBlank - private String title; - /** - * 内容 - */ - @NotBlank - private String content; - /** - * 接收人 - */ - private String receiver; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getReceiver() { - return receiver; - } +public class MessageDTO extends MessageBO { - public void setReceiver(String receiver) { - this.receiver = receiver; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/PrivilegeDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/PrivilegeDTO.java index f4ac1f00..82f37ba6 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/PrivilegeDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/PrivilegeDTO.java @@ -16,46 +16,19 @@ */ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +import io.leafage.basic.hypervisor.bo.PrivilegeBO; /** * dto class for privilege. * * @author wq li 2019/8/31 15:50 */ -public class PrivilegeDTO { +public class PrivilegeDTO extends PrivilegeBO { /** * 上级 */ private Long superiorId; - /** - * 名称 - */ - @NotBlank - @Size(max = 16) - private String name; - /** - * 类型 - */ - @NotNull - private Character type; - /** - * 图标 - */ - private String icon; - /** - * 路径 - */ - @NotBlank - private String path; - /** - * 描述 - */ - private String description; - public Long getSuperiorId() { return superiorId; @@ -65,43 +38,4 @@ public void setSuperiorId(Long superiorId) { this.superiorId = superiorId; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Character getType() { - return type; - } - - public void setType(Character type) { - this.type = type; - } - - public String getIcon() { - return icon; - } - - public void setIcon(String icon) { - this.icon = icon; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RegionDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RegionDTO.java index 297f02d5..3e5e5bb5 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RegionDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RegionDTO.java @@ -17,47 +17,19 @@ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; - -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.RegionBO; /** * dto class for region. * * @author wq li 2021-10-12 10:06 */ -public class RegionDTO implements Serializable { +public class RegionDTO extends RegionBO { /** - * 名称 - */ - @NotBlank - private String name; - /** - * 上级 + * superior */ private Long superiorId; - /** - * 邮编 - */ - private Integer postalCode; - /** - * 区号 - */ - private String areaCode; - /** - * 描述 - */ - private String description; - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } public Long getSuperiorId() { return superiorId; @@ -66,28 +38,4 @@ public Long getSuperiorId() { public void setSuperiorId(Long superiorId) { this.superiorId = superiorId; } - - public Integer getPostalCode() { - return postalCode; - } - - public void setPostalCode(Integer postalCode) { - this.postalCode = postalCode; - } - - public String getAreaCode() { - return areaCode; - } - - public void setAreaCode(String areaCode) { - this.areaCode = areaCode; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RoleDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RoleDTO.java index d199c5a4..ca66b7cd 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RoleDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/RoleDTO.java @@ -16,47 +16,19 @@ */ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; - -import java.io.Serializable; -import java.util.Set; +import io.leafage.basic.hypervisor.bo.RoleBO; /** * dto class for role. * * @author wq li 2019/8/31 15:50 */ -public class RoleDTO implements Serializable { +public class RoleDTO extends RoleBO { /** - * 名称 - */ - @NotBlank - @Size(max = 16) - private String name; - /** - * 上级 + * superior */ private Long superiorId; - /** - * 描述 - */ - @Size(max = 32) - private String description; - /** - * 资源列表 - */ - private Set privileges; - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } public Long getSuperiorId() { return superiorId; @@ -66,20 +38,4 @@ public void setSuperiorId(Long superiorId) { this.superiorId = superiorId; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Set getAuthorities() { - return privileges; - } - - public void setAuthorities(Set privileges) { - this.privileges = privileges; - } - } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/UserDTO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/UserDTO.java index 0876bea6..dd3dc6ad 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/UserDTO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/dto/UserDTO.java @@ -16,67 +16,13 @@ */ package io.leafage.basic.hypervisor.dto; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; - -import java.io.Serializable; +import io.leafage.basic.hypervisor.bo.UserBO; /** * dto class for user. * * @author wq li 2019/8/31 15:50 **/ -public class UserDTO implements Serializable { - - /** - * user - */ - @NotBlank - @Size(min = 4, max = 16) - private String username; - /** - * 姓 - */ - private String firstname; - /** - * 名 - */ - private String lastname; - /** - * 描述 - */ - private String description; - - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } - - public String getLastname() { - return lastname; - } - - public void setLastname(String lastname) { - this.lastname = lastname; - } - - public String getDescription() { - return description; - } +public class UserDTO extends UserBO { - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java index e616b6bc..e0b4e044 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java @@ -18,7 +18,6 @@ import io.leafage.basic.hypervisor.domain.Group; import io.leafage.basic.hypervisor.dto.GroupDTO; -import io.leafage.basic.hypervisor.repository.GroupMembersRepository; import io.leafage.basic.hypervisor.repository.GroupRepository; import io.leafage.basic.hypervisor.service.GroupService; import io.leafage.basic.hypervisor.vo.GroupVO; @@ -47,11 +46,9 @@ public class GroupServiceImpl extends ServletAbstractTreeNodeService implements GroupService { private final GroupRepository groupRepository; - private final GroupMembersRepository groupMembersRepository; - public GroupServiceImpl(GroupRepository groupRepository, GroupMembersRepository groupMembersRepository) { + public GroupServiceImpl(GroupRepository groupRepository) { this.groupRepository = groupRepository; - this.groupMembersRepository = groupMembersRepository; } @Override @@ -114,8 +111,6 @@ private GroupVO convertOuter(Group group) { BeanCopier copier = BeanCopier.create(Group.class, GroupVO.class, false); copier.copy(group, vo, null); - long count = groupMembersRepository.countByGroupIdAndEnabledTrue(group.getId()); - vo.setCount(count); return vo; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java index cb9c4f07..ad9ea6f1 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java @@ -18,7 +18,6 @@ import io.leafage.basic.hypervisor.domain.Role; import io.leafage.basic.hypervisor.dto.RoleDTO; -import io.leafage.basic.hypervisor.repository.RoleMembersRepository; import io.leafage.basic.hypervisor.repository.RoleRepository; import io.leafage.basic.hypervisor.service.RoleService; import io.leafage.basic.hypervisor.vo.RoleVO; @@ -47,11 +46,9 @@ public class RoleServiceImpl extends ServletAbstractTreeNodeService implements RoleService { private final RoleRepository roleRepository; - private final RoleMembersRepository roleMembersRepository; - public RoleServiceImpl(RoleRepository roleRepository, RoleMembersRepository roleMembersRepository) { + public RoleServiceImpl(RoleRepository roleRepository) { this.roleRepository = roleRepository; - this.roleMembersRepository = roleMembersRepository; } @Override @@ -125,8 +122,6 @@ private RoleVO convertOuter(Role role) { BeanCopier copier = BeanCopier.create(Role.class, RoleVO.class, false); copier.copy(role, vo, null); - long count = roleMembersRepository.countByRoleIdAndEnabledTrue(role.getId()); - vo.setCount(count); return vo; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/AccessLogVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/AccessLogVO.java index b956f211..cdb28a7f 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/AccessLogVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/AccessLogVO.java @@ -17,167 +17,41 @@ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.AccessLogBO; + +import java.time.Instant; + /** * vo class for access log. * * @author liwenqinag 2022/4/15 13:39 **/ -public class AccessLogVO { - - /** - * IP地址 - */ - private String ip; - - /** - * 地理位置 - */ - private String location; - - /** - * 用户代理信息 - */ - private String userAgent; - - /** - * HTTP方法 - */ - private String httpMethod; - - /** - * 请求URL - */ - private String url; - - /** - * HTTP状态码 - */ - private Integer statusCode; - - /** - * 响应时间 - */ - private Long responseTime; - - /** - * 来源页面 - */ - private String referer; - - /** - * 会话标识符 - */ - private String sessionId; - - /** - * 设备类型 - */ - private String deviceType; +public class AccessLogVO extends AccessLogBO { /** - * 操作系统 + * 主键 */ - private String os; + private Long id; /** - * 浏览器 + * 最后更新时间 */ - private String browser; - - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } - - public String getHttpMethod() { - return httpMethod; - } - - public void setHttpMethod(String httpMethod) { - this.httpMethod = httpMethod; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Integer getStatusCode() { - return statusCode; - } - - public void setStatusCode(Integer statusCode) { - this.statusCode = statusCode; - } - - public Long getResponseTime() { - return responseTime; - } - - public void setResponseTime(Long responseTime) { - this.responseTime = responseTime; - } - - public String getReferer() { - return referer; - } + private Instant lastModifiedDate; - public void setReferer(String referer) { - this.referer = referer; - } - - public String getSessionId() { - return sessionId; - } - - public void setSessionId(String sessionId) { - this.sessionId = sessionId; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - public String getOs() { - return os; + public Long getId() { + return id; } - public void setOs(String os) { - this.os = os; + public void setId(Long id) { + this.id = id; } - public String getBrowser() { - return browser; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setBrowser(String browser) { - this.browser = browser; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/DictionaryVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/DictionaryVO.java index e2d671b0..3c952ad6 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/DictionaryVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/DictionaryVO.java @@ -17,49 +17,39 @@ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.DictionaryBO; + +import java.time.Instant; + /** * vo class for dictionary. * * @author wq li 2022-04-06 17:33 */ -public class DictionaryVO { +public class DictionaryVO extends DictionaryBO { /** - * 名称 - */ - private String name; - /** - * 简称 + * 主键 */ - private String alias; + private Long id; + /** * 上级 */ private String superior; + /** - * 描述 - */ - private String description; - /** - * 是否可用 + * 最后更新时间 */ - private boolean enabled; + private Instant lastModifiedDate; - public String getName() { - return name; + public Long getId() { + return id; } - public void setName(String name) { - this.name = name; - } - - public String getAlias() { - return alias; - } - - public void setAlias(String alias) { - this.alias = alias; + public void setId(Long id) { + this.id = id; } public String getSuperior() { @@ -70,19 +60,11 @@ public void setSuperior(String superior) { this.superior = superior; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isEnabled() { - return enabled; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setEnabled(boolean enabled) { - this.enabled = enabled; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/GroupVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/GroupVO.java index 75a87556..a9cc98ad 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/GroupVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/GroupVO.java @@ -16,64 +16,39 @@ */ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.GroupBO; + +import java.time.Instant; + /** * vo class for group. * * @author wq li 2019/8/31 15:50 */ -public class GroupVO { +public class GroupVO extends GroupBO { /** - * 名称 - */ - private String name; - /** - * 别民 + * 主键 */ - private String alias; - /** - * 负责人 - */ - private String principal; + private Long id; + /** * 上级 */ private String superior; + /** - * 描述 - */ - private String description; - /** - * 是否可用 - */ - private boolean enabled; - /** - * 用户数 + * 最后更新时间 */ - private long count; + private Instant lastModifiedDate; - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; + public Long getId() { + return id; } - public String getAlias() { - return alias; - } - - public void setAlias(String alias) { - this.alias = alias; - } - - public String getPrincipal() { - return principal; - } - - public void setPrincipal(String principal) { - this.principal = principal; + public void setId(Long id) { + this.id = id; } public String getSuperior() { @@ -84,27 +59,11 @@ public void setSuperior(String superior) { this.superior = superior; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public long getCount() { - return count; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setCount(long count) { - this.count = count; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/MessageVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/MessageVO.java index fddc715b..0f567f9c 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/MessageVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/MessageVO.java @@ -17,47 +17,41 @@ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.MessageBO; + +import java.time.Instant; + /** * vo class for message. * * @author wq li 2022/1/29 17:20 **/ -public class MessageVO { +public class MessageVO extends MessageBO { /** - * 标题 - */ - private String title; - /** - * 内容 + * 主键 */ - private String content; + private Long id; + /** - * 接收人 + * 最后更新时间 */ - private String receiver; - - public String getTitle() { - return title; - } + private Instant lastModifiedDate; - public void setTitle(String title) { - this.title = title; - } - public String getContent() { - return content; + public Long getId() { + return id; } - public void setContent(String content) { - this.content = content; + public void setId(Long id) { + this.id = id; } - public String getReceiver() { - return receiver; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setReceiver(String receiver) { - this.receiver = receiver; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/PrivilegeVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/PrivilegeVO.java index e86024a9..0363c21b 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/PrivilegeVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/PrivilegeVO.java @@ -16,108 +16,41 @@ */ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.PrivilegeBO; + +import java.time.Instant; + /** * vo class for privilege. * * @author wq li 2019/8/31 15:50 */ -public class PrivilegeVO { +public class PrivilegeVO extends PrivilegeBO { /** - * 上级 - */ - private String superior; - /** - * 名称 - */ - private String name; - /** - * 类型 - */ - private Character type; - /** - * 图标 - */ - private String icon; - /** - * 路径 + * 主键 */ - private String path; - /** - * role数 - */ - private long count; - /** - * 描述 - */ - private String description; + private Long id; + /** - * 是否可用 + * 最后更新时间 */ - private boolean enabled; - - - public String getSuperior() { - return superior; - } - - public void setSuperior(String superior) { - this.superior = superior; - } + private Instant lastModifiedDate; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Character getType() { - return type; - } - - public void setType(Character type) { - this.type = type; - } - - public long getCount() { - return count; - } - - public void setCount(long count) { - this.count = count; - } - - public String getIcon() { - return icon; - } - - public void setIcon(String icon) { - this.icon = icon; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - public String getDescription() { - return description; + public Long getId() { + return id; } - public void setDescription(String description) { - this.description = description; + public void setId(Long id) { + this.id = id; } - public boolean isEnabled() { - return enabled; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setEnabled(boolean enabled) { - this.enabled = enabled; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RegionVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RegionVO.java index b7000373..1bd285e1 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RegionVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RegionVO.java @@ -17,53 +17,39 @@ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.RegionBO; + +import java.time.Instant; + /** * vo class for region. * * @author wq li 2021/9/19 17:20 **/ -public class RegionVO { +public class RegionVO extends RegionBO { /** - * 名称 - */ - private String name; - /** - * 简称 + * 主键 */ - private String alias; + private Long id; + /** * 上级 */ private String superior; + /** - * 邮编 - */ - private Integer postalCode; - /** - * 区号 - */ - private String areaCode; - /** - * 描述 + * 最后更新时间 */ - private String description; - + private Instant lastModifiedDate; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getAlias() { - return alias; + public Long getId() { + return id; } - public void setAlias(String alias) { - this.alias = alias; + public void setId(Long id) { + this.id = id; } public String getSuperior() { @@ -74,27 +60,11 @@ public void setSuperior(String superior) { this.superior = superior; } - public Integer getPostalCode() { - return postalCode; - } - - public void setPostalCode(Integer postalCode) { - this.postalCode = postalCode; - } - - public String getAreaCode() { - return areaCode; - } - - public void setAreaCode(String areaCode) { - this.areaCode = areaCode; - } - - public String getDescription() { - return description; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setDescription(String description) { - this.description = description; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RoleVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RoleVO.java index e9262825..4be86b18 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RoleVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/RoleVO.java @@ -16,64 +16,39 @@ */ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.RoleBO; + +import java.time.Instant; + /** * vo class for role. * * @author wq li 2019/8/31 15:50 */ -public class RoleVO { +public class RoleVO extends RoleBO { /** - * 名称 - */ - private String name; - /** - * 上级 + * 主键 */ - private String superior; - /** - * 描述 - */ - private String description; - /** - * user数 - */ - private long count; + private Long id; + /** - * 是否可用 + * 状态 */ private boolean enabled; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getSuperior() { - return superior; - } - - public void setSuperior(String superior) { - this.superior = superior; - } - - public String getDescription() { - return description; - } + /** + * 最后更新时间 + */ + private Instant lastModifiedDate; - public void setDescription(String description) { - this.description = description; - } - public long getCount() { - return count; + public Long getId() { + return id; } - public void setCount(long count) { - this.count = count; + public void setId(Long id) { + this.id = id; } public boolean isEnabled() { @@ -83,4 +58,12 @@ public boolean isEnabled() { public void setEnabled(boolean enabled) { this.enabled = enabled; } + + public Instant getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/UserVO.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/UserVO.java index b6a33462..346037b3 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/UserVO.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/vo/UserVO.java @@ -17,62 +17,41 @@ package io.leafage.basic.hypervisor.vo; +import io.leafage.basic.hypervisor.bo.UserBO; + +import java.time.Instant; + /** * vo class for user. * * @author wq li 2019/8/31 15:50 **/ -public class UserVO { +public class UserVO extends UserBO { /** - * user - */ - private String username; - /** - * 姓 + * 是否锁定 */ - private String firstname; - /** - * 名 - */ - private String lastname; + private boolean accountNonLocked; /** - * 描述 + * 最后更新时间 */ - private String description; - - + private Instant lastModifiedDate; - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } - public String getLastname() { - return lastname; + public boolean isAccountNonLocked() { + return accountNonLocked; } - public void setLastname(String lastname) { - this.lastname = lastname; + public void setAccountNonLocked(boolean accountNonLocked) { + this.accountNonLocked = accountNonLocked; } - public String getDescription() { - return description; + public Instant getLastModifiedDate() { + return lastModifiedDate; } - public void setDescription(String description) { - this.description = description; + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; } } diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/DictionaryControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/DictionaryControllerTest.java index 52ef0527..026ff3e4 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/DictionaryControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/DictionaryControllerTest.java @@ -75,13 +75,11 @@ class DictionaryControllerTest { void init() { dictionaryVO = new DictionaryVO(); dictionaryVO.setName("gender"); - dictionaryVO.setAlias("gender"); dictionaryVO.setSuperior("superior"); dictionaryVO.setDescription("description"); dictionaryDTO = new DictionaryDTO(); dictionaryDTO.setName("gender"); - dictionaryDTO.setAlias("gender"); dictionaryDTO.setSuperiorId(1L); dictionaryDTO.setDescription("description"); } diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/GroupControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/GroupControllerTest.java index b54b4381..20606be2 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/GroupControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/GroupControllerTest.java @@ -80,10 +80,8 @@ class GroupControllerTest { void init() { groupVO = new GroupVO(); groupVO.setName("test"); - groupVO.setAlias("alias"); groupVO.setPrincipal("test"); groupVO.setSuperior("superior"); - groupVO.setCount(2L); groupDTO = new GroupDTO(); groupDTO.setName("test"); @@ -94,7 +92,7 @@ void init() { @Test void retrieve() throws Exception { - Pageable pageable = PageRequest.of(0,2); + Pageable pageable = PageRequest.of(0, 2); Page voPage = new PageImpl<>(List.of(groupVO), pageable, 2L); given(this.groupService.retrieve(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString())).willReturn(voPage); diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/MessageControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/MessageControllerTest.java index 0e6ab8e7..538a3d0e 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/MessageControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/MessageControllerTest.java @@ -75,12 +75,12 @@ void init() { messageVO = new MessageVO(); messageVO.setTitle("test"); messageVO.setReceiver("23234"); - messageVO.setContent("content"); + messageVO.setContext("content"); messageDTO = new MessageDTO(); messageDTO.setTitle("test"); messageDTO.setReceiver("23234"); - messageDTO.setContent("content"); + messageDTO.setContext("content"); } @Test @@ -107,7 +107,7 @@ void fetch() throws Exception { given(this.messageService.fetch(Mockito.anyLong())).willReturn(messageVO); mvc.perform(get("/messages/{id}", Mockito.anyLong())).andExpect(status().isOk()) - .andExpect(jsonPath("$.content").value("content")).andDo(print()).andReturn(); + .andExpect(jsonPath("$.context").value("content")).andDo(print()).andReturn(); } @Test diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/PrivilegeControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/PrivilegeControllerTest.java index 331359f8..d13ca222 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/PrivilegeControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/PrivilegeControllerTest.java @@ -83,7 +83,6 @@ void init() { privilegeVO.setIcon("icon"); privilegeVO.setPath("path"); privilegeVO.setType('M'); - privilegeVO.setSuperior("superior"); privilegeDTO = new PrivilegeDTO(); privilegeDTO.setName("test"); diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RegionControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RegionControllerTest.java index dd8e9db5..62cab989 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RegionControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RegionControllerTest.java @@ -74,7 +74,6 @@ class RegionControllerTest { void init() { regionVO = new RegionVO(); regionVO.setName("test"); - regionVO.setAlias("alias"); regionVO.setAreaCode("23234"); regionVO.setPostalCode(1212); regionVO.setSuperior("superior"); diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RoleControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RoleControllerTest.java index 5e1bdc65..8e74e8d1 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RoleControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/RoleControllerTest.java @@ -86,13 +86,11 @@ class RoleControllerTest { void init() { roleVO = new RoleVO(); roleVO.setName("test"); - roleVO.setSuperior("superior"); roleVO.setDescription("description"); roleDTO = new RoleDTO(); roleDTO.setName("test"); roleDTO.setSuperiorId(1L); - roleDTO.setAuthorities(Set.of("test")); roleDTO.setDescription("description"); } diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/UserControllerTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/UserControllerTest.java index d935fbeb..878b10e5 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/UserControllerTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/controller/UserControllerTest.java @@ -69,13 +69,11 @@ void init() { userVO.setUsername("test"); userVO.setFirstname("john"); userVO.setLastname("steven"); - userVO.setDescription("description"); userDTO = new UserDTO(); userDTO.setUsername("test"); userDTO.setFirstname("john"); userDTO.setLastname("steven"); - userDTO.setDescription("description"); } @Test diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImplTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImplTest.java index 8e7bf48a..c35cdbd5 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImplTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImplTest.java @@ -19,7 +19,6 @@ import io.leafage.basic.hypervisor.domain.Group; import io.leafage.basic.hypervisor.dto.GroupDTO; -import io.leafage.basic.hypervisor.repository.GroupMembersRepository; import io.leafage.basic.hypervisor.repository.GroupRepository; import io.leafage.basic.hypervisor.vo.GroupVO; import org.junit.jupiter.api.Assertions; @@ -52,9 +51,6 @@ @ExtendWith(MockitoExtension.class) class GroupServiceImplTest { - @Mock - private GroupMembersRepository groupMembersRepository; - @Mock private GroupRepository groupRepository; @@ -79,8 +75,6 @@ void retrieve() { given(this.groupRepository.findAll(PageRequest.of(0, 2, Sort.by("id")))) .willReturn(page); - given(this.groupMembersRepository.countByGroupIdAndEnabledTrue(Mockito.anyLong())).willReturn(Mockito.anyLong()); - Page voPage = groupService.retrieve(0, 2, "id"); Assertions.assertNotNull(voPage.getContent()); } @@ -89,8 +83,6 @@ void retrieve() { void create() { given(this.groupRepository.saveAndFlush(Mockito.any(Group.class))).willReturn(Mockito.mock(Group.class)); - given(this.groupMembersRepository.countByGroupIdAndEnabledTrue(Mockito.anyLong())).willReturn(2L); - GroupVO groupVO = groupService.create(Mockito.mock(GroupDTO.class)); verify(this.groupRepository, times(1)).saveAndFlush(Mockito.any(Group.class)); @@ -110,8 +102,6 @@ void modify() { given(this.groupRepository.save(Mockito.any(Group.class))).willReturn(Mockito.mock(Group.class)); - given(this.groupMembersRepository.countByGroupIdAndEnabledTrue(Mockito.anyLong())).willReturn(Mockito.anyLong()); - GroupVO groupVO = groupService.modify(1L, groupDTO); verify(this.groupRepository, times(1)).save(Mockito.any(Group.class)); diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImplTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImplTest.java index fc487772..392b9f4f 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImplTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImplTest.java @@ -19,7 +19,6 @@ import io.leafage.basic.hypervisor.domain.Role; import io.leafage.basic.hypervisor.dto.RoleDTO; -import io.leafage.basic.hypervisor.repository.RoleMembersRepository; import io.leafage.basic.hypervisor.repository.RoleRepository; import io.leafage.basic.hypervisor.vo.RoleVO; import org.junit.jupiter.api.Assertions; @@ -39,7 +38,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.Set; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.times; @@ -53,9 +51,6 @@ @ExtendWith(MockitoExtension.class) class RoleServiceImplTest { - @Mock - private RoleMembersRepository roleMembersRepository; - @Mock private RoleRepository roleRepository; @@ -69,7 +64,6 @@ void init() { roleDTO = new RoleDTO(); roleDTO.setName("role"); roleDTO.setDescription("role"); - roleDTO.setAuthorities(Set.of("add")); roleDTO.setSuperiorId(1L); } @@ -78,8 +72,6 @@ void retrieve() { Page page = new PageImpl<>(List.of(Mockito.mock(Role.class))); given(this.roleRepository.findAll(PageRequest.of(0, 2, Sort.by("id")))).willReturn(page); - given(this.roleMembersRepository.countByRoleIdAndEnabledTrue(Mockito.anyLong())).willReturn(Mockito.anyLong()); - Page voPage = roleService.retrieve(0, 2, "id"); Assertions.assertNotNull(voPage.getContent()); @@ -89,8 +81,6 @@ void retrieve() { void fetch() { given(this.roleRepository.findById(Mockito.anyLong())).willReturn(Optional.ofNullable(Mockito.mock(Role.class))); - given(this.roleMembersRepository.countByRoleIdAndEnabledTrue(Mockito.anyLong())).willReturn(2L); - RoleVO roleVO = roleService.fetch(Mockito.anyLong()); Assertions.assertNotNull(roleVO); @@ -100,8 +90,6 @@ void fetch() { void create() { given(this.roleRepository.saveAndFlush(Mockito.any(Role.class))).willReturn(Mockito.mock(Role.class)); - given(this.roleMembersRepository.countByRoleIdAndEnabledTrue(Mockito.anyLong())).willReturn(2L); - RoleVO roleVO = roleService.create(Mockito.mock(RoleDTO.class)); verify(this.roleRepository, times(1)).saveAndFlush(Mockito.any(Role.class)); @@ -114,8 +102,6 @@ void modify() { given(this.roleRepository.save(Mockito.any(Role.class))).willReturn(Mockito.mock(Role.class)); - given(this.roleMembersRepository.countByRoleIdAndEnabledTrue(Mockito.anyLong())).willReturn(Mockito.anyLong()); - RoleVO roleVO = roleService.modify(1L, roleDTO); verify(this.roleRepository, times(1)).save(Mockito.any(Role.class)); diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/UserServiceImplTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/UserServiceImplTest.java index b694e1a9..f4ecbfb8 100644 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/UserServiceImplTest.java +++ b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/UserServiceImplTest.java @@ -61,7 +61,6 @@ void init() { userDTO.setUsername("test"); userDTO.setFirstname("三"); userDTO.setLastname("张"); - userDTO.setDescription("user"); } diff --git a/pom.xml b/pom.xml index f59fb545..46e1e80b 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ https://sonarcloud.io 0.3.0 - 1.2.1 + 1.2.3 From af3284c885ae7751d85be2ed397eb94fc22015fa Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Sat, 23 Mar 2024 23:30:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=A4=84=E7=90=86lastModifiedDate=E7=9A=84?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CategoryServiceImpl.java | 7 +++++ .../service/impl/CommentServiceImpl.java | 6 ++++ .../assets/service/impl/PostsServiceImpl.java | 5 +++ assets/src/main/resources/application.yaml | 3 -- hypervisor/pom.xml | 8 ++--- .../basic/hypervisor/audit/AuditMetadata.java | 2 ++ .../AuthorizationServerConfiguration.java | 31 ++++++++++--------- .../service/impl/AccessLogServiceImpl.java | 7 +++++ .../service/impl/DictionaryServiceImpl.java | 6 ++++ .../service/impl/GroupServiceImpl.java | 5 +++ .../service/impl/MessageServiceImpl.java | 7 +++++ .../service/impl/PrivilegeServiceImpl.java | 5 +++ .../service/impl/RegionServiceImpl.java | 5 +++ .../service/impl/RoleServiceImpl.java | 6 +++- .../service/impl/UserServiceImpl.java | 6 ++++ .../src/main/resources/application.yaml | 3 -- 16 files changed, 87 insertions(+), 25 deletions(-) diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java index 121ce401..eae21b3d 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java @@ -31,6 +31,9 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import java.time.Instant; +import java.util.Optional; + /** * category service impl. * @@ -116,6 +119,10 @@ private CategoryVO convertOuter(Category category) { BeanCopier copier = BeanCopier.create(Category.class, CategoryVO.class, false); copier.copy(category, vo, null); + // get lastModifiedDate + Optional optionalInstant = category.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); + long count = postRepository.countByCategoryId(category.getId()); vo.setCount(count); return vo; diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java index f366455b..fb512703 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java @@ -29,7 +29,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import java.time.Instant; import java.util.List; +import java.util.Optional; /** * comment service impl. @@ -85,6 +87,10 @@ private CommentVO convertOuter(Comment comment) { BeanCopier copier = BeanCopier.create(Comment.class, CommentVO.class, false); copier.copy(comment, vo, null); + // get lastModifiedDate + Optional optionalInstant = comment.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); + Long count = commentRepository.countByReplier(comment.getId()); vo.setCount(count); return vo; diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java index 82b12ac3..f40d21a0 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java @@ -35,6 +35,7 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import java.time.Instant; import java.util.Optional; import java.util.Set; @@ -174,6 +175,10 @@ private PostVO convertOuter(Post post) { BeanCopier copier = BeanCopier.create(Post.class, PostVO.class, false); copier.copy(post, vo, null); + // get lastModifiedDate + Optional optionalInstant = post.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); + // 转换 tags if (StringUtils.hasText(post.getTags())) { String tags = post.getTags().substring(1, post.getTags().length() - 1) diff --git a/assets/src/main/resources/application.yaml b/assets/src/main/resources/application.yaml index 3bf9cfb8..3c9e6641 100644 --- a/assets/src/main/resources/application.yaml +++ b/assets/src/main/resources/application.yaml @@ -16,9 +16,6 @@ spring: jpa: open-in-view: false - generate-ddl: true - hibernate: - ddl-auto: create security: oauth2: diff --git a/hypervisor/pom.xml b/hypervisor/pom.xml index 675c7460..a083c8df 100644 --- a/hypervisor/pom.xml +++ b/hypervisor/pom.xml @@ -50,10 +50,10 @@ org.springframework.cloud spring-cloud-starter-consul-discovery - - - - + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + org.postgresql postgresql diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java index 7ec4bec4..e3f111b9 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java @@ -20,6 +20,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.domain.Auditable; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.Instant; import java.util.Objects; @@ -31,6 +32,7 @@ * @author wq li 2020-12-20 9:54 */ @MappedSuperclass +@EntityListeners(AuditingEntityListener.class) public abstract class AuditMetadata implements Auditable { /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java index 9347d67b..e8511bf1 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/config/AuthorizationServerConfiguration.java @@ -17,21 +17,24 @@ package io.leafage.basic.hypervisor.config; -//import org.springframework.security.config.Customizer; -//import org.springframework.security.config.annotation.web.builders.HttpSecurity; -//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -//import org.springframework.security.web.SecurityFilterChain; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.Customizer; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.SecurityFilterChain; -//@Configuration -//@EnableWebSecurity +@Configuration +@EnableWebSecurity public class AuthorizationServerConfiguration { -// @Bean -// public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { -// http.authorizeHttpRequests((authorize) -> authorize -// .requestMatchers(HttpMethod.GET).permitAll() -// .anyRequest().authenticated()) -// .oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults())); -// return http.build(); -// } + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.authorizeHttpRequests((authorize) -> authorize + .requestMatchers(HttpMethod.GET).permitAll() + .anyRequest().authenticated()) + .oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults())); + return http.build(); + } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java index afed81e3..e9e7740a 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java @@ -27,6 +27,9 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import java.time.Instant; +import java.util.Optional; + /** * access log service impl. * @@ -60,6 +63,10 @@ private AccessLogVO convert(AccessLog accessLog) { AccessLogVO vo = new AccessLogVO(); BeanCopier copier = BeanCopier.create(AccessLog.class, AccessLogVO.class, false); copier.copy(accessLog, vo, null); + + // get lastModifiedDate + Optional optionalInstant = accessLog.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java index d026c1c7..e70f01c9 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java @@ -29,7 +29,9 @@ import org.springframework.util.Assert; import top.leafage.common.servlet.ServletAbstractTreeNodeService; +import java.time.Instant; import java.util.List; +import java.util.Optional; /** * dictionary service impl. @@ -94,6 +96,10 @@ private DictionaryVO convert(Dictionary dictionary) { DictionaryVO vo = new DictionaryVO(); BeanCopier copier = BeanCopier.create(Dictionary.class, DictionaryVO.class, false); copier.copy(dictionary, vo, null); + + // get lastModifiedDate + Optional optionalInstant = dictionary.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java index e0b4e044..0e5c4a14 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java @@ -33,9 +33,11 @@ import top.leafage.common.TreeNode; import top.leafage.common.servlet.ServletAbstractTreeNodeService; +import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; /** * group service impl. @@ -111,6 +113,9 @@ private GroupVO convertOuter(Group group) { BeanCopier copier = BeanCopier.create(Group.class, GroupVO.class, false); copier.copy(group, vo, null); + // get lastModifiedDate + Optional optionalInstant = group.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java index ab49544a..18c3252f 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java @@ -30,6 +30,9 @@ import org.springframework.util.Assert; import top.leafage.common.servlet.ServletAbstractTreeNodeService; +import java.time.Instant; +import java.util.Optional; + /** * message service impl. * @@ -76,6 +79,10 @@ private MessageVO convertOuter(Message message) { MessageVO vo = new MessageVO(); BeanCopier copier = BeanCopier.create(Message.class, MessageVO.class, false); copier.copy(message, vo, null); + + // get lastModifiedDate + Optional optionalInstant = message.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java index 97f61cb1..a9979fb0 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java @@ -34,6 +34,7 @@ import top.leafage.common.TreeNode; import top.leafage.common.servlet.ServletAbstractTreeNodeService; +import java.time.Instant; import java.util.*; /** @@ -106,6 +107,10 @@ private PrivilegeVO convertOuter(Privilege privilege) { PrivilegeVO vo = new PrivilegeVO(); BeanCopier copier = BeanCopier.create(Privilege.class, PrivilegeVO.class, false); copier.copy(privilege, vo, null); + + // get lastModifiedDate + Optional optionalInstant = privilege.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java index 1060626f..3b512df0 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java @@ -28,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import java.time.Instant; import java.util.List; import java.util.Optional; @@ -118,6 +119,10 @@ private RegionVO convertOuter(Region region) { Optional optional = regionRepository.findById(region.getSuperiorId()); optional.ifPresent(superior -> vo.setSuperior(superior.getName())); } + + // get lastModifiedDate + Optional optionalInstant = region.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java index ad9ea6f1..e3a3ad27 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java @@ -33,9 +33,11 @@ import top.leafage.common.TreeNode; import top.leafage.common.servlet.ServletAbstractTreeNodeService; +import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; /** * role service impl. @@ -121,7 +123,9 @@ private RoleVO convertOuter(Role role) { RoleVO vo = new RoleVO(); BeanCopier copier = BeanCopier.create(Role.class, RoleVO.class, false); copier.copy(role, vo, null); - + // get lastModifiedDate + Optional optionalInstant = role.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java index 215fc6a3..3b5ef2af 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java @@ -30,6 +30,9 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import java.time.Instant; +import java.util.Optional; + /** * user service impl. * @@ -106,6 +109,9 @@ private UserVO convertOuter(User user) { BeanCopier copier = BeanCopier.create(User.class, UserVO.class, false); copier.copy(user, vo, null); + // get lastModifiedDate + Optional optionalInstant = user.getLastModifiedDate(); + optionalInstant.ifPresent(vo::setLastModifiedDate); return vo; } diff --git a/hypervisor/src/main/resources/application.yaml b/hypervisor/src/main/resources/application.yaml index a9f652ed..114d3770 100644 --- a/hypervisor/src/main/resources/application.yaml +++ b/hypervisor/src/main/resources/application.yaml @@ -16,9 +16,6 @@ spring: jpa: open-in-view: false - generate-ddl: true - hibernate: - ddl-auto: create security: oauth2: From a0257e3696826bfcecc61cf9873a906ebdbcd8c7 Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Sun, 24 Mar 2024 20:07:39 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9auth=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafage/basic/assets/domain/Category.java | 2 +- .../io/leafage/basic/assets/domain/Post.java | 1 - assets/src/main/resources/application.yaml | 3 + assets/src/main/resources/sql/table-ddl.sql | 178 ++++---- .../AuthorizationServerConfiguration.java | 85 ++-- .../main/java/io/leafage/auth/jose/Jwks.java | 59 --- .../basic/hypervisor/audit/AuditMetadata.java | 1 - .../basic/hypervisor/domain/Authorities.java | 48 ++ .../leafage/basic/hypervisor/domain/User.java | 72 ++- .../src/main/resources/application.yaml | 3 + .../src/main/resources/sql/table-ddl.sql | 418 +++++++++--------- 11 files changed, 471 insertions(+), 399 deletions(-) delete mode 100644 auth/src/main/java/io/leafage/auth/jose/Jwks.java create mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java diff --git a/assets/src/main/java/io/leafage/basic/assets/domain/Category.java b/assets/src/main/java/io/leafage/basic/assets/domain/Category.java index 509785b2..8fa6da9a 100644 --- a/assets/src/main/java/io/leafage/basic/assets/domain/Category.java +++ b/assets/src/main/java/io/leafage/basic/assets/domain/Category.java @@ -40,7 +40,7 @@ public class Category extends AuditMetadata { /** * 是否可用 */ - @Column(name = "is_enabled", nullable = false) + @Column(name = "enabled", nullable = false) private boolean enabled = true; /** diff --git a/assets/src/main/java/io/leafage/basic/assets/domain/Post.java b/assets/src/main/java/io/leafage/basic/assets/domain/Post.java index 28f7769c..6a79c15a 100644 --- a/assets/src/main/java/io/leafage/basic/assets/domain/Post.java +++ b/assets/src/main/java/io/leafage/basic/assets/domain/Post.java @@ -57,7 +57,6 @@ public class Post extends AuditMetadata { /** * 是否可用 */ - @Column(name = "is_enabled") private boolean enabled = true; diff --git a/assets/src/main/resources/application.yaml b/assets/src/main/resources/application.yaml index 3c9e6641..3bf9cfb8 100644 --- a/assets/src/main/resources/application.yaml +++ b/assets/src/main/resources/application.yaml @@ -16,6 +16,9 @@ spring: jpa: open-in-view: false + generate-ddl: true + hibernate: + ddl-auto: create security: oauth2: diff --git a/assets/src/main/resources/sql/table-ddl.sql b/assets/src/main/resources/sql/table-ddl.sql index f8e0de1b..afe0d59d 100644 --- a/assets/src/main/resources/sql/table-ddl.sql +++ b/assets/src/main/resources/sql/table-ddl.sql @@ -1,103 +1,111 @@ -drop table if exists categories; - -/*==============================================================*/ -/* Table: categories */ -/*==============================================================*/ -create table categories -( - id bigserial not null primary key, - name varchar(127) not null UNIQUE, - description varchar(255), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Drop table if exists categories +DROP TABLE IF EXISTS categories; + +-- Create table categories +CREATE TABLE categories ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + name varchar(127) NOT NULL UNIQUE COMMENT '名称', + description varchar(255) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); + +-- Add comment to the table +COMMENT ON TABLE categories IS '类别表'; + +-- Create unique index on categories table CREATE UNIQUE INDEX idx_unique_name ON categories (name); +COMMENT ON INDEX idx_unique_name IS '类别名称唯一索引'; +-- Drop table if exists posts +DROP TABLE IF EXISTS posts; -drop table if exists posts; - -/*==============================================================*/ -/* Table: posts */ -/*==============================================================*/ -CREATE TABLE posts -( - id bigserial not null primary key, - title varchar(127) not null, - tags varchar[], - cover varchar(127), - category_id bigint not null, - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP, - CONSTRAINT fk_category - FOREIGN KEY (category_id) REFERENCES categories(id) +-- Create table posts +CREATE TABLE posts ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + title varchar(127) NOT NULL COMMENT '标题', + tags varchar[] COMMENT '标签', + cover varchar(127) COMMENT '封面', + category_id bigint NOT NULL COMMENT '类别ID', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + CONSTRAINT fk_category FOREIGN KEY (category_id) REFERENCES categories(id) ); +-- Add comment to the table +COMMENT ON TABLE posts IS '帖子表'; + +-- Create index on category_id column CREATE INDEX idx_category_id ON posts(category_id); +COMMENT ON INDEX idx_category_id IS '帖子类别ID索引'; + +-- Create index on created_by column CREATE INDEX idx_created_by ON posts(created_by); +COMMENT ON INDEX idx_created_by IS '帖子创建者索引'; +-- Drop table if exists post_content +DROP TABLE IF EXISTS post_content; -drop table if exists post_content; - -/*==============================================================*/ -/* Table: post_content */ -/*==============================================================*/ -CREATE TABLE post_content -( - id bigserial not null primary key, - post_id bigint not null UNIQUE, - content text, - created_by varchar(32) not null, - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null, - last_modified_date timestamp not null default CURRENT_TIMESTAMP, - CONSTRAINT fk_post_content_post - FOREIGN KEY (post_id) REFERENCES posts(id) +-- Create table post_content +CREATE TABLE post_content ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + post_id bigint NOT NULL UNIQUE COMMENT '帖子ID', + content text COMMENT '内容', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + CONSTRAINT fk_post_content_post FOREIGN KEY (post_id) REFERENCES posts(id) ); +-- Add comment to the table +COMMENT ON TABLE post_content IS '帖子内容表'; + +-- Create unique index on post_id column CREATE UNIQUE INDEX idx_unique_post_id ON post_content (post_id); +COMMENT ON INDEX idx_unique_post_id IS '帖子ID唯一索引'; +-- Drop table if exists comments +DROP TABLE IF EXISTS comments; -drop table if exists comments; - -/*==============================================================*/ -/* Table: comments */ -/*==============================================================*/ -CREATE TABLE comments -( - id bigserial not null primary key, - post_id bigint not null, - country varchar(255), - location varchar(255), - context varchar(512), - created_by varchar(32) not null, - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null, - last_modified_date timestamp not null default CURRENT_TIMESTAMP, - CONSTRAINT fk_comments_post - FOREIGN KEY (post_id) REFERENCES posts(id) +-- Create table comments +CREATE TABLE comments ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + post_id bigint NOT NULL COMMENT '帖子ID', + country varchar(255) COMMENT '国家', + location varchar(255) COMMENT '位置', + context varchar(512) COMMENT '内容', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + CONSTRAINT fk_comments_post FOREIGN KEY (post_id) REFERENCES posts(id) ); +-- Add comment to the table +COMMENT ON TABLE comments IS '评论表'; + +-- Drop table if exists post_statistics +DROP TABLE IF EXISTS post_statistics; + +-- Create table post_statistics +CREATE TABLE post_statistics ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + post_id bigint NOT NULL COMMENT '帖子ID', + viewed bigint COMMENT '浏览次数', + likes bigint COMMENT '点赞次数', + comments bigint COMMENT '评论次数', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' +); -drop table if exists post_statistics; - -/*==============================================================*/ -/* Table: post_statistics */ -/*==============================================================*/ -CREATE TABLE post_statistics -( - id bigserial not null primary key, - post_id bigint not null, - viewed bigint, - likes bigint, - comments bigint, - created_by varchar(32) not null, - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null, - last_modified_date timestamp not null default CURRENT_TIMESTAMP -); \ No newline at end of file +-- Add comment to the table +COMMENT ON TABLE post_statistics IS '帖子统计信息表'; diff --git a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java index 6d069228..1b82524c 100644 --- a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java +++ b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java @@ -19,16 +19,16 @@ import com.nimbusds.jose.jwk.JWKSet; import com.nimbusds.jose.jwk.RSAKey; +import com.nimbusds.jose.jwk.source.ImmutableJWKSet; import com.nimbusds.jose.jwk.source.JWKSource; import com.nimbusds.jose.proc.SecurityContext; -import io.leafage.auth.jose.Jwks; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.core.session.SessionRegistry; -import org.springframework.security.core.session.SessionRegistryImpl; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.jwt.JwtDecoder; import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationConsentService; @@ -38,12 +38,19 @@ import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository; import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository; import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; +import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer; import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings; import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.session.HttpSessionEventPublisher; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; +import org.springframework.security.web.util.matcher.MediaTypeRequestMatcher; import javax.sql.DataSource; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.util.UUID; import static org.springframework.security.config.Customizer.withDefaults; @@ -53,21 +60,39 @@ * @author wq li 2021-12-21 17:02 */ @Configuration +@EnableWebSecurity public class AuthorizationServerConfiguration { + public static KeyPair generateRsaKey() { + KeyPair keyPair; + try { + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(2048); + keyPair = keyPairGenerator.generateKeyPair(); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + return keyPair; + } + @Bean @Order(1) public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http); - return http.formLogin(withDefaults()).build(); - } - - @Bean - @Order(2) - SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception { - http.authorizeHttpRequests(authorize -> - authorize.anyRequest().authenticated()) - .formLogin(withDefaults()); + http.getConfigurer(OAuth2AuthorizationServerConfigurer.class) + .oidc(withDefaults()); // Enable OpenID Connect 1.0 + http + // Redirect to the login page when not authenticated from the + // authorization endpoint + .exceptionHandling((exceptions) -> exceptions + .defaultAuthenticationEntryPointFor( + new LoginUrlAuthenticationEntryPoint("/login"), + new MediaTypeRequestMatcher(MediaType.TEXT_HTML) + ) + ) + // Accept access tokens for User Info and/or Client Registration + .oauth2ResourceServer((resourceServer) -> resourceServer + .jwt(withDefaults())); return http.build(); } @@ -76,16 +101,6 @@ UserDetailsService userDetailsService(DataSource dataSource) { return new JdbcUserDetailsManager(dataSource); } - @Bean - SessionRegistry sessionRegistry() { - return new SessionRegistryImpl(); - } - - @Bean - HttpSessionEventPublisher httpSessionEventPublisher() { - return new HttpSessionEventPublisher(); - } - @Bean public RegisteredClientRepository registeredClientRepository(JdbcTemplate jdbcTemplate) { return new JdbcRegisteredClientRepository(jdbcTemplate); @@ -103,11 +118,31 @@ public OAuth2AuthorizationConsentService authorizationConsentService(JdbcTemplat return new JdbcOAuth2AuthorizationConsentService(jdbcTemplate, registeredClientRepository); } + @Bean + @Order(2) + public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception { + http + .authorizeHttpRequests((authorize) -> authorize + .anyRequest().authenticated() + ) + .passwordManagement(withDefaults()) + // Form login handles the redirect to the login page from the + // authorization server filter chain + .formLogin(withDefaults()); + return http.build(); + } + @Bean public JWKSource jwkSource() { - RSAKey rsaKey = Jwks.generateRsa(); + KeyPair keyPair = generateRsaKey(); + RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); + RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); + RSAKey rsaKey = new RSAKey.Builder(publicKey) + .privateKey(privateKey) + .keyID(UUID.randomUUID().toString()) + .build(); JWKSet jwkSet = new JWKSet(rsaKey); - return (jwkSelector, securityContext) -> jwkSelector.select(jwkSet); + return new ImmutableJWKSet<>(jwkSet); } @Bean diff --git a/auth/src/main/java/io/leafage/auth/jose/Jwks.java b/auth/src/main/java/io/leafage/auth/jose/Jwks.java deleted file mode 100644 index 052f1389..00000000 --- a/auth/src/main/java/io/leafage/auth/jose/Jwks.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.auth.jose; - -import com.nimbusds.jose.jwk.RSAKey; - -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.util.UUID; - -/** - * jwks - * - * @author wq li 2021-12-21 17:02 - */ -public final class Jwks { - - private Jwks() { - } - - public static RSAKey generateRsa() { - KeyPair keyPair = generateRsaKey(); - RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); - RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); - return new RSAKey.Builder(publicKey) - .privateKey(privateKey) - .keyID(UUID.randomUUID().toString()) - .build(); - } - - static KeyPair generateRsaKey() { - KeyPair keyPair; - try { - KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); - keyPairGenerator.initialize(2048); - keyPair = keyPairGenerator.generateKeyPair(); - } catch (Exception ex) { - throw new IllegalStateException(ex); - } - return keyPair; - } -} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java index e3f111b9..975335c8 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/audit/AuditMetadata.java @@ -45,7 +45,6 @@ public abstract class AuditMetadata implements Auditable /** * 是否可用 */ - @Column(name = "is_enabled") private boolean enabled = true; /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java new file mode 100644 index 00000000..fd82c189 --- /dev/null +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018-2024 little3201. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.leafage.basic.hypervisor.domain; + +import io.leafage.basic.hypervisor.audit.AuditMetadata; +import jakarta.persistence.Entity; +import jakarta.persistence.Index; +import jakarta.persistence.Table; + +@Entity +@Table(name = "authorities", indexes = {@Index(name = "ix_auth_username", columnList = "username")}) +public class Authorities extends AuditMetadata { + + private String username; + + private String authority; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAuthority() { + return authority; + } + + public void setAuthority(String authority) { + this.authority = authority; + } +} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java index e60cedfd..32b55805 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java @@ -23,7 +23,7 @@ import jakarta.persistence.Index; import jakarta.persistence.Table; -import java.time.LocalDateTime; +import java.time.Instant; /** * model class for user. @@ -40,6 +40,12 @@ public class User extends AuditMetadata { @Column(name = "username", nullable = false, unique = true) private String username; + /** + * password + */ + @Column(name = "password", nullable = false) + private String password; + /** * 名 */ @@ -56,22 +62,34 @@ public class User extends AuditMetadata { private String avatar; /** - * user有效期 + * 有效 + */ + @Column(name = "account_non_expired") + private boolean accountNonExpired = true; + + /** + * 有效期 */ @Column(name = "account_expires_at") - private LocalDateTime accountExpiresAt; + private Instant accountExpiresAt; /** - * 是否锁定 + * 未锁定 */ - @Column(name = "is_account_locked") - private boolean accountLocked; + @Column(name = "account_non_locked") + private boolean accountNonLocked = true; + + /** + * 密码有效 + */ + @Column(name = "credentials_non_expired") + private boolean credentialsNonExpired = true; /** * 密码有效期 */ @Column(name = "credentials_expires_at") - private LocalDateTime credentialsExpiresAt; + private Instant credentialsExpiresAt; public String getUsername() { @@ -82,6 +100,14 @@ public void setUsername(String username) { this.username = username; } + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + public String getFirstname() { return firstname; } @@ -106,27 +132,43 @@ public void setAvatar(String avatar) { this.avatar = avatar; } - public LocalDateTime getAccountExpiresAt() { + public boolean isAccountNonExpired() { + return accountNonExpired; + } + + public void setAccountNonExpired(boolean accountNonExpired) { + this.accountNonExpired = accountNonExpired; + } + + public Instant getAccountExpiresAt() { return accountExpiresAt; } - public void setAccountExpiresAt(LocalDateTime accountExpiresAt) { + public void setAccountExpiresAt(Instant accountExpiresAt) { this.accountExpiresAt = accountExpiresAt; } - public boolean isAccountLocked() { - return accountLocked; + public boolean isAccountNonLocked() { + return accountNonLocked; + } + + public void setAccountNonLocked(boolean accountNonLocked) { + this.accountNonLocked = accountNonLocked; + } + + public boolean isCredentialsNonExpired() { + return credentialsNonExpired; } - public void setAccountLocked(boolean accountLocked) { - this.accountLocked = accountLocked; + public void setCredentialsNonExpired(boolean credentialsNonExpired) { + this.credentialsNonExpired = credentialsNonExpired; } - public LocalDateTime getCredentialsExpiresAt() { + public Instant getCredentialsExpiresAt() { return credentialsExpiresAt; } - public void setCredentialsExpiresAt(LocalDateTime credentialsExpiresAt) { + public void setCredentialsExpiresAt(Instant credentialsExpiresAt) { this.credentialsExpiresAt = credentialsExpiresAt; } } diff --git a/hypervisor/src/main/resources/application.yaml b/hypervisor/src/main/resources/application.yaml index 114d3770..a9f652ed 100644 --- a/hypervisor/src/main/resources/application.yaml +++ b/hypervisor/src/main/resources/application.yaml @@ -16,6 +16,9 @@ spring: jpa: open-in-view: false + generate-ddl: true + hibernate: + ddl-auto: create security: oauth2: diff --git a/hypervisor/src/main/resources/sql/table-ddl.sql b/hypervisor/src/main/resources/sql/table-ddl.sql index a91259f7..1b79a86e 100644 --- a/hypervisor/src/main/resources/sql/table-ddl.sql +++ b/hypervisor/src/main/resources/sql/table-ddl.sql @@ -1,239 +1,233 @@ -drop table if exists groups; - -/*==============================================================*/ -/* Table: groups */ -/*==============================================================*/ -create table groups -( - id bigserial not null primary key, - name varchar(64) not null UNIQUE, - principal varchar(16), - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Drop table if exists groups +DROP TABLE IF EXISTS groups; + +-- Create table groups +CREATE TABLE groups ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + name varchar(64) NOT NULL UNIQUE COMMENT '名称', + principal varchar(16) COMMENT '负责人', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); - -drop table if exists users; - -/*==============================================================*/ -/* Table: users */ -/*==============================================================*/ -create table users -( - id bigserial not null primary key, - username varchar(16) not null UNIQUE, - password varchar(255) not null , - firstname varchar(16), - lastname varchar(16), - avatar varchar(127), - account_expires_at timestamp, - credentials_expires_at timestamp, - account_non_locked boolean not null default true, - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Add comment to the table +COMMENT ON TABLE groups IS '用户组表'; + +-- Drop table if exists users +DROP TABLE IF EXISTS users; + +-- Create table users +CREATE TABLE users ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + username varchar(16) NOT NULL UNIQUE COMMENT '用户名', + password varchar(255) NOT NULL COMMENT '密码', + firstname varchar(16) COMMENT '名字', + lastname varchar(16) COMMENT '姓氏', + avatar varchar(127) COMMENT '头像', + account_expires_at timestamp COMMENT '账号过期时间', + credentials_expires_at timestamp COMMENT '凭证过期时间', + account_non_locked boolean NOT NULL DEFAULT true COMMENT '账号是否非锁定', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); - -drop table if exists roles; - -/*==============================================================*/ -/* Table: roles */ -/*==============================================================*/ -create table roles -( - id bigserial not null primary key, - name varchar(64) not null UNIQUE, - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Add comment to the table +COMMENT ON TABLE users IS '用户表'; + +-- Drop table if exists roles +DROP TABLE IF EXISTS roles; + +-- Create table roles +CREATE TABLE roles ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + name varchar(64) NOT NULL UNIQUE COMMENT '名称', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); +-- Add comment to the table +COMMENT ON TABLE roles IS '角色表'; -drop table if exists group_members; - -/*==============================================================*/ -/* Table: group_members */ -/*==============================================================*/ -create table group_members -( - id bigserial not null primary key, - group_id bigint not null, - username varchar(32) not null, - CONSTRAINT fk_group_members_group - FOREIGN KEY (group_id) REFERENCES groups(id), - CONSTRAINT fk_group_members_username - FOREIGN KEY (username) REFERENCES users(username) -); - +-- Drop table if exists group_members +DROP TABLE IF EXISTS group_members; -drop table if exists group_roles; - -/*==============================================================*/ -/* Table: group_roles */ -/*==============================================================*/ -create table group_roles -( - id bigserial not null primary key, - group_id bigint not null, - role_id bigint not null, - CONSTRAINT fk_group_roles_group - FOREIGN KEY (group_id) REFERENCES groups(id), - CONSTRAINT fk_group_roles_role - FOREIGN KEY (role_id) REFERENCES roles(id) +-- Create table group_members +CREATE TABLE group_members ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + group_id bigint NOT NULL COMMENT '用户组ID', + username varchar(32) NOT NULL COMMENT '用户名', + CONSTRAINT fk_group_members_group FOREIGN KEY (group_id) REFERENCES groups(id), + CONSTRAINT fk_group_members_username FOREIGN KEY (username) REFERENCES users(username) ); +-- Add comment to the table +COMMENT ON TABLE group_members IS '用户组成员关系表'; + +-- Drop table if exists group_roles +DROP TABLE IF EXISTS group_roles; -drop table if exists role_members; - -/*==============================================================*/ -/* Table: role_members */ -/*==============================================================*/ -create table role_members -( - id bigserial not null primary key, - role_id bigint not null, - username varchar(32) not null, - CONSTRAINT fk_role_members_role - FOREIGN KEY (role_id) REFERENCES roles(id), - CONSTRAINT fk_role_members_username - FOREIGN KEY (username) REFERENCES users(username) +-- Create table group_roles +CREATE TABLE group_roles ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + group_id bigint NOT NULL COMMENT '用户组ID', + role_id bigint NOT NULL COMMENT '角色ID', + CONSTRAINT fk_group_roles_group FOREIGN KEY (group_id) REFERENCES groups(id), + CONSTRAINT fk_group_roles_role FOREIGN KEY (role_id) REFERENCES roles(id) ); +-- Add comment to the table +COMMENT ON TABLE group_roles IS '用户组角色关系表'; -drop table if exists privileges; - -/*==============================================================*/ -/* Table: privileges */ -/*==============================================================*/ -create table privileges -( - id bigserial not null primary key, - superior_id bigint, - name varchar(64) not null, - type character(1) not null, - path varchar(127), - icon varchar(127), - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP -); +-- Drop table if exists role_members +DROP TABLE IF EXISTS role_members; +-- Create table role_members +CREATE TABLE role_members ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + role_id bigint NOT NULL COMMENT '角色ID', + username varchar(32) NOT NULL COMMENT '用户名', + CONSTRAINT fk_role_members_role FOREIGN KEY (role_id) REFERENCES roles(id), + CONSTRAINT fk_role_members_username FOREIGN KEY (username) REFERENCES users(username) +); -drop table if exists role_privileges; - -/*==============================================================*/ -/* Table: role_privileges */ -/*==============================================================*/ -create table role_privileges -( - id bigserial not null primary key, - role_id bigint not null, - privilege_id bigint not null, - CONSTRAINT fk_role_privileges_role - FOREIGN KEY (role_id) REFERENCES roles(id), - CONSTRAINT fk_role_privileges_privilege - FOREIGN KEY (privilege_id) REFERENCES privileges(id) +-- Add comment to the table +COMMENT ON TABLE role_members IS '角色成员关系表'; + +-- Drop table if exists privileges +DROP TABLE IF EXISTS privileges; + +-- Create table privileges +CREATE TABLE privileges ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + superior_id bigint COMMENT '上级ID', + name varchar(64) NOT NULL COMMENT '名称', + type character(1) NOT NULL COMMENT '类型', + path varchar(127) COMMENT '路径', + icon varchar(127) COMMENT '图标', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); +-- Add comment to the table +COMMENT ON TABLE privileges IS '权限表'; -drop table if exists dictionaries; - -/*==============================================================*/ -/* Table: dictionaries */ -/*==============================================================*/ -create table dictionaries -( - id bigserial not null primary key, - name varchar(64) not null, - superior_id bigint, - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP -); +-- Drop table if exists role_privileges +DROP TABLE IF EXISTS role_privileges; +-- Create table role_privileges +CREATE TABLE role_privileges ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + role_id bigint NOT NULL COMMENT '角色ID', + privilege_id bigint NOT NULL COMMENT '权限ID', + CONSTRAINT fk_role_privileges_role FOREIGN KEY (role_id) REFERENCES roles(id), + CONSTRAINT fk_role_privileges_privilege FOREIGN KEY (privilege_id) REFERENCES privileges(id) +); -drop table if exists messages; - -/*==============================================================*/ -/* Table: messages */ -/*==============================================================*/ -create table messages -( - id bigserial not null primary key, - title varchar(255) not null, - context text, - is_read boolean not null default false, - receiver varchar(32) not null, - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Add comment to the table +COMMENT ON TABLE role_privileges IS '角色权限关系表'; + +-- Drop table if exists dictionaries +DROP TABLE IF EXISTS dictionaries; + +-- Create table dictionaries +CREATE TABLE dictionaries ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + name varchar(64) NOT NULL COMMENT '名称', + superior_id bigint COMMENT '上级ID', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); +-- Add comment to the table +COMMENT ON TABLE dictionaries IS '字典表'; + +-- Drop table if exists messages +DROP TABLE IF EXISTS messages; + +-- Create table messages +CREATE TABLE messages ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + title varchar(255) NOT NULL COMMENT '标题', + context text COMMENT '内容', + is_read boolean NOT NULL DEFAULT false COMMENT + -- 是否已读 + receiver varchar(32) NOT NULL COMMENT '接收者', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' +); -drop table if exists regions; - -/*==============================================================*/ -/* Table: regions */ -/*==============================================================*/ -create table regions -( - id bigserial not null primary key, - name varchar(64) not null, - superior_id bigint, - postal_code bigint, - area_code bigint, - description varchar(512), - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP +-- Add comment to the table +COMMENT ON TABLE messages IS '消息表'; + +-- Drop table if exists regions +DROP TABLE IF EXISTS regions; + +-- Create table regions +CREATE TABLE regions ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + name varchar(64) NOT NULL COMMENT '名称', + superior_id bigint COMMENT '上级ID', + postal_code bigint COMMENT '邮政编码', + area_code bigint COMMENT '区号', + description varchar(512) COMMENT '描述', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' ); +-- Add comment to the table +COMMENT ON TABLE regions IS '地区表'; + +-- Drop table if exists access_logs +DROP TABLE IF EXISTS access_logs; + +-- Create table access_logs +CREATE TABLE access_logs ( + id bigserial PRIMARY KEY NOT NULL COMMENT '主键', + ip inet COMMENT 'IP地址', + location varchar(127) COMMENT '位置', + context text COMMENT '内容', + user_agent varchar(255) COMMENT '用户代理信息', + http_method varchar(10) COMMENT 'HTTP方法', + url text COMMENT '请求URL', + status_code integer COMMENT 'HTTP状态码', + response_time bigint COMMENT '响应时间', + referer varchar(255) COMMENT '来源页面', + session_id varchar(50) COMMENT '会话标识符', + device_type varchar(20) COMMENT '设备类型', + os varchar(50) COMMENT '操作系统', + browser varchar(50) COMMENT '浏览器', + enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', + created_by varchar(32) NOT NULL COMMENT '创建者', + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' +); -drop table if exists access_logs; - -/*==============================================================*/ -/* Table: access_logs */ -/*==============================================================*/ -create table access_logs -( - id bigserial not null primary key, - ip inet, - location varchar(127), - context text, - user_agent varchar(255), -- 用户代理信息 - http_method varchar(10), -- HTTP方法 - url text, -- 请求URL - status_code integer, -- HTTP状态码 - response_time bigint, -- 响应时间 - referer varchar(255), -- 来源页面 - session_id varchar(50), -- 会话标识符 - device_type varchar(20), -- 设备类型 - os varchar(50), -- 操作系统 - browser varchar(50) -- 浏览器 - is_enabled boolean not null default true, - created_by varchar(32) not null , - created_date timestamp not null default CURRENT_TIMESTAMP, - last_modified_by varchar(32) not null , - last_modified_date timestamp not null default CURRENT_TIMESTAMP -); \ No newline at end of file +-- Add comment to the table +COMMENT ON TABLE access_logs IS '访问日志表'; From 9b9aea83edd636c8b4bafcdaa711518373d217d6 Mon Sep 17 00:00:00 2001 From: wq Date: Mon, 25 Mar 2024 22:24:09 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9B=B4=E6=AD=A3ddl;=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=A1=A8=E7=BB=93=E6=9E=84=EF=BC=8C=E5=AF=B9=E8=B1=A1=EF=BC=8C?= =?UTF-8?q?=E9=80=82=E9=85=8Dspring=20security=20jdbc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/src/main/resources/sql/table-ddl.sql | 139 ++++--- .../AuthorizationServerConfiguration.java | 5 +- auth/src/main/resources/sql/table-ddl.sql | 165 +++++--- .../controller/GroupController.java | 18 - .../basic/hypervisor/domain/AccessLog.java | 3 +- .../basic/hypervisor/domain/Authorities.java | 33 +- .../basic/hypervisor/domain/Dictionary.java | 5 +- .../basic/hypervisor/domain/Group.java | 54 +-- ...{GroupRoles.java => GroupAuthorities.java} | 39 +- .../basic/hypervisor/domain/GroupMembers.java | 28 +- .../basic/hypervisor/domain/Message.java | 3 +- .../basic/hypervisor/domain/Privilege.java | 3 +- .../basic/hypervisor/domain/Region.java | 2 +- .../leafage/basic/hypervisor/domain/Role.java | 6 +- .../basic/hypervisor/domain/RoleMembers.java | 25 +- .../hypervisor/domain/RolePrivileges.java | 27 +- .../leafage/basic/hypervisor/domain/User.java | 78 +--- .../repository/GroupMembersRepository.java | 7 - .../repository/GroupRolesRepository.java | 56 --- .../repository/RoleMembersRepository.java | 7 - .../repository/RolePrivilegesRepository.java | 7 - .../hypervisor/service/GroupRolesService.java | 56 --- .../hypervisor/service/GroupService.java | 9 - .../service/impl/GroupRolesServiceImpl.java | 64 --- .../service/impl/GroupServiceImpl.java | 15 +- .../service/impl/MessageServiceImpl.java | 3 +- .../src/main/resources/application.yaml | 3 - .../src/main/resources/sql/table-ddl.sql | 390 ++++++++++++------ .../impl/GroupRolesServiceImplTest.java | 77 ---- 29 files changed, 581 insertions(+), 746 deletions(-) rename hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/{GroupRoles.java => GroupAuthorities.java} (62%) delete mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupRolesRepository.java delete mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupRolesService.java delete mode 100644 hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImpl.java delete mode 100644 hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImplTest.java diff --git a/assets/src/main/resources/sql/table-ddl.sql b/assets/src/main/resources/sql/table-ddl.sql index afe0d59d..240c547f 100644 --- a/assets/src/main/resources/sql/table-ddl.sql +++ b/assets/src/main/resources/sql/table-ddl.sql @@ -3,18 +3,26 @@ DROP TABLE IF EXISTS categories; -- Create table categories CREATE TABLE categories ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - name varchar(127) NOT NULL UNIQUE COMMENT '名称', - description varchar(255) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + name varchar(127) NOT NULL UNIQUE, + description varchar(255), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(32) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(32) NOT NULL, + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE categories IS '类别表'; +COMMENT ON COLUMN categories.id IS '主键'; +COMMENT ON COLUMN categories.name IS '名称'; +COMMENT ON COLUMN categories.description IS '描述'; +COMMENT ON COLUMN categories.enabled IS '是否启用'; +COMMENT ON COLUMN categories.created_by IS '创建者'; +COMMENT ON COLUMN categories.created_date IS '创建时间'; +COMMENT ON COLUMN categories.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN categories.last_modified_date IS '最后修改时间'; -- Create unique index on categories table CREATE UNIQUE INDEX idx_unique_name ON categories (name); @@ -25,21 +33,31 @@ DROP TABLE IF EXISTS posts; -- Create table posts CREATE TABLE posts ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - title varchar(127) NOT NULL COMMENT '标题', - tags varchar[] COMMENT '标签', - cover varchar(127) COMMENT '封面', - category_id bigint NOT NULL COMMENT '类别ID', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + id bigserial PRIMARY KEY NOT NULL, + title varchar(127) NOT NULL, + tags varchar[], + cover varchar(127), + category_id bigint NOT NULL, + enabled boolean NOT NULL DEFAULT true, + created_by varchar(32) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(32) NOT NULL, + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT fk_category FOREIGN KEY (category_id) REFERENCES categories(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE posts IS '帖子表'; +COMMENT ON COLUMN posts.id IS '主键'; +COMMENT ON COLUMN posts.title IS '标题'; +COMMENT ON COLUMN posts.tags IS '标签'; +COMMENT ON COLUMN posts.cover IS '封面'; +COMMENT ON COLUMN posts.category_id IS '类别ID'; +COMMENT ON COLUMN posts.enabled IS '是否启用'; +COMMENT ON COLUMN posts.created_by IS '创建者'; +COMMENT ON COLUMN posts.created_date IS '创建时间'; +COMMENT ON COLUMN posts.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN posts.last_modified_date IS '最后修改时间'; -- Create index on category_id column CREATE INDEX idx_category_id ON posts(category_id); @@ -54,18 +72,25 @@ DROP TABLE IF EXISTS post_content; -- Create table post_content CREATE TABLE post_content ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - post_id bigint NOT NULL UNIQUE COMMENT '帖子ID', - content text COMMENT '内容', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + id bigserial PRIMARY KEY NOT NULL, + post_id bigint NOT NULL UNIQUE, + content text, + created_by varchar(32) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(32) NOT NULL, + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT fk_post_content_post FOREIGN KEY (post_id) REFERENCES posts(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE post_content IS '帖子内容表'; +COMMENT ON COLUMN post_content.id IS '主键'; +COMMENT ON COLUMN post_content.post_id IS '帖子ID'; +COMMENT ON COLUMN post_content.content IS '内容'; +COMMENT ON COLUMN post_content.created_by IS '创建者'; +COMMENT ON COLUMN post_content.created_date IS '创建时间'; +COMMENT ON COLUMN post_content.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN post_content.last_modified_date IS '最后修改时间'; -- Create unique index on post_id column CREATE UNIQUE INDEX idx_unique_post_id ON post_content (post_id); @@ -76,36 +101,54 @@ DROP TABLE IF EXISTS comments; -- Create table comments CREATE TABLE comments ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - post_id bigint NOT NULL COMMENT '帖子ID', - country varchar(255) COMMENT '国家', - location varchar(255) COMMENT '位置', - context varchar(512) COMMENT '内容', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间', + id bigserial PRIMARY KEY NOT NULL, + post_id bigint NOT NULL, + country varchar(255), + location varchar(255), + context varchar(512), + created_by varchar(32) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(32) NOT NULL, + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT fk_comments_post FOREIGN KEY (post_id) REFERENCES posts(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE comments IS '评论表'; +COMMENT ON COLUMN comments.id IS '主键'; +COMMENT ON COLUMN comments.post_id IS '帖子ID'; +COMMENT ON COLUMN comments.country IS '国家'; +COMMENT ON COLUMN comments.location IS '位置'; +COMMENT ON COLUMN comments.context IS '内容'; +COMMENT ON COLUMN comments.created_by IS '创建者'; +COMMENT ON COLUMN comments.created_date IS '创建时间'; +COMMENT ON COLUMN comments.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN comments.last_modified_date IS '最后修改时间'; -- Drop table if exists post_statistics DROP TABLE IF EXISTS post_statistics; -- Create table post_statistics CREATE TABLE post_statistics ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - post_id bigint NOT NULL COMMENT '帖子ID', - viewed bigint COMMENT '浏览次数', - likes bigint COMMENT '点赞次数', - comments bigint COMMENT '评论次数', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + post_id bigint NOT NULL, + viewed bigint, + likes bigint, + comments bigint, + created_by varchar(32) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(32) NOT NULL, + last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE post_statistics IS '帖子统计信息表'; +COMMENT ON COLUMN post_statistics.id IS '主键'; +COMMENT ON COLUMN post_statistics.post_id IS '帖子ID'; +COMMENT ON COLUMN post_statistics.viewed IS '浏览次数'; +COMMENT ON COLUMN post_statistics.likes IS '点赞次数'; +COMMENT ON COLUMN post_statistics.comments IS '评论次数'; +COMMENT ON COLUMN post_statistics.created_by IS '创建者'; +COMMENT ON COLUMN post_statistics.created_date IS '创建时间'; +COMMENT ON COLUMN post_statistics.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN post_statistics.last_modified_date IS '最后修改时间'; diff --git a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java index 1b82524c..5030637a 100644 --- a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java +++ b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java @@ -29,6 +29,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.jwt.JwtDecoder; import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationConsentService; @@ -98,7 +99,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h @Bean UserDetailsService userDetailsService(DataSource dataSource) { - return new JdbcUserDetailsManager(dataSource); + JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager(dataSource); + jdbcUserDetailsManager.createUser(User.withUsername("admin").password("123456").accountLocked(true).roles("ADMIN").build()); + return jdbcUserDetailsManager; } @Bean diff --git a/auth/src/main/resources/sql/table-ddl.sql b/auth/src/main/resources/sql/table-ddl.sql index a497e8ee..1506bb86 100644 --- a/auth/src/main/resources/sql/table-ddl.sql +++ b/auth/src/main/resources/sql/table-ddl.sql @@ -1,77 +1,110 @@ -drop table if exists oauth_registered_client; +-- Drop table if exists oauth_registered_client; +DROP TABLE IF EXISTS oauth_registered_client; -/*==============================================================*/ -/* Table: oauth_registered_client */ -/*==============================================================*/ -create table oauth_registered_client -( - id varchar(100) not null comment '主键', - client_id varchar(100) not null comment '客户端ID', - client_id_issued_at timestamp not null comment '生效时间', - client_secret varchar(200) not null comment '密钥', - client_secret_expires_at timestamp comment '密钥失效时间', - client_name varchar(200) comment '名称', - client_authorization_methods varchar(1000) comment '认证方法', - authorization_grant_types varchar(1000) comment '授权方式', - redirect_uris varchar(1000) comment '跳转连接', - scopes varchar(1000) comment '作用域', - client_settings varchar(2000) comment '客户端设置', - token_settings varchar(2000) comment 'token 设置', - primary key (id) +-- Create table oauth_registered_client +CREATE TABLE oauth_registered_client ( + id VARCHAR(100) NOT NULL, + client_id VARCHAR(100) NOT NULL, + client_id_issued_at TIMESTAMP NOT NULL, + client_secret VARCHAR(200) NOT NULL, + client_secret_expires_at TIMESTAMP, + client_name VARCHAR(200), + client_authorization_methods VARCHAR(1000), + authorization_grant_types VARCHAR(1000), + redirect_uris VARCHAR(1000), + scopes VARCHAR(1000), + client_settings VARCHAR(2000), + token_settings VARCHAR(2000), + PRIMARY KEY (id) ); -alter table oauth_registered_client comment 'client 信息'; +-- Add comment to the table and columns +COMMENT ON TABLE oauth_registered_client IS 'client 信息'; +COMMENT ON COLUMN oauth_registered_client.id IS '主键'; +COMMENT ON COLUMN oauth_registered_client.client_id IS '客户端ID'; +COMMENT ON COLUMN oauth_registered_client.client_id_issued_at IS '生效时间'; +COMMENT ON COLUMN oauth_registered_client.client_secret IS '密钥'; +COMMENT ON COLUMN oauth_registered_client.client_secret_expires_at IS '密钥失效时间'; +COMMENT ON COLUMN oauth_registered_client.client_name IS '名称'; +COMMENT ON COLUMN oauth_registered_client.client_authorization_methods IS '认证方法'; +COMMENT ON COLUMN oauth_registered_client.authorization_grant_types IS '授权方式'; +COMMENT ON COLUMN oauth_registered_client.redirect_uris IS '跳转连接'; +COMMENT ON COLUMN oauth_registered_client.scopes IS '作用域'; +COMMENT ON COLUMN oauth_registered_client.client_settings IS '客户端设置'; +COMMENT ON COLUMN oauth_registered_client.token_settings IS 'token 设置'; +-- Drop table if exists oauth_authorization +DROP TABLE IF EXISTS oauth_authorization; -drop table if exists oauth_authorization; - -/*==============================================================*/ -/* Table: oauth_authorization */ -/*==============================================================*/ -create table oauth_authorization -( - id varchar(100) not null comment '主键', - registered_client_id varchar(100) not null comment '客户端ID', - principal_name timestamp not null comment '认证账号', - authorization_grant_type varchar(1000) not null comment '授权类型', - attributes varchar(4000) comment '参数', - state varchar(500) comment '状态', - authorization_code_value blob comment 'authorization code', - authorization_code_issued_at timestamp comment 'authorization code生效时间', - authorization_code_expires_at timestamp comment 'authorization code失效时间', - authorization_code_metadata varchar(2000) comment 'authorization code 元数据', - access_token_value blob comment 'access token', - access_token_issued_at timestamp comment 'access token 生效时间', - access_token_expires_at timestamp comment 'access_token 失效时间', - access_token_metadata varchar(2000) comment 'access token元数据', - access_token_type varchar(100) comment 'access token 类型', - access_token_scopes varchar(1000) comment 'access token 域', - oidc_id_token_value blob comment 'oidc token', - oidc_id_token_issued_at timestamp comment 'oidc token 生效时间', - oidc_id_token_expires_at timestamp comment 'oidc token 失效时间', - oidc_id_token_metadata varchar(2000) comment 'oidc token 元数据', - refresh_token_value blob comment 'refresh token', - refresh_token_issued_at timestamp comment 'refresh token 生效时间', - refresh_token_expires_at timestamp comment 'refresh token 失效时间', - refresh_token_metadata varchar(2000) comment 'refresh token 元数据', - primary key (id) +-- Create table oauth_authorization +CREATE TABLE oauth_authorization ( + id VARCHAR(100) NOT NULL, + registered_client_id VARCHAR(100) NOT NULL, + principal_name TIMESTAMP NOT NULL, + authorization_grant_type VARCHAR(1000) NOT NULL, + attributes VARCHAR(4000), + state VARCHAR(500), + authorization_code_value BYTEA, + authorization_code_issued_at TIMESTAMP, + authorization_code_expires_at TIMESTAMP, + authorization_code_metadata VARCHAR(2000), + access_token_value BYTEA, + access_token_issued_at TIMESTAMP, + access_token_expires_at TIMESTAMP, + access_token_metadata VARCHAR(2000), + access_token_type VARCHAR(100), + access_token_scopes VARCHAR(1000), + oidc_id_token_value BYTEA, + oidc_id_token_issued_at TIMESTAMP, + oidc_id_token_expires_at TIMESTAMP, + oidc_id_token_metadata VARCHAR(2000), + refresh_token_value BYTEA, + refresh_token_issued_at TIMESTAMP, + refresh_token_expires_at TIMESTAMP, + refresh_token_metadata VARCHAR(2000), + PRIMARY KEY (id) ); -alter table oauth_authorization comment '授权信息'; - +-- Add comment to the table and columns +COMMENT ON TABLE oauth_authorization IS '授权信息'; +COMMENT ON COLUMN oauth_authorization.id IS '主键'; +COMMENT ON COLUMN oauth_authorization.registered_client_id IS '客户端ID'; +COMMENT ON COLUMN oauth_authorization.principal_name IS '认证账号'; +COMMENT ON COLUMN oauth_authorization.authorization_grant_type IS '授权类型'; +COMMENT ON COLUMN oauth_authorization.attributes IS '参数'; +COMMENT ON COLUMN oauth_authorization.state IS '状态'; +COMMENT ON COLUMN oauth_authorization.authorization_code_value IS 'authorization code'; +COMMENT ON COLUMN oauth_authorization.authorization_code_issued_at IS 'authorization code生效时间'; +COMMENT ON COLUMN oauth_authorization.authorization_code_expires_at IS 'authorization code失效时间'; +COMMENT ON COLUMN oauth_authorization.authorization_code_metadata IS 'authorization code 元数据'; +COMMENT ON COLUMN oauth_authorization.access_token_value IS 'access token'; +COMMENT ON COLUMN oauth_authorization.access_token_issued_at IS 'access token 生效时间'; +COMMENT ON COLUMN oauth_authorization.access_token_expires_at IS 'access_token 失效时间'; +COMMENT ON COLUMN oauth_authorization.access_token_metadata IS 'access token元数据'; +COMMENT ON COLUMN oauth_authorization.access_token_type IS 'access token 类型'; +COMMENT ON COLUMN oauth_authorization.access_token_scopes IS 'access token 域'; +COMMENT ON COLUMN oauth_authorization.oidc_id_token_value IS 'oidc token'; +COMMENT ON COLUMN oauth_authorization.oidc_id_token_issued_at IS 'oidc token 生效时间'; +COMMENT ON COLUMN oauth_authorization.oidc_id_token_expires_at IS 'oidc token 失效时间'; +COMMENT ON COLUMN oauth_authorization.oidc_id_token_metadata IS 'oidc token 元数据'; +COMMENT ON COLUMN oauth_authorization.refresh_token_value IS 'refresh token'; +COMMENT ON COLUMN oauth_authorization.refresh_token_issued_at IS 'refresh token 生效时间'; +COMMENT ON COLUMN oauth_authorization.refresh_token_expires_at IS 'refresh token 失效时间'; +COMMENT ON COLUMN oauth_authorization.refresh_token_metadata IS 'refresh token 元数据'; -drop table if exists oauth_authorization_consent; +-- Drop table if exists oauth_authorization_consent +DROP TABLE IF EXISTS oauth_authorization_consent; -/*==============================================================*/ -/* Table: oauth_authorization_consent */ -/*==============================================================*/ -create table oauth_authorization_consent -( - registered_client_id varchar(100) not null comment '客户端ID', - principal_name varchar(200) not null comment '认证账号', - authorities varchar(1000) not null comment '权限', - primary key () +-- Create table oauth_authorization_consent +CREATE TABLE oauth_authorization_consent ( + registered_client_id VARCHAR(100) NOT NULL, + principal_name VARCHAR(200) NOT NULL, + authorities VARCHAR(1000) NOT NULL, + PRIMARY KEY () ); -alter table oauth_authorization_consent comment '认证内容'; - +-- Add comment to the table and columns +COMMENT ON TABLE oauth_authorization_consent IS '认证内容'; +COMMENT ON COLUMN oauth_authorization_consent.registered_client_id IS '客户端ID'; +COMMENT ON COLUMN oauth_authorization_consent.principal_name IS '认证账号'; +COMMENT ON COLUMN oauth_authorization_consent.authorities IS '权限'; diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/GroupController.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/GroupController.java index b66be498..2bd9c8a8 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/GroupController.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/controller/GroupController.java @@ -28,7 +28,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import top.leafage.common.TreeNode; import java.util.List; @@ -71,23 +70,6 @@ public ResponseEntity> retrieve(@RequestParam int page, @RequestPa return ResponseEntity.ok(voPage); } - /** - * 查询树形数据 - * - * @return 查询到的数据,否则返回空 - */ - @GetMapping("/tree") - public ResponseEntity> tree() { - List treeNodes; - try { - treeNodes = groupService.tree(); - } catch (Exception e) { - logger.info("Retrieve group tree occurred an error: ", e); - return ResponseEntity.noContent().build(); - } - return ResponseEntity.ok(treeNodes); - } - /** * 查询信息 * diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/AccessLog.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/AccessLog.java index 4896bd10..ee531430 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/AccessLog.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/AccessLog.java @@ -21,7 +21,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -30,7 +29,7 @@ * @author wq li 2022/1/26 15:20 **/ @Entity -@Table(name = "access_logs", indexes = {@Index(name = "idx_access_logs_created_by", columnList = "created_by")}) +@Table(name = "access_logs") public class AccessLog extends AuditMetadata { /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java index fd82c189..8cf23ce1 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Authorities.java @@ -17,19 +17,40 @@ package io.leafage.basic.hypervisor.domain; -import io.leafage.basic.hypervisor.audit.AuditMetadata; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; +import jakarta.persistence.*; @Entity -@Table(name = "authorities", indexes = {@Index(name = "ix_auth_username", columnList = "username")}) -public class Authorities extends AuditMetadata { +@Table(name = "authorities") +public class Authorities { + /** + * 主键 + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + /** + * username + */ + @Column(name = "username", length = 50) private String username; + /** + * authority + */ + @Column(name = "authority", length = 50) private String authority; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public String getUsername() { return username; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Dictionary.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Dictionary.java index a7f9aa39..09f0d610 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Dictionary.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Dictionary.java @@ -20,7 +20,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -29,13 +28,13 @@ * @author wq li 2022-04-06 17:33 */ @Entity -@Table(name = "dictionaries", indexes = {@Index(name = "uni_dictionaries_name", columnList = "name")}) +@Table(name = "dictionaries") public class Dictionary extends AuditMetadata { /** * 名称 */ - @Column(name = "name", nullable = false) + @Column(name = "name", nullable = false, length = 50) private String name; /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Group.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Group.java index dc2e3fc0..e259955d 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Group.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Group.java @@ -19,7 +19,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -28,62 +27,23 @@ * @author wq li 2020-12-20 9:54 */ @Entity -@Table(name = "groups", indexes = {@Index(name = "uni_groups_name", columnList = "name")}) +@Table(name = "groups") public class Group extends AuditMetadata { /** * 名称 */ - @Column(name = "name", nullable = false, unique = true) - private String name; + @Column(name = "group_name", nullable = false, length = 50) + private String groupName; - /** - * 负责人主键 - */ - private Long principal; - - /** - * 上级 - */ - @Column(name = "superior_id") - private Long superiorId; - - /** - * 描述 - */ - private String description; - - - public Long getPrincipal() { - return principal; - } - - public void setPrincipal(Long principal) { - this.principal = principal; - } - - public Long getSuperiorId() { - return superiorId; - } - public void setSuperiorId(Long superiorId) { - this.superiorId = superiorId; + public String getGroupName() { + return groupName; } - public String getName() { - return name; + public void setGroupName(String groupName) { + this.groupName = groupName; } - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupRoles.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupAuthorities.java similarity index 62% rename from hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupRoles.java rename to hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupAuthorities.java index 396de98f..83735885 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupRoles.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupAuthorities.java @@ -17,11 +17,7 @@ package io.leafage.basic.hypervisor.domain; -import io.leafage.basic.hypervisor.audit.AuditMetadata; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; +import jakarta.persistence.*; /** * model class for group roles. @@ -29,9 +25,15 @@ * @author wq li 2022/1/26 15:20 */ @Entity -@Table(name = "group_roles", indexes = {@Index(name = "idx_group_roles_group_id", columnList = "group_id"), - @Index(name = "idx_group_roles_role_id", columnList = "role_id")}) -public class GroupRoles extends AuditMetadata { +@Table(name = "group_authorities") +public class GroupAuthorities { + + /** + * 主键 + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; /** * group主键 @@ -42,9 +44,17 @@ public class GroupRoles extends AuditMetadata { /** * role主键 */ - @Column(name = "role_id", nullable = false) - private Long roleId; + @Column(name = "authority", nullable = false, length = 50) + private String authority; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } public Long getGroupId() { return groupId; @@ -54,11 +64,12 @@ public void setGroupId(Long groupId) { this.groupId = groupId; } - public Long getRoleId() { - return roleId; + + public String getAuthority() { + return authority; } - public void setRoleId(Long roleId) { - this.roleId = roleId; + public void setAuthority(String authority) { + this.authority = authority; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupMembers.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupMembers.java index 5b338491..ca84ff96 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupMembers.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/GroupMembers.java @@ -16,11 +16,7 @@ */ package io.leafage.basic.hypervisor.domain; -import io.leafage.basic.hypervisor.audit.AuditMetadata; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; +import jakarta.persistence.*; /** * model class for group members. @@ -28,9 +24,15 @@ * @author wq li 2022/1/26 15:20 */ @Entity -@Table(name = "group_members", indexes = {@Index(name = "idx_group_members_group_id", columnList = "group_id"), - @Index(name = "idx_group_members_username", columnList = "username")}) -public class GroupMembers extends AuditMetadata { +@Table(name = "group_members") +public class GroupMembers { + + /** + * 主键 + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; /** * group主键 @@ -41,10 +43,18 @@ public class GroupMembers extends AuditMetadata { /** * 用户名 */ - @Column(name = "username", nullable = false) + @Column(name = "username", nullable = false, length = 50) private String username; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public Long getGroupId() { return groupId; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Message.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Message.java index 918f56a6..b45b3d21 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Message.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Message.java @@ -20,7 +20,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -29,7 +28,7 @@ * @author wq li 2022/1/29 17:20 **/ @Entity -@Table(name = "messages", indexes = {@Index(name = "idx_messages_receiver", columnList = "receiver")}) +@Table(name = "messages") public class Message extends AuditMetadata { /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Privilege.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Privilege.java index 684dd025..868d2109 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Privilege.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Privilege.java @@ -19,7 +19,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -28,7 +27,7 @@ * @author wq li 2019/8/31 15:50 */ @Entity -@Table(name = "privileges", indexes = {@Index(name = "uni_privileges_name", columnList = "name")}) +@Table(name = "privileges") public class Privilege extends AuditMetadata { /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Region.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Region.java index 095659fb..4f89e687 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Region.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Region.java @@ -34,7 +34,7 @@ public class Region extends AuditMetadata { /** * 名称 */ - @Column(name = "name", nullable = false) + @Column(name = "name", nullable = false, length = 50) private String name; /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Role.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Role.java index f3d1f412..209b00be 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Role.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/Role.java @@ -19,7 +19,6 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; /** @@ -28,13 +27,13 @@ * @author wq li 2020-12-20 9:54 */ @Entity -@Table(name = "roles", indexes = {@Index(name = "uni_roles_name", columnList = "name")}) +@Table(name = "roles") public class Role extends AuditMetadata { /** * 名称 */ - @Column(name = "name", nullable = false, unique = true) + @Column(name = "name", nullable = false, unique = true, length = 50) private String name; /** * 上级主键 @@ -46,7 +45,6 @@ public class Role extends AuditMetadata { private String description; - public String getName() { return name; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RoleMembers.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RoleMembers.java index 82de234d..a91eef25 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RoleMembers.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RoleMembers.java @@ -16,11 +16,7 @@ */ package io.leafage.basic.hypervisor.domain; -import io.leafage.basic.hypervisor.audit.AuditMetadata; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; +import jakarta.persistence.*; /** * model class for role members. @@ -28,10 +24,15 @@ * @author wq li 2022/1/26 15:20 */ @Entity -@Table(name = "role_members", indexes = {@Index(name = "idx_role_members_group_id", columnList = "role_id"), - @Index(name = "idx_role_members_username", columnList = "username")}) -public class RoleMembers extends AuditMetadata { +@Table(name = "role_members") +public class RoleMembers { + /** + * 主键 + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; /** * group主键 @@ -46,6 +47,14 @@ public class RoleMembers extends AuditMetadata { private String username; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public Long getRoleId() { return roleId; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RolePrivileges.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RolePrivileges.java index ad052bdd..fc37ac0d 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RolePrivileges.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/RolePrivileges.java @@ -16,11 +16,7 @@ */ package io.leafage.basic.hypervisor.domain; -import io.leafage.basic.hypervisor.audit.AuditMetadata; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; +import jakarta.persistence.*; /** * model class for role privileges. @@ -28,15 +24,22 @@ * @author wq li 2022/1/26 15:20 */ @Entity -@Table(name = "role_privileges", indexes = {@Index(name = "idx_role_privileges_role_id", columnList = "role_id"), - @Index(name = "idx_role_privileges_privilege_id", columnList = "privilege_id")}) -public class RolePrivileges extends AuditMetadata { +@Table(name = "role_privileges") +public class RolePrivileges { + + /** + * 主键 + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; /** * role主键 */ @Column(name = "role_id", nullable = false) private Long roleId; + /** * 资源主键 */ @@ -44,6 +47,14 @@ public class RolePrivileges extends AuditMetadata { private Long privilegeId; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public Long getRoleId() { return roleId; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java index 32b55805..b2482da0 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java @@ -20,30 +20,27 @@ import io.leafage.basic.hypervisor.audit.AuditMetadata; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Index; import jakarta.persistence.Table; -import java.time.Instant; - /** * model class for user. * * @author wq li 2020-12-20 9:54 */ @Entity -@Table(name = "users", indexes = {@Index(name = "uni_users_username", columnList = "username")}) +@Table(name = "users") public class User extends AuditMetadata { /** * user */ - @Column(name = "username", nullable = false, unique = true) + @Column(name = "username", nullable = false, unique = true, length = 50) private String username; /** * password */ - @Column(name = "password", nullable = false) + @Column(name = "password", nullable = false, length = 50) private String password; /** @@ -61,36 +58,6 @@ public class User extends AuditMetadata { */ private String avatar; - /** - * 有效 - */ - @Column(name = "account_non_expired") - private boolean accountNonExpired = true; - - /** - * 有效期 - */ - @Column(name = "account_expires_at") - private Instant accountExpiresAt; - - /** - * 未锁定 - */ - @Column(name = "account_non_locked") - private boolean accountNonLocked = true; - - /** - * 密码有效 - */ - @Column(name = "credentials_non_expired") - private boolean credentialsNonExpired = true; - - /** - * 密码有效期 - */ - @Column(name = "credentials_expires_at") - private Instant credentialsExpiresAt; - public String getUsername() { return username; @@ -132,43 +99,4 @@ public void setAvatar(String avatar) { this.avatar = avatar; } - public boolean isAccountNonExpired() { - return accountNonExpired; - } - - public void setAccountNonExpired(boolean accountNonExpired) { - this.accountNonExpired = accountNonExpired; - } - - public Instant getAccountExpiresAt() { - return accountExpiresAt; - } - - public void setAccountExpiresAt(Instant accountExpiresAt) { - this.accountExpiresAt = accountExpiresAt; - } - - public boolean isAccountNonLocked() { - return accountNonLocked; - } - - public void setAccountNonLocked(boolean accountNonLocked) { - this.accountNonLocked = accountNonLocked; - } - - public boolean isCredentialsNonExpired() { - return credentialsNonExpired; - } - - public void setCredentialsNonExpired(boolean credentialsNonExpired) { - this.credentialsNonExpired = credentialsNonExpired; - } - - public Instant getCredentialsExpiresAt() { - return credentialsExpiresAt; - } - - public void setCredentialsExpiresAt(Instant credentialsExpiresAt) { - this.credentialsExpiresAt = credentialsExpiresAt; - } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupMembersRepository.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupMembersRepository.java index fa4066ab..1d46fa6b 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupMembersRepository.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupMembersRepository.java @@ -46,11 +46,4 @@ public interface GroupMembersRepository extends JpaRepository findByUsername(String username); - /** - * 统计关联user - * - * @param groupId groupID - * @return 用户数 - */ - long countByGroupIdAndEnabledTrue(Long groupId); } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupRolesRepository.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupRolesRepository.java deleted file mode 100644 index 0ec075b7..00000000 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/GroupRolesRepository.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package io.leafage.basic.hypervisor.repository; - -import io.leafage.basic.hypervisor.domain.GroupRoles; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * group roles repository. - * - * @author wq li 2018/12/17 19:37 - **/ -@Repository -public interface GroupRolesRepository extends JpaRepository { - - /** - * 根据group查user - * - * @param groupId group主键 - * @return 关联数据集 - */ - List findByGroupId(Long groupId); - - /** - * 根据user查group - * - * @param roleId role主键 - * @return 关联数据集 - */ - List findByRoleId(Long roleId); - - /** - * 统计关联user - * - * @param groupId groupID - * @return 用户数 - */ - long countByGroupIdAndEnabledTrue(Long groupId); -} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RoleMembersRepository.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RoleMembersRepository.java index 32096ccd..65f480db 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RoleMembersRepository.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RoleMembersRepository.java @@ -46,11 +46,4 @@ public interface RoleMembersRepository extends JpaRepository */ List findByRoleId(Long roleId); - /** - * 统计关联user - * - * @param roleId role主键 - * @return 用户数 - */ - long countByRoleIdAndEnabledTrue(Long roleId); } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RolePrivilegesRepository.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RolePrivilegesRepository.java index 9ffd89d7..4cd2013d 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RolePrivilegesRepository.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/repository/RolePrivilegesRepository.java @@ -46,11 +46,4 @@ public interface RolePrivilegesRepository extends JpaRepository findByPrivilegeId(Long privilegeId); - /** - * 统计关联privilege - * - * @param roleId role主键 - * @return 用户数 - */ - long countByRoleIdAndEnabledTrue(Long roleId); } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupRolesService.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupRolesService.java deleted file mode 100644 index 14db4d7c..00000000 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupRolesService.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.hypervisor.service; - -import io.leafage.basic.hypervisor.domain.GroupRoles; - -import java.util.List; -import java.util.Set; - -/** - * group roles service. - * - * @author wq li 2024/2/2 15:20 - **/ -public interface GroupRolesService { - - /** - * 查询关联 role - * - * @param groupId group主键 - * @return 数据集 - */ - List roles(Long groupId); - - /** - * 查询关联 group - * - * @param roleId 主键 - * @return 数据集 - */ - List groups(Long roleId); - - /** - * 保存用户-group关系 - * - * @param groupId group主键 - * @param roleIds roleId集合 - * @return 结果集 - */ - List relation(Long groupId, Set roleIds); -} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupService.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupService.java index 2be3bfdc..dcf4bb10 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupService.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/GroupService.java @@ -19,11 +19,8 @@ import io.leafage.basic.hypervisor.dto.GroupDTO; import io.leafage.basic.hypervisor.vo.GroupVO; import org.springframework.data.domain.Page; -import top.leafage.common.TreeNode; import top.leafage.common.servlet.ServletBasicService; -import java.util.List; - /** * group service. * @@ -41,10 +38,4 @@ public interface GroupService extends ServletBasicService { */ Page retrieve(int page, int size, String sort); - /** - * 获取树结构数据 - * - * @return 树结构数据集 - */ - List tree(); } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImpl.java deleted file mode 100644 index be11f14b..00000000 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.hypervisor.service.impl; - -import io.leafage.basic.hypervisor.domain.GroupRoles; -import io.leafage.basic.hypervisor.repository.GroupRolesRepository; -import io.leafage.basic.hypervisor.service.GroupRolesService; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Set; - -/** - * group roles service impl. - * - * @author wq li 2024/2/2 15:20 - **/ -public class GroupRolesServiceImpl implements GroupRolesService { - - private final GroupRolesRepository groupRolesRepository; - - public GroupRolesServiceImpl(GroupRolesRepository groupRolesRepository) { - this.groupRolesRepository = groupRolesRepository; - } - - @Override - public List roles(Long groupId) { - return groupRolesRepository.findByGroupId(groupId); - } - - @Override - public List groups(Long roleId) { - return groupRolesRepository.findByRoleId(roleId); - } - - @Override - public List relation(Long groupId, Set roleIds) { - Assert.notNull(groupId, "group id must not be null."); - Assert.notEmpty(roleIds, "role ids must not be empty."); - - List groupRoles = roleIds.stream().map(roleId -> { - GroupRoles groupRole = new GroupRoles(); - groupRole.setGroupId(groupId); - groupRole.setRoleId(roleId); - return groupRole; - }).toList(); - return groupRolesRepository.saveAllAndFlush(groupRoles); - } -} diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java index 0e5c4a14..15e62a58 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java @@ -45,7 +45,7 @@ * @author wq li 2018/12/17 19:25 **/ @Service -public class GroupServiceImpl extends ServletAbstractTreeNodeService implements GroupService { +public class GroupServiceImpl implements GroupService { private final GroupRepository groupRepository; @@ -59,19 +59,6 @@ public Page retrieve(int page, int size, String sort) { return groupRepository.findAll(pageable).map(this::convertOuter); } - @Override - public List tree() { - List groups = groupRepository.findByEnabledTrue(); - if (!CollectionUtils.isEmpty(groups)) { - return groups.stream().filter(g -> g.getSuperiorId() == null).map(g -> { - TreeNode treeNode = new TreeNode(g.getId(), g.getName()); - treeNode.setChildren(this.convert(groups)); - return treeNode; - }).toList(); - } - return Collections.emptyList(); - } - @Override public GroupVO create(GroupDTO dto) { Group group = new Group(); diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java index 18c3252f..bc1b1568 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java @@ -28,7 +28,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import top.leafage.common.servlet.ServletAbstractTreeNodeService; import java.time.Instant; import java.util.Optional; @@ -39,7 +38,7 @@ * @author wq li 2022/1/26 15:20 **/ @Service -public class MessageServiceImpl extends ServletAbstractTreeNodeService implements MessageService { +public class MessageServiceImpl implements MessageService { private final MessageRepository messageRepository; diff --git a/hypervisor/src/main/resources/application.yaml b/hypervisor/src/main/resources/application.yaml index a9f652ed..114d3770 100644 --- a/hypervisor/src/main/resources/application.yaml +++ b/hypervisor/src/main/resources/application.yaml @@ -16,9 +16,6 @@ spring: jpa: open-in-view: false - generate-ddl: true - hibernate: - ddl-auto: create security: oauth2: diff --git a/hypervisor/src/main/resources/sql/table-ddl.sql b/hypervisor/src/main/resources/sql/table-ddl.sql index 1b79a86e..0d86c31b 100644 --- a/hypervisor/src/main/resources/sql/table-ddl.sql +++ b/hypervisor/src/main/resources/sql/table-ddl.sql @@ -3,231 +3,361 @@ DROP TABLE IF EXISTS groups; -- Create table groups CREATE TABLE groups ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - name varchar(64) NOT NULL UNIQUE COMMENT '名称', - principal varchar(16) COMMENT '负责人', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + group_name varchar(50) NOT NULL, + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50), + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50), + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE groups IS '用户组表'; +COMMENT ON COLUMN groups.id IS '主键'; +COMMENT ON COLUMN groups.group_name IS '名称'; +COMMENT ON COLUMN groups.enabled IS '是否启用'; +COMMENT ON COLUMN groups.created_by IS '创建者'; +COMMENT ON COLUMN groups.created_date IS '创建时间'; +COMMENT ON COLUMN groups.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN groups.last_modified_date IS '最后修改时间'; -- Drop table if exists users DROP TABLE IF EXISTS users; -- Create table users CREATE TABLE users ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - username varchar(16) NOT NULL UNIQUE COMMENT '用户名', - password varchar(255) NOT NULL COMMENT '密码', - firstname varchar(16) COMMENT '名字', - lastname varchar(16) COMMENT '姓氏', - avatar varchar(127) COMMENT '头像', - account_expires_at timestamp COMMENT '账号过期时间', - credentials_expires_at timestamp COMMENT '凭证过期时间', - account_non_locked boolean NOT NULL DEFAULT true COMMENT '账号是否非锁定', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + username varchar(50) UNIQUE NOT NULL, + password varchar(50) NOT NULL, + firstname varchar(16), + lastname varchar(16), + avatar varchar(127), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50), + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50), + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE users IS '用户表'; +COMMENT ON COLUMN users.id IS '主键'; +COMMENT ON COLUMN users.username IS '用户名'; +COMMENT ON COLUMN users.password IS '密码'; +COMMENT ON COLUMN users.firstname IS '名字'; +COMMENT ON COLUMN users.lastname IS '姓氏'; +COMMENT ON COLUMN users.avatar IS '头像'; +COMMENT ON COLUMN users.enabled IS '是否启用'; +COMMENT ON COLUMN users.created_by IS '创建者'; +COMMENT ON COLUMN users.created_date IS '创建时间'; +COMMENT ON COLUMN users.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN users.last_modified_date IS '最后修改时间'; + +-- Drop table if exists authorities +DROP TABLE IF EXISTS authorities; + +-- Create table authorities +CREATE TABLE authorities ( + id bigserial PRIMARY KEY NOT NULL, + username varchar(50) not null, + authority varchar(50) not null, + CONSTRAINT fk_authorities_users FOREIGN KEY(username) references users(username) +); + +-- Add comment to the table and columns +COMMENT ON TABLE authorities IS '用户权限表'; +COMMENT ON COLUMN authorities.id IS '主键'; +COMMENT ON COLUMN authorities.username IS '用户名'; +COMMENT ON COLUMN authorities.authority IS '权限'; + +-- Create unique index +CREATE UNIQUE INDEX ix_auth_username ON authorities (username, authority); -- Drop table if exists roles DROP TABLE IF EXISTS roles; -- Create table roles CREATE TABLE roles ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - name varchar(64) NOT NULL UNIQUE COMMENT '名称', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + name varchar(50) NOT NULL, + description varchar(512), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50), + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50), + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE roles IS '角色表'; +COMMENT ON COLUMN roles.id IS '主键'; +COMMENT ON COLUMN roles.name IS '名称'; +COMMENT ON COLUMN roles.description IS '描述'; +COMMENT ON COLUMN roles.enabled IS '是否启用'; +COMMENT ON COLUMN roles.created_by IS '创建者'; +COMMENT ON COLUMN roles.created_date IS '创建时间'; +COMMENT ON COLUMN roles.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN roles.last_modified_date IS '最后修改时间'; -- Drop table if exists group_members DROP TABLE IF EXISTS group_members; -- Create table group_members CREATE TABLE group_members ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - group_id bigint NOT NULL COMMENT '用户组ID', - username varchar(32) NOT NULL COMMENT '用户名', - CONSTRAINT fk_group_members_group FOREIGN KEY (group_id) REFERENCES groups(id), - CONSTRAINT fk_group_members_username FOREIGN KEY (username) REFERENCES users(username) + id bigserial PRIMARY KEY NOT NULL, + group_id bigint NOT NULL, + username varchar(50) NOT NULL, + CONSTRAINT fk_group_members_group foreign key(group_id) references groups(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE group_members IS '用户组成员关系表'; +COMMENT ON COLUMN group_members.id IS '主键'; +COMMENT ON COLUMN group_members.group_id IS '用户组ID'; +COMMENT ON COLUMN group_members.username IS '用户名'; + +-- Drop table if exists group_authorities +DROP TABLE IF EXISTS group_authorities; + +-- Create table group_authorities +CREATE TABLE group_authorities ( + id bigserial PRIMARY KEY NOT NULL, + group_id bigint NOT NULL, + authority varchar(50) NOT NULL, + CONSTRAINT fk_group_authorities_group FOREIGN KEY(group_id) references groups(id) +); --- Drop table if exists group_roles -DROP TABLE IF EXISTS group_roles; - --- Create table group_roles -CREATE TABLE group_roles ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - group_id bigint NOT NULL COMMENT '用户组ID', - role_id bigint NOT NULL COMMENT '角色ID', - CONSTRAINT fk_group_roles_group FOREIGN KEY (group_id) REFERENCES groups(id), - CONSTRAINT fk_group_roles_role FOREIGN KEY (role_id) REFERENCES roles(id) +-- Add comment to the table and columns +COMMENT ON TABLE group_authorities IS '用户组权限关系表'; +COMMENT ON COLUMN group_authorities.id IS '主键'; +COMMENT ON COLUMN group_authorities.group_id IS '用户组ID'; +COMMENT ON COLUMN group_authorities.authority IS '权限'; + +-- Drop table if exists persistent_logins +DROP TABLE IF EXISTS persistent_logins; + +-- Create table persistent_logins +CREATE TABLE persistent_logins ( + username varchar(64) not null, + series varchar(64) primary key, + token varchar(64) not null, + last_used timestamp not null ); --- Add comment to the table -COMMENT ON TABLE group_roles IS '用户组角色关系表'; +-- Add comment to the table and columns +COMMENT ON TABLE persistent_logins IS '持久化登录表'; +COMMENT ON COLUMN persistent_logins.username IS '用户名'; +COMMENT ON COLUMN persistent_logins.series IS '系列'; +COMMENT ON COLUMN persistent_logins.token IS '令牌'; +COMMENT ON COLUMN persistent_logins.last_used IS '最后使用时间'; -- Drop table if exists role_members DROP TABLE IF EXISTS role_members; -- Create table role_members CREATE TABLE role_members ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - role_id bigint NOT NULL COMMENT '角色ID', - username varchar(32) NOT NULL COMMENT '用户名', - CONSTRAINT fk_role_members_role FOREIGN KEY (role_id) REFERENCES roles(id), - CONSTRAINT fk_role_members_username FOREIGN KEY (username) REFERENCES users(username) + id bigserial PRIMARY KEY NOT NULL, + role_id bigint NOT NULL, + username varchar(50) NOT NULL, + CONSTRAINT fk_role_members_role FOREIGN KEY (role_id) REFERENCES roles(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE role_members IS '角色成员关系表'; +COMMENT ON COLUMN role_members.id IS '主键'; +COMMENT ON COLUMN role_members.role_id IS '角色ID'; +COMMENT ON COLUMN role_members.username IS '用户名'; -- Drop table if exists privileges DROP TABLE IF EXISTS privileges; -- Create table privileges CREATE TABLE privileges ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - superior_id bigint COMMENT '上级ID', - name varchar(64) NOT NULL COMMENT '名称', - type character(1) NOT NULL COMMENT '类型', - path varchar(127) COMMENT '路径', - icon varchar(127) COMMENT '图标', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + superior_id bigint, + name varchar(50) NOT NULL, + type character(1) NOT NULL, + path varchar(127), + icon varchar(127), + description varchar(512), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50) NOT NULL, + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE privileges IS '权限表'; +COMMENT ON COLUMN privileges.id IS '主键'; +COMMENT ON COLUMN privileges.superior_id IS '上级ID'; +COMMENT ON COLUMN privileges.name IS '名称'; +COMMENT ON COLUMN privileges.type IS '类型'; +COMMENT ON COLUMN privileges.path IS '路径'; +COMMENT ON COLUMN privileges.icon IS '图标'; +COMMENT ON COLUMN privileges.description IS '描述'; +COMMENT ON COLUMN privileges.enabled IS '是否启用'; +COMMENT ON COLUMN privileges.created_by IS '创建者'; +COMMENT ON COLUMN privileges.created_date IS '创建时间'; +COMMENT ON COLUMN privileges.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN privileges.last_modified_date IS '最后修改时间'; -- Drop table if exists role_privileges DROP TABLE IF EXISTS role_privileges; -- Create table role_privileges CREATE TABLE role_privileges ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - role_id bigint NOT NULL COMMENT '角色ID', - privilege_id bigint NOT NULL COMMENT '权限ID', + id bigserial PRIMARY KEY NOT NULL, + role_id bigint NOT NULL, + privilege_id bigint NOT NULL, CONSTRAINT fk_role_privileges_role FOREIGN KEY (role_id) REFERENCES roles(id), CONSTRAINT fk_role_privileges_privilege FOREIGN KEY (privilege_id) REFERENCES privileges(id) ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE role_privileges IS '角色权限关系表'; +COMMENT ON COLUMN role_privileges.id IS '主键'; +COMMENT ON COLUMN role_privileges.role_id IS '角色ID'; +COMMENT ON COLUMN role_privileges.privilege_id IS '权限ID'; -- Drop table if exists dictionaries DROP TABLE IF EXISTS dictionaries; -- Create table dictionaries CREATE TABLE dictionaries ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - name varchar(64) NOT NULL COMMENT '名称', - superior_id bigint COMMENT '上级ID', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + name varchar(50) NOT NULL, + superior_id bigint, + description varchar(512), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50) NOT NULL, + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE dictionaries IS '字典表'; +COMMENT ON COLUMN dictionaries.id IS '主键'; +COMMENT ON COLUMN dictionaries.name IS '名称'; +COMMENT ON COLUMN dictionaries.superior_id IS '上级ID'; +COMMENT ON COLUMN dictionaries.description IS '描述'; +COMMENT ON COLUMN dictionaries.enabled IS '是否启用'; +COMMENT ON COLUMN dictionaries.created_by IS '创建者'; +COMMENT ON COLUMN dictionaries.created_date IS '创建时间'; +COMMENT ON COLUMN dictionaries.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN dictionaries.last_modified_date IS '最后修改时间'; -- Drop table if exists messages DROP TABLE IF EXISTS messages; -- Create table messages CREATE TABLE messages ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - title varchar(255) NOT NULL COMMENT '标题', - context text COMMENT '内容', - is_read boolean NOT NULL DEFAULT false COMMENT - -- 是否已读 - receiver varchar(32) NOT NULL COMMENT '接收者', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + title varchar(255) NOT NULL, + context text, + is_read boolean NOT NULL DEFAULT false, + receiver varchar(50) NOT NULL, + description varchar(512), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50) NOT NULL, + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE messages IS '消息表'; +COMMENT ON COLUMN messages.id IS '主键'; +COMMENT ON COLUMN messages.title IS '标题'; +COMMENT ON COLUMN messages.context IS '内容'; +COMMENT ON COLUMN messages.is_read IS '是否已读'; +COMMENT ON COLUMN messages.receiver IS '接收者'; +COMMENT ON COLUMN messages.description IS '描述'; +COMMENT ON COLUMN messages.enabled IS '是否启用'; +COMMENT ON COLUMN messages.created_by IS '创建者'; +COMMENT ON COLUMN messages.created_date IS '创建时间'; +COMMENT ON COLUMN messages.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN messages.last_modified_date IS '最后修改时间'; -- Drop table if exists regions DROP TABLE IF EXISTS regions; -- Create table regions CREATE TABLE regions ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - name varchar(64) NOT NULL COMMENT '名称', - superior_id bigint COMMENT '上级ID', - postal_code bigint COMMENT '邮政编码', - area_code bigint COMMENT '区号', - description varchar(512) COMMENT '描述', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + name varchar(50) NOT NULL, + superior_id bigint, + postal_code bigint, + area_code bigint, + description varchar(512), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50) NOT NULL, + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50) NOT NULL, + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE regions IS '地区表'; +COMMENT ON COLUMN regions.id IS '主键'; +COMMENT ON COLUMN regions.name IS '名称'; +COMMENT ON COLUMN regions.superior_id IS '上级ID'; +COMMENT ON COLUMN regions.postal_code IS '邮政编码'; +COMMENT ON COLUMN regions.area_code IS '区号'; +COMMENT ON COLUMN regions.description IS '描述'; +COMMENT ON COLUMN regions.enabled IS '是否启用'; +COMMENT ON COLUMN regions.created_by IS '创建者'; +COMMENT ON COLUMN regions.created_date IS '创建时间'; +COMMENT ON COLUMN regions.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN regions.last_modified_date IS '最后修改时间'; -- Drop table if exists access_logs DROP TABLE IF EXISTS access_logs; -- Create table access_logs CREATE TABLE access_logs ( - id bigserial PRIMARY KEY NOT NULL COMMENT '主键', - ip inet COMMENT 'IP地址', - location varchar(127) COMMENT '位置', - context text COMMENT '内容', - user_agent varchar(255) COMMENT '用户代理信息', - http_method varchar(10) COMMENT 'HTTP方法', - url text COMMENT '请求URL', - status_code integer COMMENT 'HTTP状态码', - response_time bigint COMMENT '响应时间', - referer varchar(255) COMMENT '来源页面', - session_id varchar(50) COMMENT '会话标识符', - device_type varchar(20) COMMENT '设备类型', - os varchar(50) COMMENT '操作系统', - browser varchar(50) COMMENT '浏览器', - enabled boolean NOT NULL DEFAULT true COMMENT '是否启用', - created_by varchar(32) NOT NULL COMMENT '创建者', - created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - last_modified_by varchar(32) NOT NULL COMMENT '最后修改者', - last_modified_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间' + id bigserial PRIMARY KEY NOT NULL, + ip inet, + location varchar(127), + context text, + user_agent varchar(255), + http_method varchar(10), + url text, + status_code integer, + response_time bigint, + referer varchar(255), + session_id varchar(50), + device_type varchar(20), + os varchar(50), + browser varchar(50), + enabled boolean NOT NULL DEFAULT true, + created_by varchar(50), + created_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_modified_by varchar(50), + last_modified_date timestamp ); --- Add comment to the table +-- Add comment to the table and columns COMMENT ON TABLE access_logs IS '访问日志表'; +COMMENT ON COLUMN access_logs.id IS '主键'; +COMMENT ON COLUMN access_logs.ip IS 'IP地址'; +COMMENT ON COLUMN access_logs.location IS '位置'; +COMMENT ON COLUMN access_logs.context IS '内容'; +COMMENT ON COLUMN access_logs.user_agent IS '用户代理信息'; +COMMENT ON COLUMN access_logs.http_method IS 'HTTP方法'; +COMMENT ON COLUMN access_logs.url IS '请求URL'; +COMMENT ON COLUMN access_logs.status_code IS 'HTTP状态码'; +COMMENT ON COLUMN access_logs.response_time IS '响应时间'; +COMMENT ON COLUMN access_logs.referer IS '来源页面'; +COMMENT ON COLUMN access_logs.session_id IS '会话标识符'; +COMMENT ON COLUMN access_logs.device_type IS '设备类型'; +COMMENT ON COLUMN access_logs.os IS '操作系统'; +COMMENT ON COLUMN access_logs.browser IS '浏览器'; +COMMENT ON COLUMN access_logs.enabled IS '是否启用'; +COMMENT ON COLUMN access_logs.created_by IS '创建者'; +COMMENT ON COLUMN access_logs.created_date IS '创建时间'; +COMMENT ON COLUMN access_logs.last_modified_by IS '最后修改者'; +COMMENT ON COLUMN access_logs.last_modified_date IS '最后修改时间'; + diff --git a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImplTest.java b/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImplTest.java deleted file mode 100644 index 30f6ed80..00000000 --- a/hypervisor/src/test/java/io/leafage/basic/hypervisor/service/impl/GroupRolesServiceImplTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2018-2024 little3201. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.leafage.basic.hypervisor.service.impl; - -import io.leafage.basic.hypervisor.domain.GroupRoles; -import io.leafage.basic.hypervisor.repository.GroupRolesRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; -import java.util.Set; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - - -/** - * group roles service test. - * - * @author wq li 2024/2/2 15:38 - **/ -@ExtendWith(MockitoExtension.class) -class GroupRolesServiceImplTest { - - @Mock - private GroupRolesRepository groupRolesRepository; - - @InjectMocks - private GroupRolesServiceImpl groupRolesService; - - @Test - void roles() { - given(this.groupRolesRepository.findByGroupId(Mockito.anyLong())).willReturn(List.of(Mockito.mock(GroupRoles.class))); - - List roles = groupRolesService.roles(Mockito.anyLong()); - Assertions.assertNotNull(roles); - } - - @Test - void groups() { - given(this.groupRolesRepository.findByRoleId(Mockito.anyLong())).willReturn(List.of(Mockito.mock(GroupRoles.class))); - - List groups = groupRolesService.groups(Mockito.anyLong()); - Assertions.assertNotNull(groups); - } - - @Test - void relation() { - given(this.groupRolesRepository.saveAllAndFlush(Mockito.anyCollection())).willReturn(Mockito.anyList()); - - List relation = groupRolesService.relation(1L, Set.of(1L)); - - verify(this.groupRolesRepository, times(1)).saveAllAndFlush(Mockito.anyList()); - Assertions.assertNotNull(relation); - } -} \ No newline at end of file From 080749cd782a3fb73fa2cbb41696bd6b4a6dd673 Mon Sep 17 00:00:00 2001 From: wq Date: Mon, 25 Mar 2024 22:54:25 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6=E4=B8=BA127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/config/AuthorizationServerConfiguration.java | 8 +++++++- .../java/io/leafage/basic/hypervisor/domain/User.java | 2 +- hypervisor/src/main/resources/sql/table-ddl.sql | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java index 5030637a..4743f85e 100644 --- a/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java +++ b/auth/src/main/java/io/leafage/auth/config/AuthorizationServerConfiguration.java @@ -29,6 +29,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.jwt.JwtDecoder; @@ -51,6 +52,7 @@ import java.security.KeyPairGenerator; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; +import java.util.List; import java.util.UUID; import static org.springframework.security.config.Customizer.withDefaults; @@ -100,7 +102,11 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h @Bean UserDetailsService userDetailsService(DataSource dataSource) { JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager(dataSource); - jdbcUserDetailsManager.createUser(User.withUsername("admin").password("123456").accountLocked(true).roles("ADMIN").build()); + if (!jdbcUserDetailsManager.userExists("admin")) { + jdbcUserDetailsManager.createUser(User.withUsername("admin").password("123456").roles("ADMIN").build()); + jdbcUserDetailsManager.addUserToGroup("admin", "manager"); + } + return jdbcUserDetailsManager; } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java index b2482da0..cca5c11d 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/domain/User.java @@ -40,7 +40,7 @@ public class User extends AuditMetadata { /** * password */ - @Column(name = "password", nullable = false, length = 50) + @Column(name = "password", nullable = false, length = 127) private String password; /** diff --git a/hypervisor/src/main/resources/sql/table-ddl.sql b/hypervisor/src/main/resources/sql/table-ddl.sql index 0d86c31b..f617a8a6 100644 --- a/hypervisor/src/main/resources/sql/table-ddl.sql +++ b/hypervisor/src/main/resources/sql/table-ddl.sql @@ -29,7 +29,7 @@ DROP TABLE IF EXISTS users; CREATE TABLE users ( id bigserial PRIMARY KEY NOT NULL, username varchar(50) UNIQUE NOT NULL, - password varchar(50) NOT NULL, + password varchar(127) NOT NULL, firstname varchar(16), lastname varchar(16), avatar varchar(127),