diff --git a/.idea/excise-demo.iml b/.idea/excise-demo.iml index d6ebd48..b107a2d 100644 --- a/.idea/excise-demo.iml +++ b/.idea/excise-demo.iml @@ -2,7 +2,9 @@ - + + + diff --git a/demo/demo/README.md b/demo/demo/README.md index 4cc70b3..cfc681f 100644 --- a/demo/demo/README.md +++ b/demo/demo/README.md @@ -52,4 +52,17 @@ 若无指定,则统计到当天日期 -4、统计角色关联的用户数 \ No newline at end of file +4、统计角色关联的用户数 + + + + +修改 MySQL 密码:123456->Mm,123456 + +修改 Redis 密码为:123456-> + +完成了日志框架的配置 + +以 jar 的方式部署到 Linux 上,并启动 + +完善了部分接口:同一父节点下名称不能重复 \ No newline at end of file diff --git a/demo/demo/pom.xml b/demo/demo/pom.xml index 49252ff..6a6bf61 100644 --- a/demo/demo/pom.xml +++ b/demo/demo/pom.xml @@ -5,11 +5,14 @@ com.example demo 0.0.1-SNAPSHOT + jar demo demo 1.8 UTF-8 + + UTF-8 2.6.13 @@ -79,6 +82,23 @@ pagehelper-spring-boot-starter 1.4.7 + + + + + + + + + + + + + + + + + @@ -110,7 +130,7 @@ ${spring-boot.version} demo.DemoApplication - true + false @@ -123,5 +143,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/demo/src/main/java/demo/Controller/CaseInfoController.java b/demo/demo/src/main/java/demo/Controller/CaseInfoController.java index 2bcf928..647d191 100644 --- a/demo/demo/src/main/java/demo/Controller/CaseInfoController.java +++ b/demo/demo/src/main/java/demo/Controller/CaseInfoController.java @@ -103,7 +103,6 @@ public class CaseInfoController { } caseInfo.setNodeId(caseInfoVO.getNodeId() != null ? caseInfoVO.getNodeId() : caseInfo.getNodeId()); caseInfo.setEditor(caseInfoVO.getEditor() != null ? caseInfoVO.getEditor() : caseInfo.getEditor()); - log.info(caseInfo.getEditor()); caseInfoService.update(caseInfo); return Result.success("更新用例成功"); } diff --git a/demo/demo/src/main/java/demo/Controller/CaseTreeController.java b/demo/demo/src/main/java/demo/Controller/CaseTreeController.java index 437cb20..1e62b85 100644 --- a/demo/demo/src/main/java/demo/Controller/CaseTreeController.java +++ b/demo/demo/src/main/java/demo/Controller/CaseTreeController.java @@ -20,15 +20,19 @@ public class CaseTreeController { @PostMapping("/insert") public Result insertNode(@Valid CaseTreeVO caseTreeVO) { - //确认新建节点名称未被占用 - CaseTree caseTree = caseTreeService.findByNodeName(caseTreeVO.getNodeName()); - if(caseTree == null) { - caseTreeService.addNode(caseTreeVO.getNodeName(), caseTreeVO.getParentNodeId(), caseTreeVO.getCreator()); - return Result.success("新建节点成功"); - } - else{ - return Result.error(401,"节点已存在"); + if(caseTreeVO.getParentNodeId() != null) { + //同一父节点下名称不能重复 + List caseTreeList = caseTreeService.findByNodeNameAll(caseTreeVO.getNodeName()); + for(CaseTree caseTree : caseTreeList) { + if(caseTree.getIsLeaf() == 0)continue; + Integer parentNodeId = caseTree.getParentNodeId(); + if(parentNodeId == caseTreeVO.getParentNodeId()) { + return Result.error(401,"同一父节点下名称不能重复"); + } + } } + caseTreeService.addNode(caseTreeVO.getNodeName(), caseTreeVO.getParentNodeId(), caseTreeVO.getCreator()); + return Result.success("新建节点成功"); } @DeleteMapping("/delete") diff --git a/demo/demo/src/main/java/demo/Controller/LogController.java b/demo/demo/src/main/java/demo/Controller/LogController.java new file mode 100644 index 0000000..bc9b330 --- /dev/null +++ b/demo/demo/src/main/java/demo/Controller/LogController.java @@ -0,0 +1,21 @@ +package demo.Controller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class LogController { + private Logger log = LoggerFactory.getLogger(LogController.class); + + @RequestMapping("/testLog") + public String testLog(String msg) { + log.info("这是info信息:{}", msg); + log.debug("这是debug信息:{}", msg); + log.warn("这是warn信息:{}", msg); + log.error("这是error信息:{}", msg); + return "success"; + } +} diff --git a/demo/demo/src/main/java/demo/Controller/RoleController.java b/demo/demo/src/main/java/demo/Controller/RoleController.java index 2b89a98..897e036 100644 --- a/demo/demo/src/main/java/demo/Controller/RoleController.java +++ b/demo/demo/src/main/java/demo/Controller/RoleController.java @@ -3,19 +3,12 @@ package demo.Controller; import demo.Entity.*; import demo.Service.RoleService; import demo.Service.UserRoleService; -import lombok.Value; import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.Date; import java.util.List; @Slf4j @@ -85,7 +78,6 @@ public class RoleController { @GetMapping("/query") public Result> queryRole() { List roleList = roleService.findAll(); - log.info("Retrieved roles: {}", roleList); return Result.success(roleList); } diff --git a/demo/demo/src/main/java/demo/Controller/UserController.java b/demo/demo/src/main/java/demo/Controller/UserController.java index 0db1c72..3bc9ad2 100644 --- a/demo/demo/src/main/java/demo/Controller/UserController.java +++ b/demo/demo/src/main/java/demo/Controller/UserController.java @@ -1,7 +1,6 @@ package demo.Controller; import demo.Entity.*; -import demo.Service.RoleService; import demo.Service.UserRoleService; import demo.Service.UserService; import lombok.extern.slf4j.Slf4j; @@ -14,10 +13,6 @@ import javax.transaction.Transactional; import javax.validation.Valid; import javax.validation.constraints.Pattern; import java.time.Duration; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.Date; import java.util.List; @Slf4j diff --git a/demo/demo/src/main/java/demo/Controller/UserRoleController.java b/demo/demo/src/main/java/demo/Controller/UserRoleController.java index ee25163..40c8b91 100644 --- a/demo/demo/src/main/java/demo/Controller/UserRoleController.java +++ b/demo/demo/src/main/java/demo/Controller/UserRoleController.java @@ -1,22 +1,9 @@ package demo.Controller; -import demo.Entity.*; -import demo.Service.RoleService; -import lombok.Value; import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Param; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.Date; -import java.util.List; - @Slf4j @RestController @RequestMapping("/role") diff --git a/demo/demo/src/main/java/demo/Mapper/CaseTreeMapper.java b/demo/demo/src/main/java/demo/Mapper/CaseTreeMapper.java index 4325031..9cc2b90 100644 --- a/demo/demo/src/main/java/demo/Mapper/CaseTreeMapper.java +++ b/demo/demo/src/main/java/demo/Mapper/CaseTreeMapper.java @@ -16,8 +16,9 @@ public interface CaseTreeMapper { @Select("SELECT * FROM case_tree WHERE NODE_NAME = #{nodeName}") CaseTree findByNodeName(@Param("nodeName") String nodeName); - @Insert("INSERT INTO case_tree (NODE_NAME, ID_PATH, CREATOR, CREATE_TIME, EDITOR, UPDATE_TIME) VALUES (#{nodeName}, NULL, #{creator}, NOW(), #{creator}, NOW())") - void addNode(@Param("nodeName") String nodeName, @Param("creator") String creator); + @Insert("INSERT INTO case_tree (NODE_NAME, CREATOR, CREATE_TIME, UPDATE_TIME) VALUES (#{nodeName}, #{creator}, NOW(), NOW())") + @Options(useGeneratedKeys = true, keyProperty = "id") + void addNode(CaseTree caseTree); @Update("UPDATE case_tree SET PARENT_NODE_ID = #{parentNodeId}, IS_LEAF = #{isLeaf} WHERE ID = #{id}") void set(@Param("id") Integer id, @Param("parentNodeId") Integer parentNodeId, @Param("isLeaf") Integer isLeaf); @@ -36,4 +37,7 @@ public interface CaseTreeMapper { @Select("SELECT * FROM case_tree") List findAll(); + + @Select("SELECT * FROM case_tree WHERE NODE_NAME = #{nodeName}") + List findByNodeNameAll(@Param("nodeName") String nodeName); } \ No newline at end of file diff --git a/demo/demo/src/main/java/demo/Mapper/RoleMapper.java b/demo/demo/src/main/java/demo/Mapper/RoleMapper.java index 6d513ce..dcf5fcb 100644 --- a/demo/demo/src/main/java/demo/Mapper/RoleMapper.java +++ b/demo/demo/src/main/java/demo/Mapper/RoleMapper.java @@ -11,7 +11,7 @@ import java.util.List; @Mapper public interface RoleMapper { - @Insert("insert into role(ROLE_NAME, ROLE_CODE, CREATE_TIME, UPDATE_TIME) values(#{roleName}, #{roleCode}, NOW(), NOW()") + @Insert("insert into role(ROLE_NAME, ROLE_CODE, CREATE_TIME, UPDATE_TIME) values(#{roleName}, #{roleCode}, NOW(), NOW())") void insert(@Param("roleName") String roleName, @Param("roleCode") String roleCode); @Select("select * from role where ROLE_NAME = #{roleName}") diff --git a/demo/demo/src/main/java/demo/Service/CaseTreeService.java b/demo/demo/src/main/java/demo/Service/CaseTreeService.java index 8397b42..5d7824d 100644 --- a/demo/demo/src/main/java/demo/Service/CaseTreeService.java +++ b/demo/demo/src/main/java/demo/Service/CaseTreeService.java @@ -15,17 +15,26 @@ public class CaseTreeService { @Autowired private CaseTreeMapper caseTreeMapper; + public List findByNodeNameAll(String nodeName) { + return caseTreeMapper.findByNodeNameAll(nodeName); + } + @Transactional(rollbackOn = Exception.class) public void addNode(String nodeName, Integer parentNodeId, String creator) { if(parentNodeId == null) { - caseTreeMapper.addNode(nodeName, creator); - CaseTree caseTree = caseTreeMapper.findByNodeName(nodeName); + CaseTree caseTree = new CaseTree(); + caseTree.setNodeName(nodeName); + caseTree.setCreator(creator); + caseTreeMapper.addNode(caseTree); caseTreeMapper.set(caseTree.getId(), caseTree.getId(), 0); caseTreeMapper.setPath(caseTree.getId(), caseTree.getId() + ""); } else { - caseTreeMapper.addNode(nodeName, creator); - CaseTree caseTree = caseTreeMapper.findByNodeName(nodeName); + CaseTree caseTree = new CaseTree(); + caseTree.setNodeName(nodeName); + caseTree.setParentNodeId(parentNodeId); + caseTree.setCreator(creator); + caseTreeMapper.addNode(caseTree); caseTreeMapper.set(caseTree.getId(), parentNodeId, 0); CaseTree parentNode = caseTreeMapper.findByNodeId(parentNodeId); caseTreeMapper.setIsLeaf(parentNodeId, parentNode.getIsLeaf() + 1); diff --git a/demo/demo/src/main/resources/application.yml b/demo/demo/src/main/resources/application.yml index 9ea702a..789b4ae 100644 --- a/demo/demo/src/main/resources/application.yml +++ b/demo/demo/src/main/resources/application.yml @@ -3,13 +3,15 @@ server: spring: datasource: username: root - password: 123456 + password: Mm,123456 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test_repo +# url: jdbc:mysql://192.168.137.128:3306/test_repo redis: - host: localhost + host: localhsot +# host: 192.168.137.128 port: 6379 - password: 123456 # 如果没有密码,可以省略 + password: # 如果没有密码,可以省略 database: 0 # 默认数据库索引 timeout: 5000ms # 连接超时时间 diff --git a/demo/demo/src/main/resources/logback.xml b/demo/demo/src/main/resources/logback.xml new file mode 100644 index 0000000..a596909 --- /dev/null +++ b/demo/demo/src/main/resources/logback.xml @@ -0,0 +1,209 @@ + + + + + + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n + + + + + + + ERROR + DENY + ACCEPT + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n + + + ${LOG_HOME}/.%d{yyyy-MM-dd}-info.log + 30 + + + + + + + ERROR + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n + + + ${LOG_HOME}/.%d{yyyy-MM-dd}-error.log + 30 + + + + + + 0 + 256 + + + + + 0 + 256 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sql/db.sql b/sql/db.sql new file mode 100644 index 0000000..95b1a8b --- /dev/null +++ b/sql/db.sql @@ -0,0 +1,78 @@ +drop database if exists test_repo; + +create database test_repo; + +use test_repo; + +drop table if exists case_info; + +create table case_info +( + ID tinyint auto_increment comment '主键' + primary key, + CASE_NAME varchar(100) charset utf8mb3 null comment '用例名称', + NODE_ID tinyint not null comment '用例树节点', + CREATOR varchar(32) charset utf8mb3 null comment '创建人', + CREATE_TIME datetime null comment '创建时间', + EDITOR varchar(32) charset utf8mb3 null comment '修改人', + UPDATE_TIME datetime null comment '修改时间' +) + comment '用例信息表'; + +drop table if exists case_tree; + +create table case_tree +( + ID tinyint auto_increment comment '主键' + primary key, + NODE_NAME varchar(50) charset utf8mb3 null comment '树节点名称', + PARENT_NODE_ID tinyint null comment '父节点ID', + IS_LEAF tinyint default 0 not null comment '是否叶子节点(0-是)', + ID_PATH varchar(350) charset utf8mb3 null comment 'ID全路径', + CREATOR varchar(32) charset utf8mb3 null comment '创建人', + CREATE_TIME datetime null comment '创建时间', + EDITOR varchar(32) charset utf8mb3 null comment '修改人', + UPDATE_TIME datetime null comment '修改时间' +) + comment '用例树表'; + +drop table if exists role; + +create table role +( + ID tinyint auto_increment comment '主键' + primary key, + ROLE_NAME varchar(50) charset utf8mb3 null comment '角色名称', + ROLE_CODE varchar(50) charset utf8mb3 null comment '角色代号(英文代号)', + CREATE_TIME datetime null comment '创建时间', + UPDATE_TIME datetime null comment '更新时间', + constraint ROLE_CODE + unique (ROLE_CODE) +) + comment '角色表'; + +drop table if exists user; + +create table user +( + ID tinyint auto_increment comment '主键' + primary key, + LOGIN_NAME varchar(50) charset utf8mb3 null comment '用户登录名', + USER_CHN_NAME varchar(50) charset utf8mb3 null comment '用户中文名称', + CREATE_TIME datetime null comment '创建时间', + UPDATE_TIME datetime null comment '更新时间', + PASSWORD varchar(16) default '123456' not null comment '密码' +) + comment '用户信息表'; + +drop table if exists user_role_relation; + +create table user_role_relation +( + ID tinyint auto_increment comment '主键' + primary key, + USER_ID tinyint null comment '用户ID', + ROLE_ID tinyint null comment '角色ID', + CREATE_TIME datetime null comment '创建时间' +) + comment '用户-角色关系表'; \ No newline at end of file