diff --git a/README.md b/README.md index d1dc21c..1d04e67 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,15 @@ ### 主要框架 -| 技术 | 说明 | 官网 | -| -------------- | ------------ | ------------------------------------------------------------ | -| SpringBoot | 后端框架 | [https://spring.io/projects/spring-boot](https://spring.io/projects/spring-boot) | -| SpringSecurity | 登录认证 | [https://spring.io/projects/spring-security](https://spring.io/projects/spring-security) | -| jjwt | 生成Token | [https://github.com/jwtk/jjwt](https://github.com/jwtk/jjwt) | -| MyBatis-Plus | ORM框架 | [https://baomidou.com/pages/24112f/](https://baomidou.com/pages/24112f/) | -| oshi-core | 获取本机信息 | [https://github.com/oshi/oshi](https://github.com/oshi/oshi) | -| hutool-all | 工具包 | [https://github.com/dromara/hutool](https://github.com/dromara/hutool) | -| jsch | 连接控制台 | [http://www.jcraft.com/jsch/](http://www.jcraft.com/jsch/) | +| 技术 | 说明 | 官网 | +|----------------|---------|------------------------------------------------------------------------------------------| +| SpringBoot | 后端框架 | [https://spring.io/projects/spring-boot](https://spring.io/projects/spring-boot) | +| SpringSecurity | 登录认证 | [https://spring.io/projects/spring-security](https://spring.io/projects/spring-security) | +| jjwt | 生成Token | [https://github.com/jwtk/jjwt](https://github.com/jwtk/jjwt) | +| MyBatis-Plus | ORM框架 | [https://baomidou.com/pages/24112f/](https://baomidou.com/pages/24112f/) | +| oshi-core | 获取本机信息 | [https://github.com/oshi/oshi](https://github.com/oshi/oshi) | +| hutool-all | 工具包 | [https://github.com/dromara/hutool](https://github.com/dromara/hutool) | +| jsch | 连接控制台 | [http://www.jcraft.com/jsch/](http://www.jcraft.com/jsch/) | ### 中间件&其他服务 diff --git a/pom.xml b/pom.xml index 465a263..8729a68 100644 --- a/pom.xml +++ b/pom.xml @@ -9,12 +9,12 @@ com.mzaxd - Noodles + BPS 0.0.1-SNAPSHOT - Noodles - Noodles + BPS-Server + BPS-Server - 1.8 + 17 @@ -30,10 +30,11 @@ org.springframework.boot spring-boot-starter-data-redis + - com.mysql - mysql-connector-j - runtime + com.alibaba + druid-spring-boot-starter + 1.2.15 @@ -55,7 +56,7 @@ com.alibaba fastjson - 1.2.33 + 1.2.83 @@ -84,10 +85,6 @@ springfox-swagger-ui 2.9.2 - - org.springframework.boot - spring-boot-starter-amqp - org.apache.commons commons-lang3 @@ -107,28 +104,11 @@ org.springframework.boot spring-boot-starter-aop - - - org.lionsoul - ip2region - 2.7.0 - cn.hutool hutool-all - 5.3.7 - - - javax.mail - mail - 1.4.7 - - - - com.alibaba - easyexcel - 3.2.1 + 5.8.24 @@ -143,12 +123,6 @@ ganymed-ssh2 262 - - - de.codecentric - spring-boot-admin-starter-client - 2.7.8 - diff --git a/src/main/java/com/mzaxd/noodles/NoodlesApplication.java b/src/main/java/com/mzaxd/bps/BPSApplication.java similarity index 59% rename from src/main/java/com/mzaxd/noodles/NoodlesApplication.java rename to src/main/java/com/mzaxd/bps/BPSApplication.java index 814a90f..68fb94e 100644 --- a/src/main/java/com/mzaxd/noodles/NoodlesApplication.java +++ b/src/main/java/com/mzaxd/bps/BPSApplication.java @@ -1,9 +1,8 @@ -package com.mzaxd.noodles; +package com.mzaxd.bps; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.scheduling.annotation.EnableScheduling; /** @@ -11,11 +10,11 @@ import org.springframework.scheduling.annotation.EnableScheduling; */ @SpringBootApplication @EnableScheduling -@MapperScan("com.mzaxd.noodles.mapper") -public class NoodlesApplication { +@MapperScan("com.mzaxd.bps.mapper") +public class BPSApplication { public static void main(String[] args) { - SpringApplication.run(NoodlesApplication.class, args); + SpringApplication.run(BPSApplication.class, args); } } diff --git a/src/main/java/com/mzaxd/noodles/annotation/SysLog.java b/src/main/java/com/mzaxd/bps/annotation/SysLog.java similarity index 72% rename from src/main/java/com/mzaxd/noodles/annotation/SysLog.java rename to src/main/java/com/mzaxd/bps/annotation/SysLog.java index b327858..d052529 100644 --- a/src/main/java/com/mzaxd/noodles/annotation/SysLog.java +++ b/src/main/java/com/mzaxd/bps/annotation/SysLog.java @@ -1,6 +1,6 @@ -package com.mzaxd.noodles.annotation; +package com.mzaxd.bps.annotation; -import com.mzaxd.noodles.enums.OperationEnum; +import com.mzaxd.bps.enums.OperationEnum; import java.lang.annotation.*; diff --git a/src/main/java/com/mzaxd/noodles/aspect/SysLogAspect.java b/src/main/java/com/mzaxd/bps/aspect/SysLogAspect.java similarity index 69% rename from src/main/java/com/mzaxd/noodles/aspect/SysLogAspect.java rename to src/main/java/com/mzaxd/bps/aspect/SysLogAspect.java index 56c0e88..de4232d 100644 --- a/src/main/java/com/mzaxd/noodles/aspect/SysLogAspect.java +++ b/src/main/java/com/mzaxd/bps/aspect/SysLogAspect.java @@ -1,10 +1,10 @@ -package com.mzaxd.noodles.aspect; +package com.mzaxd.bps.aspect; import com.alibaba.fastjson.JSON; -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.entity.AuditLog; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.AuditLogService; +import com.mzaxd.bps.annotation.SysLog; +import com.mzaxd.bps.domain.entity.AuditLog; +import com.mzaxd.bps.service.AuditLogService; +import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -14,19 +14,19 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Method; -import java.time.LocalDateTime; /** * @author 13439 */ @Component @Aspect +@Slf4j public class SysLogAspect { @Resource private AuditLogService auditLogService; - @Pointcut("@annotation(com.mzaxd.noodles.annotation.SysLog)") + @Pointcut("@annotation(com.mzaxd.bps.annotation.SysLog)") public void logPointCut() { } @@ -45,24 +45,24 @@ public class SysLogAspect { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); - AuditLog log = new AuditLog(); + AuditLog auditLog = new AuditLog(); SysLog syslog = method.getAnnotation(SysLog.class); if (syslog != null) { //注解上的描述 - log.setOperation(syslog.operation().getOperation()); - log.setOperationType(syslog.operation().getOperationType()); + auditLog.setOperation(syslog.operation().getOperation()); + auditLog.setOperationType(syslog.operation().getOperationType()); } //请求的参数 Object[] args = joinPoint.getArgs(); try { String params = JSON.toJSONString(args); - log.setParam(params); + auditLog.setParam(params); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); } //保存系统日志 - auditLogService.save(log); + auditLogService.save(auditLog); } } diff --git a/src/main/java/com/mzaxd/noodles/config/FastJsonRedisSerializer.java b/src/main/java/com/mzaxd/bps/config/FastJsonRedisSerializer.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/config/FastJsonRedisSerializer.java rename to src/main/java/com/mzaxd/bps/config/FastJsonRedisSerializer.java index 7075f42..16fc36f 100644 --- a/src/main/java/com/mzaxd/noodles/config/FastJsonRedisSerializer.java +++ b/src/main/java/com/mzaxd/bps/config/FastJsonRedisSerializer.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.parser.ParserConfig; @@ -53,4 +53,4 @@ public class FastJsonRedisSerializer implements RedisSerializer { protected JavaType getJavaType(Class clazz) { return TypeFactory.defaultInstance().constructType(clazz); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/MyBatisPlusConfig.java b/src/main/java/com/mzaxd/bps/config/MyBatisPlusConfig.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/config/MyBatisPlusConfig.java rename to src/main/java/com/mzaxd/bps/config/MyBatisPlusConfig.java index 3904253..33f3b3b 100644 --- a/src/main/java/com/mzaxd/noodles/config/MyBatisPlusConfig.java +++ b/src/main/java/com/mzaxd/bps/config/MyBatisPlusConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; @@ -23,4 +23,4 @@ public class MyBatisPlusConfig { mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); return mybatisPlusInterceptor; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/RedisConfig.java b/src/main/java/com/mzaxd/bps/config/RedisConfig.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/config/RedisConfig.java rename to src/main/java/com/mzaxd/bps/config/RedisConfig.java index 26f8b16..1e1ffb5 100644 --- a/src/main/java/com/mzaxd/noodles/config/RedisConfig.java +++ b/src/main/java/com/mzaxd/bps/config/RedisConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,4 +28,4 @@ public class RedisConfig { template.afterPropertiesSet(); return template; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/RestTemplateConfig.java b/src/main/java/com/mzaxd/bps/config/RestTemplateConfig.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/config/RestTemplateConfig.java rename to src/main/java/com/mzaxd/bps/config/RestTemplateConfig.java index 1e4c4d6..77b159a 100644 --- a/src/main/java/com/mzaxd/noodles/config/RestTemplateConfig.java +++ b/src/main/java/com/mzaxd/bps/config/RestTemplateConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/mzaxd/noodles/config/SecurityConfig.java b/src/main/java/com/mzaxd/bps/config/SecurityConfig.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/config/SecurityConfig.java rename to src/main/java/com/mzaxd/bps/config/SecurityConfig.java index fdaf3a4..3468c5e 100644 --- a/src/main/java/com/mzaxd/noodles/config/SecurityConfig.java +++ b/src/main/java/com/mzaxd/bps/config/SecurityConfig.java @@ -1,11 +1,10 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; -import com.mzaxd.noodles.filter.JwtAuthenticationTokenFilter; +import com.mzaxd.bps.filter.JwtAuthenticationTokenFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; diff --git a/src/main/java/com/mzaxd/noodles/config/SwaggerConfig.java b/src/main/java/com/mzaxd/bps/config/SwaggerConfig.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/config/SwaggerConfig.java rename to src/main/java/com/mzaxd/bps/config/SwaggerConfig.java index 0c8f582..811ab9d 100644 --- a/src/main/java/com/mzaxd/noodles/config/SwaggerConfig.java +++ b/src/main/java/com/mzaxd/bps/config/SwaggerConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -23,7 +23,7 @@ public class SwaggerConfig { .build(); } private ApiInfo apiInfo() { - Contact contact = new Contact("一个人的团队", "http://www.my.com", "my@my.com"); + Contact contact = new Contact("一个人的团队", "https://www.my.com", "my@my.com"); return new ApiInfoBuilder() .title("文档标题") .description("文档描述") @@ -31,4 +31,4 @@ public class SwaggerConfig { .version("1.0.0") // 版本 .build(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/WebConfig.java b/src/main/java/com/mzaxd/bps/config/WebConfig.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/config/WebConfig.java rename to src/main/java/com/mzaxd/bps/config/WebConfig.java index f0a8d92..996fe76 100644 --- a/src/main/java/com/mzaxd/noodles/config/WebConfig.java +++ b/src/main/java/com/mzaxd/bps/config/WebConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializerFeature; @@ -47,8 +47,7 @@ public class WebConfig implements WebMvcConfigurer { fastJsonConfig.setSerializeConfig(SerializeConfig.globalInstance); fastConverter.setFastJsonConfig(fastJsonConfig); - HttpMessageConverter converter = fastConverter; - return converter; + return fastConverter; } @Override @@ -56,4 +55,4 @@ public class WebConfig implements WebMvcConfigurer { converters.add(fastJsonHttpMessageConverters()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/WebSocketConfig.java b/src/main/java/com/mzaxd/bps/config/WebSocketConfig.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/config/WebSocketConfig.java rename to src/main/java/com/mzaxd/bps/config/WebSocketConfig.java index 8f85a3e..a6d9c8e 100644 --- a/src/main/java/com/mzaxd/noodles/config/WebSocketConfig.java +++ b/src/main/java/com/mzaxd/bps/config/WebSocketConfig.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.config; +package com.mzaxd.bps.config; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.web.servlet.ServletContextInitializer; diff --git a/src/main/java/com/mzaxd/noodles/constant/OsConstant.java b/src/main/java/com/mzaxd/bps/constant/OsConstant.java similarity index 82% rename from src/main/java/com/mzaxd/noodles/constant/OsConstant.java rename to src/main/java/com/mzaxd/bps/constant/OsConstant.java index 70796f8..46bb90c 100644 --- a/src/main/java/com/mzaxd/noodles/constant/OsConstant.java +++ b/src/main/java/com/mzaxd/bps/constant/OsConstant.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.constant; +package com.mzaxd.bps.constant; /** * @author Mzaxd diff --git a/src/main/java/com/mzaxd/noodles/constant/RabbitMqConstant.java b/src/main/java/com/mzaxd/bps/constant/RabbitMqConstant.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/constant/RabbitMqConstant.java rename to src/main/java/com/mzaxd/bps/constant/RabbitMqConstant.java index 56e14af..48990b7 100644 --- a/src/main/java/com/mzaxd/noodles/constant/RabbitMqConstant.java +++ b/src/main/java/com/mzaxd/bps/constant/RabbitMqConstant.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.constant; +package com.mzaxd.bps.constant; /** * @author root diff --git a/src/main/java/com/mzaxd/noodles/constant/RedisConstant.java b/src/main/java/com/mzaxd/bps/constant/RedisConstant.java similarity index 95% rename from src/main/java/com/mzaxd/noodles/constant/RedisConstant.java rename to src/main/java/com/mzaxd/bps/constant/RedisConstant.java index 13f3592..5e13156 100644 --- a/src/main/java/com/mzaxd/noodles/constant/RedisConstant.java +++ b/src/main/java/com/mzaxd/bps/constant/RedisConstant.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.constant; +package com.mzaxd.bps.constant; /** * @author root diff --git a/src/main/java/com/mzaxd/noodles/constant/SystemConstant.java b/src/main/java/com/mzaxd/bps/constant/SystemConstant.java similarity index 98% rename from src/main/java/com/mzaxd/noodles/constant/SystemConstant.java rename to src/main/java/com/mzaxd/bps/constant/SystemConstant.java index 2962ad6..055459f 100644 --- a/src/main/java/com/mzaxd/noodles/constant/SystemConstant.java +++ b/src/main/java/com/mzaxd/bps/constant/SystemConstant.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.constant; +package com.mzaxd.bps.constant; /** * @author root diff --git a/src/main/java/com/mzaxd/noodles/constant/UrlConstant.java b/src/main/java/com/mzaxd/bps/constant/UrlConstant.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/constant/UrlConstant.java rename to src/main/java/com/mzaxd/bps/constant/UrlConstant.java index d18ab62..315acd3 100644 --- a/src/main/java/com/mzaxd/noodles/constant/UrlConstant.java +++ b/src/main/java/com/mzaxd/bps/constant/UrlConstant.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.constant; +package com.mzaxd.bps.constant; /** * @author root diff --git a/src/main/java/com/mzaxd/noodles/controller/AuthController.java b/src/main/java/com/mzaxd/bps/controller/AuthController.java similarity index 56% rename from src/main/java/com/mzaxd/noodles/controller/AuthController.java rename to src/main/java/com/mzaxd/bps/controller/AuthController.java index 4df1e85..8eb4d1b 100644 --- a/src/main/java/com/mzaxd/noodles/controller/AuthController.java +++ b/src/main/java/com/mzaxd/bps/controller/AuthController.java @@ -1,10 +1,10 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.User; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.LoginService; +import com.mzaxd.bps.annotation.SysLog; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.User; +import com.mzaxd.bps.enums.OperationEnum; +import com.mzaxd.bps.service.LoginService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -20,23 +20,23 @@ public class AuthController { private LoginService loginService; @PostMapping("/login") - public ResponseResult login(@RequestBody User user) { + public ResponseResult login(@RequestBody User user) { return loginService.login(user); } @SysLog(operation = OperationEnum.USER_FIRST_USE) @PostMapping("/updateAccount") - public ResponseResult updateAccount(@RequestBody User user) { + public ResponseResult updateAccount(@RequestBody User user) { return loginService.updateAccount(user); } @PostMapping("/logout") - public ResponseResult logout() { + public ResponseResult logout() { return loginService.logout(); } @GetMapping("/deleteAccount") - public ResponseResult deleteAccount() { + public ResponseResult deleteAccount() { return loginService.deleteAccount(); } diff --git a/src/main/java/com/mzaxd/bps/controller/DashboardController.java b/src/main/java/com/mzaxd/bps/controller/DashboardController.java new file mode 100644 index 0000000..4c1c6af --- /dev/null +++ b/src/main/java/com/mzaxd/bps/controller/DashboardController.java @@ -0,0 +1,37 @@ +package com.mzaxd.bps.controller; + +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.service.DashboardService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author 13439 + */ + +@RestController +@RequestMapping("/dashboard") +public class DashboardController { + + @Resource + private DashboardService dashboardService; + + @GetMapping("/getInstancesRealTimeData") + public ResponseResult getInstancesRealTimeData() { + return dashboardService.getInstancesRealTimeData(); + } + + @GetMapping("/getRecentConsoleList") + public ResponseResult getRecentConsoleList() { + return dashboardService.getRecentConsoleList(); + } + + @GetMapping("/getAffectedServirList") + public ResponseResult getAffectedServirList() { + return dashboardService.getAffectedServirList(); + } + +} diff --git a/src/main/java/com/mzaxd/noodles/controller/LogController.java b/src/main/java/com/mzaxd/bps/controller/LogController.java similarity index 85% rename from src/main/java/com/mzaxd/noodles/controller/LogController.java rename to src/main/java/com/mzaxd/bps/controller/LogController.java index 8e81d49..886384d 100644 --- a/src/main/java/com/mzaxd/noodles/controller/LogController.java +++ b/src/main/java/com/mzaxd/bps/controller/LogController.java @@ -1,7 +1,7 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.service.AuditLogService; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.service.AuditLogService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; diff --git a/src/main/java/com/mzaxd/noodles/controller/NotificationController.java b/src/main/java/com/mzaxd/bps/controller/NotificationController.java similarity index 77% rename from src/main/java/com/mzaxd/noodles/controller/NotificationController.java rename to src/main/java/com/mzaxd/bps/controller/NotificationController.java index a1865de..c43a992 100644 --- a/src/main/java/com/mzaxd/noodles/controller/NotificationController.java +++ b/src/main/java/com/mzaxd/bps/controller/NotificationController.java @@ -1,14 +1,12 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.NotificationService; -import io.swagger.models.auth.In; +import com.mzaxd.bps.annotation.SysLog; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.enums.OperationEnum; +import com.mzaxd.bps.service.NotificationService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; /** * @author 13439 diff --git a/src/main/java/com/mzaxd/noodles/controller/OtherController.java b/src/main/java/com/mzaxd/bps/controller/OtherController.java similarity index 83% rename from src/main/java/com/mzaxd/noodles/controller/OtherController.java rename to src/main/java/com/mzaxd/bps/controller/OtherController.java index b415afb..5bdd974 100644 --- a/src/main/java/com/mzaxd/noodles/controller/OtherController.java +++ b/src/main/java/com/mzaxd/bps/controller/OtherController.java @@ -1,18 +1,14 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.search.SearchCategory; -import com.mzaxd.noodles.domain.search.SearchItem; -import com.mzaxd.noodles.util.SearchUtil; -import org.springframework.stereotype.Controller; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.search.SearchCategory; +import com.mzaxd.bps.domain.search.SearchItem; +import com.mzaxd.bps.util.SearchUtil; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/com/mzaxd/noodles/controller/SettingController.java b/src/main/java/com/mzaxd/bps/controller/SettingController.java similarity index 81% rename from src/main/java/com/mzaxd/noodles/controller/SettingController.java rename to src/main/java/com/mzaxd/bps/controller/SettingController.java index 18b796b..1af8841 100644 --- a/src/main/java/com/mzaxd/noodles/controller/SettingController.java +++ b/src/main/java/com/mzaxd/bps/controller/SettingController.java @@ -1,10 +1,10 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.vo.SmtpVo; -import com.mzaxd.noodles.domain.vo.SystemVo; -import com.mzaxd.noodles.domain.vo.TerminalVo; -import com.mzaxd.noodles.service.SystemSettingService; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.vo.SmtpVo; +import com.mzaxd.bps.domain.vo.SystemVo; +import com.mzaxd.bps.domain.vo.TerminalVo; +import com.mzaxd.bps.service.SystemSettingService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; diff --git a/src/main/java/com/mzaxd/noodles/controller/SystemController.java b/src/main/java/com/mzaxd/bps/controller/SystemController.java similarity index 77% rename from src/main/java/com/mzaxd/noodles/controller/SystemController.java rename to src/main/java/com/mzaxd/bps/controller/SystemController.java index 9ea8538..4ade8a1 100644 --- a/src/main/java/com/mzaxd/noodles/controller/SystemController.java +++ b/src/main/java/com/mzaxd/bps/controller/SystemController.java @@ -1,7 +1,7 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.service.UserService; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.service.UserService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/src/main/java/com/mzaxd/noodles/controller/UserController.java b/src/main/java/com/mzaxd/bps/controller/UserController.java similarity index 66% rename from src/main/java/com/mzaxd/noodles/controller/UserController.java rename to src/main/java/com/mzaxd/bps/controller/UserController.java index 8d720d9..4d91b25 100644 --- a/src/main/java/com/mzaxd/noodles/controller/UserController.java +++ b/src/main/java/com/mzaxd/bps/controller/UserController.java @@ -1,16 +1,14 @@ -package com.mzaxd.noodles.controller; +package com.mzaxd.bps.controller; -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.User; -import com.mzaxd.noodles.domain.vo.UserInfoVo; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.UserService; -import com.mzaxd.noodles.util.IpUtil; +import com.mzaxd.bps.annotation.SysLog; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.User; +import com.mzaxd.bps.domain.vo.UserInfoVo; +import com.mzaxd.bps.enums.OperationEnum; +import com.mzaxd.bps.service.UserService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.Map; /** @@ -33,12 +31,6 @@ public class UserController { return userService.updateUserInfo(user); } - @GetMapping("/profileHeader/{id}") - public ResponseResult profileHeader(@PathVariable("id") Integer id, HttpServletRequest request) { - String ipAddr = IpUtil.getIpAddr(request); - return userService.getProfileHeader(id, ipAddr); - } - @GetMapping("/profile") public ResponseResult profile() { return userService.getProfile(); @@ -62,4 +54,4 @@ public class UserController { } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/ResponseResult.java b/src/main/java/com/mzaxd/bps/domain/ResponseResult.java similarity index 54% rename from src/main/java/com/mzaxd/noodles/domain/ResponseResult.java rename to src/main/java/com/mzaxd/bps/domain/ResponseResult.java index 7889cd8..0298596 100644 --- a/src/main/java/com/mzaxd/noodles/domain/ResponseResult.java +++ b/src/main/java/com/mzaxd/bps/domain/ResponseResult.java @@ -1,13 +1,17 @@ -package com.mzaxd.noodles.domain; +package com.mzaxd.bps.domain; import com.fasterxml.jackson.annotation.JsonInclude; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import lombok.Getter; +import lombok.Setter; import java.io.Serializable; /** * @author Mzaxd */ +@Setter +@Getter @JsonInclude(JsonInclude.Include.NON_NULL) public class ResponseResult implements Serializable { private Integer code; @@ -35,49 +39,51 @@ public class ResponseResult implements Serializable { this.msg = msg; } - public static ResponseResult errorResult(int code, String msg) { - ResponseResult result = new ResponseResult(); + public static ResponseResult errorResult(int code, String msg) { + ResponseResult result = new ResponseResult<>(); return result.error(code, msg); } - public static ResponseResult okResult() { - ResponseResult result = new ResponseResult(); - return result; + + public static ResponseResult okResult() { + return (ResponseResult) new ResponseResult<>(); } - public static ResponseResult okResult(int code, String msg) { - ResponseResult result = new ResponseResult(); + + public static ResponseResult okResult(int code, String msg) { + ResponseResult result = new ResponseResult<>(); return result.ok(code, null, msg); } - public static ResponseResult okResult(String msg, Object data) { + + public static ResponseResult okResult(String msg, Object data) { ResponseResult result = setAppHttpCodeEnum(AppHttpCodeEnum.SUCCESS); result.setMsg(msg); - if(data!=null) { + if (data != null) { result.setData(data); } return result; } - public static ResponseResult okResult(Object data) { + public static ResponseResult okResult(Object data) { ResponseResult result = setAppHttpCodeEnum(AppHttpCodeEnum.SUCCESS, AppHttpCodeEnum.SUCCESS.getMsg()); - if(data!=null) { + if (data != null) { result.setData(data); } return result; } - public static ResponseResult errorResult(AppHttpCodeEnum enums){ - return setAppHttpCodeEnum(enums,enums.getMsg()); + public static ResponseResult errorResult(AppHttpCodeEnum enums) { + return setAppHttpCodeEnum(enums, enums.getMsg()); } - public static ResponseResult errorResult(AppHttpCodeEnum enums, String msg){ - return setAppHttpCodeEnum(enums,msg); + public static ResponseResult errorResult(AppHttpCodeEnum enums, String msg) { + return setAppHttpCodeEnum(enums, msg); } - public static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums){ - return okResult(enums.getCode(),enums.getMsg()); + public static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums) { + return okResult(enums.getCode(), enums.getMsg()); } - private static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums, String msg){ - return okResult(enums.getCode(),msg); + private static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums, String msg) { + return okResult(enums.getCode(), msg); } public ResponseResult error(Integer code, String msg) { @@ -104,28 +110,4 @@ public class ResponseResult implements Serializable { return this; } - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getMsg() { - return msg; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public T getData() { - return data; - } - - public void setData(T data) { - this.data = data; - } - -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/AuditLog.java b/src/main/java/com/mzaxd/bps/domain/entity/AuditLog.java similarity index 80% rename from src/main/java/com/mzaxd/noodles/domain/entity/AuditLog.java rename to src/main/java/com/mzaxd/bps/domain/entity/AuditLog.java index 309b839..db9b59e 100644 --- a/src/main/java/com/mzaxd/noodles/domain/entity/AuditLog.java +++ b/src/main/java/com/mzaxd/bps/domain/entity/AuditLog.java @@ -1,19 +1,16 @@ -package com.mzaxd.noodles.domain.entity; +package com.mzaxd.bps.domain.entity; import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; -import java.util.Objects; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import java.util.Date; + /** - * + * * @author 13439 * @TableName audit_log */ @@ -23,7 +20,7 @@ import lombok.experimental.Accessors; @AllArgsConstructor @Accessors(chain = true) @EqualsAndHashCode(of = "param") -public class AuditLog implements Serializable { +public class AuditLog { /** * id */ @@ -57,7 +54,4 @@ public class AuditLog implements Serializable { @TableField(fill = FieldFill.INSERT) private Long createBy; - @TableField(exist = false) - private static final long serialVersionUID = 1L; - -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/LoginUser.java b/src/main/java/com/mzaxd/bps/domain/entity/LoginUser.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/domain/entity/LoginUser.java rename to src/main/java/com/mzaxd/bps/domain/entity/LoginUser.java index 91e96fd..3ae287e 100644 --- a/src/main/java/com/mzaxd/noodles/domain/entity/LoginUser.java +++ b/src/main/java/com/mzaxd/bps/domain/entity/LoginUser.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.entity; +package com.mzaxd.bps.domain.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/Notification.java b/src/main/java/com/mzaxd/bps/domain/entity/Notification.java similarity index 86% rename from src/main/java/com/mzaxd/noodles/domain/entity/Notification.java rename to src/main/java/com/mzaxd/bps/domain/entity/Notification.java index 3f6b44b..698054f 100644 --- a/src/main/java/com/mzaxd/noodles/domain/entity/Notification.java +++ b/src/main/java/com/mzaxd/bps/domain/entity/Notification.java @@ -1,17 +1,15 @@ -package com.mzaxd.noodles.domain.entity; +package com.mzaxd.bps.domain.entity; import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import java.util.Date; + /** - * + * * @TableName notification */ @TableName(value ="notification") @@ -19,7 +17,7 @@ import lombok.experimental.Accessors; @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) -public class Notification implements Serializable { +public class Notification { /** * 主键id */ @@ -71,7 +69,4 @@ public class Notification implements Serializable { * 删除标志(0代表未删除,1代表已删除) */ private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/SystemSetting.java b/src/main/java/com/mzaxd/bps/domain/entity/SystemSetting.java similarity index 82% rename from src/main/java/com/mzaxd/noodles/domain/entity/SystemSetting.java rename to src/main/java/com/mzaxd/bps/domain/entity/SystemSetting.java index 0699bb4..a27ef04 100644 --- a/src/main/java/com/mzaxd/noodles/domain/entity/SystemSetting.java +++ b/src/main/java/com/mzaxd/bps/domain/entity/SystemSetting.java @@ -1,24 +1,21 @@ -package com.mzaxd.noodles.domain.entity; +package com.mzaxd.bps.domain.entity; import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** - * + * * @TableName system_setting */ @TableName(value ="system_setting") @Data @NoArgsConstructor @AllArgsConstructor -public class SystemSetting implements Serializable { +public class SystemSetting { /** * id */ @@ -80,6 +77,4 @@ public class SystemSetting implements Serializable { */ private String background; - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/User.java b/src/main/java/com/mzaxd/bps/domain/entity/User.java similarity index 86% rename from src/main/java/com/mzaxd/noodles/domain/entity/User.java rename to src/main/java/com/mzaxd/bps/domain/entity/User.java index cbe1e20..a7195c3 100644 --- a/src/main/java/com/mzaxd/noodles/domain/entity/User.java +++ b/src/main/java/com/mzaxd/bps/domain/entity/User.java @@ -1,21 +1,20 @@ -package com.mzaxd.noodles.domain.entity; +package com.mzaxd.bps.domain.entity; import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import lombok.experimental.Accessors; -import java.io.Serializable; import java.util.Date; /** - * + * * @author root * @TableName user */ @TableName(value ="user") @Data @Accessors(chain = true) -public class User implements Serializable { +public class User { /** * 主键id */ @@ -81,6 +80,4 @@ public class User implements Serializable { */ private Integer delFlag; - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/domain/message/Cpu.java b/src/main/java/com/mzaxd/bps/domain/message/Cpu.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/message/Cpu.java rename to src/main/java/com/mzaxd/bps/domain/message/Cpu.java index a491981..5b82aff 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/Cpu.java +++ b/src/main/java/com/mzaxd/bps/domain/message/Cpu.java @@ -1,6 +1,6 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; -import com.mzaxd.noodledetector.util.Arith; +import com.mzaxd.bps.util.Arith; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/message/DynamicData.java b/src/main/java/com/mzaxd/bps/domain/message/DynamicData.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/domain/message/DynamicData.java rename to src/main/java/com/mzaxd/bps/domain/message/DynamicData.java index b65f960..3c15d04 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/DynamicData.java +++ b/src/main/java/com/mzaxd/bps/domain/message/DynamicData.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/message/Mem.java b/src/main/java/com/mzaxd/bps/domain/message/Mem.java similarity index 83% rename from src/main/java/com/mzaxd/noodles/domain/message/Mem.java rename to src/main/java/com/mzaxd/bps/domain/message/Mem.java index 7ba2af1..f1ce6f2 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/Mem.java +++ b/src/main/java/com/mzaxd/bps/domain/message/Mem.java @@ -1,11 +1,10 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; /** * @author Mzaxd * @since 2023-02-05 10:50 */ -import com.mzaxd.noodledetector.util.Arith; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/message/NetWork.java b/src/main/java/com/mzaxd/bps/domain/message/NetWork.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/message/NetWork.java rename to src/main/java/com/mzaxd/bps/domain/message/NetWork.java index b235d59..48fcf57 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/NetWork.java +++ b/src/main/java/com/mzaxd/bps/domain/message/NetWork.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; /** * @author Mzaxd diff --git a/src/main/java/com/mzaxd/noodles/domain/message/Os.java b/src/main/java/com/mzaxd/bps/domain/message/Os.java similarity index 90% rename from src/main/java/com/mzaxd/noodles/domain/message/Os.java rename to src/main/java/com/mzaxd/bps/domain/message/Os.java index ff63d86..20fd284 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/Os.java +++ b/src/main/java/com/mzaxd/bps/domain/message/Os.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/message/Server.java b/src/main/java/com/mzaxd/bps/domain/message/Server.java similarity index 86% rename from src/main/java/com/mzaxd/noodles/domain/message/Server.java rename to src/main/java/com/mzaxd/bps/domain/message/Server.java index e70cb14..4a57256 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/Server.java +++ b/src/main/java/com/mzaxd/bps/domain/message/Server.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; /** * @author Mzaxd @@ -38,7 +38,7 @@ public class Server { /** * Os相关信息 */ - private com.mzaxd.noodles.domain.message.Os os = new Os(); + private com.mzaxd.bps.domain.message.Os os = new Os(); /** * CPU相关信息 @@ -58,7 +58,7 @@ public class Server { /** * 磁盘相关信息 */ - private List sysFiles = new LinkedList(); + private List sysFiles = new LinkedList<>(); /** * 网络相关信息 diff --git a/src/main/java/com/mzaxd/noodles/domain/message/Sys.java b/src/main/java/com/mzaxd/bps/domain/message/Sys.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/message/Sys.java rename to src/main/java/com/mzaxd/bps/domain/message/Sys.java index efec726..b4f6c15 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/Sys.java +++ b/src/main/java/com/mzaxd/bps/domain/message/Sys.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; /** * @author Mzaxd diff --git a/src/main/java/com/mzaxd/noodles/domain/message/SysFile.java b/src/main/java/com/mzaxd/bps/domain/message/SysFile.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/message/SysFile.java rename to src/main/java/com/mzaxd/bps/domain/message/SysFile.java index 5bff942..a2ef9de 100644 --- a/src/main/java/com/mzaxd/noodles/domain/message/SysFile.java +++ b/src/main/java/com/mzaxd/bps/domain/message/SysFile.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.message; +package com.mzaxd.bps.domain.message; /** * @author Mzaxd diff --git a/src/main/java/com/mzaxd/noodles/domain/search/SearchCategory.java b/src/main/java/com/mzaxd/bps/domain/search/SearchCategory.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/search/SearchCategory.java rename to src/main/java/com/mzaxd/bps/domain/search/SearchCategory.java index b7496fe..7c716c1 100644 --- a/src/main/java/com/mzaxd/noodles/domain/search/SearchCategory.java +++ b/src/main/java/com/mzaxd/bps/domain/search/SearchCategory.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.search; +package com.mzaxd.bps.domain.search; import com.alibaba.fastjson.annotation.JSONType; import lombok.Getter; diff --git a/src/main/java/com/mzaxd/noodles/domain/search/SearchItem.java b/src/main/java/com/mzaxd/bps/domain/search/SearchItem.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/search/SearchItem.java rename to src/main/java/com/mzaxd/bps/domain/search/SearchItem.java index d0b3998..0eaf721 100644 --- a/src/main/java/com/mzaxd/noodles/domain/search/SearchItem.java +++ b/src/main/java/com/mzaxd/bps/domain/search/SearchItem.java @@ -1,7 +1,6 @@ -package com.mzaxd.noodles.domain.search; +package com.mzaxd.bps.domain.search; import com.alibaba.fastjson.annotation.JSONType; -import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.ToString; diff --git a/src/main/java/com/mzaxd/noodles/domain/search/Url.java b/src/main/java/com/mzaxd/bps/domain/search/Url.java similarity index 91% rename from src/main/java/com/mzaxd/noodles/domain/search/Url.java rename to src/main/java/com/mzaxd/bps/domain/search/Url.java index 01fca30..5ffb691 100644 --- a/src/main/java/com/mzaxd/noodles/domain/search/Url.java +++ b/src/main/java/com/mzaxd/bps/domain/search/Url.java @@ -1,7 +1,6 @@ -package com.mzaxd.noodles.domain.search; +package com.mzaxd.bps.domain.search; import com.alibaba.fastjson.annotation.JSONType; -import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.ToString; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/AccountVo.java b/src/main/java/com/mzaxd/bps/domain/vo/AccountVo.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/domain/vo/AccountVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/AccountVo.java index 9912542..f0c1d3f 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/AccountVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/AccountVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/AffectedServirListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/AffectedServirListVo.java similarity index 95% rename from src/main/java/com/mzaxd/noodles/domain/vo/AffectedServirListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/AffectedServirListVo.java index f25a153..4f00554 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/AffectedServirListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/AffectedServirListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/AuditLogListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/AuditLogListVo.java similarity index 74% rename from src/main/java/com/mzaxd/noodles/domain/vo/AuditLogListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/AuditLogListVo.java index 3f2974f..7ae1eb8 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/AuditLogListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/AuditLogListVo.java @@ -1,9 +1,5 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ContainerSelectVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ContainerSelectVo.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/vo/ContainerSelectVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ContainerSelectVo.java index 0dc46b5..0def6af 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ContainerSelectVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ContainerSelectVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ContainerVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ContainerVo.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/domain/vo/ContainerVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ContainerVo.java index 4dda494..2dd0616 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ContainerVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ContainerVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineDrawerVo.java b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineDrawerVo.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/vo/HostMachineDrawerVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/HostMachineDrawerVo.java index 1c5f145..fcbddea 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineDrawerVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineDrawerVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineListVo.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/domain/vo/HostMachineListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/HostMachineListVo.java index d3dea9b..436c47a 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineVo.java b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineVo.java similarity index 91% rename from src/main/java/com/mzaxd/noodles/domain/vo/HostMachineVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/HostMachineVo.java index fd69f7e..0502b04 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/HostMachineVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/HostMachineVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/HostPanelVo.java b/src/main/java/com/mzaxd/bps/domain/vo/HostPanelVo.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/domain/vo/HostPanelVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/HostPanelVo.java index 6f62699..b4e8a36 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/HostPanelVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/HostPanelVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/HostVo.java b/src/main/java/com/mzaxd/bps/domain/vo/HostVo.java similarity index 95% rename from src/main/java/com/mzaxd/noodles/domain/vo/HostVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/HostVo.java index 47d0986..dd506c0 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/HostVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/HostVo.java @@ -1,6 +1,5 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import io.swagger.models.auth.In; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/NotificationListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/NotificationListVo.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/domain/vo/NotificationListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/NotificationListVo.java index 45ae383..2aac570 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/NotificationListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/NotificationListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/OsVo.java b/src/main/java/com/mzaxd/bps/domain/vo/OsVo.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/vo/OsVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/OsVo.java index b194c68..a87b82c 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/OsVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/OsVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ProfileHeaderVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ProfileHeaderVo.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/vo/ProfileHeaderVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ProfileHeaderVo.java index ce491d1..3367a60 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ProfileHeaderVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ProfileHeaderVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ProfileVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ProfileVo.java similarity index 84% rename from src/main/java/com/mzaxd/noodles/domain/vo/ProfileVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ProfileVo.java index 4a35ec5..7d3e010 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ProfileVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ProfileVo.java @@ -1,7 +1,5 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.TableField; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/RecentConsoleListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/RecentConsoleListVo.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/domain/vo/RecentConsoleListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/RecentConsoleListVo.java index 129c701..1cc8eba 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/RecentConsoleListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/RecentConsoleListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/SaveOrUpdateServirVo.java b/src/main/java/com/mzaxd/bps/domain/vo/SaveOrUpdateServirVo.java similarity index 72% rename from src/main/java/com/mzaxd/noodles/domain/vo/SaveOrUpdateServirVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/SaveOrUpdateServirVo.java index f33d06b..6704de2 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/SaveOrUpdateServirVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/SaveOrUpdateServirVo.java @@ -1,14 +1,9 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Date; import java.util.List; /** diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ServirContainerVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ServirContainerVo.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/domain/vo/ServirContainerVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ServirContainerVo.java index 8d9cf7d..9d6f214 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ServirContainerVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ServirContainerVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ServirHostVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ServirHostVo.java similarity index 77% rename from src/main/java/com/mzaxd/noodles/domain/vo/ServirHostVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ServirHostVo.java index 23add75..5ca7bfd 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ServirHostVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ServirHostVo.java @@ -1,7 +1,5 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/ServirListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/ServirListVo.java similarity index 95% rename from src/main/java/com/mzaxd/noodles/domain/vo/ServirListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/ServirListVo.java index dffe1e6..f190feb 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/ServirListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/ServirListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/SmtpVo.java b/src/main/java/com/mzaxd/bps/domain/vo/SmtpVo.java similarity index 91% rename from src/main/java/com/mzaxd/noodles/domain/vo/SmtpVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/SmtpVo.java index a5c3d0f..03322e7 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/SmtpVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/SmtpVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/SshLinkVo.java b/src/main/java/com/mzaxd/bps/domain/vo/SshLinkVo.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/domain/vo/SshLinkVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/SshLinkVo.java index 7fba0e1..b772a37 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/SshLinkVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/SshLinkVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/SystemVo.java b/src/main/java/com/mzaxd/bps/domain/vo/SystemVo.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/domain/vo/SystemVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/SystemVo.java index 24fe8be..674181a 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/SystemVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/SystemVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/TagVo.java b/src/main/java/com/mzaxd/bps/domain/vo/TagVo.java similarity index 83% rename from src/main/java/com/mzaxd/noodles/domain/vo/TagVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/TagVo.java index 568db32..43a1107 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/TagVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/TagVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/TerminalVo.java b/src/main/java/com/mzaxd/bps/domain/vo/TerminalVo.java similarity index 94% rename from src/main/java/com/mzaxd/noodles/domain/vo/TerminalVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/TerminalVo.java index afe533e..aad163e 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/TerminalVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/TerminalVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/UserInfoVo.java b/src/main/java/com/mzaxd/bps/domain/vo/UserInfoVo.java similarity index 72% rename from src/main/java/com/mzaxd/noodles/domain/vo/UserInfoVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/UserInfoVo.java index d7811c1..d16d8fd 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/UserInfoVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/UserInfoVo.java @@ -1,7 +1,5 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.Data; /** diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/VirtualMachineListVo.java b/src/main/java/com/mzaxd/bps/domain/vo/VirtualMachineListVo.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/domain/vo/VirtualMachineListVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/VirtualMachineListVo.java index b635bc1..93e1e4d 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/VirtualMachineListVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/VirtualMachineListVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/mzaxd/noodles/domain/vo/VmVo.java b/src/main/java/com/mzaxd/bps/domain/vo/VmVo.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/domain/vo/VmVo.java rename to src/main/java/com/mzaxd/bps/domain/vo/VmVo.java index 0fdd4c5..95d8009 100644 --- a/src/main/java/com/mzaxd/noodles/domain/vo/VmVo.java +++ b/src/main/java/com/mzaxd/bps/domain/vo/VmVo.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.domain.vo; +package com.mzaxd.bps.domain.vo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/mzaxd/noodles/enums/AppHttpCodeEnum.java b/src/main/java/com/mzaxd/bps/enums/AppHttpCodeEnum.java similarity index 89% rename from src/main/java/com/mzaxd/noodles/enums/AppHttpCodeEnum.java rename to src/main/java/com/mzaxd/bps/enums/AppHttpCodeEnum.java index 1b7f5ac..e1528d7 100644 --- a/src/main/java/com/mzaxd/noodles/enums/AppHttpCodeEnum.java +++ b/src/main/java/com/mzaxd/bps/enums/AppHttpCodeEnum.java @@ -1,9 +1,12 @@ -package com.mzaxd.noodles.enums; +package com.mzaxd.bps.enums; + +import lombok.Getter; /** * @author Mzaxd */ +@Getter public enum AppHttpCodeEnum { /** * 操作成功通用返回信息 @@ -55,11 +58,4 @@ public enum AppHttpCodeEnum { this.msg = errorMessage; } - public int getCode() { - return code; - } - - public String getMsg() { - return msg; - } } diff --git a/src/main/java/com/mzaxd/noodles/enums/OperationEnum.java b/src/main/java/com/mzaxd/bps/enums/OperationEnum.java similarity index 91% rename from src/main/java/com/mzaxd/noodles/enums/OperationEnum.java rename to src/main/java/com/mzaxd/bps/enums/OperationEnum.java index 9ea78a1..7100133 100644 --- a/src/main/java/com/mzaxd/noodles/enums/OperationEnum.java +++ b/src/main/java/com/mzaxd/bps/enums/OperationEnum.java @@ -1,4 +1,6 @@ -package com.mzaxd.noodles.enums; +package com.mzaxd.bps.enums; + +import lombok.Getter; /** * 操作日志-操作类型 @@ -6,6 +8,7 @@ package com.mzaxd.noodles.enums; * @author 13439 */ +@Getter public enum OperationEnum { /** @@ -111,11 +114,4 @@ public enum OperationEnum { this.operationType = operationType; } - public String getOperation() { - return operation; - } - - public String getOperationType() { - return operationType; - } } diff --git a/src/main/java/com/mzaxd/noodles/exception/SystemException.java b/src/main/java/com/mzaxd/bps/exception/SystemException.java similarity index 64% rename from src/main/java/com/mzaxd/noodles/exception/SystemException.java rename to src/main/java/com/mzaxd/bps/exception/SystemException.java index c9bb00a..5a0b4b5 100644 --- a/src/main/java/com/mzaxd/noodles/exception/SystemException.java +++ b/src/main/java/com/mzaxd/bps/exception/SystemException.java @@ -1,6 +1,7 @@ -package com.mzaxd.noodles.exception; +package com.mzaxd.bps.exception; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import lombok.Getter; /** * @@ -8,24 +9,17 @@ import com.mzaxd.noodles.enums.AppHttpCodeEnum; * @date 11/27/22 3:19 AM */ +@Getter public class SystemException extends RuntimeException{ private final int code; private final String msg; - public int getCode() { - return code; - } - - public String getMsg() { - return msg; - } - public SystemException(AppHttpCodeEnum httpCodeEnum) { super(httpCodeEnum.getMsg()); this.code = httpCodeEnum.getCode(); this.msg = httpCodeEnum.getMsg(); } - + } diff --git a/src/main/java/com/mzaxd/noodles/filter/JwtAuthenticationTokenFilter.java b/src/main/java/com/mzaxd/bps/filter/JwtAuthenticationTokenFilter.java similarity index 80% rename from src/main/java/com/mzaxd/noodles/filter/JwtAuthenticationTokenFilter.java rename to src/main/java/com/mzaxd/bps/filter/JwtAuthenticationTokenFilter.java index 8025798..502f51b 100644 --- a/src/main/java/com/mzaxd/noodles/filter/JwtAuthenticationTokenFilter.java +++ b/src/main/java/com/mzaxd/bps/filter/JwtAuthenticationTokenFilter.java @@ -1,13 +1,14 @@ -package com.mzaxd.noodles.filter; +package com.mzaxd.bps.filter; import com.alibaba.fastjson.JSON; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.LoginUser; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.util.JwtUtil; -import com.mzaxd.noodles.util.RedisCache; -import com.mzaxd.noodles.util.WebUtils; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.LoginUser; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.util.JwtUtil; +import com.mzaxd.bps.util.RedisCache; +import com.mzaxd.bps.util.WebUtils; import io.jsonwebtoken.Claims; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; @@ -26,6 +27,7 @@ import java.util.Objects; * @author root */ @Component +@Slf4j public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { @Resource @@ -45,10 +47,10 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { try { claims = JwtUtil.parseJWT(token); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); //token超时 token非法 //响应告诉前端需要重新登录 - ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN); + ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN); WebUtils.renderString(response, JSON.toJSONString(result)); return; } @@ -58,7 +60,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { //如果redis中没有用户信息 if (Objects.isNull(loginUser)) { //说明登录过期 需要重新登录 - ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN); + ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN); WebUtils.renderString(response, JSON.toJSONString(result)); return; } diff --git a/src/main/java/com/mzaxd/noodles/handler/AccessDeniedHandlerImpl.java b/src/main/java/com/mzaxd/bps/handler/AccessDeniedHandlerImpl.java similarity index 67% rename from src/main/java/com/mzaxd/noodles/handler/AccessDeniedHandlerImpl.java rename to src/main/java/com/mzaxd/bps/handler/AccessDeniedHandlerImpl.java index db998c7..ea7772c 100644 --- a/src/main/java/com/mzaxd/noodles/handler/AccessDeniedHandlerImpl.java +++ b/src/main/java/com/mzaxd/bps/handler/AccessDeniedHandlerImpl.java @@ -1,9 +1,10 @@ -package com.mzaxd.noodles.handler; +package com.mzaxd.bps.handler; import com.alibaba.fastjson.JSON; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.util.WebUtils; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.util.WebUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.stereotype.Component; @@ -16,12 +17,13 @@ import javax.servlet.http.HttpServletResponse; * @author root */ @Component +@Slf4j public class AccessDeniedHandlerImpl implements AccessDeniedHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws ServletException { - accessDeniedException.printStackTrace(); - ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NO_OPERATOR_AUTH); + log.error(accessDeniedException.getMessage()); + ResponseResult result = ResponseResult.errorResult(AppHttpCodeEnum.NO_OPERATOR_AUTH); //响应给前端 WebUtils.renderString(response, JSON.toJSONString(result)); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/handler/AuthenticationEntryPointImpl.java b/src/main/java/com/mzaxd/bps/handler/AuthenticationEntryPointImpl.java similarity index 83% rename from src/main/java/com/mzaxd/noodles/handler/AuthenticationEntryPointImpl.java rename to src/main/java/com/mzaxd/bps/handler/AuthenticationEntryPointImpl.java index bddb960..c315c94 100644 --- a/src/main/java/com/mzaxd/noodles/handler/AuthenticationEntryPointImpl.java +++ b/src/main/java/com/mzaxd/bps/handler/AuthenticationEntryPointImpl.java @@ -1,9 +1,10 @@ -package com.mzaxd.noodles.handler; +package com.mzaxd.bps.handler; import com.alibaba.fastjson.JSON; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.util.WebUtils; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.util.WebUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.InsufficientAuthenticationException; import org.springframework.security.core.AuthenticationException; @@ -17,14 +18,15 @@ import javax.servlet.http.HttpServletResponse; * @author root */ @Component +@Slf4j public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { - authException.printStackTrace(); + log.error(authException.getMessage()); //InsufficientAuthenticationException //BadCredentialsException - ResponseResult result; + ResponseResult result; if (authException instanceof BadCredentialsException) { result = ResponseResult.errorResult(AppHttpCodeEnum.LOGIN_ERROR.getCode(), authException.getMessage()); } else if (authException instanceof InsufficientAuthenticationException) { diff --git a/src/main/java/com/mzaxd/noodles/handler/GlobalExceptionHandler.java b/src/main/java/com/mzaxd/bps/handler/GlobalExceptionHandler.java similarity index 62% rename from src/main/java/com/mzaxd/noodles/handler/GlobalExceptionHandler.java rename to src/main/java/com/mzaxd/bps/handler/GlobalExceptionHandler.java index 63cf1b8..9f1c06e 100644 --- a/src/main/java/com/mzaxd/noodles/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/mzaxd/bps/handler/GlobalExceptionHandler.java @@ -1,8 +1,8 @@ -package com.mzaxd.noodles.handler; +package com.mzaxd.bps.handler; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.exception.SystemException; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -15,17 +15,17 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; public class GlobalExceptionHandler { @ExceptionHandler(SystemException.class) - public ResponseResult systemExceptionHandler(SystemException e) { + public ResponseResult systemExceptionHandler(SystemException e) { //打印异常信息 - log.error("出现了异常! {}", e); + log.error("出现了异常! {}", e.getMessage()); //从异常对象中获取提示信息封装返回 return ResponseResult.errorResult(e.getCode(), e.getMsg()); } @ExceptionHandler(Exception.class) - public ResponseResult exceptionHandler(Exception e) { + public ResponseResult exceptionHandler(Exception e) { //打印异常信息 - log.error("出现了异常! {}", e); + log.error("出现了异常! {}", e.getMessage()); //从异常对象中获取提示信息封装返回 return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, e.getMessage()); } diff --git a/src/main/java/com/mzaxd/noodles/handler/MyMetaObjectHandler.java b/src/main/java/com/mzaxd/bps/handler/MyMetaObjectHandler.java similarity index 88% rename from src/main/java/com/mzaxd/noodles/handler/MyMetaObjectHandler.java rename to src/main/java/com/mzaxd/bps/handler/MyMetaObjectHandler.java index d313673..51624f9 100644 --- a/src/main/java/com/mzaxd/noodles/handler/MyMetaObjectHandler.java +++ b/src/main/java/com/mzaxd/bps/handler/MyMetaObjectHandler.java @@ -1,7 +1,8 @@ -package com.mzaxd.noodles.handler; +package com.mzaxd.bps.handler; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import com.mzaxd.noodles.util.SecurityUtils; +import com.mzaxd.bps.util.SecurityUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.reflection.MetaObject; import org.springframework.stereotype.Component; @@ -10,6 +11,7 @@ import java.util.Date; /** * @author root */ +@Slf4j @Component public class MyMetaObjectHandler implements MetaObjectHandler { @Override @@ -18,7 +20,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { try { userId = SecurityUtils.getUserId(); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); //表示是自己创建 userId = -1L; } @@ -40,4 +42,4 @@ public class MyMetaObjectHandler implements MetaObjectHandler { this.setFieldValByName("updateTime", new Date(), metaObject); this.setFieldValByName("updateBy", userId, metaObject); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/mapper/AuditLogMapper.java b/src/main/java/com/mzaxd/bps/mapper/AuditLogMapper.java similarity index 65% rename from src/main/java/com/mzaxd/noodles/mapper/AuditLogMapper.java rename to src/main/java/com/mzaxd/bps/mapper/AuditLogMapper.java index 99f6b48..d181b1e 100644 --- a/src/main/java/com/mzaxd/noodles/mapper/AuditLogMapper.java +++ b/src/main/java/com/mzaxd/bps/mapper/AuditLogMapper.java @@ -1,13 +1,12 @@ -package com.mzaxd.noodles.mapper; +package com.mzaxd.bps.mapper; -import com.mzaxd.noodles.domain.entity.AuditLog; +import com.mzaxd.bps.domain.entity.AuditLog; import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** * @author 13439 * @description 针对表【audit_log】的数据库操作Mapper * @createDate 2023-02-13 12:19:26 -* @Entity com.mzaxd.noodles.domain.entity.AuditLog */ public interface AuditLogMapper extends BaseMapper { diff --git a/src/main/java/com/mzaxd/noodles/mapper/NotificationMapper.java b/src/main/java/com/mzaxd/bps/mapper/NotificationMapper.java similarity index 64% rename from src/main/java/com/mzaxd/noodles/mapper/NotificationMapper.java rename to src/main/java/com/mzaxd/bps/mapper/NotificationMapper.java index 6e9ed8e..688a881 100644 --- a/src/main/java/com/mzaxd/noodles/mapper/NotificationMapper.java +++ b/src/main/java/com/mzaxd/bps/mapper/NotificationMapper.java @@ -1,13 +1,12 @@ -package com.mzaxd.noodles.mapper; +package com.mzaxd.bps.mapper; -import com.mzaxd.noodles.domain.entity.Notification; +import com.mzaxd.bps.domain.entity.Notification; import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** * @author 13439 * @description 针对表【notification】的数据库操作Mapper * @createDate 2023-02-16 16:04:53 -* @Entity com.mzaxd.noodles.domain.entity.Notification */ public interface NotificationMapper extends BaseMapper { diff --git a/src/main/java/com/mzaxd/noodles/mapper/SystemSettingMapper.java b/src/main/java/com/mzaxd/bps/mapper/SystemSettingMapper.java similarity index 64% rename from src/main/java/com/mzaxd/noodles/mapper/SystemSettingMapper.java rename to src/main/java/com/mzaxd/bps/mapper/SystemSettingMapper.java index 1e2422a..6d6a21d 100644 --- a/src/main/java/com/mzaxd/noodles/mapper/SystemSettingMapper.java +++ b/src/main/java/com/mzaxd/bps/mapper/SystemSettingMapper.java @@ -1,13 +1,12 @@ -package com.mzaxd.noodles.mapper; +package com.mzaxd.bps.mapper; -import com.mzaxd.noodles.domain.entity.SystemSetting; +import com.mzaxd.bps.domain.entity.SystemSetting; import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** * @author 13439 * @description 针对表【system_setting】的数据库操作Mapper * @createDate 2023-02-16 20:25:57 -* @Entity com.mzaxd.noodles.domain.entity.SystemSetting */ public interface SystemSettingMapper extends BaseMapper { diff --git a/src/main/java/com/mzaxd/noodles/mapper/UserMapper.java b/src/main/java/com/mzaxd/bps/mapper/UserMapper.java similarity index 65% rename from src/main/java/com/mzaxd/noodles/mapper/UserMapper.java rename to src/main/java/com/mzaxd/bps/mapper/UserMapper.java index 01626f0..3fac8ca 100644 --- a/src/main/java/com/mzaxd/noodles/mapper/UserMapper.java +++ b/src/main/java/com/mzaxd/bps/mapper/UserMapper.java @@ -1,13 +1,12 @@ -package com.mzaxd.noodles.mapper; +package com.mzaxd.bps.mapper; -import com.mzaxd.noodles.domain.entity.User; +import com.mzaxd.bps.domain.entity.User; import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** * @author root * @description 针对表【user】的数据库操作Mapper * @createDate 2023-01-28 09:16:07 -* @Entity com.mzaxd.noodles.domain.entity.User */ public interface UserMapper extends BaseMapper { diff --git a/src/main/java/com/mzaxd/noodles/service/AuditLogService.java b/src/main/java/com/mzaxd/bps/service/AuditLogService.java similarity index 64% rename from src/main/java/com/mzaxd/noodles/service/AuditLogService.java rename to src/main/java/com/mzaxd/bps/service/AuditLogService.java index fd233d6..6a01a7f 100644 --- a/src/main/java/com/mzaxd/noodles/service/AuditLogService.java +++ b/src/main/java/com/mzaxd/bps/service/AuditLogService.java @@ -1,7 +1,7 @@ -package com.mzaxd.noodles.service; +package com.mzaxd.bps.service; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.AuditLog; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.AuditLog; import com.baomidou.mybatisplus.extension.service.IService; /** @@ -18,7 +18,7 @@ public interface AuditLogService extends IService { * @param currentPage * @return */ - ResponseResult getLogList(Integer perPage, Integer currentPage); + ResponseResult getLogList(Integer perPage, Integer currentPage); /** * 获取参数 @@ -26,12 +26,12 @@ public interface AuditLogService extends IService { * @param id * @return */ - ResponseResult getParam(Integer id); + ResponseResult getParam(Integer id); /** * 获取用户日志 * * @return */ - ResponseResult getUserLog(); + ResponseResult getUserLog(); } diff --git a/src/main/java/com/mzaxd/noodles/service/DashboardService.java b/src/main/java/com/mzaxd/bps/service/DashboardService.java similarity index 63% rename from src/main/java/com/mzaxd/noodles/service/DashboardService.java rename to src/main/java/com/mzaxd/bps/service/DashboardService.java index bdb943a..654d07f 100644 --- a/src/main/java/com/mzaxd/noodles/service/DashboardService.java +++ b/src/main/java/com/mzaxd/bps/service/DashboardService.java @@ -1,6 +1,6 @@ -package com.mzaxd.noodles.service; +package com.mzaxd.bps.service; -import com.mzaxd.noodles.domain.ResponseResult; +import com.mzaxd.bps.domain.ResponseResult; /** * @author 13439 @@ -11,14 +11,14 @@ public interface DashboardService { * * @return */ - ResponseResult getInstancesRealTimeData(); + ResponseResult getInstancesRealTimeData(); /** * 获取最近连接过的控制台列表 * * @return */ - ResponseResult getRecentConsoleList(); + ResponseResult getRecentConsoleList(); /** * 获取所有受影响的服务 @@ -27,5 +27,5 @@ public interface DashboardService { * @author mzaxd * @date 2023/3/8 9:43 */ - ResponseResult getAffectedServirList(); + ResponseResult getAffectedServirList(); } diff --git a/src/main/java/com/mzaxd/noodles/service/LoginService.java b/src/main/java/com/mzaxd/bps/service/LoginService.java similarity index 68% rename from src/main/java/com/mzaxd/noodles/service/LoginService.java rename to src/main/java/com/mzaxd/bps/service/LoginService.java index d2cd340..c0145f6 100644 --- a/src/main/java/com/mzaxd/noodles/service/LoginService.java +++ b/src/main/java/com/mzaxd/bps/service/LoginService.java @@ -1,8 +1,8 @@ -package com.mzaxd.noodles.service; +package com.mzaxd.bps.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.User; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.User; /** * @author root @@ -17,7 +17,7 @@ public interface LoginService extends IService { * @param user * @return ResponseResult */ - ResponseResult login(User user); + ResponseResult login(User user); /** * 后台用户退出登陆 @@ -26,7 +26,7 @@ public interface LoginService extends IService { * @date 12/6/22 2:07 PM * @return ResponseResult */ - ResponseResult logout(); + ResponseResult logout(); /** * 首次登陆时 修改账户信息 @@ -34,12 +34,12 @@ public interface LoginService extends IService { * @param user * @return */ - ResponseResult updateAccount(User user); + ResponseResult updateAccount(User user); /** * 删除账号 * * @return */ - ResponseResult deleteAccount(); + ResponseResult deleteAccount(); } diff --git a/src/main/java/com/mzaxd/bps/service/NotificationService.java b/src/main/java/com/mzaxd/bps/service/NotificationService.java new file mode 100644 index 0000000..a11cbdf --- /dev/null +++ b/src/main/java/com/mzaxd/bps/service/NotificationService.java @@ -0,0 +1,36 @@ +package com.mzaxd.bps.service; + +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.Notification; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author 13439 +* @description 针对表【notification】的数据库操作Service +* @createDate 2023-02-16 16:04:53 +*/ +public interface NotificationService extends IService { + + /** + * 提醒列表 + * @param tab + * @param perPage + * @param currentPage + * @return + */ + ResponseResult getNotificationList(Integer tab, Integer perPage, Integer currentPage); + + /** + * 获取新通知数量 + * @return + */ + ResponseResult getNotificationCount(); + + /** + * 确认提醒 + * + * @param id + * @return + */ + ResponseResult affirmNotification(Long id); +} diff --git a/src/main/java/com/mzaxd/noodles/service/SystemSettingService.java b/src/main/java/com/mzaxd/bps/service/SystemSettingService.java similarity index 56% rename from src/main/java/com/mzaxd/noodles/service/SystemSettingService.java rename to src/main/java/com/mzaxd/bps/service/SystemSettingService.java index d2bf4ee..41023ad 100644 --- a/src/main/java/com/mzaxd/noodles/service/SystemSettingService.java +++ b/src/main/java/com/mzaxd/bps/service/SystemSettingService.java @@ -1,11 +1,11 @@ -package com.mzaxd.noodles.service; +package com.mzaxd.bps.service; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.SystemSetting; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.SystemSetting; import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.vo.SmtpVo; -import com.mzaxd.noodles.domain.vo.SystemVo; -import com.mzaxd.noodles.domain.vo.TerminalVo; +import com.mzaxd.bps.domain.vo.SmtpVo; +import com.mzaxd.bps.domain.vo.SystemVo; +import com.mzaxd.bps.domain.vo.TerminalVo; /** * @author 13439 @@ -19,7 +19,7 @@ public interface SystemSettingService extends IService { * * @return */ - ResponseResult getSmtpSetting(); + ResponseResult getSmtpSetting(); /** * 保存smtp设置 @@ -27,14 +27,14 @@ public interface SystemSettingService extends IService { * @param smtpVo * @return */ - ResponseResult saveSmtpSetting(SmtpVo smtpVo); + ResponseResult saveSmtpSetting(SmtpVo smtpVo); /** * 获取终端设置 * * @return */ - ResponseResult getTerminalSetting(); + ResponseResult getTerminalSetting(); /** * 报错终端设置 @@ -42,14 +42,14 @@ public interface SystemSettingService extends IService { * @param terminalVo * @return */ - ResponseResult saveTerminalSetting(TerminalVo terminalVo); + ResponseResult saveTerminalSetting(TerminalVo terminalVo); /** * 获取系统设置 * * @return */ - ResponseResult getSystemSetting(); + ResponseResult getSystemSetting(); /** @@ -58,5 +58,5 @@ public interface SystemSettingService extends IService { * @param systemVo * @return */ - ResponseResult saveSystemSetting(SystemVo systemVo); + ResponseResult saveSystemSetting(SystemVo systemVo); } diff --git a/src/main/java/com/mzaxd/noodles/service/UserService.java b/src/main/java/com/mzaxd/bps/service/UserService.java similarity index 59% rename from src/main/java/com/mzaxd/noodles/service/UserService.java rename to src/main/java/com/mzaxd/bps/service/UserService.java index a500eb0..ce8abd4 100644 --- a/src/main/java/com/mzaxd/noodles/service/UserService.java +++ b/src/main/java/com/mzaxd/bps/service/UserService.java @@ -1,9 +1,9 @@ -package com.mzaxd.noodles.service; +package com.mzaxd.bps.service; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.User; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.User; import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.vo.UserInfoVo; +import com.mzaxd.bps.domain.vo.UserInfoVo; /** * @author root @@ -19,7 +19,7 @@ public interface UserService extends IService { * @date 1/29/23 4:16 AM * @return ResponseResult */ - ResponseResult userInfo(); + ResponseResult userInfo(); /** * 修改用户信息 @@ -29,35 +29,27 @@ public interface UserService extends IService { * @param user * @return ResponseResult */ - ResponseResult updateUserInfo(User user); - - /** - * 返回个人信息页面头部数据 - * - * @param id - * @return - */ - ResponseResult getProfileHeader(Integer id, String ip); + ResponseResult updateUserInfo(User user); /** * 返回profile页面所需数据 * * @return */ - ResponseResult getProfile(); + ResponseResult getProfile(); /** * 通过判断默认账户的state状态来判断是否第一次使用 * @return */ - ResponseResult isFirstUse(); + ResponseResult isFirstUse(); /** * 修改密码 * @param password * @return */ - ResponseResult changePassword(String password); + ResponseResult changePassword(String password); /** * 通过id获取UserInfo @@ -65,12 +57,12 @@ public interface UserService extends IService { * @param id * @return */ - ResponseResult getUserInfo(Integer id); + ResponseResult getUserInfo(Integer id); /** * 修改账号信息 * @param userData * @return */ - ResponseResult updateUserInfo(UserInfoVo userData); + ResponseResult updateUserInfo(UserInfoVo userData); } diff --git a/src/main/java/com/mzaxd/noodles/service/impl/AuditLogServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/AuditLogServiceImpl.java similarity index 74% rename from src/main/java/com/mzaxd/noodles/service/impl/AuditLogServiceImpl.java rename to src/main/java/com/mzaxd/bps/service/impl/AuditLogServiceImpl.java index 20a8a7f..6d0eb7e 100644 --- a/src/main/java/com/mzaxd/noodles/service/impl/AuditLogServiceImpl.java +++ b/src/main/java/com/mzaxd/bps/service/impl/AuditLogServiceImpl.java @@ -1,18 +1,20 @@ -package com.mzaxd.noodles.service.impl; +package com.mzaxd.bps.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.domain.vo.*; -import com.mzaxd.noodles.mapper.UserMapper; -import com.mzaxd.noodles.service.AuditLogService; -import com.mzaxd.noodles.mapper.AuditLogMapper; -import com.mzaxd.noodles.util.BeanCopyUtils; +import com.mzaxd.bps.constant.SystemConstant; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.*; +import com.mzaxd.bps.domain.vo.*; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.mapper.UserMapper; +import com.mzaxd.bps.service.AuditLogService; +import com.mzaxd.bps.mapper.AuditLogMapper; +import com.mzaxd.bps.util.BeanCopyUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -23,6 +25,7 @@ import java.util.List; * @createDate 2023-02-13 12:19:26 */ @Service +@Transactional(rollbackFor = SystemException.class) public class AuditLogServiceImpl extends ServiceImpl implements AuditLogService{ @@ -30,7 +33,7 @@ public class AuditLogServiceImpl extends ServiceImpl private UserMapper userMapper; @Override - public ResponseResult getLogList(Integer perPage, Integer currentPage) { + public ResponseResult getLogList(Integer perPage, Integer currentPage) { //分页 PageHelper.startPage(currentPage, perPage); LambdaQueryWrapper auditLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -52,13 +55,13 @@ public class AuditLogServiceImpl extends ServiceImpl } @Override - public ResponseResult getParam(Integer id) { + public ResponseResult getParam(Integer id) { AuditLog auditLog = getById(id); return ResponseResult.okResult(auditLog.getParam()); } @Override - public ResponseResult getUserLog() { + public ResponseResult getUserLog() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AuditLog::getOperationType, SystemConstant.LOG_USER); queryWrapper.orderByDesc(AuditLog::getCreateTime); diff --git a/src/main/java/com/mzaxd/noodles/service/impl/LoginServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/LoginServiceImpl.java similarity index 76% rename from src/main/java/com/mzaxd/noodles/service/impl/LoginServiceImpl.java rename to src/main/java/com/mzaxd/bps/service/impl/LoginServiceImpl.java index 40f6615..f26a598 100644 --- a/src/main/java/com/mzaxd/noodles/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/mzaxd/bps/service/impl/LoginServiceImpl.java @@ -1,22 +1,23 @@ -package com.mzaxd.noodles.service.impl; +package com.mzaxd.bps.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.LoginUser; -import com.mzaxd.noodles.domain.entity.User; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.mapper.UserMapper; -import com.mzaxd.noodles.service.LoginService; -import com.mzaxd.noodles.service.UserService; -import com.mzaxd.noodles.util.JwtUtil; -import com.mzaxd.noodles.util.RedisCache; -import com.mzaxd.noodles.util.SecurityUtils; +import com.mzaxd.bps.constant.SystemConstant; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.LoginUser; +import com.mzaxd.bps.domain.entity.User; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.mapper.UserMapper; +import com.mzaxd.bps.service.LoginService; +import com.mzaxd.bps.util.JwtUtil; +import com.mzaxd.bps.util.RedisCache; +import com.mzaxd.bps.util.SecurityUtils; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.HashMap; @@ -27,6 +28,7 @@ import java.util.Objects; * @author root */ @Service +@Transactional(rollbackFor = {SystemException.class}) public class LoginServiceImpl extends ServiceImpl implements LoginService { @Resource @@ -39,7 +41,7 @@ public class LoginServiceImpl extends ServiceImpl implements L private UserMapper userMapper; @Override - public ResponseResult login(User user) { + public ResponseResult login(User user) { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword()); Authentication authenticate = authenticationManager.authenticate(authenticationToken); //判断是否认证通过 @@ -60,7 +62,7 @@ public class LoginServiceImpl extends ServiceImpl implements L } @Override - public ResponseResult logout() { + public ResponseResult logout() { //获取当前登录的用户id Long userId = SecurityUtils.getUserId(); //删除redis中对应的值 @@ -69,7 +71,7 @@ public class LoginServiceImpl extends ServiceImpl implements L } @Override - public ResponseResult updateAccount(User user) { + public ResponseResult updateAccount(User user) { //获取当前登录的用户id Long userId = SecurityUtils.getUserId(); User defaultUser = getById(userId); @@ -81,7 +83,7 @@ public class LoginServiceImpl extends ServiceImpl implements L } @Override - public ResponseResult deleteAccount() { + public ResponseResult deleteAccount() { Long userId = SecurityUtils.getUserId(); userMapper.deleteById(userId); return ResponseResult.okResult(); diff --git a/src/main/java/com/mzaxd/bps/service/impl/NotificationServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/NotificationServiceImpl.java new file mode 100644 index 0000000..3c6968e --- /dev/null +++ b/src/main/java/com/mzaxd/bps/service/impl/NotificationServiceImpl.java @@ -0,0 +1,70 @@ +package com.mzaxd.bps.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mzaxd.bps.constant.RedisConstant; +import com.mzaxd.bps.constant.SystemConstant; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.Notification; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.service.NotificationService; +import com.mzaxd.bps.mapper.NotificationMapper; +import com.mzaxd.bps.util.SystemSettingUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +/** + * @author 13439 + * @description 针对表【notification】的数据库操作Service实现 + * @createDate 2023-02-16 16:04:53 + */ +@Service +@Slf4j +@Transactional(rollbackFor = SystemException.class) +public class NotificationServiceImpl extends ServiceImpl + implements NotificationService { + + @Resource + private SystemSettingUtils systemSettingUtils; + + @Resource + private RedisTemplate redisTemplate; + + @Override + public ResponseResult affirmNotification(Long id) { + Notification notification = getById(id); + if (SystemConstant.INSTANCETYPE_HOST.equals(notification.getInstanceType())) { + redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_HOST_IDS, notification.getInstanceId().toString()); + } + if (SystemConstant.INSTANCETYPE_VM.equals(notification.getInstanceType())) { + redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_VM_IDS, notification.getInstanceId().toString()); + } + if (SystemConstant.INSTANCETYPE_CONTAINER.equals(notification.getInstanceType())) { + redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_CONTAINER_IDS, notification.getInstanceId().toString()); + } + saveOrUpdate(notification.setAffirm(SystemConstant.NOTIFICATION_AFFIRM)); + return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "处理完成"); + } + + @Override + public ResponseResult getNotificationList(Integer tab, Integer perPage, Integer currentPage) { + return null; + } + + @Override + public ResponseResult getNotificationCount() { + LambdaQueryWrapper notificationLambdaQueryWrapper = new LambdaQueryWrapper<>(); + notificationLambdaQueryWrapper.eq(Notification::getAffirm, SystemConstant.NOTIFICATION_NOT_AFFIRM); + return ResponseResult.okResult(count(notificationLambdaQueryWrapper)); + } + +} + + + + diff --git a/src/main/java/com/mzaxd/noodles/service/impl/SystemSettingServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/SystemSettingServiceImpl.java similarity index 71% rename from src/main/java/com/mzaxd/noodles/service/impl/SystemSettingServiceImpl.java rename to src/main/java/com/mzaxd/bps/service/impl/SystemSettingServiceImpl.java index e595565..695d73c 100644 --- a/src/main/java/com/mzaxd/noodles/service/impl/SystemSettingServiceImpl.java +++ b/src/main/java/com/mzaxd/bps/service/impl/SystemSettingServiceImpl.java @@ -1,16 +1,18 @@ -package com.mzaxd.noodles.service.impl; +package com.mzaxd.bps.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.SystemSetting; -import com.mzaxd.noodles.domain.vo.SmtpVo; -import com.mzaxd.noodles.domain.vo.SystemVo; -import com.mzaxd.noodles.domain.vo.TerminalVo; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.service.SystemSettingService; -import com.mzaxd.noodles.mapper.SystemSettingMapper; -import com.mzaxd.noodles.util.BeanCopyUtils; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.SystemSetting; +import com.mzaxd.bps.domain.vo.SmtpVo; +import com.mzaxd.bps.domain.vo.SystemVo; +import com.mzaxd.bps.domain.vo.TerminalVo; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.service.SystemSettingService; +import com.mzaxd.bps.mapper.SystemSettingMapper; +import com.mzaxd.bps.util.BeanCopyUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * @author 13439 @@ -18,18 +20,19 @@ import org.springframework.stereotype.Service; * @createDate 2023-02-16 20:25:57 */ @Service +@Transactional(rollbackFor = SystemException.class) public class SystemSettingServiceImpl extends ServiceImpl implements SystemSettingService{ @Override - public ResponseResult getSmtpSetting() { + public ResponseResult getSmtpSetting() { SystemSetting systemSetting = getSetting(); SmtpVo smtpVo = BeanCopyUtils.copyBean(systemSetting, SmtpVo.class); return ResponseResult.okResult(smtpVo); } @Override - public ResponseResult saveSmtpSetting(SmtpVo smtpVo) { + public ResponseResult saveSmtpSetting(SmtpVo smtpVo) { SystemSetting systemSetting = getById(1); systemSetting.setServerEmail(smtpVo.getServerEmail()); systemSetting.setEmailPass(smtpVo.getEmailPass()); @@ -39,14 +42,14 @@ public class SystemSettingServiceImpl extends ServiceImpl getTerminalSetting() { SystemSetting systemSetting = getSetting(); TerminalVo terminalVo = BeanCopyUtils.copyBean(systemSetting, TerminalVo.class); return ResponseResult.okResult(terminalVo); } @Override - public ResponseResult saveTerminalSetting(TerminalVo terminalVo) { + public ResponseResult saveTerminalSetting(TerminalVo terminalVo) { SystemSetting systemSetting = getById(1); systemSetting.setRendererType(terminalVo.getRendererType()); systemSetting.setFontSize(terminalVo.getFontSize()); @@ -58,14 +61,14 @@ public class SystemSettingServiceImpl extends ServiceImpl getSystemSetting() { SystemSetting systemSetting = getSetting(); SystemVo systemVo = BeanCopyUtils.copyBean(systemSetting, SystemVo.class); return ResponseResult.okResult(systemVo); } @Override - public ResponseResult saveSystemSetting(SystemVo systemVo) { + public ResponseResult saveSystemSetting(SystemVo systemVo) { SystemSetting systemSetting = getById(1); systemSetting.setLogExpire(systemVo.getLogExpire()); systemSetting.setDefaultLang(systemVo.getDefaultLang()); diff --git a/src/main/java/com/mzaxd/noodles/service/impl/UserDetailServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/UserDetailServiceImpl.java similarity index 78% rename from src/main/java/com/mzaxd/noodles/service/impl/UserDetailServiceImpl.java rename to src/main/java/com/mzaxd/bps/service/impl/UserDetailServiceImpl.java index 7cf49ce..27adc39 100644 --- a/src/main/java/com/mzaxd/noodles/service/impl/UserDetailServiceImpl.java +++ b/src/main/java/com/mzaxd/bps/service/impl/UserDetailServiceImpl.java @@ -1,13 +1,15 @@ -package com.mzaxd.noodles.service.impl; +package com.mzaxd.bps.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.domain.entity.LoginUser; -import com.mzaxd.noodles.domain.entity.User; -import com.mzaxd.noodles.mapper.UserMapper; +import com.mzaxd.bps.domain.entity.LoginUser; +import com.mzaxd.bps.domain.entity.User; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.mapper.UserMapper; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Objects; @@ -18,6 +20,7 @@ import java.util.Objects; * @createDate 2022-11-26 12:24:08 */ @Service +@Transactional(rollbackFor = SystemException.class) public class UserDetailServiceImpl implements UserDetailsService { @Resource diff --git a/src/main/java/com/mzaxd/bps/service/impl/UserServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..81f5e38 --- /dev/null +++ b/src/main/java/com/mzaxd/bps/service/impl/UserServiceImpl.java @@ -0,0 +1,98 @@ +package com.mzaxd.bps.service.impl; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mzaxd.bps.domain.ResponseResult; +import com.mzaxd.bps.domain.entity.User; +import com.mzaxd.bps.domain.vo.ProfileVo; +import com.mzaxd.bps.domain.vo.UserInfoVo; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.mapper.UserMapper; +import com.mzaxd.bps.service.UserService; +import com.mzaxd.bps.util.BeanCopyUtils; +import com.mzaxd.bps.util.SecurityUtils; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +/** +* @author root +* @description 针对表【user】的数据库操作Service实现 +* @createDate 2023-01-28 09:16:07 +*/ +@Service +@Transactional(rollbackFor = SystemException.class) +public class UserServiceImpl extends ServiceImpl + implements UserService{ + + @Resource + private PasswordEncoder passwordEncoder; + + @Override + public ResponseResult userInfo() { + //获取当前用户id + Long userId = SecurityUtils.getUserId(); + //根据id查询用户信息 + User user = getById(userId); + //将用户信息封装Vo并返回 + UserInfoVo userInfoVo = BeanCopyUtils.copyBean(user, UserInfoVo.class); + return ResponseResult.okResult(userInfoVo); + } + + @Override + public ResponseResult updateUserInfo(User user) { + updateById(user); + return ResponseResult.okResult(); + } + + @Override + public ResponseResult getProfile() { + //获取当前用户id + Long userId = SecurityUtils.getUserId(); + User user = getById(userId); + ProfileVo profile = BeanCopyUtils.copyBean(user, ProfileVo.class); + return ResponseResult.okResult(profile); + } + + @Override + public ResponseResult isFirstUse() { + User user = getById(1); + if (user.getUserState() == 0) { + return ResponseResult.okResult(true); + } else { + return ResponseResult.okResult(false); + } + } + + @Override + public ResponseResult changePassword(String password) { + Long userId = SecurityUtils.getUserId(); + User user = getById(userId); + user.setPassword(passwordEncoder.encode(password)); + saveOrUpdate(user); + return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "密码修改成功"); + } + + @Override + public ResponseResult getUserInfo(Integer id) { + User user = getById(id); + UserInfoVo userInfoVo = BeanCopyUtils.copyBean(user, UserInfoVo.class); + return ResponseResult.okResult(userInfoVo); + } + + @Override + public ResponseResult updateUserInfo(UserInfoVo userData) { + Long userId = SecurityUtils.getUserId(); + User user = getById(userId); + user.setEmail(userData.getEmail()).setUserName(userData.getUserName()).setNickName(userData.getNickName()).setAvatar(userData.getAvatar()); + saveOrUpdate(user); + return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "账号信息修改成功"); + } +} + + + + diff --git a/src/main/java/com/mzaxd/noodles/util/Arith.java b/src/main/java/com/mzaxd/bps/util/Arith.java similarity index 98% rename from src/main/java/com/mzaxd/noodles/util/Arith.java rename to src/main/java/com/mzaxd/bps/util/Arith.java index d564418..24af383 100644 --- a/src/main/java/com/mzaxd/noodles/util/Arith.java +++ b/src/main/java/com/mzaxd/bps/util/Arith.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodledetector.util; +package com.mzaxd.bps.util; /** * @author Mzaxd diff --git a/src/main/java/com/mzaxd/noodles/util/BeanCopyUtils.java b/src/main/java/com/mzaxd/bps/util/BeanCopyUtils.java similarity index 87% rename from src/main/java/com/mzaxd/noodles/util/BeanCopyUtils.java rename to src/main/java/com/mzaxd/bps/util/BeanCopyUtils.java index ee3f12b..7846298 100644 --- a/src/main/java/com/mzaxd/noodles/util/BeanCopyUtils.java +++ b/src/main/java/com/mzaxd/bps/util/BeanCopyUtils.java @@ -1,5 +1,6 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import java.util.List; @@ -9,6 +10,7 @@ import java.util.stream.Collectors; * @author Mzaxd * @since 2022-11-22 15:36 */ +@Slf4j public class BeanCopyUtils { private BeanCopyUtils() { @@ -22,7 +24,7 @@ public class BeanCopyUtils { //实现属性copy BeanUtils.copyProperties(source, result); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); } //返回结果 return result; diff --git a/src/main/java/com/mzaxd/noodles/util/CpuUtil.java b/src/main/java/com/mzaxd/bps/util/CpuUtil.java similarity index 93% rename from src/main/java/com/mzaxd/noodles/util/CpuUtil.java rename to src/main/java/com/mzaxd/bps/util/CpuUtil.java index 7c97341..d836fcc 100644 --- a/src/main/java/com/mzaxd/noodles/util/CpuUtil.java +++ b/src/main/java/com/mzaxd/bps/util/CpuUtil.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; import oshi.SystemInfo; import oshi.hardware.CentralProcessor; diff --git a/src/main/java/com/mzaxd/noodles/util/FormatUtil.java b/src/main/java/com/mzaxd/bps/util/FormatUtil.java similarity index 99% rename from src/main/java/com/mzaxd/noodles/util/FormatUtil.java rename to src/main/java/com/mzaxd/bps/util/FormatUtil.java index fd628b8..599281f 100644 --- a/src/main/java/com/mzaxd/noodles/util/FormatUtil.java +++ b/src/main/java/com/mzaxd/bps/util/FormatUtil.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodledetector.util; +package com.mzaxd.bps.util; import java.math.BigInteger; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/com/mzaxd/noodles/util/JwtUtil.java b/src/main/java/com/mzaxd/bps/util/JwtUtil.java similarity index 97% rename from src/main/java/com/mzaxd/noodles/util/JwtUtil.java rename to src/main/java/com/mzaxd/bps/util/JwtUtil.java index 251e19d..1f2b9d9 100644 --- a/src/main/java/com/mzaxd/noodles/util/JwtUtil.java +++ b/src/main/java/com/mzaxd/bps/util/JwtUtil.java @@ -1,10 +1,9 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; -import org.springframework.stereotype.Component; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; @@ -119,4 +118,4 @@ public class JwtUtil { .parseClaimsJws(jwt) .getBody(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/util/RedisCache.java b/src/main/java/com/mzaxd/bps/util/RedisCache.java similarity index 92% rename from src/main/java/com/mzaxd/noodles/util/RedisCache.java rename to src/main/java/com/mzaxd/bps/util/RedisCache.java index 53ba07f..a251adb 100644 --- a/src/main/java/com/mzaxd/noodles/util/RedisCache.java +++ b/src/main/java/com/mzaxd/bps/util/RedisCache.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.HashOperations; @@ -71,7 +71,7 @@ public class RedisCache { * @return true=设置成功;false=设置失败 */ public boolean expire(final String key, final long timeout, final TimeUnit unit) { - return redisTemplate.expire(key, timeout, unit); + return Boolean.TRUE.equals(redisTemplate.expire(key, timeout, unit)); } /** @@ -101,18 +101,8 @@ public class RedisCache { * * @param key */ - public boolean deleteObject(final String key) { - return redisTemplate.delete(key); - } - - /** - * 删除集合对象 - * - * @param collection 多个对象 - * @return - */ - public long deleteObject(final Collection collection) { - return redisTemplate.delete(collection); + public void deleteObject(final String key) { + redisTemplate.delete(key); } /** @@ -146,9 +136,8 @@ public class RedisCache { */ public BoundSetOperations setCacheSet(final String key, final Set dataSet) { BoundSetOperations setOperation = redisTemplate.boundSetOps(key); - Iterator it = dataSet.iterator(); - while (it.hasNext()) { - setOperation.add(it.next()); + for (T t : dataSet) { + setOperation.add(t); } return setOperation; } @@ -252,4 +241,4 @@ public class RedisCache { public void incrementCacheMapValue(String key, String hKey, long v) { redisTemplate.boundHashOps(key).increment(hKey, v); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/util/SearchUtil.java b/src/main/java/com/mzaxd/bps/util/SearchUtil.java similarity index 90% rename from src/main/java/com/mzaxd/noodles/util/SearchUtil.java rename to src/main/java/com/mzaxd/bps/util/SearchUtil.java index f7a07d8..e2dbabd 100644 --- a/src/main/java/com/mzaxd/noodles/util/SearchUtil.java +++ b/src/main/java/com/mzaxd/bps/util/SearchUtil.java @@ -1,11 +1,10 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; -import com.mzaxd.noodles.domain.search.SearchCategory; -import com.mzaxd.noodles.domain.search.SearchItem; +import com.mzaxd.bps.domain.search.SearchCategory; +import com.mzaxd.bps.domain.search.SearchItem; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; /** * @author ThinkBook diff --git a/src/main/java/com/mzaxd/noodles/util/SecurityUtils.java b/src/main/java/com/mzaxd/bps/util/SecurityUtils.java similarity index 89% rename from src/main/java/com/mzaxd/noodles/util/SecurityUtils.java rename to src/main/java/com/mzaxd/bps/util/SecurityUtils.java index ea1ead5..2f6bc7d 100644 --- a/src/main/java/com/mzaxd/noodles/util/SecurityUtils.java +++ b/src/main/java/com/mzaxd/bps/util/SecurityUtils.java @@ -1,6 +1,6 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; -import com.mzaxd.noodles.domain.entity.LoginUser; +import com.mzaxd.bps.domain.entity.LoginUser; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -31,4 +31,4 @@ public class SecurityUtils { public static Long getUserId() { return getLoginUser().getUser().getId(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/bps/util/SshLinkUtil.java b/src/main/java/com/mzaxd/bps/util/SshLinkUtil.java new file mode 100644 index 0000000..08be603 --- /dev/null +++ b/src/main/java/com/mzaxd/bps/util/SshLinkUtil.java @@ -0,0 +1,8 @@ +package com.mzaxd.bps.util; + +/** + * @author 13439 + */ +public class SshLinkUtil { + +} diff --git a/src/main/java/com/mzaxd/noodles/util/SystemInfoUtils.java b/src/main/java/com/mzaxd/bps/util/SystemInfoUtils.java similarity index 96% rename from src/main/java/com/mzaxd/noodles/util/SystemInfoUtils.java rename to src/main/java/com/mzaxd/bps/util/SystemInfoUtils.java index 8fe8e3b..9383050 100644 --- a/src/main/java/com/mzaxd/noodles/util/SystemInfoUtils.java +++ b/src/main/java/com/mzaxd/bps/util/SystemInfoUtils.java @@ -1,4 +1,4 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -23,10 +23,10 @@ import java.util.Properties; **/ public class SystemInfoUtils { private static final int OSHI_WAIT_SECOND = 1000; - private static SystemInfo systemInfo = new SystemInfo(); - private static HardwareAbstractionLayer hardware = systemInfo.getHardware(); - private static OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); - + private static final SystemInfo systemInfo = new SystemInfo(); + private static final HardwareAbstractionLayer hardware = systemInfo.getHardware(); + private static final OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); + public static JSONObject getCpuInfo() { JSONObject cpuInfo = new JSONObject(); CentralProcessor processor = hardware.getProcessor(); @@ -55,7 +55,7 @@ public class SystemInfoUtils { cpuInfo.put("idle", new DecimalFormat("#.##%").format(1.0 - (idle * 1.0 / totalCpu))); return cpuInfo; } - + /** * 系统jvm信息 */ @@ -81,7 +81,7 @@ public class SystemInfoUtils { cpuInfo.put("jdkHome", props.getProperty("java.home")); return cpuInfo; } - + /** * 系统内存信息 */ @@ -102,7 +102,7 @@ public class SystemInfoUtils { cpuInfo.put("usageRate", new DecimalFormat("#.##%").format((totalByte - acaliableByte) * 1.0 / totalByte)); return cpuInfo; } - + /** * 系统盘符信息 */ @@ -135,7 +135,7 @@ public class SystemInfoUtils { } return sysFiles; } - + /** * 系统信息 */ @@ -154,7 +154,7 @@ public class SystemInfoUtils { cpuInfo.put("userDir", props.getProperty("user.dir")); return cpuInfo; } - + /** * 所有系统信息 */ @@ -167,7 +167,7 @@ public class SystemInfoUtils { info.put("sysFileInfo", getSysFileInfo()); return info; } - + /** * 单位转换 */ @@ -189,4 +189,4 @@ public class SystemInfoUtils { double tbNumber = gbNumber / FORMAT; return new DecimalFormat("#.##TB").format(tbNumber); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/util/SystemSettingUtils.java b/src/main/java/com/mzaxd/bps/util/SystemSettingUtils.java similarity index 83% rename from src/main/java/com/mzaxd/noodles/util/SystemSettingUtils.java rename to src/main/java/com/mzaxd/bps/util/SystemSettingUtils.java index 475d423..e4ed9e7 100644 --- a/src/main/java/com/mzaxd/noodles/util/SystemSettingUtils.java +++ b/src/main/java/com/mzaxd/bps/util/SystemSettingUtils.java @@ -1,10 +1,10 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; import cn.hutool.extra.mail.MailAccount; -import com.mzaxd.noodles.domain.entity.SystemSetting; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.exception.SystemException; -import com.mzaxd.noodles.service.SystemSettingService; +import com.mzaxd.bps.domain.entity.SystemSetting; +import com.mzaxd.bps.enums.AppHttpCodeEnum; +import com.mzaxd.bps.exception.SystemException; +import com.mzaxd.bps.service.SystemSettingService; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -40,7 +40,7 @@ public class SystemSettingUtils { //获取系统设置 SystemSetting setting = systemSettingService.getById(1); //如果不配置目标邮箱的话,默认目标邮箱为服务器邮箱地址 - String target = ""; + String target; if (StringUtils.hasText(setting.getNotificationEmail())) { target = setting.getNotificationEmail(); } else { diff --git a/src/main/java/com/mzaxd/noodles/util/UrlUtil.java b/src/main/java/com/mzaxd/bps/util/UrlUtil.java similarity index 80% rename from src/main/java/com/mzaxd/noodles/util/UrlUtil.java rename to src/main/java/com/mzaxd/bps/util/UrlUtil.java index c60f656..a97044d 100644 --- a/src/main/java/com/mzaxd/noodles/util/UrlUtil.java +++ b/src/main/java/com/mzaxd/bps/util/UrlUtil.java @@ -1,6 +1,6 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; -import com.mzaxd.noodles.constant.UrlConstant; +import com.mzaxd.bps.constant.UrlConstant; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -49,13 +49,6 @@ public class UrlUtil { return inetAddress.isReachable(5000); } - public static boolean isServiceOnline(String serverName, int port) throws IOException { - Socket socket = new Socket(serverName, port); - log.info("[实例状态检测]:" + serverName + ":" + port + "服务已经开启"); - socket.close(); - return true; - } - public static int getPort(String address) { String[] parts = address.split(":"); return Integer.parseInt(parts[1]); diff --git a/src/main/java/com/mzaxd/noodles/util/WebUtils.java b/src/main/java/com/mzaxd/bps/util/WebUtils.java similarity index 80% rename from src/main/java/com/mzaxd/noodles/util/WebUtils.java rename to src/main/java/com/mzaxd/bps/util/WebUtils.java index fba235e..a14397c 100644 --- a/src/main/java/com/mzaxd/noodles/util/WebUtils.java +++ b/src/main/java/com/mzaxd/bps/util/WebUtils.java @@ -1,13 +1,17 @@ -package com.mzaxd.noodles.util; +package com.mzaxd.bps.util; + +import lombok.extern.slf4j.Slf4j; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; /** * @author root */ +@Slf4j public class WebUtils { /** * 将字符串渲染到客户端 @@ -23,7 +27,7 @@ public class WebUtils { response.setCharacterEncoding("utf-8"); response.getWriter().print(string); } catch (IOException e) { - e.printStackTrace(); + log.error(e.getMessage()); } } @@ -31,7 +35,7 @@ public class WebUtils { public static void setDownLoadHeader(String filename, HttpServletResponse response) throws UnsupportedEncodingException { response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setCharacterEncoding("utf-8"); - String fname= URLEncoder.encode(filename,"UTF-8").replaceAll("\\+", "%20"); + String fname= URLEncoder.encode(filename, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); response.setHeader("Content-disposition","attachment; filename="+fname); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mzaxd/noodles/config/RabbitMqConfig.java b/src/main/java/com/mzaxd/noodles/config/RabbitMqConfig.java deleted file mode 100644 index 6ec3ff4..0000000 --- a/src/main/java/com/mzaxd/noodles/config/RabbitMqConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.mzaxd.noodles.config; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mzaxd.noodles.constant.RabbitMqConstant; -import org.springframework.amqp.core.Binding; -import org.springframework.amqp.core.BindingBuilder; -import org.springframework.amqp.core.DirectExchange; -import org.springframework.amqp.core.Queue; -import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; -import org.springframework.amqp.support.converter.MessageConverter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Mzaxd - * @since 2023-02-06 12:51 - */ -@Configuration -public class RabbitMqConfig { - - @Bean - public Queue rabbitmqDemoDirectQueue() { - /** - * 1、name: 队列名称 - * 2、durable: 是否持久化 - * 3、exclusive: 是否独享、排外的。如果设置为true,定义为排他队列。则只有创建者可以使用此队列。也就是private私有的。 - * 4、autoDelete: 是否自动删除。也就是临时队列。当最后一个消费者断开连接后,会自动删除。 - * */ - return new Queue(RabbitMqConstant.DYNAMIC_DATA_TOPIC, true, false, false); - } - - @Bean - public DirectExchange rabbitmqDemoDirectExchange() { - //Direct交换机 - return new DirectExchange(RabbitMqConstant.DYNAMIC_DATA_EXCHANGE, true, false); - } - - @Bean - public Binding bindDirect() { - //链式写法,绑定交换机和队列,并设置匹配键 - return BindingBuilder - //绑定队列 - .bind(rabbitmqDemoDirectQueue()) - //到交换机 - .to(rabbitmqDemoDirectExchange()) - //并设置匹配键 - .with(RabbitMqConstant.DYNAMIC_DATA_ROUTING); - } - - @Bean - public MessageConverter jsonMessageConverter(ObjectMapper objectMapper) { - return new Jackson2JsonMessageConverter(objectMapper); - } -} diff --git a/src/main/java/com/mzaxd/noodles/controller/ContainerController.java b/src/main/java/com/mzaxd/noodles/controller/ContainerController.java deleted file mode 100644 index 685d290..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/ContainerController.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.vo.ContainerVo; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.ContainerService; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import java.util.List; -import java.util.Map; - -/** - * @author root - */ -@RestController -@RequestMapping("/container") -public class ContainerController { - - @Resource - private ContainerService containerService; - - @GetMapping("/containerList/summaryStatistics") - public ResponseResult containerListSummaryStatistics() { - return containerService.containerListSummaryStatistics(); - } - - @GetMapping("/containerList") - public ResponseResult containerListWithCondition( - @RequestParam(value = "q", required = false) String nameLike, - @RequestParam(value = "selectedHost", required = false) List selectedHost, - @RequestParam(value = "selectedStatus", required = false) List selectedStatus, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return containerService.containerListWithCondition(nameLike, selectedHost, selectedStatus, perPage, currentPage); - } - - @GetMapping("/allHost") - public ResponseResult hostDrawer() { - return containerService.getAllHost(); - } - - @SysLog(operation = OperationEnum.CONTAINER_DELETE) - @DeleteMapping("/delete/{id}") - public ResponseResult deleteContainer(@PathVariable("id") Integer id) { - return containerService.deleteContainerById(id); - } - - @SysLog(operation = OperationEnum.CONTAINER_ADD) - @PostMapping("/addContainer") - public ResponseResult addContainer(@RequestBody Map container) { - return containerService.addContainer(container.get("container")); - } - - @GetMapping("/{id}") - public ResponseResult getContainer(@PathVariable("id") Integer id) { - return containerService.getContainer(id); - } - @SysLog(operation = OperationEnum.CONTAINER_UPDATE) - @PostMapping("/updateContainer") - public ResponseResult updateVm(@RequestBody Map container) { - return containerService.updateContainer(container.get("container")); - } - - @GetMapping("/allContainer") - public ResponseResult allContainer() { - return containerService.getAllContainer(); - } - - @GetMapping("/associatedContainers") - public ResponseResult getAssociatedContainers( - @RequestParam("hostId") Integer hostId, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return containerService.getAssociatedContainers(hostId, perPage, currentPage); - } - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/DashboardController.java b/src/main/java/com/mzaxd/noodles/controller/DashboardController.java deleted file mode 100644 index a803304..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/DashboardController.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.service.DashboardService; -import com.mzaxd.noodles.service.EveryDayDataService; -import com.mzaxd.noodles.service.HostDetectorService; -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; - -import javax.annotation.Resource; - -/** - * @author 13439 - */ - -@RestController -@RequestMapping("/dashboard") -public class DashboardController { - - @Resource - private HostDetectorService detectorService; - - @Resource - private EveryDayDataService everyDayDataService; - - @Resource - private DashboardService dashboardService; - - @GetMapping("/getMemInfo") - public ResponseResult getMemInfo() { - return detectorService.getMemInfo(); - } - - @GetMapping("/getAuditLogCountYesterday") - public ResponseResult getAuditLogCountYesterday() { - return everyDayDataService.getAuditLogCountYesterday(); - } - - @GetMapping("/getInstancesHistory") - public ResponseResult getInstancesHistory() { - return everyDayDataService.getInstancesHistory(); - } - - @GetMapping("/getInstancesRealTimeData") - public ResponseResult getInstancesRealTimeData() { - return dashboardService.getInstancesRealTimeData(); - } - - @GetMapping("/getRecentConsoleList") - public ResponseResult getRecentConsoleList() { - return dashboardService.getRecentConsoleList(); - } - - @GetMapping("/getAffectedServirList") - public ResponseResult getAffectedServirList() { - return dashboardService.getAffectedServirList(); - } - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/DetectorController.java b/src/main/java/com/mzaxd/noodles/controller/DetectorController.java deleted file mode 100644 index 6bdbe77..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/DetectorController.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.mzaxd.noodles.controller; - - -import com.mzaxd.noodles.constant.UrlConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.service.HostDetectorService; -import com.mzaxd.noodles.util.UrlUtil; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * @author root - */ -@RestController -@RequestMapping("/detector") -public class DetectorController { - - @Resource - private HostDetectorService hostDetectorService; - - @GetMapping("/isValidUrl/{protocol}/{ip}/{port}") - public ResponseResult isValidUrl(@PathVariable String protocol,@PathVariable String ip, @PathVariable String port) { - return hostDetectorService.isValidUrl(protocol,ip,port); - } - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/HostController.java b/src/main/java/com/mzaxd/noodles/controller/HostController.java deleted file mode 100644 index c3e8b64..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/HostController.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.alibaba.excel.EasyExcel; -import com.alibaba.fastjson.JSON; -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.vo.HostVo; -import com.mzaxd.noodles.domain.vo.VmVo; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.util.WebUtils; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Map; - -/** - * @author root - */ -@RestController -@RequestMapping("/host") -public class HostController { - - @Resource - private HostMachineService hostMachineService; - - @GetMapping("/drawer") - public ResponseResult hostDrawer() { - return hostMachineService.getHostDrawer(); - } - - @GetMapping("/vmList") - public ResponseResult vmListWithCondition( - @RequestParam(value = "q", required = false) String nameLike, - @RequestParam(value = "selectedKernel", required = false) List selectedKernel, - @RequestParam(value = "selectedHost", required = false) List selectedHost, - @RequestParam(value = "selectedStatus", required = false) List selectedStatus, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return hostMachineService.vmListWithCondition(nameLike, selectedKernel, selectedHost, selectedStatus, perPage, currentPage); - } - - @GetMapping("/vmList/summaryStatistics") - public ResponseResult vmListSummaryStatistics() { - return hostMachineService.vmListSummaryStatistics(); - } - - @SysLog(operation = OperationEnum.VM_ADD) - @PostMapping("/addVm") - public ResponseResult addVm(@RequestBody Map vmVo) { - return hostMachineService.addVm(vmVo.get("vm")); - } - - @SysLog(operation = OperationEnum.VM_UPDATE) - @PostMapping("/updateVm") - public ResponseResult updateVm(@RequestBody Map vmVo) { - return hostMachineService.updateVm(vmVo.get("vm")); - } - - @SysLog(operation = OperationEnum.VM_DELETE) - @DeleteMapping("/deleteVm/{id}") - public ResponseResult deleteVm(@PathVariable("id") Integer id) { - return hostMachineService.deleteVmById(id); - } - - @SysLog(operation = OperationEnum.HOST_DELETE) - @DeleteMapping("/deleteHost/{id}") - public ResponseResult deleteHost(@PathVariable("id") Integer id) { - return hostMachineService.deleteHostById(id); - } - - @GetMapping("/vm/{id}") - public ResponseResult getVmById(@PathVariable("id") Integer id) { - return hostMachineService.getVmById(id); - } - - @SysLog(operation = OperationEnum.HOST_UPDATE) - @PostMapping("/updateHost") - public ResponseResult updateHost(@RequestBody Map hostVo) { - return hostMachineService.updateHost(hostVo.get("host")); - } - - @GetMapping("/host/{id}") - public ResponseResult getHostById(@PathVariable("id") Integer id) { - return hostMachineService.getHostById(id); - } - - @GetMapping("/hostList") - public ResponseResult hostListWithCondition( - @RequestParam(value = "q", required = false) String nameLike, - @RequestParam(value = "selectedStatus", required = false) List selectedStatus, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return hostMachineService.hostListWithCondition(nameLike, selectedStatus, perPage, currentPage); - } - - @SysLog(operation = OperationEnum.HOST_ADD) - @PostMapping("/addHost") - public ResponseResult addHost(@RequestBody Map hostVo) { - return hostMachineService.addHost(hostVo.get("host")); - } - - @GetMapping("/hostDetail/{id}") - public ResponseResult getHostDetail(@PathVariable("id") Integer id) { - return hostMachineService.getHostDetail(id); - } - - @GetMapping("/associatedVms") - public ResponseResult getAssociatedVms( - @RequestParam("hostId") Integer hostId, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return hostMachineService.getAssociatedVms(hostId, perPage, currentPage); - } - - @GetMapping("/associatedDisks/{id}") - public ResponseResult getAssociatedDisks(@PathVariable("id") Integer id){ - return hostMachineService.getAssociatedDisks(id); - } - - @GetMapping("/associatedNetworkIfs/{id}") - public ResponseResult getAssociatedNetworkIfs(@PathVariable("id") Integer id) { - return hostMachineService.getAssociatedNetworkIfs(id); - } - - @GetMapping("/startSendDynamicData/{id}") - public ResponseResult startSendDynamicData(@PathVariable("id") Integer hostId) { - return hostMachineService.startSendDynamicData(hostId); - } - - @GetMapping("/stopSendDynamicData/{id}") - public ResponseResult stopSendDynamicData(@PathVariable("id") Integer hostId) { - return hostMachineService.stopSendDynamicData(hostId); - } - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/ServirController.java b/src/main/java/com/mzaxd/noodles/controller/ServirController.java deleted file mode 100644 index b927576..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/ServirController.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.vo.SaveOrUpdateServirVo; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.ServirService; -import com.mzaxd.noodles.service.TagService; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import java.util.List; -import java.util.Map; - -/** - * @author 13439 - */ -@RestController -@RequestMapping("/servir") -public class ServirController { - - @Resource - private TagService tagService; - - @Resource - private ServirService servirService; - - - @GetMapping("/tags") - public ResponseResult getAllTag() { - return tagService.getAllTag(); - } - - @GetMapping("/servirList") - public ResponseResult servirListWithCondition( - @RequestParam(value = "q", required = false) String nameLike, - @RequestParam(value = "selectedTags", required = false) List selectedTags, - @RequestParam("perPage") Integer perPage, - @RequestParam("currentPage") Integer currentPage) { - return servirService.servirListWithCondition(nameLike, selectedTags, perPage, currentPage); - } - - @SysLog(operation = OperationEnum.SERVIR_ADD) - @PostMapping("/addServir") - public ResponseResult addServir(@RequestBody Map saveOrUpdateServirVoMap) { - return servirService.addServir(saveOrUpdateServirVoMap.get("servir")); - } - @SysLog(operation = OperationEnum.SERVIR_UPDATE) - @PostMapping("/updateServir") - public ResponseResult updateServir(@RequestBody Map saveOrUpdateServirVoMap) { - return servirService.updateServir(saveOrUpdateServirVoMap.get("servir")); - } - - @SysLog(operation = OperationEnum.SERVIR_DELETE) - @DeleteMapping("/deleteServir/{id}") - public ResponseResult deleteServir(@PathVariable("id") Integer id) { - return servirService.deleteServirById(id); - } - - @GetMapping("/{id}") - public ResponseResult getServirDataById(@PathVariable("id") Integer id) { - return servirService.getServirById(id); - } - - @GetMapping("/getRemark/{id}") - public ResponseResult getRemarkById(@PathVariable("id") Integer id) { - return servirService.getRemarkById(id); - } - - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/SshLinkController.java b/src/main/java/com/mzaxd/noodles/controller/SshLinkController.java deleted file mode 100644 index 3ba829b..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/SshLinkController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.mzaxd.noodles.annotation.SysLog; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.SshLinkService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * @author 13439 - */ -@RestController -@RequestMapping("/sshLink") -public class SshLinkController { - - @Resource - private SshLinkService sshLinkService; - - @SysLog(operation = OperationEnum.CONSOLE_CONNECT) - @GetMapping("/getInstanceInfo/{sshId}") - public ResponseResult getInstanceInfo(@PathVariable("sshId") Long sshId) { - return sshLinkService.getInstanceInfo(sshId); - } - - -} diff --git a/src/main/java/com/mzaxd/noodles/controller/TagController.java b/src/main/java/com/mzaxd/noodles/controller/TagController.java deleted file mode 100644 index 396e5dd..0000000 --- a/src/main/java/com/mzaxd/noodles/controller/TagController.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mzaxd.noodles.controller; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.service.TagService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * @author 13439 - */ -@RestController -@RequestMapping("/tag") -public class TagController { - - @Resource - private TagService tagService; - - @GetMapping("/allTag") - public ResponseResult getAllTag() { - return tagService.getAllTag(); - } -} diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/Container.java b/src/main/java/com/mzaxd/noodles/domain/entity/Container.java deleted file mode 100644 index 43f0b31..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/Container.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName container - */ -@TableName(value ="container") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class Container implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 名称 - */ - private String name; - - /** - * 描述 - */ - private String description; - - /** - * 图像 - */ - private String avatar; - - /** - * 镜像名 - */ - private String imageName; - - /** - * WebUi URL - */ - private String webUi; - - /** - * 实际服务器地址(不带协议,不带端口号) - */ - private String serverAddress; - - /** - * 宿主机id - */ - private Long hostMachineId; - - /** - * ssh连接信息表id - */ - private Long sshId; - - /** - * 状态(0运行 1停止 2暂停 3未知) - */ - private Integer containerState; - - /** - * 提醒方式(0不提醒 1浏览器 2邮件 3浏览器&邮件) - */ - private Integer notify; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - /** - * 容器编号 - */ - private String containerId; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/EveryDayData.java b/src/main/java/com/mzaxd/noodles/domain/entity/EveryDayData.java deleted file mode 100644 index 88adf5f..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/EveryDayData.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName every_data - */ -@TableName(value ="everyday_data") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class EveryDayData implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 主机总数 - */ - private Integer hostCount; - - /** - * 主机在线数量 - */ - private Integer hostOnlineCount; - - /** - * 主机离线数量 - */ - private Integer hostOfflineCount; - - /** - * 主机状态未知数量 - */ - private Integer hostUnknownCount; - - /** - * 虚拟机总数 - */ - private Integer vmCount; - - /** - * 虚拟机在线数量 - */ - private Integer vmOnlineCount; - - /** - * 虚拟机离线数量 - */ - private Integer vmOfflineCount; - - /** - * 虚拟机状态未知数量 - */ - private Integer vmUnknownCount; - - /** - * 容器总数 - */ - private Integer containerCount; - - /** - * 容器在线数量 - */ - private Integer containerOnlineCount; - - /** - * 容器离线数量 - */ - private Integer containerOfflineCount; - - /** - * 容器状态未知数量 - */ - private Integer containerUnknownCount; - - /** - * 服务总数 - */ - private Integer servirCount; - - /** - * 操作数 - */ - private Integer auditCount; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/HostDetector.java b/src/main/java/com/mzaxd/noodles/domain/entity/HostDetector.java deleted file mode 100644 index fa6c07a..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/HostDetector.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * - * @author root - * @TableName host_detector - */ -@TableName(value ="host_detector") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class HostDetector implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 物理机id - */ - private Long hostMachineId; - - /** - * 探测器uuid(和机器一一绑定) - */ - private String detectorUuid; - - /** - * 探测器地址 - */ - private String detectorIpAddress; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/HostMachine.java b/src/main/java/com/mzaxd/noodles/domain/entity/HostMachine.java deleted file mode 100644 index edca780..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/HostMachine.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName host_machine - */ -@TableName(value ="host_machine") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class HostMachine implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 名称 - */ - private String name; - - /** - * 描述 - */ - private String description; - - /** - * 图像 - */ - private String avatar; - - /** - * ssh连接信息表id - */ - private Long sshId; - - /** - * 操作系统id - */ - private Long osId; - - /** - * 管理ip地址 - */ - private String manageIp; - - /** - * 实际服务器地址(不带协议,不带端口号) - */ - private String serverAddress; - - /** - * 宿主机id(0代表物理机没有宿主机) - */ - private Long hostMachineId; - - /** - * 核心线程数 - */ - private Long threads; - - /** - * 内存 - */ - private Long memory; - - /** - * 状态(0在线 1离线 2睡眠 3未知) - */ - private Integer hostMachineState; - - /** - * 提醒方式(0不提醒 1浏览器 2邮件 3浏览器&邮件) - */ - private Integer notify; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/Os.java b/src/main/java/com/mzaxd/noodles/domain/entity/Os.java deleted file mode 100644 index 6ddc8ad..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/Os.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * - * @author root - * @TableName os - */ -@TableName(value ="os") -@Data -@Accessors(chain = true) -public class Os implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 名称 - */ - private String name; - - /** - * 描述 - */ - private String description; - - /** - * 1代表Linux 2代表WindowsNT 3代表FreeBSD - */ - private Integer kernel; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id(0表示由系统创建) - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/Servir.java b/src/main/java/com/mzaxd/noodles/domain/entity/Servir.java deleted file mode 100644 index efe9394..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/Servir.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import java.io.Serializable; -import java.util.Date; - -import com.baomidou.mybatisplus.annotation.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName servir - */ -@TableName(value ="servir") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class Servir implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 名称 - */ - private String name; - - /** - * 描述 - */ - private String description; - - /** - * 图像 - */ - private String avatar; - - /** - * 备注 - */ - private String remark; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/ServirContainer.java b/src/main/java/com/mzaxd/noodles/domain/entity/ServirContainer.java deleted file mode 100644 index 37609ae..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/ServirContainer.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * - * @author 13439 - * @TableName servir_container - */ -@TableName(value ="servir_container") -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ServirContainer implements Serializable { - /** - * id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 服务id - */ - private Long servirId; - - /** - * 容器id - */ - private Long containerId; - - /** - * 描述(关联方式) - */ - private String description; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/ServirHost.java b/src/main/java/com/mzaxd/noodles/domain/entity/ServirHost.java deleted file mode 100644 index d3a941b..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/ServirHost.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName servir_host - */ -@TableName(value ="servir_host") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class ServirHost implements Serializable { - /** - * id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 服务id - */ - private Long servirId; - - /** - * 服务器id(物理机、虚拟机都可以) - */ - private Long hostId; - - /** - * 描述(关联方式) - */ - private String description; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/ServirTag.java b/src/main/java/com/mzaxd/noodles/domain/entity/ServirTag.java deleted file mode 100644 index 65222ed..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/ServirTag.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * - * @author 13439 - * @TableName servir_tag - */ -@TableName(value ="servir_tag") -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ServirTag implements Serializable { - /** - * id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 服务id - */ - private Long servirId; - - /** - * 标签id - */ - private Long tagId; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/SshLink.java b/src/main/java/com/mzaxd/noodles/domain/entity/SshLink.java deleted file mode 100644 index fd3751a..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/SshLink.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName ssh_link - */ -@TableName(value ="ssh_link") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class SshLink implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 账号 - */ - private String host; - - /** - * 名称 - */ - private String name; - - /** - * 端口号 - */ - private Integer port; - - /** - * 密码 - */ - private String password; - - /** - * 控制台类型(bash/sh) - */ - private String consoleType; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/entity/Tag.java b/src/main/java/com/mzaxd/noodles/domain/entity/Tag.java deleted file mode 100644 index 8a06512..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/entity/Tag.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.mzaxd.noodles.domain.entity; - -import com.baomidou.mybatisplus.annotation.*; - -import java.io.Serializable; -import java.util.Date; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * - * @author 13439 - * @TableName tag - */ -@TableName(value ="tag") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class Tag implements Serializable { - /** - * 主键id - */ - @TableId(type = IdType.AUTO) - private Long id; - - /** - * 名称 - */ - private String name; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 创建人id - */ - @TableField(fill = FieldFill.INSERT) - private Long createBy; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.UPDATE) - private Date updateTime; - - /** - * 更新人id - */ - @TableField(fill = FieldFill.UPDATE) - private Long updateBy; - - /** - * 删除标志(0代表未删除,1代表已删除) - */ - private Integer delFlag; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/noodles/domain/ssh/SshMessage.java b/src/main/java/com/mzaxd/noodles/domain/ssh/SshMessage.java deleted file mode 100644 index d0c8a22..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/ssh/SshMessage.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.mzaxd.noodles.domain.ssh; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author 13439 - */ - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class SshMessage { - - private String op; - - private Integer cols; - - private Integer rows; - - private String data; - -} diff --git a/src/main/java/com/mzaxd/noodles/domain/ssh/SshModel.java b/src/main/java/com/mzaxd/noodles/domain/ssh/SshModel.java deleted file mode 100644 index 89fe568..0000000 --- a/src/main/java/com/mzaxd/noodles/domain/ssh/SshModel.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.mzaxd.noodles.domain.ssh; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.core.util.EnumUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONArray; -import com.mzaxd.noodles.util.StringUtil; - -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.List; - -/** - * @ProjectName SshModel - * @author Administrator - * @version 1.0.0 - * @Description SshModel实体类 - * @createTime 2022/5/2 0002 15:29 - */ -public class SshModel { - - private String name; - private String host; - private Integer port; - private String user; - private String password; - /** - * 编码格式 - */ - private String charset; - - /** - * 文件目录 - */ - private String fileDirs; - - /** - * ssh 私钥 - */ - private String privateKey; - - private String connectType; - - /** - * 不允许执行的命令 - */ - private String notAllowedCommand; - - /** - * 允许编辑的后缀文件 - */ - private String allowEditSuffix; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNotAllowedCommand() { - return notAllowedCommand; - } - - public void setNotAllowedCommand(String notAllowedCommand) { - this.notAllowedCommand = notAllowedCommand; - } - - public ConnectType connectType() { - return EnumUtil.fromString(ConnectType.class, this.connectType, ConnectType.PASS); - } - - public String getConnectType() { - return connectType; - } - - public void setConnectType(String connectType) { - this.connectType = connectType; - } - - public String getPrivateKey() { - return privateKey; - } - - public void setPrivateKey(String privateKey) { - this.privateKey = privateKey; - } - - public String getFileDirs() { - return fileDirs; - } - - public void setFileDirs(String fileDirs) { - this.fileDirs = fileDirs; - } - - public List fileDirs() { - return StringUtil.jsonConvertArray(this.fileDirs, String.class); - } - - public void fileDirs(List fileDirs) { - if (fileDirs != null) { - for (int i = fileDirs.size() - 1; i >= 0; i--) { - String s = fileDirs.get(i); - fileDirs.set(i, FileUtil.normalize(s)); - } - this.fileDirs = JSONArray.toJSONString(fileDirs); - } else { - this.fileDirs = null; - } - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public Integer getPort() { - return port; - } - - public void setPort(Integer port) { - this.port = port; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getCharset() { - return charset; - } - - public void setCharset(String charset) { - this.charset = charset; - } - - public Charset getCharsetT() { - Charset charset; - try { - charset = Charset.forName(this.getCharset()); - } catch (Exception e) { - charset = CharsetUtil.CHARSET_UTF_8; - } - return charset; - } - - public List allowEditSuffix() { - return StringUtil.jsonConvertArray(this.allowEditSuffix, String.class); - } - - public void allowEditSuffix(List allowEditSuffix) { - if (allowEditSuffix == null) { - this.allowEditSuffix = null; - } else { - this.allowEditSuffix = JSONArray.toJSONString(allowEditSuffix); - } - } - - public String getAllowEditSuffix() { - return allowEditSuffix; - } - - public void setAllowEditSuffix(String allowEditSuffix) { - this.allowEditSuffix = allowEditSuffix; - } - - /** - * 检查是否包含禁止命令 - * - * @param sshItem 实体 - * @param inputItem 输入的命令 - * @return false 存在禁止输入的命令 - */ - public static boolean checkInputItem(SshModel sshItem, String inputItem) { - // 检查禁止执行的命令 - String notAllowedCommand = StrUtil.emptyToDefault(sshItem.getNotAllowedCommand(), StrUtil.EMPTY).toLowerCase(); - if (StrUtil.isEmpty(notAllowedCommand)) { - return true; - } - List split = Arrays.asList(StrUtil.split(notAllowedCommand, StrUtil.COMMA)); - inputItem = inputItem.toLowerCase(); - List commands = Arrays.asList(StrUtil.split(inputItem, StrUtil.CR)); - commands.addAll(Arrays.asList(StrUtil.split(inputItem, "&"))); - for (String s : split) { - // - boolean anyMatch = commands.stream().anyMatch(item -> StrUtil.startWithAny(item, s + StrUtil.SPACE, ("&" + s + StrUtil.SPACE), StrUtil.SPACE + s + StrUtil.SPACE)); - if (anyMatch) { - return false; - } - // - anyMatch = commands.stream().anyMatch(item -> StrUtil.equals(item, s)); - if (anyMatch) { - return false; - } - } - return true; - } - - public enum ConnectType { - /** - * 账号密码 - */ - PASS, - /** - * 密钥 - */ - PUBKEY - } -} diff --git a/src/main/java/com/mzaxd/noodles/job/CheckInstancesStatus.java b/src/main/java/com/mzaxd/noodles/job/CheckInstancesStatus.java deleted file mode 100644 index 31bd5da..0000000 --- a/src/main/java/com/mzaxd/noodles/job/CheckInstancesStatus.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.mzaxd.noodles.job; - -import cn.hutool.http.HttpRequest; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.constant.UrlConstant; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.service.*; -import com.mzaxd.noodles.util.CpuUtil; -import com.mzaxd.noodles.util.RedisCache; -import com.mzaxd.noodles.util.UrlUtil; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import javax.annotation.Resource; -import java.util.*; -import java.util.concurrent.*; - -/** - * 检测所有实例的在线状态 - * - * @author 13439 - */ - -@Slf4j -@Component -public class CheckInstancesStatus { - - @Resource - private ContainerService containerService; - - @Resource - private HostMachineService hostMachineService; - - @Resource - private HostDetectorService hostDetectorService; - - @Resource - private NotificationService notificationService; - - @Resource - private RedisCache redisCache; - - @Resource - private RedisTemplate redisTemplate; - - /** - * 检查实例状态并且发送对应的提醒 - */ - @SneakyThrows - @Scheduled(cron = "* 0/2 * * * ?") - public void checkInstancesStatus() { - List containers = containerService.list(); - - // Create a thread pool with a fixed number of threads - ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - - // Submit each container to the thread pool for processing - for (Container container : containers) { - executor.submit(() -> { - try { - if (!StringUtils.hasText(container.getWebUi()) && !StringUtils.hasText(container.getServerAddress())) { - container.setContainerState(SystemConstant.CONTAINER_STATE_UNKNOWN); - containerService.saveOrUpdate(container); - return; - } - //通过Socket(IP+端口)判断是否在线 - if (StringUtils.hasText(container.getServerAddress())) { - if (UrlUtil.isServiceOnline(UrlUtil.getHostname(container.getServerAddress()), UrlUtil.getPort(container.getServerAddress()))) { - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - containerService.saveOrUpdate(container); - return; - } - } - //通过HTTP请求判断是否在线 - HttpRequest.get(container.getWebUi()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - containerService.saveOrUpdate(container); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_EXITED); - containerService.saveOrUpdate(container); - // 判断 Redis 里面有没有,如果有就不需要提醒,如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (CollectionUtils.isEmpty(set)) { - set = new HashSet<>(); - } - // 如果 Redis 里面有,说明已经发送过了未 check 的通知,所以不需要发送,直接返回 - if (set.contains(container.getId().toString())) { - return; - } else { - // 根据实例对应的提醒方式进行提醒 - if (container.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } - if (container.getNotify().equals(SystemConstant.NOTIFY_BROWSER)) { - notificationService.sendContainerOfflineNotification(container.getId()); - set.add(container.getId().toString()); - } - if (container.getNotify().equals(SystemConstant.NOTIFY_EMAIL)) { - notificationService.sendContainerOfflineEmail(container.getId()); - set.add(container.getId().toString()); - } - if (container.getNotify().equals(SystemConstant.NOTIFY_BROWSER_EMAIL)) { - notificationService.sendContainerOfflineNotificationEmail(container.getId()); - set.add(container.getId().toString()); - } - } - redisCache.setCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS, set); - } - }); - } - - // Shutdown the thread pool and wait for all tasks to complete - executor.shutdown(); - executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - - //检测虚拟机在线状态 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - List vms = hostMachineService.list(vmWrapper); - vms.forEach(vm -> { - try { - if (!StringUtils.hasText(vm.getServerAddress()) && !StringUtils.hasText(vm.getServerAddress())) { - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - hostMachineService.saveOrUpdate(vm); - return; - } - //通过Ping的方式判断是否在线 - if (StringUtils.hasText(vm.getServerAddress())) { - if (UrlUtil.isHostOnline(vm.getServerAddress())) { - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachineService.saveOrUpdate(vm); - return; - } - } - //通过HTTP请求的方式判断是否在线 - HttpRequest.get(vm.getManageIp()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachineService.saveOrUpdate(vm); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - hostMachineService.saveOrUpdate(vm); - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_VM_IDS); - if (CollectionUtils.isEmpty(set)) { - set = new HashSet<>(); - } - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(vm.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (vm.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } - if (vm.getNotify().equals(SystemConstant.NOTIFY_BROWSER)) { - notificationService.sendContainerOfflineNotification(vm.getId()); - set.add(vm.getId().toString()); - } - if (vm.getNotify().equals(SystemConstant.NOTIFY_EMAIL)) { - notificationService.sendContainerOfflineEmail(vm.getId()); - set.add(vm.getId().toString()); - } - if (vm.getNotify().equals(SystemConstant.NOTIFY_BROWSER_EMAIL)) { - notificationService.sendContainerOfflineNotificationEmail(vm.getId()); - set.add(vm.getId().toString()); - } - } - redisCache.setCacheSet(RedisConstant.NOTIFY_VM_IDS, set); - } - }); - - //检测物理机在线状态(检测物理机要用探测器的isTureUrl接口) - LambdaQueryWrapper detectorWrapper = new LambdaQueryWrapper<>(); - List hostDetectors = hostDetectorService.list(detectorWrapper); - List hostMachines = new ArrayList<>(); - hostDetectors.forEach(detector -> { - try { - HttpRequest.get(detector.getDetectorIpAddress() + UrlConstant.DETECTOR_IS_TRUE_URL).setConnectionTimeout(5000).execute(true); - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachineService.saveOrUpdate(hostMachine); - } - } catch (Exception exception) { - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - hostMachineService.saveOrUpdate(hostMachine); - } - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_HOST_IDS); - if (CollectionUtils.isEmpty(set)) { - set = new HashSet<>(); - } - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(hostMachine.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_BROWSER)) { - notificationService.sendContainerOfflineNotification(hostMachine.getId()); - set.add(hostMachine.getId().toString()); - } - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_EMAIL)) { - notificationService.sendContainerOfflineEmail(hostMachine.getId()); - set.add(hostMachine.getId().toString()); - } - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_BROWSER_EMAIL)) { - notificationService.sendContainerOfflineNotificationEmail(hostMachine.getId()); - set.add(hostMachine.getId().toString()); - } - } - redisCache.setCacheSet(RedisConstant.NOTIFY_HOST_IDS, set); - } - }); - } -} diff --git a/src/main/java/com/mzaxd/noodles/job/EveryDayDataCollect.java b/src/main/java/com/mzaxd/noodles/job/EveryDayDataCollect.java deleted file mode 100644 index 1c7146f..0000000 --- a/src/main/java/com/mzaxd/noodles/job/EveryDayDataCollect.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.mzaxd.noodles.job; - -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.entity.AuditLog; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.entity.EveryDayData; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.service.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.Date; -import java.util.Map; - -/** - * @author 13439 - */ - -@Slf4j -@Component -public class EveryDayDataCollect { - - @Resource - private HostMachineService hostMachineService; - - @Resource - private ContainerService containerService; - - @Resource - private ServirService servirService; - - @Resource - private AuditLogService auditLogService; - - @Resource - private EveryDayDataService everyDayDataService; - - /** - * 每天晚上收集今日数据 - */ - @Scheduled(cron = "0 59 23 * * ?") - public void everyDayDataCollect() { - EveryDayData everyDayData = new EveryDayData(); - LambdaQueryWrapper auditLogWrapper = new LambdaQueryWrapper<>(); - Map hostStateInfo = hostMachineService.getHostStateInfo(); - Map vmStateInfo = hostMachineService.getVmStateInfo(); - Map containerStateInfo = containerService.getContainerStateInfo(); - //设置主机总数 - everyDayData.setHostCount(hostStateInfo.get("hostCount")); - //设置主机在线总数 - everyDayData.setHostOnlineCount(hostStateInfo.get("hostOnlineCount")); - //设置主机离线总数 - everyDayData.setHostOfflineCount(hostStateInfo.get("hostOfflineCount")); - //设置主机未知总数 - everyDayData.setHostUnknownCount(hostStateInfo.get("hostUnknownCount")); - //设置虚拟机总数 - everyDayData.setVmCount(vmStateInfo.get("vmCount")); - //设置虚拟机在线总数 - everyDayData.setVmOnlineCount(vmStateInfo.get("vmOnlineCount")); - //设置虚拟机离线总数 - everyDayData.setVmOfflineCount(vmStateInfo.get("vmOfflineCount")); - //设置虚拟机未知总数 - everyDayData.setVmUnknownCount(vmStateInfo.get("vmUnknownCount")); - //设置容器总数 - everyDayData.setContainerCount(containerStateInfo.get("containerCount")); - //设置容器在线总数 - everyDayData.setContainerOnlineCount(containerStateInfo.get("containerOnlineCount")); - //设置容器离线总数 - everyDayData.setContainerOfflineCount(containerStateInfo.get("containerOfflineCount")); - //设置容器未知总数 - everyDayData.setContainerUnknownCount(containerStateInfo.get("containerUnknownCount")); - //设置服务总数 - everyDayData.setServirCount(servirService.count()); - //设置操作总数 - auditLogWrapper.ge(AuditLog::getCreateTime, DateUtil.beginOfDay(DateUtil.date())); - auditLogWrapper.lt(AuditLog::getCreateTime, DateUtil.endOfDay(DateUtil.date())); - everyDayData.setAuditCount(auditLogService.count(auditLogWrapper)); - everyDayDataService.save(everyDayData); - } -} diff --git a/src/main/java/com/mzaxd/noodles/listener/RabbitDynamicDataConsumer.java b/src/main/java/com/mzaxd/noodles/listener/RabbitDynamicDataConsumer.java deleted file mode 100644 index bbed4de..0000000 --- a/src/main/java/com/mzaxd/noodles/listener/RabbitDynamicDataConsumer.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.mzaxd.noodles.listener; - -import com.mzaxd.noodles.constant.RabbitMqConstant; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.util.RedisCache; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.annotation.Queue; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; - -/** - * @author root - */ -@Slf4j -@Component -@RabbitListener(queuesToDeclare = @Queue(RabbitMqConstant.DYNAMIC_DATA_TOPIC)) -public class RabbitDynamicDataConsumer { - - @Resource - private RedisCache redisCache; - - @RabbitHandler - public void process(@Payload DynamicData dynamicData) { - log.info("开始消费动态数据消息"); - //将Redis中旧的数据删除 - redisCache.deleteObject(RedisConstant.DYNAMIC_DATA + dynamicData.getDetectorId()); - //将新的动态数据存入Redis - redisCache.setCacheObject(RedisConstant.DYNAMIC_DATA + dynamicData.getDetectorId(), dynamicData); - log.info("更新Redis中动态数据成功"); - } -} diff --git a/src/main/java/com/mzaxd/noodles/mapper/ContainerMapper.java b/src/main/java/com/mzaxd/noodles/mapper/ContainerMapper.java deleted file mode 100644 index 37e4443..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/ContainerMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.Container; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author root -* @description 针对表【container】的数据库操作Mapper -* @createDate 2023-02-02 06:26:00 -* @Entity com.mzaxd.noodles.domain.entity.Container -*/ -public interface ContainerMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/EveryDayDataMapper.java b/src/main/java/com/mzaxd/noodles/mapper/EveryDayDataMapper.java deleted file mode 100644 index 77d6383..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/EveryDayDataMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.EveryDayData; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【every_data】的数据库操作Mapper -* @createDate 2023-02-21 12:52:12 -* @Entity com.mzaxd.noodles.domain.entity.EveryDayData -*/ -public interface EveryDayDataMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/HostDetectorMapper.java b/src/main/java/com/mzaxd/noodles/mapper/HostDetectorMapper.java deleted file mode 100644 index 42ea251..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/HostDetectorMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author root -* @description 针对表【host_detector】的数据库操作Mapper -* @createDate 2023-02-05 13:18:46 -* @Entity com.mzaxd.noodles.domain.entity.HostDetector -*/ -public interface HostDetectorMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/HostMachineMapper.java b/src/main/java/com/mzaxd/noodles/mapper/HostMachineMapper.java deleted file mode 100644 index 2c8a4e7..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/HostMachineMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -import java.util.List; - -/** -* @author root -* @description 针对表【host_machine】的数据库操作Mapper -* @createDate 2023-01-30 01:24:08 -* @Entity com.mzaxd.noodles.domain.entity.HostMachine -*/ -public interface HostMachineMapper extends BaseMapper { - - /** - * 返回VMList所需的所有数据 - * - * @param nameLike - * @param selectedKernel - * @param selectedHost - * @param selectedStatus - * @param perPage - * @param currentPage - * @return - */ - List vmListWithCondition(String nameLike, List selectedKernel, List selectedHost, List selectedStatus, Integer perPage, Integer currentPage); -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/OsMapper.java b/src/main/java/com/mzaxd/noodles/mapper/OsMapper.java deleted file mode 100644 index 76a3067..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/OsMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.Os; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author root -* @description 针对表【os】的数据库操作Mapper -* @createDate 2023-01-30 13:20:28 -* @Entity com.mzaxd.noodles.domain.entity.Os -*/ -public interface OsMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/ServirContainerMapper.java b/src/main/java/com/mzaxd/noodles/mapper/ServirContainerMapper.java deleted file mode 100644 index da249f2..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/ServirContainerMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.ServirContainer; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【servir_container】的数据库操作Mapper -* @createDate 2023-02-11 20:48:45 -* @Entity com.mzaxd.noodles.domain.entity.ServirContainer -*/ -public interface ServirContainerMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/ServirHostMapper.java b/src/main/java/com/mzaxd/noodles/mapper/ServirHostMapper.java deleted file mode 100644 index 86912fa..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/ServirHostMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.ServirHost; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【servir_host】的数据库操作Mapper -* @createDate 2023-02-11 20:48:51 -* @Entity com.mzaxd.noodles.domain.entity.ServirHost -*/ -public interface ServirHostMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/ServirMapper.java b/src/main/java/com/mzaxd/noodles/mapper/ServirMapper.java deleted file mode 100644 index 5ec1e16..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/ServirMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.mzaxd.noodles.domain.entity.Servir; - -/** -* @author 13439 -* @description 针对表【service】的数据库操作Mapper -* @createDate 2023-02-11 17:51:37 -* @Entity com.mzaxd.noodles.domain.entity.Service -*/ -public interface ServirMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/ServirTagMapper.java b/src/main/java/com/mzaxd/noodles/mapper/ServirTagMapper.java deleted file mode 100644 index 9430ae8..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/ServirTagMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.ServirTag; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【servir_tag】的数据库操作Mapper -* @createDate 2023-02-11 19:40:35 -* @Entity com.mzaxd.noodles.domain.entity.ServirTag -*/ -public interface ServirTagMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/SshLinkMapper.java b/src/main/java/com/mzaxd/noodles/mapper/SshLinkMapper.java deleted file mode 100644 index 472359d..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/SshLinkMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.SshLink; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【ssh_link】的数据库操作Mapper -* @createDate 2023-02-24 20:30:25 -* @Entity com.mzaxd.noodles.domain.entity.SshLink -*/ -public interface SshLinkMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/mapper/TagMapper.java b/src/main/java/com/mzaxd/noodles/mapper/TagMapper.java deleted file mode 100644 index a0cdd65..0000000 --- a/src/main/java/com/mzaxd/noodles/mapper/TagMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mzaxd.noodles.mapper; - -import com.mzaxd.noodles.domain.entity.Tag; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 13439 -* @description 针对表【tag】的数据库操作Mapper -* @createDate 2023-02-11 18:26:12 -* @Entity com.mzaxd.noodles.domain.entity.Tag -*/ -public interface TagMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/ContainerService.java b/src/main/java/com/mzaxd/noodles/service/ContainerService.java deleted file mode 100644 index 829498f..0000000 --- a/src/main/java/com/mzaxd/noodles/service/ContainerService.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Container; -import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.vo.ContainerVo; - -import java.util.List; -import java.util.Map; - -/** -* @author root -* @description 针对表【container】的数据库操作Service -* @createDate 2023-02-02 06:26:00 -*/ -public interface ContainerService extends IService { - - /** - * 返回简要统计信息 - * - * @author mzaxd - * @date 2/2/23 6:26 AM - * @return ResponseResult - */ - ResponseResult containerListSummaryStatistics(); - - /** - * 容器列表 - * - * @author mzaxd - * @date 2/2/23 7:06 AM - * @param nameLike - * @param selectedHost - * @param selectedStatus - * @param perPage - * @param currentPage - * @return ResponseResult - */ - ResponseResult containerListWithCondition(String nameLike, List selectedHost, List selectedStatus, Integer perPage, Integer currentPage); - - /** - * 获取所有宿主机 - * - * @author mzaxd - * @date 2/2/23 9:08 AM - * @return ResponseResult - */ - ResponseResult getAllHost(); - - /** - * 根据id删除容器 - * - * @author mzaxd - * @date 2/2/23 11:07 AM - * @param id - * @return ResponseResult - */ - ResponseResult deleteContainerById(Integer id); - - /** - * 添加容器 - * - * @author mzaxd - * @date 2/2/23 12:02 PM - * @param vm - * @return ResponseResult - */ - ResponseResult addContainer(ContainerVo vm); - - /** - * 根据id获取容器 - * - * @author mzaxd - * @date 2/2/23 12:45 PM - * @param id - * @return ResponseResult - */ - ResponseResult getContainer(Integer id); - - /** - * 编辑容器 - * - * @author mzaxd - * @date 2/2/23 1:15 PM - * @param container - * @return ResponseResult - */ - ResponseResult updateContainer(ContainerVo container); - - /** - * 获取所有容器 - * - * @return - */ - ResponseResult getAllContainer(); - - /** - * 根据物理机id查找容器 - * - * @param id - * @param rowPerPage - * @param currentPage - * @return - */ - ResponseResult getAssociatedContainers(Integer id, Integer rowPerPage, Integer currentPage); - - - /** - * 获取容器状态信息 - * - * @return - */ - Map getContainerStateInfo(); -} diff --git a/src/main/java/com/mzaxd/noodles/service/EveryDayDataService.java b/src/main/java/com/mzaxd/noodles/service/EveryDayDataService.java deleted file mode 100644 index eb17568..0000000 --- a/src/main/java/com/mzaxd/noodles/service/EveryDayDataService.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.EveryDayData; -import com.baomidou.mybatisplus.extension.service.IService; - -import java.util.List; - -/** -* @author 13439 -* @description 针对表【every_data】的数据库操作Service -* @createDate 2023-02-21 12:52:12 -*/ -public interface EveryDayDataService extends IService { - - /** - * 返回昨日操作次数 - * - * @return - */ - ResponseResult getAuditLogCountYesterday(); - - /** - * 返回昨日实例情况 - * - * @return - */ - ResponseResult getInstancesHistory(); - - /** - * 获取昨天的每日数据 - * - * @return - */ - EveryDayData getYesterdayData(); - - /** - * 获取上周的每日数据 - * - * @return - */ - List getLastWeekData(); - - /** - * 获取前六天的每日数据 - * - * @return - */ - List getLastSixDayData(); - -} diff --git a/src/main/java/com/mzaxd/noodles/service/HostDetectorService.java b/src/main/java/com/mzaxd/noodles/service/HostDetectorService.java deleted file mode 100644 index 34b0c93..0000000 --- a/src/main/java/com/mzaxd/noodles/service/HostDetectorService.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.domain.message.Server; - -import java.util.List; -import java.util.Map; - -/** -* @author root -* @description 针对表【host_detector】的数据库操作Service -* @createDate 2023-02-05 13:18:46 -*/ -public interface HostDetectorService extends IService { - - /** - * 判断探测器IP是否有效 - * - * @author mzaxd - * @date 2/7/23 6:32 AM - * @param url - * @return ResponseResult - */ - boolean isValidUrl(String url); - - /** - * 获取所有在线的探测器 - * - * @author mzaxd - * @date 2/8/23 4:38 AM - * @return HostDetector - */ - List getAllALiveDetectors(); - - /** - * 返回所有探测器获取动态数据 - * - * @author mzaxd - * @date 2/8/23 6:28 AM - * @param allAliveDetector - * @return Map - */ - Map getDynamicData(List allAliveDetector); - - /** - * 指定探测器获取动态数据 - * - * @author mzaxd - * @date 2/8/23 6:28 AM - * @param detector - * @return Map - */ - Map getDynamicDataByDetector(HostDetector detector); - - /** - * 检查是否是有效探测器地址 - * - * @param protocol - * @param ip - * @param port - * @return - */ - ResponseResult isValidUrl(String protocol, String ip, String port); - - /** - * 根据url获取远程主机信息 - * - * @param url - * @return - */ - Server detectorGetInfoByUrl(String url); - - /** - * 返回内存整体使用信息 - * - * @return - */ - ResponseResult getMemInfo(); -} diff --git a/src/main/java/com/mzaxd/noodles/service/HostMachineService.java b/src/main/java/com/mzaxd/noodles/service/HostMachineService.java deleted file mode 100644 index 17ffa53..0000000 --- a/src/main/java/com/mzaxd/noodles/service/HostMachineService.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.vo.HostVo; -import com.mzaxd.noodles.domain.vo.VmVo; - -import java.util.List; -import java.util.Map; - -/** -* @author root -* @description 针对表【host_machine】的数据库操作Service -* @createDate 2023-01-30 01:24:08 -*/ -public interface HostMachineService extends IService { - - /** - * 返回所有host的部分数据 - * - * @author mzaxd - * @date 1/30/23 1:25 AM - * @return ResultSet - */ - ResponseResult getHostDrawer(); - - /** - * 按照一定条件返回vm的List - * - * @author mzaxd - * @date 1/30/23 10:32 AM - * @param nameLike - * @param selectedKernel - * @param selectedHost - * @param selectedStatus - * @param perPage - * @param currentPage - * @return ResponseResult - */ - ResponseResult vmListWithCondition(String nameLike, List selectedKernel, List selectedHost, List selectedStatus, Integer perPage, Integer currentPage); - - /** - * 返回VM总数和三种状态的数据 - * - * @author mzaxd - * @date 1/31/23 10:22 AM - * @return ResponseResult - */ - ResponseResult vmListSummaryStatistics(); - - /** - * 修改vm - * - * @author mzaxd - * @date 2/1/23 3:05 AM - * @param addVmVo - * @return ResponseResult - */ - ResponseResult updateVm(VmVo addVmVo); - - /** - * 根据id删除vm - * - * @author mzaxd - * @date 2/1/23 5:11 AM - * @param id - * @return ResponseResult - */ - ResponseResult deleteVmById(Integer id); - - /** - * 根据id查找vm - * - * @author mzaxd - * @date 2/1/23 10:33 AM - * @param id - * @return ResponseResult - */ - ResponseResult getVmById(Integer id); - - /** - * 添加vm - * - * @author mzaxd - * @date 2/1/23 3:05 AM - * @param vm - * @return ResponseResult - */ - ResponseResult addVm(VmVo vm); - - /** - * 按照一定条件返回物理机的List - * - * @author mzaxd - * @date 2/5/23 1:05 PM - * @param nameLike - * @param selectedStatus - * @param perPage - * @param currentPage - * @return ResponseResult - */ - ResponseResult hostListWithCondition(String nameLike, List selectedStatus, Integer perPage, Integer currentPage); - - /** - * 添加物理机 - * - * @author mzaxd - * @date 2/7/23 8:39 AM - * @param host - * @return ResponseResult - */ - ResponseResult addHost(HostVo host); - - /** - * 根据id返回Host - * - * @param id - * @return - */ - ResponseResult getHostById(Integer id); - - /** - * 修改host - * - * @param host - * @return - */ - ResponseResult updateHost(HostVo host); - - /** - * 通过id删除host - * - * @param id - * @return - */ - ResponseResult deleteHostById(Integer id); - - /** - * 获取主机详细信息 - * - * @param id - * @return - */ - ResponseResult getHostDetail(Integer id); - - /** - * 获取所有基于此ID的虚拟机 - * - * @param id - * @param perPage - * @param currentPage - * @return - */ - ResponseResult getAssociatedVms(Integer id, Integer perPage, Integer currentPage); - - /** - * 获取所有物理机的磁盘信息 - * - * @param id - * @return - */ - ResponseResult getAssociatedDisks(Integer id); - - /** - * 获取所有物理机的网络接口信息 - * - * @param id - * @return - */ - ResponseResult getAssociatedNetworkIfs(Integer id); - - /** - * 获取物理机状态信息 - * - * @return - */ - Map getHostStateInfo(); - - /** - * 获取虚拟机状态信息 - * - * @return - */ - Map getVmStateInfo(); - - /** - * 根据前端发来的hostID通知对应探测器开始发送动态数据 - * @param hostId - * @return - */ - ResponseResult startSendDynamicData(Integer hostId); - - /** - * 根据前端发来的hostID通知对应探测器停止发送动态数据 - * @param hostId - * @return - */ - ResponseResult stopSendDynamicData(Integer hostId); -} diff --git a/src/main/java/com/mzaxd/noodles/service/NotificationService.java b/src/main/java/com/mzaxd/noodles/service/NotificationService.java deleted file mode 100644 index 3ee8c30..0000000 --- a/src/main/java/com/mzaxd/noodles/service/NotificationService.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Notification; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【notification】的数据库操作Service -* @createDate 2023-02-16 16:04:53 -*/ -public interface NotificationService extends IService { - - /** - * 发送容器掉线通知 - * @param id - */ - void sendContainerOfflineNotification(Long id); - - /** - * 发送容器掉线通知和邮件 - * @param id - */ - void sendContainerOfflineNotificationEmail(Long id); - - /** - * 发送容器掉线邮件 - * @param id - */ - void sendContainerOfflineEmail(Long id); - - /** - * 发送虚拟机掉线通知 - * @param id - */ - void sendVmOfflineNotification(Long id); - - /** - * 发送虚拟机掉线邮件 - * @param id - */ - void sendVmOfflineEmail(Long id); - - /** - * 发送虚拟机掉线通知和邮件 - * @param id - */ - void sendVmOfflineNotificationEmail(Long id); - - /** - * 发送物理机掉线通知 - * @param id - */ - void sendHostOfflineNotification(Long id); - - /** - * 发送物理机掉线邮件 - * @param id - */ - void sendHostOfflineEmail(Long id); - - /** - * 发送物理机掉线通知和邮件 - * @param id - */ - void sendHostOfflineNotificationEmail(Long id); - - - /** - * 提醒列表 - * @param tab - * @param perPage - * @param currentPage - * @return - */ - ResponseResult getNotificationList(Integer tab, Integer perPage, Integer currentPage); - - /** - * 获取新通知数量 - * @return - */ - ResponseResult getNotificationCount(); - - /** - * 确认提醒 - * - * @param id - * @return - */ - ResponseResult affirmNotification(Long id); -} diff --git a/src/main/java/com/mzaxd/noodles/service/OsService.java b/src/main/java/com/mzaxd/noodles/service/OsService.java deleted file mode 100644 index 6dc5968..0000000 --- a/src/main/java/com/mzaxd/noodles/service/OsService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.entity.Os; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author root -* @description 针对表【os】的数据库操作Service -* @createDate 2023-01-30 13:20:28 -*/ -public interface OsService extends IService { - -} diff --git a/src/main/java/com/mzaxd/noodles/service/ServirContainerService.java b/src/main/java/com/mzaxd/noodles/service/ServirContainerService.java deleted file mode 100644 index 255b4ae..0000000 --- a/src/main/java/com/mzaxd/noodles/service/ServirContainerService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.entity.ServirContainer; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【servir_container】的数据库操作Service -* @createDate 2023-02-11 20:48:45 -*/ -public interface ServirContainerService extends IService { - -} diff --git a/src/main/java/com/mzaxd/noodles/service/ServirHostService.java b/src/main/java/com/mzaxd/noodles/service/ServirHostService.java deleted file mode 100644 index 3b259d3..0000000 --- a/src/main/java/com/mzaxd/noodles/service/ServirHostService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.entity.ServirHost; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【servir_host】的数据库操作Service -* @createDate 2023-02-11 20:48:51 -*/ -public interface ServirHostService extends IService { - -} diff --git a/src/main/java/com/mzaxd/noodles/service/ServirService.java b/src/main/java/com/mzaxd/noodles/service/ServirService.java deleted file mode 100644 index 66229df..0000000 --- a/src/main/java/com/mzaxd/noodles/service/ServirService.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Servir; -import com.baomidou.mybatisplus.extension.service.IService; -import com.mzaxd.noodles.domain.vo.SaveOrUpdateServirVo; -import com.mzaxd.noodles.domain.vo.ServirListVo; - -import java.util.List; - -/** -* @author 13439 -* @description 针对表【servir】的数据库操作Service -* @createDate 2023-02-11 18:00:24 -*/ -public interface ServirService extends IService { - - - /** - * 根据条件返回所有服务 - * - * @param nameLike - * @param selectedTags - * @param perPage - * @param currentPage - * @return - */ - ResponseResult servirListWithCondition(String nameLike, List selectedTags, Integer perPage, Integer currentPage); - - /** - * 添加服务 - * - * @param servir - * @return - */ - ResponseResult addServir(SaveOrUpdateServirVo servir); - - /** - * 根据id删除服务 - * - * @param id - * @return - */ - ResponseResult deleteServirById(Integer id); - - /** - * 根据id查找 - * - * @param id - * @return - */ - ResponseResult getServirById(Integer id); - - /** - * 改 - * - * @param - * @return - */ - ResponseResult updateServir(SaveOrUpdateServirVo saveOrUpdateServirVo); - - /** - * 获取备注 - * - * @param id - * @return - */ - ResponseResult getRemarkById(Integer id); - -} diff --git a/src/main/java/com/mzaxd/noodles/service/ServirTagService.java b/src/main/java/com/mzaxd/noodles/service/ServirTagService.java deleted file mode 100644 index 30ee5e7..0000000 --- a/src/main/java/com/mzaxd/noodles/service/ServirTagService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.entity.ServirTag; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【servir_tag】的数据库操作Service -* @createDate 2023-02-11 19:40:35 -*/ -public interface ServirTagService extends IService { - -} diff --git a/src/main/java/com/mzaxd/noodles/service/SshLinkService.java b/src/main/java/com/mzaxd/noodles/service/SshLinkService.java deleted file mode 100644 index af2e07a..0000000 --- a/src/main/java/com/mzaxd/noodles/service/SshLinkService.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.SshLink; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【ssh_link】的数据库操作Service -* @createDate 2023-02-24 20:30:25 -*/ -public interface SshLinkService extends IService { - - /** - * 根据sshId返回实例信息 - * - * @param sshId - * @return - */ - ResponseResult getInstanceInfo(Long sshId); - - - /** - * 根据sshId返回对应的Object - * - * @param sshId - * @return - */ - Object getInstanceInfoBySshId(Long sshId); -} diff --git a/src/main/java/com/mzaxd/noodles/service/TagService.java b/src/main/java/com/mzaxd/noodles/service/TagService.java deleted file mode 100644 index 5ffda68..0000000 --- a/src/main/java/com/mzaxd/noodles/service/TagService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mzaxd.noodles.service; - -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Tag; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 13439 -* @description 针对表【tag】的数据库操作Service -* @createDate 2023-02-11 18:26:12 -*/ -public interface TagService extends IService { - - /** - * 获取所有tag - * - * @return - */ - ResponseResult getAllTag(); -} diff --git a/src/main/java/com/mzaxd/noodles/service/impl/ContainerServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/ContainerServiceImpl.java deleted file mode 100644 index 3703ce1..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/ContainerServiceImpl.java +++ /dev/null @@ -1,229 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.vo.*; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.mapper.HostMachineMapper; -import com.mzaxd.noodles.mapper.NotificationMapper; -import com.mzaxd.noodles.service.ContainerService; -import com.mzaxd.noodles.mapper.ContainerMapper; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.service.SshLinkService; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.SshLinkUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; - -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @author root - * @description 针对表【container】的数据库操作Service实现 - * @createDate 2023-02-02 06:26:00 - */ -@Service -@Slf4j -public class ContainerServiceImpl extends ServiceImpl - implements ContainerService { - - @Resource - private ContainerMapper containerMapper; - - @Resource - private HostMachineService hostMachineService; - - @Resource - private HostMachineMapper hostMachineMapper; - - @Resource - private SshLinkService sshLinkService; - - @Resource - private NotificationMapper notificationMapper; - - @Override - public ResponseResult containerListSummaryStatistics() { - //设置查询所有在线vm的条件 - LambdaQueryWrapper runningWrapper = new LambdaQueryWrapper<>(); - runningWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_RUNNING); - //设置查询所有离线vm的条件 - LambdaQueryWrapper exitedWrapper = new LambdaQueryWrapper<>(); - exitedWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_EXITED); - //设置查询所有未知vm的条件 - LambdaQueryWrapper pausedWrapper = new LambdaQueryWrapper<>(); - pausedWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_UNKNOWN); - - int total = count(); - int running = count(runningWrapper); - int exited = count(exitedWrapper); - int paused = count(pausedWrapper); - HashMap result = new HashMap<>(4); - result.put("total", total); - result.put("running", running); - result.put("exited", exited); - result.put("unknown", paused); - return ResponseResult.okResult(result); - - } - - @Override - public ResponseResult containerListWithCondition(String nameLike, List selectedHost, List selectedStatus, Integer perPage, Integer currentPage) { - //设置查询条件 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.like(StringUtils.hasText(nameLike), Container::getDescription, nameLike); - wrapper.in(Objects.nonNull(selectedHost), Container::getHostMachineId, selectedHost); - wrapper.in(Objects.nonNull(selectedStatus), Container::getContainerState, selectedStatus); - //分页 - PageHelper.startPage(currentPage, perPage); - //查询 - List containers = list(wrapper); - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(containers, perPage); - - //封装结果返回 - List containerListVos = BeanCopyUtils.copyBeanList(containers, ContainerVo.class); - - containerListVos.forEach(containerListVo -> { - HostMachine hostMachine = hostMachineMapper.selectById(containerListVo.getHostMachineId()); - HostMachineVo hostMachineVo = BeanCopyUtils.copyBean(hostMachine, HostMachineVo.class); - containerListVo.setHostMachine(hostMachineVo); - }); - - pageInfo.setList(containerListVos); - return ResponseResult.okResult(pageInfo); - } - - @Override - public ResponseResult getAllHost() { - List hostMachines = hostMachineService.list(); - List hostMachineVos = BeanCopyUtils.copyBeanList(hostMachines, HostMachineVo.class); - return ResponseResult.okResult(hostMachineVos); - } - - @Override - public ResponseResult deleteContainerById(Integer id) { - if (removeById(id)) { - //删除掉线提醒 - LambdaQueryWrapper notificationLambdaQueryWrapper = new LambdaQueryWrapper<>(); - notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id); - notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_CONTAINER); - notificationMapper.delete(notificationLambdaQueryWrapper); - log.info("删除id为{}的虚拟机的所有掉线提醒", id); - return ResponseResult.okResult("删除成功"); - } - return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR); - } - - @Override - public ResponseResult addContainer(ContainerVo containerVo) { - Container container = BeanCopyUtils.copyBean(containerVo, Container.class); - SshLink sshLink = new SshLink(); - if (SshLinkUtil.isContainerSshLinkParamValid(containerVo)) { - sshLink.setConsoleType(containerVo.getSshType()) - .setHost(containerVo.getSshHost()) - .setPort(containerVo.getSshPort()) - .setName(containerVo.getSshUser()) - .setPassword(containerVo.getSshPwd()); - sshLinkService.save(sshLink); - container.setSshId(sshLink.getId()); - } - save(container); - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getContainer(Integer id) { - Container container = getById(id); - ContainerVo containerVo = BeanCopyUtils.copyBean(container, ContainerVo.class); - if (Objects.nonNull(getById(id).getSshId())) { - SshLink sshLink = sshLinkService.getById(container.getSshId()); - containerVo.setSshType(sshLink.getConsoleType()) - .setSshHost(sshLink.getHost()) - .setSshPort(sshLink.getPort()) - .setSshUser(sshLink.getName()) - .setSshPwd(sshLink.getPassword()); - } - return ResponseResult.okResult(containerVo); - } - - @Override - public ResponseResult updateContainer(ContainerVo containerVo) { - Container container = BeanCopyUtils.copyBean(containerVo, Container.class); - //改ssh - SshLink sshLink = null; - if (Objects.nonNull(getById(containerVo.getId()).getSshId())) { - sshLink = sshLinkService.getById(getById(containerVo.getId()).getSshId()); - } else { - sshLink = new SshLink(); - } - if (SshLinkUtil.isContainerSshLinkParamValid(containerVo)) { - sshLink.setConsoleType(containerVo.getSshType()) - .setHost(containerVo.getSshHost()) - .setPort(containerVo.getSshPort()) - .setName(containerVo.getSshUser()) - .setPassword(containerVo.getSshPwd()); - sshLinkService.saveOrUpdate(sshLink); - container.setSshId(sshLink.getId()); - } - saveOrUpdate(container); - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getAllContainer() { - List containers = list(); - List containerSelectVos = BeanCopyUtils.copyBeanList(containers, ContainerSelectVo.class); - return ResponseResult.okResult(containerSelectVos); - } - - @Override - public ResponseResult getAssociatedContainers(Integer id, Integer perPage, Integer currentPage) { - LambdaQueryWrapper containerLambdaQueryWrapper = new LambdaQueryWrapper<>(); - containerLambdaQueryWrapper.eq(Container::getHostMachineId, id); - //分页 - PageHelper.startPage(currentPage, perPage); - List containers = list(containerLambdaQueryWrapper); - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(containers, perPage); - List containerVos = BeanCopyUtils.copyBeanList(containers, ContainerVo.class); - pageInfo.setList(containerVos); - return ResponseResult.okResult(pageInfo); - } - - @Override - public Map getContainerStateInfo() { - HashMap result = new HashMap<>(); - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - //设置容器总数 - result.put("containerCount", count()); - //设置容器在线总数 - containerWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_RUNNING); - result.put("containerOnlineCount", count(containerWrapper)); - containerWrapper.clear(); - //设置容器离线总数 - containerWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_EXITED); - result.put("containerOfflineCount", count(containerWrapper)); - containerWrapper.clear(); - //设置容器未知总数 - containerWrapper.eq(Container::getContainerState, SystemConstant.CONTAINER_STATE_UNKNOWN); - result.put("containerUnknownCount", count(containerWrapper)); - containerWrapper.clear(); - return result; - } -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/DashboardServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/DashboardServiceImpl.java deleted file mode 100644 index 79da4cb..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/DashboardServiceImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.domain.vo.*; -import com.mzaxd.noodles.enums.OperationEnum; -import com.mzaxd.noodles.service.*; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.RedisCache; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import javax.annotation.Resource; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author 13439 - */ -@Service -public class DashboardServiceImpl implements DashboardService { - - @Resource - private HostMachineService hostMachineService; - - @Resource - private ContainerServiceImpl containerService; - - @Resource - private EveryDayDataService everyDayDataService; - - @Resource - private ServirService servirService; - - @Resource - private AuditLogService auditLogService; - - @Resource - private SshLinkService sshLinkService; - - @Resource - private RedisCache redisCache; - - @Resource - private ServirHostService servirHostService; - - @Resource - private ServirContainerService servirContainerService; - - @Override - public ResponseResult getInstancesRealTimeData() { - HashMap result = new HashMap<>(); - Map hostStateInfo = hostMachineService.getHostStateInfo(); - Map vmStateInfo = hostMachineService.getVmStateInfo(); - Map containerStateInfo = containerService.getContainerStateInfo(); - List lastSixDayData = everyDayDataService.getLastSixDayData(); - List servirCountList = lastSixDayData.stream().map(EveryDayData::getServirCount).collect(Collectors.toList()); - servirCountList.add(servirService.count()); - result.put("servirCountList", servirCountList); - result.put("hostCount", hostStateInfo.get("hostCount")); - result.put("hostOnlineCount", hostStateInfo.get("hostOnlineCount")); - result.put("vmCount", vmStateInfo.get("vmCount")); - result.put("vmOnlineCount", vmStateInfo.get("vmOnlineCount")); - result.put("containerCount", containerStateInfo.get("containerCount")); - result.put("containerOnlineCount", containerStateInfo.get("containerOnlineCount")); - return ResponseResult.okResult(result); - } - - @Override - public ResponseResult getRecentConsoleList() { - LambdaQueryWrapper auditLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); - auditLogLambdaQueryWrapper.eq(AuditLog::getOperation, OperationEnum.CONSOLE_CONNECT.getOperation()).orderByDesc(AuditLog::getCreateTime); - List list = auditLogService.list(auditLogLambdaQueryWrapper); - if (Objects.nonNull(list)) { - List recentConsoleListVos = list.stream() - .distinct() - .limit(7L) - .map(auditLog -> { - Long sshId = JSON.parseArray(auditLog.getParam(), Long.class).get(0); - Object instance = sshLinkService.getInstanceInfoBySshId((sshId)); - if (Objects.nonNull(instance)) { - RecentConsoleListVo recentConsoleListVo = BeanCopyUtils.copyBean(instance, RecentConsoleListVo.class); - recentConsoleListVo.setSshId(sshId); - return recentConsoleListVo; - } - return null; - }).filter(Objects::nonNull).collect(Collectors.toList()); - return ResponseResult.okResult(recentConsoleListVos); - } - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getAffectedServirList() { - HashSet affectedServirIds = new HashSet<>(); - //Key是受影响的服务的id,也就是affectedServirId - HashMap> offlineContainer = new HashMap<>(); - HashMap> offlineHost = new HashMap<>(); - List result = new ArrayList<>(); - //判断Redis里面有没有掉线容器Id 如果没有就说明没有受影响的服务 - Set containerSet = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (!CollectionUtils.isEmpty(containerSet)){ - containerSet.forEach(s -> { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(ServirContainer::getContainerId, Long.valueOf(s)); - //根据Redis中掉线容器Id来查找所有关联的服务 - List servirContainers = servirContainerService.list(lambdaQueryWrapper); - //填充受影响的服务Id和 服务-容器关系 的Map - servirContainers.forEach(servirContainer -> { - Long servirId = servirContainer.getServirId(); - Long containerId = servirContainer.getContainerId(); - affectedServirIds.add(servirId); - if (Objects.nonNull(offlineContainer.get(servirId))) { - offlineContainer.get(servirId).add(containerId); - } else { - List containerIds = new ArrayList<>(); - containerIds.add(containerId); - offlineContainer.put(servirId, containerIds); - } - }); - }); - } - - //判断Redis里面有没有掉线的物理机Id或虚拟机Id 如果没有就说明没有受影响的服务 - Set vmSet = redisCache.getCacheSet(RedisConstant.NOTIFY_VM_IDS); - Set serverSet = redisCache.getCacheSet(RedisConstant.NOTIFY_HOST_IDS); - Set hostSet = new HashSet<>(); - hostSet.addAll(vmSet); - hostSet.addAll(serverSet); - if (!CollectionUtils.isEmpty(hostSet)){ - hostSet.forEach(s -> { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(ServirHost::getHostId, Long.valueOf(s)); - //根据Redis中掉线hostId来查找所有关联的服务 - List servirHosts = servirHostService.list(lambdaQueryWrapper); - //填充受影响的服务Id和 服务-容器关系 的Map - servirHosts.forEach(servirHost -> { - Long servirId = servirHost.getServirId(); - Long hostId = servirHost.getHostId(); - affectedServirIds.add(servirId); - if (Objects.nonNull(offlineHost.get(servirId))) { - offlineHost.get(servirId).add(hostId); - } else { - List hostIds = new ArrayList<>(); - hostIds.add(hostId); - offlineHost.put(servirId, hostIds); - } - }); - }); - } - affectedServirIds.forEach(servirId -> { - //查询对应服务 - Servir servir = servirService.getById(servirId); - AffectedServirListVo affectedServirListVo = BeanCopyUtils.copyBean(servir, AffectedServirListVo.class); - - //根据offlineContainer查找对应的容器 - List containerIds = offlineContainer.get(servirId); - //根据服务Id查询所有掉线container - if (!CollectionUtils.isEmpty(containerIds)) { - List offlineContainers = containerIds.stream().map(containerId -> containerService.getById(containerId)).collect(Collectors.toList()); - List containerVos = BeanCopyUtils.copyBeanList(offlineContainers, ContainerVo.class); - affectedServirListVo.setContainers(containerVos); - } - - //根据offlineContainer查找对应的容器 - List hostIds = offlineHost.get(servirId); - //根据offlineHost查找对应的物理机或虚拟机 - if (!CollectionUtils.isEmpty(hostIds)) { - List offlineHosts = hostIds.stream().map(hostId -> hostMachineService.getById(hostId)).collect(Collectors.toList()); - List hostVos = BeanCopyUtils.copyBeanList(offlineHosts, HostVo.class); - affectedServirListVo.setHosts(hostVos); - } - result.add(affectedServirListVo); - }); - return ResponseResult.okResult(result); - } -} diff --git a/src/main/java/com/mzaxd/noodles/service/impl/EveryDayDataServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/EveryDayDataServiceImpl.java deleted file mode 100644 index 893d856..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/EveryDayDataServiceImpl.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import cn.hutool.core.date.DateUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.EveryDayData; -import com.mzaxd.noodles.mapper.EveryDayDataMapper; -import com.mzaxd.noodles.service.EveryDayDataService; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.ZoneId; -import java.util.*; - -/** - * @author 13439 - * @description 针对表【every_data】的数据库操作Service实现 - * @createDate 2023-02-21 12:52:12 - */ -@Service -public class EveryDayDataServiceImpl extends ServiceImpl - implements EveryDayDataService { - - @Override - public ResponseResult getAuditLogCountYesterday() { - ArrayList result = new ArrayList<>(); - for (EveryDayData lastWeekDatum : getLastWeekData()) { - result.add(lastWeekDatum.getAuditCount()); - } - return ResponseResult.okResult(result); - } - - @Override - public ResponseResult getInstancesHistory() { - EveryDayData yesterdayData = getYesterdayData(); - HashMap result = new HashMap<>(); - result.put("hostCount", yesterdayData.getHostCount()); - result.put("hostOnlineCount", yesterdayData.getHostOnlineCount()); - result.put("hostOfflineCount", yesterdayData.getHostOfflineCount()); - result.put("hostUnknownCount", yesterdayData.getHostUnknownCount()); - result.put("vmCount", yesterdayData.getVmCount()); - result.put("vmOnlineCount", yesterdayData.getVmOnlineCount()); - result.put("vmOfflineCount", yesterdayData.getVmOfflineCount()); - result.put("vmUnknownCount", yesterdayData.getVmUnknownCount()); - result.put("containerCount", yesterdayData.getContainerCount()); - result.put("containerOnlineCount", yesterdayData.getContainerOnlineCount()); - result.put("containerOfflineCount", yesterdayData.getContainerOfflineCount()); - result.put("containerUnknownCount", yesterdayData.getContainerUnknownCount()); - return ResponseResult.okResult(result); - } - - private LambdaQueryWrapper getYesterdayLambdaWrapper() { - LambdaQueryWrapper everyDayDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); - everyDayDataLambdaQueryWrapper.ge(EveryDayData::getCreateTime, DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), -1))); - everyDayDataLambdaQueryWrapper.lt(EveryDayData::getCreateTime, DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(), -1))); - return everyDayDataLambdaQueryWrapper; - } - - @Override - public EveryDayData getYesterdayData() { - EveryDayData everyData = getOne(getYesterdayLambdaWrapper()); - if (Objects.nonNull(everyData)) { - return everyData; - } else { - everyData = createDefaultEverydayData(); - } - return everyData; - } - - public EveryDayData createDefaultEverydayData() { - EveryDayData everyDayData = new EveryDayData(); - everyDayData.setHostCount(0).setHostOnlineCount(0).setHostOfflineCount(0).setHostUnknownCount(0) - .setVmCount(0).setVmOnlineCount(0).setVmOfflineCount(0).setVmUnknownCount(0) - .setContainerCount(0).setContainerOnlineCount(0).setContainerOfflineCount(0).setContainerUnknownCount(0) - .setAuditCount(0).setServirCount(0); - return everyDayData; - } - - private LambdaQueryWrapper getLastWeekLambdaWrapper() { - LambdaQueryWrapper everyDayDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); - everyDayDataLambdaQueryWrapper.ge(EveryDayData::getCreateTime, DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), -7))); - everyDayDataLambdaQueryWrapper.lt(EveryDayData::getCreateTime, DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(), -1))); - return everyDayDataLambdaQueryWrapper; - } - - @Override - public List getLastWeekData() { - return getLastDate(7, getLastWeekLambdaWrapper()); - } - - public List getLastDate(int dayNum, LambdaQueryWrapper lambdaQueryWrapper) { - // 今天的前一天是截止日期 - LocalDate end = LocalDate.now().minusDays(1); - // 七天前是起始日期 - LocalDate start = end.minusDays(6); - List list = list(lambdaQueryWrapper); - - // 如果不足7条,则补充空数据 - int missingDays = dayNum - list.size(); - if (missingDays > 0) { - List emptyData = new ArrayList<>(); - for (int i = 0; i < missingDays; i++) { - EveryDayData data = createDefaultEverydayData(); - data.setCreateTime(Date.from(start.plusDays(i).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); - emptyData.add(data); - } - emptyData.addAll(list); - list = emptyData; - } - return list; - } - - - private LambdaQueryWrapper getLastSixDayLambdaWrapper() { - LambdaQueryWrapper everyDayDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); - everyDayDataLambdaQueryWrapper.ge(EveryDayData::getCreateTime, DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), -6))); - everyDayDataLambdaQueryWrapper.lt(EveryDayData::getCreateTime, DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(), -1))); - return everyDayDataLambdaQueryWrapper; - } - - @Override - public List getLastSixDayData() { - return getLastDate(6, getLastSixDayLambdaWrapper()); - } -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/HostDetectorServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/HostDetectorServiceImpl.java deleted file mode 100644 index 18838a9..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/HostDetectorServiceImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import cn.hutool.core.net.NetUtil; -import cn.hutool.core.util.NumberUtil; -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.constant.UrlConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.EveryDayData; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.domain.message.Server; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.exception.SystemException; -import com.mzaxd.noodles.mapper.HostDetectorMapper; -import com.mzaxd.noodles.service.HostDetectorService; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.RedisCache; -import com.mzaxd.noodles.util.UrlUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; - -import javax.annotation.Resource; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author root - * @description 针对表【host_detector】的数据库操作Service实现 - * @createDate 2023-02-05 13:18:46 - */ -@Slf4j -@Service -public class HostDetectorServiceImpl extends ServiceImpl - implements HostDetectorService { - - @Resource - private HostMachineService hostMachineService; - - @Resource - private RestTemplate restTemplate; - - @Resource - private RedisCache redisCache; - - @Override - public List getAllALiveDetectors() { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_ONLINE); - queryWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - List hostMachines = hostMachineService.list(queryWrapper); - - List hostMachineIds = hostMachines.stream().map(HostMachine::getId).collect(Collectors.toList()); - - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.in(HostDetector::getHostMachineId, hostMachineIds); - List hostDetectors = list(wrapper); - return hostDetectors; - } - - @Override - public Map getDynamicData(List allAliveDetector) { - HashMap map = new HashMap<>(); - for (HostDetector detector : allAliveDetector) { - DynamicData dynamicData = (DynamicData) redisCache.getCacheObject(RedisConstant.DYNAMIC_DATA + detector.getDetectorUuid()); - map.put(detector.getHostMachineId(), dynamicData); - } - return map; - } - - @Override - public Map getDynamicDataByDetector(HostDetector detector) { - HashMap map = new HashMap<>(); - DynamicData dynamicData = (DynamicData) redisCache.getCacheObject(RedisConstant.DYNAMIC_DATA + detector.getDetectorUuid()); - map.put(detector.getHostMachineId(), dynamicData); - return map; - } - - @Override - public ResponseResult isValidUrl(String protocol, String ip, String port) { - if (!NetUtil.isValidPort(Integer.parseInt(port))) { - throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR); - } - String url = UrlUtil.getUrl(protocol, ip, port, UrlConstant.DETECTOR_IS_TRUE_URL); - boolean validUrl = isValidUrl(url); - if (validUrl) { - return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "连接成功"); - } - return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "连接失败"); - } - - @Override - public boolean isValidUrl(String url) { - log.info("尝试连接探测器:{}", url); - ResponseResult response = restTemplate.getForObject(url, ResponseResult.class); - if (response != null && response.getCode().equals(ResponseResult.okResult().getCode())) { - log.info("连接{}成功", url); - return true; - } - return false; - } - - @Override - public Server detectorGetInfoByUrl(String url) { - ResponseResult response = restTemplate.getForObject(url, ResponseResult.class); - if (response != null && response.getCode().equals(ResponseResult.okResult().getCode())) { - log.info("获取信息成功"); - return JSON.parseObject(JSON.toJSONString(response.getData()), Server.class); - } - return null; - } - - @Override - public ResponseResult getMemInfo() { - Map result = new HashMap<>(); - //当前在线数量 - int count = 0; - //总内存大小 - int memoryTotal = 0; - //单机最高内存使用率 - Double memoryUsedMaxRate = 0.0; - //平均内存使用率 - Double memoryUsedAvgRate = 0.0; - //平均内存使用率 - Double memoryTotalUsedRate = 0.0; - //空闲内存 - Double memoryFree = 0.0; - //已使用内存 - Double memoryUsed = 0.0; - - Map dynamicData; - try { - dynamicData = getDynamicData(getAllALiveDetectors()); - for (DynamicData data : dynamicData.values()) { - count++; - memoryFree += data.getMemFree(); - memoryUsed += data.getMemUsed(); - Double total = data.getMemFree() + data.getMemUsed(); - memoryTotal += total.intValue(); - double memoryUsedRate = memoryUsed / memoryTotal; - memoryTotalUsedRate += memoryUsedRate; - if (memoryUsedRate > memoryUsedMaxRate) { - memoryUsedMaxRate = memoryUsedRate; - } - } - memoryUsedAvgRate = memoryTotalUsedRate / count; - result.put("memoryTotal", memoryTotal); - result.put("memoryFree", memoryFree); - result.put("memoryUsed", memoryUsed); - result.put("memoryUsedMaxRate", NumberUtil.round(memoryUsedMaxRate, 4)); - result.put("memoryUsedAvgRate", NumberUtil.round(memoryUsedAvgRate, 4)); - } catch (Exception e) { - e.printStackTrace(); - result.put("memoryTotal", 0); - result.put("memoryFree", 0); - result.put("memoryUsed", 0); - result.put("memoryUsedMaxRate", 0); - result.put("memoryUsedAvgRate", 0); - } - return ResponseResult.okResult(result); - } - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/HostMachineServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/HostMachineServiceImpl.java deleted file mode 100644 index 51c4bc8..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/HostMachineServiceImpl.java +++ /dev/null @@ -1,585 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.constant.UrlConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.domain.message.Server; -import com.mzaxd.noodles.domain.vo.*; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.exception.SystemException; -import com.mzaxd.noodles.mapper.*; -import com.mzaxd.noodles.service.*; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.SshLinkUtil; -import com.mzaxd.noodles.util.UrlUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import org.springframework.web.client.RestTemplate; - -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @author root - * @description 针对表【host_machine】的数据库操作Service实现 - * @createDate 2023-01-30 01:24:08 - */ -@Service -@Slf4j -public class HostMachineServiceImpl extends ServiceImpl - implements HostMachineService { - - - @Resource - private RestTemplate restTemplate; - - @Lazy - @Resource - private HostDetectorService hostDetectorService; - - @Resource - private HostDetectorMapper hostDetectorMapper; - - @Resource - private HostMachineMapper hostMachineMapper; - - @Resource - private OsMapper osMapper; - - @Resource - private OsService osService; - - @Lazy - @Resource - private ContainerService containerService; - - @Resource - private SshLinkService sshLinkService; - - @Resource - private SshLinkMapper sshLinkMapper; - - @Resource - private NotificationMapper notificationMapper; - - @Override - public ResponseResult getHostDrawer() { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(HostMachine::getHostMachineId, SystemConstant.PHYSICAL_MACHINE); - List hostMachineList = list(wrapper); - List hostMachineDrawerVos = BeanCopyUtils.copyBeanList(hostMachineList, HostMachineDrawerVo.class); - return ResponseResult.okResult(hostMachineDrawerVos); - } - - @Override - public ResponseResult vmListWithCondition(String nameLike, List selectedKernel, List selectedHost, List selectedStatus, Integer perPage, Integer currentPage) { - //分页 - PageHelper.startPage(currentPage, perPage); - //查询 - List hostMachines = hostMachineMapper.vmListWithCondition(nameLike, selectedKernel, selectedHost, selectedStatus, perPage, currentPage); - - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(hostMachines, perPage); - - //封装结果返回 - List virtualMachineListVos = BeanCopyUtils.copyBeanList(hostMachines, VirtualMachineListVo.class); - virtualMachineListVos.forEach(virtualMachineListVo -> { - Os os = osMapper.selectById(virtualMachineListVo.getOsId()); - OsVo osVo = BeanCopyUtils.copyBean(os, OsVo.class); - virtualMachineListVo.setOs(osVo); - }); - pageInfo.setList(virtualMachineListVos); - return ResponseResult.okResult(pageInfo); - } - - @Override - public ResponseResult vmListSummaryStatistics() { - //设置查询所有vm的条件 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - //设置查询所有在线vm的条件 - LambdaQueryWrapper onlineWrapper = new LambdaQueryWrapper<>(); - onlineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_ONLINE); - onlineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - //设置查询所有离线vm的条件 - LambdaQueryWrapper offlineWrapper = new LambdaQueryWrapper<>(); - offlineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_OFFLINE); - offlineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - //设置查询所有未知vm的条件 - LambdaQueryWrapper sleepWrapper = new LambdaQueryWrapper<>(); - sleepWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - sleepWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - - int total = count(wrapper); - int online = count(onlineWrapper); - int offline = count(offlineWrapper); - int sleep = count(sleepWrapper); - HashMap result = new HashMap<>(4); - result.put("total", total); - result.put("online", online); - result.put("offline", offline); - result.put("unknown", sleep); - return ResponseResult.okResult(result); - } - - @Override - @Transactional - public ResponseResult updateVm(VmVo vmVo) { - //改Os - Os os = osService.getById(getById(vmVo.getId()).getOsId()); - os.setName(vmVo.getOsName()).setKernel(vmVo.getOsKernel()).setDescription(vmVo.getOsName()); - osService.saveOrUpdate(os); - - //改SshLink - SshLink sshLink = null; - if (Objects.nonNull(getById(vmVo.getId()).getSshId())) { - sshLink = sshLinkService.getById(getById(vmVo.getId()).getSshId()); - } else { - sshLink = new SshLink(); - } - if (SshLinkUtil.isVmSshLinkParamValid(vmVo)) { - sshLink.setHost(vmVo.getSshHost()).setPort(vmVo.getSshPort()).setName(vmVo.getSshUser()).setPassword(vmVo.getSshPwd()); - sshLinkService.saveOrUpdate(sshLink); - } - HostMachine vm = BeanCopyUtils.copyBean(vmVo, HostMachine.class); - vm.setSshId(sshLink.getId()); - saveOrUpdate(vm); - return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "修改成功"); - } - - @Override - @Transactional - public ResponseResult addVm(VmVo vmvo) { - HostMachine vm = BeanCopyUtils.copyBean(vmvo, HostMachine.class); - Os os = new Os(); - os.setName(vmvo.getOsName()).setKernel(vmvo.getOsKernel()); - osService.save(os); - vm.setOsId(os.getId()); - if (SshLinkUtil.isVmSshLinkParamValid(vmvo)) { - SshLink sshLink = new SshLink(); - sshLink.setHost(vmvo.getSshHost()).setPort(vmvo.getSshPort()).setName(vmvo.getSshUser()).setPassword(vmvo.getSshPwd()); - sshLinkService.save(sshLink); - vm.setSshId(sshLink.getId()); - } - save(vm); - return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "添加虚拟机成功"); - } - - @Override - @Transactional - public ResponseResult addHost(HostVo host) { - //判断是否能连上探测器 - String isValidUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_IS_TRUE_URL); - if (!hostDetectorService.isValidUrl(isValidUrl)) { - throw new RuntimeException("无法连接到探测器"); - } - //获取远程主机数据 - String getInfoUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_GET_INFO); - Server server = hostDetectorService.detectorGetInfoByUrl(getInfoUrl); - - //存储Os信息 - Os os = new Os(); - String osName = server.getOs().getOsName(); - os.setName(osName).setDescription(osName).setKernel(host.getOsKernel()); - osService.save(os); - - //把数据库其余字段的数据补上 - HostMachine hostMachine = BeanCopyUtils.copyBean(host, HostMachine.class); - hostMachine.setThreads((long) server.getCpu().getLogicalProcessorCount()); - hostMachine.setMemory((long) server.getMem().getTotal() * 1024); - hostMachine.setHostMachineId(SystemConstant.HOST_MACHINE_ID_HOST); - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachine.setOsId(os.getId()); - - - //存储控制台信息 - if (SshLinkUtil.isHostSshLinkParamValid(host)) { - SshLink sshLink = new SshLink(); - sshLink.setHost(host.getSshHost()).setPort(host.getSshPort()).setName(host.getSshUser()).setPassword(host.getSshPwd()); - sshLinkService.save(sshLink); - hostMachine.setSshId(sshLink.getId()); - } - - save(hostMachine); - //存储探测器信息 - HostDetector hostDetector = new HostDetector(); - - String getDetectorIdUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_GET_DETECTOR_ID); - ResponseResult response = restTemplate.getForObject(getDetectorIdUrl, ResponseResult.class); - String uuid = response.getData().toString(); - - hostDetector - .setHostMachineId(hostMachine.getId()) - .setDetectorUuid(uuid) - .setDetectorIpAddress(UrlUtil.getAddress(host.getProtocol(), host.getIp(), host.getPort())); - hostDetectorService.save(hostDetector); - - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getHostById(Integer id) { - HostMachine hostMachine = getById(id); - HostVo hostVo = BeanCopyUtils.copyBean(hostMachine, HostVo.class); - Os os = osService.getById(hostMachine.getOsId()); - hostVo.setOsKernel(os.getKernel()); - - if (Objects.nonNull(hostMachine.getSshId())) { - SshLink sshLink = sshLinkService.getById(hostMachine.getSshId()); - hostVo.setSshHost(sshLink.getHost()).setSshPort(sshLink.getPort()).setSshUser(sshLink.getName()).setSshPwd(sshLink.getPassword()); - } - - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(HostDetector::getHostMachineId, id); - HostDetector hostDetector = hostDetectorService.getOne(queryWrapper); - Map map = UrlUtil.resolveUrl(hostDetector.getDetectorIpAddress()); - hostVo.setProtocol(map.get(UrlConstant.PROTOCOL)); - hostVo.setIp(map.get(UrlConstant.IP)); - hostVo.setPort(map.get(UrlConstant.PORT)); - return ResponseResult.okResult(hostVo); - } - - @Override - @Transactional - public ResponseResult updateHost(HostVo host) { - //判断是否能连上探测器 - String isValidUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_IS_TRUE_URL); - if (!hostDetectorService.isValidUrl(isValidUrl)) { - throw new RuntimeException("无法连接到探测器"); - } - // 改探测器 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(HostDetector::getHostMachineId, host.getId()); - HostDetector hostDetector = hostDetectorService.getOne(wrapper); - //改为新的探测器地址 - hostDetector.setDetectorIpAddress(UrlUtil.getAddress(host.getProtocol(), host.getIp(), host.getPort())); - - //获取新的探测器uuid - String getDetectorIdUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_GET_DETECTOR_ID); - ResponseResult response = restTemplate.getForObject(getDetectorIdUrl, ResponseResult.class); - String uuid = response.getData().toString(); - hostDetector.setDetectorUuid(uuid); - hostDetectorService.saveOrUpdate(hostDetector); - - //通过新的地址获取新的数据 - String getInfoUrl = UrlUtil.getUrl(host.getProtocol(), host.getIp(), host.getPort(), UrlConstant.DETECTOR_GET_INFO); - Server server = hostDetectorService.detectorGetInfoByUrl(getInfoUrl); - - //改Os - Os os = osService.getById(getById(host.getId()).getOsId()); - String osName = server.getOs().getOsName(); - os.setKernel(host.getOsKernel()).setName(osName).setDescription(osName); - osService.saveOrUpdate(os); - - SshLink sshLink = null; - //改SshLink - if (Objects.nonNull(getById(host.getId()).getSshId())) { - sshLink = sshLinkService.getById(getById(host.getId()).getSshId()); - } else { - sshLink = new SshLink(); - } - if (SshLinkUtil.isHostSshLinkParamValid(host)) { - sshLink.setHost(host.getSshHost()).setPort(host.getSshPort()).setName(host.getSshUser()).setPassword(host.getSshPwd()); - sshLinkService.saveOrUpdate(sshLink); - } - - HostMachine hostMachine = BeanCopyUtils.copyBean(host, HostMachine.class); - hostMachine.setSshId(sshLink.getId()); - hostMachine.setThreads((long) server.getCpu().getLogicalProcessorCount()); - hostMachine.setMemory((long) server.getMem().getTotal() * 1024); - saveOrUpdate(hostMachine); - return ResponseResult.okResult(); - } - - @Override - @Transactional - public ResponseResult deleteHostById(Integer id) { - //判断是否还有其他容器关联此VM 如果有则不可以删除 - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - containerWrapper.eq(Container::getHostMachineId, id); - List containerList = containerService.list(containerWrapper); - - if (CollectionUtils.isNotEmpty(containerList)) { - log.info("删除失败,此物理机有关联的容器"); - throw new SystemException(AppHttpCodeEnum.EXIST_ASSOCIATION_CONTAINER); - } - - //判断是否还有其他容器关联此VM 如果有则不可以删除 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.eq(HostMachine::getHostMachineId, id); - List vmList = list(vmWrapper); - - if (CollectionUtils.isNotEmpty(vmList)) { - log.info("删除失败,此物理机有关联的虚拟机"); - throw new SystemException(AppHttpCodeEnum.EXIST_ASSOCIATION_VM); - } - //删除对应的探测器 - LambdaQueryWrapper hostDetectorWrapper = new LambdaQueryWrapper<>(); - hostDetectorWrapper.eq(HostDetector::getHostMachineId, id); - hostDetectorMapper.delete(hostDetectorWrapper); - //删除对应的os - osMapper.deleteById(getById(id).getOsId()); - //删除对应的ssh连接信息 - if (Objects.nonNull(getById(id).getSshId())) { - sshLinkMapper.deleteById(getById(id).getSshId()); - } - //删除物理机 - HostMachine hostMachine = hostMachineMapper.selectById(id); - if (Objects.nonNull(hostMachine.getOsId())) { - log.info("删除hostId为{}的host信息", id); - osMapper.deleteById(hostMachine.getOsId()); - } - //删除掉线提醒 - LambdaQueryWrapper notificationLambdaQueryWrapper = new LambdaQueryWrapper<>(); - notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id); - notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_HOST); - notificationMapper.delete(notificationLambdaQueryWrapper); - log.info("删除id为{}的物理机的所有掉线提醒", id); - - //删除物理机 - hostMachineMapper.deleteById(id); - log.info("删除id为{}的host", id); - return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "删除成功"); - } - - @Override - public ResponseResult getHostDetail(Integer id) { - HostMachine hostMachine = getById(id); - HostPanelVo hostPanelVo = BeanCopyUtils.copyBean(hostMachine, HostPanelVo.class); - LambdaQueryWrapper hostDetectorLambdaQueryWrapper = new LambdaQueryWrapper<>(); - hostDetectorLambdaQueryWrapper.eq(HostDetector::getHostMachineId, id); - HostDetector hostDetector = hostDetectorService.getOne(hostDetectorLambdaQueryWrapper); - Server server = hostDetectorService.detectorGetInfoByUrl(hostDetector.getDetectorIpAddress() + UrlConstant.DETECTOR_GET_INFO); - //查虚拟机数量 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.eq(HostMachine::getHostMachineId, id); - int vmCount = count(vmWrapper); - //查容器数量 - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - containerWrapper.eq(Container::getHostMachineId, id); - int containerCount = containerService.count(containerWrapper); - hostPanelVo.setVmCount(vmCount).setContainerCount(containerCount); - HashMap result = new HashMap<>(); - result.put("host", hostPanelVo); - result.put("hostDetail", server); - return ResponseResult.okResult(result); - } - - @Override - public ResponseResult getAssociatedVms(Integer id, Integer perPage, Integer currentPage) { - LambdaQueryWrapper hostMachineLambdaQueryWrapper = new LambdaQueryWrapper<>(); - hostMachineLambdaQueryWrapper.eq(HostMachine::getHostMachineId, id); - //分页 - PageHelper.startPage(currentPage, perPage); - List vms = list(hostMachineLambdaQueryWrapper); - List vmList = BeanCopyUtils.copyBeanList(vms, VirtualMachineListVo.class); - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(vmList, perPage); - vmList.forEach(virtualMachineListVo -> { - Os os = osService.getById(virtualMachineListVo.getOsId()); - OsVo osVo = BeanCopyUtils.copyBean(os, OsVo.class); - virtualMachineListVo.setOs(osVo); - }); - pageInfo.setList(vmList); - return ResponseResult.okResult(pageInfo); - } - - @Override - public ResponseResult getAssociatedDisks(Integer id) { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(HostDetector::getHostMachineId, id); - HostDetector hostDetector = hostDetectorService.getOne(lambdaQueryWrapper); - ResponseResult result = restTemplate.getForObject(hostDetector.getDetectorIpAddress() + UrlConstant.DETECTOR_GET_DISK_INFO, ResponseResult.class); - return ResponseResult.okResult(result.getData()); - } - - @Override - public ResponseResult getAssociatedNetworkIfs(Integer id) { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(HostDetector::getHostMachineId, id); - HostDetector hostDetector = hostDetectorService.getOne(lambdaQueryWrapper); - ResponseResult result = restTemplate.getForObject(hostDetector.getDetectorIpAddress() + UrlConstant.DETECTOR_GET_NETWORK_IF_INFO, ResponseResult.class); - return ResponseResult.okResult(result.getData()); - } - - @Override - public ResponseResult hostListWithCondition(String nameLike, List selectedStatus, Integer perPage, Integer currentPage) { - //设置查询条件 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - wrapper.like(StringUtils.hasText(nameLike), HostMachine::getDescription, nameLike); - wrapper.in(Objects.nonNull(selectedStatus), HostMachine::getHostMachineState, selectedStatus); - //分页 - PageHelper.startPage(currentPage, perPage); - //查询 - List hostMachines = list(wrapper); - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(hostMachines, perPage); - //封装结果返回 - List hostMachineListVo = BeanCopyUtils.copyBeanList(hostMachines, HostMachineListVo.class); - //设置探测器ip地址 设置Os信息 - hostMachineListVo.forEach(hostMachineVo -> { - Os os = osMapper.selectById(hostMachineVo.getOsId()); - OsVo osVo = BeanCopyUtils.copyBean(os, OsVo.class); - hostMachineVo.setOs(osVo); - }); - - pageInfo.setList(hostMachineListVo); - return ResponseResult.okResult(pageInfo); - } - - @Override - public ResponseResult deleteVmById(Integer id) { - //判断是否还有其他容器关联此VM 如果有则不可以删除 - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - containerWrapper.eq(Container::getHostMachineId, id); - List containerList = containerService.list(containerWrapper); - - if (CollectionUtils.isNotEmpty(containerList)) { - log.info("删除失败,此Vm有关联的容器"); - throw new SystemException(AppHttpCodeEnum.EXIST_ASSOCIATION_CONTAINER); - } - HostMachine hostMachine = hostMachineMapper.selectById(id); - if (Objects.nonNull(hostMachine.getOsId())) { - log.info("删除vmId为{}的Os信息", id); - osMapper.deleteById(hostMachine.getOsId()); - } - //删除对应的os - osMapper.deleteById(getById(id).getOsId()); - //删除对应的ssh连接信息 - if (Objects.nonNull(getById(id).getSshId())) { - sshLinkMapper.deleteById(getById(id).getSshId()); - } - //删除掉线提醒 - LambdaQueryWrapper notificationLambdaQueryWrapper = new LambdaQueryWrapper<>(); - notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id); - notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_VM); - notificationMapper.delete(notificationLambdaQueryWrapper); - log.info("删除id为{}的虚拟机的所有掉线提醒", id); - - hostMachineMapper.deleteById(id); - log.info("删除id为{}的vm", id); - return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "删除成功"); - } - - @Override - public ResponseResult getVmById(Integer id) { - HostMachine hostMachine = hostMachineMapper.selectById(id); - Os os = osMapper.selectById(hostMachine.getOsId()); - VmVo vmVo = BeanCopyUtils.copyBean(hostMachine, VmVo.class); - vmVo.setOsName(os.getName()).setOsKernel(os.getKernel()); - if (Objects.nonNull(hostMachine.getSshId())) { - SshLink sshLink = sshLinkService.getById(hostMachine.getSshId()); - vmVo.setSshHost(sshLink.getHost()).setSshPort(sshLink.getPort()).setSshUser(sshLink.getName()).setSshPwd(sshLink.getPassword()); - } - return ResponseResult.okResult(vmVo); - } - - /** - * 获取所有物理机当前在线信息 - * - * @return - */ - @Override - public Map getHostStateInfo() { - HashMap result = new HashMap<>(); - LambdaQueryWrapper hostMachineWrapper = new LambdaQueryWrapper<>(); - //设置主机总数 - hostMachineWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - result.put("hostCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置主机在线总数 - hostMachineWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_ONLINE); - result.put("hostOnlineCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置主机离线总数 - hostMachineWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_OFFLINE); - result.put("hostOfflineCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置主机未知总数 - hostMachineWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - result.put("hostUnknownCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - return result; - } - - /** - * 获取所有虚拟机当前在线信息 - * - * @return - */ - @Override - public Map getVmStateInfo() { - HashMap result = new HashMap<>(); - LambdaQueryWrapper hostMachineWrapper = new LambdaQueryWrapper<>(); - //设置虚拟机总数 - hostMachineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - result.put("vmCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置虚拟机在线总数 - hostMachineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_ONLINE); - result.put("vmOnlineCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置虚拟机离线总数 - hostMachineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_OFFLINE); - result.put("vmOfflineCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - //设置虚拟机未知总数 - hostMachineWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - hostMachineWrapper.eq(HostMachine::getHostMachineState, SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - result.put("vmUnknownCount", count(hostMachineWrapper)); - hostMachineWrapper.clear(); - return result; - } - - @Override - public ResponseResult startSendDynamicData(Integer hostId) { - LambdaQueryWrapper hostDetectorLambdaQueryWrapper = new LambdaQueryWrapper<>(); - hostDetectorLambdaQueryWrapper.eq(HostDetector::getHostMachineId, hostId); - HostDetector hostDetector = hostDetectorService.getOne(hostDetectorLambdaQueryWrapper); - ResponseResult result = null; - try { - result = restTemplate.getForObject(hostDetector.getDetectorIpAddress() + UrlConstant.DETECTOR_START_SEND_DYNAMIC_DATA, ResponseResult.class); - } catch (Exception e) { - throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR); - } - return result; - } - - @Override - public ResponseResult stopSendDynamicData(Integer hostId) { - LambdaQueryWrapper hostDetectorLambdaQueryWrapper = new LambdaQueryWrapper<>(); - hostDetectorLambdaQueryWrapper.eq(HostDetector::getHostMachineId, hostId); - HostDetector hostDetector = hostDetectorService.getOne(hostDetectorLambdaQueryWrapper); - ResponseResult result = null; - try { - result = restTemplate.getForObject(hostDetector.getDetectorIpAddress() + UrlConstant.DETECTOR_STOP_SEND_DYNAMIC_DATA, ResponseResult.class); - } catch (Exception e) { - throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR); - } - return result; - } - - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/NotificationServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/NotificationServiceImpl.java deleted file mode 100644 index 1484edb..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/NotificationServiceImpl.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.extra.mail.MailUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.entity.Notification; -import com.mzaxd.noodles.domain.vo.NotificationListVo; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.service.ContainerService; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.service.NotificationService; -import com.mzaxd.noodles.mapper.NotificationMapper; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.RedisCache; -import com.mzaxd.noodles.util.SystemSettingUtils; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.security.core.parameters.P; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** - * @author 13439 - * @description 针对表【notification】的数据库操作Service实现 - * @createDate 2023-02-16 16:04:53 - */ -@Service -@Slf4j -public class NotificationServiceImpl extends ServiceImpl - implements NotificationService { - - @Resource - private ContainerService containerService; - - @Resource - private HostMachineService hostMachineService; - - @Resource - private SystemSettingUtils systemSettingUtils; - - @Resource - private RedisTemplate redisTemplate; - - @Override - public void sendContainerOfflineNotification(Long id) { - Notification notification = new Notification(); - Container container = containerService.getById(id); - notification.setTitle("容器掉线") - .setType(SystemConstant.OFFLINE_NOTIFICATION) - .setSendType(container.getNotify()) - .setInstanceType(SystemConstant.INSTANCETYPE_CONTAINER) - .setInstanceId(id); - String content = String.format("容器[ %s ]已无法正常访问,请排查", container.getName()); - notification.setContent(content); - save(notification); - log.info("[掉线提醒]:发送浏览器提醒:{}", content); - } - - @Override - public void sendContainerOfflineNotificationEmail(Long id) { - sendContainerOfflineNotification(id); - sendContainerOfflineEmail(id); - } - - @Override - public void sendContainerOfflineEmail(Long id) { - Container container = containerService.getById(id); - String time = LocalDateTime.now().toString(); - String content = String.format("发现容器[ %s ]掉线---- %s", container.getName(), time); - MailUtil.send(systemSettingUtils.getMailAccount(), CollUtil.newArrayList(systemSettingUtils.getMailTarget()), "Noodles掉线提醒", content, false); - log.info("[掉线提醒]:发送邮件提醒:{}", content); - } - - @Override - public void sendVmOfflineNotification(Long id) { - Notification notification = new Notification(); - HostMachine vm = hostMachineService.getById(id); - notification.setTitle("虚拟机掉线") - .setType(SystemConstant.OFFLINE_NOTIFICATION) - .setSendType(vm.getNotify()) - .setInstanceType(SystemConstant.INSTANCETYPE_VM) - .setInstanceId(id); - String content = String.format("虚拟机[ %s ]已无法正常访问,请排查", vm.getName()); - notification.setContent(content); - save(notification); - log.info("[掉线提醒]:发送浏览器提醒:{}", content); - } - - @Override - public void sendVmOfflineEmail(Long id) { - HostMachine vm = hostMachineService.getById(id); - String time = LocalDateTime.now().toString(); - String content = String.format("发现虚拟机[ %s ]掉线---- %s", vm.getName(), time); - MailUtil.send(systemSettingUtils.getMailAccount(), CollUtil.newArrayList(systemSettingUtils.getMailTarget()), "Noodles掉线提醒", content, false); - log.info("[掉线提醒]:发送邮件提醒:{}", content); - } - - @Override - public void sendVmOfflineNotificationEmail(Long id) { - sendVmOfflineNotification(id); - sendVmOfflineEmail(id); - } - - @Override - public void sendHostOfflineNotification(Long id) { - Notification notification = new Notification(); - HostMachine host = hostMachineService.getById(id); - notification.setTitle("物理机掉线") - .setType(SystemConstant.OFFLINE_NOTIFICATION) - .setSendType(host.getNotify()) - .setInstanceType(SystemConstant.INSTANCETYPE_HOST) - .setInstanceId(id); - String content = String.format("无法连接到物理机[ %s ]的探测器,请排查", host.getName()); - notification.setContent(content); - save(notification); - log.info("[掉线提醒]:发送浏览器提醒:{}", content); - } - - @Override - public void sendHostOfflineEmail(Long id) { - HostMachine host = hostMachineService.getById(id); - String time = LocalDateTime.now().toString(); - String content = String.format("发现物理机[ %s ]掉线---- %s", host.getName(), time); - MailUtil.send(systemSettingUtils.getMailAccount(), CollUtil.newArrayList(systemSettingUtils.getMailTarget()), "Noodles掉线提醒", content, false); - log.info("[掉线提醒]:发送邮件提醒:{}", content); - } - - @Override - public void sendHostOfflineNotificationEmail(Long id) { - sendHostOfflineNotification(id); - sendHostOfflineEmail(id); - } - - @Override - public ResponseResult getNotificationList(Integer tab, Integer perPage, Integer currentPage) { - LambdaQueryWrapper notificationWrapper = new LambdaQueryWrapper<>(); - notificationWrapper.orderByDesc(Notification::getCreateTime); - List notificationList = new ArrayList<>(); - if (tab.equals(SystemConstant.FRONTEND_NOTIFICATION_NOT_AFFIRM)) { - notificationWrapper.eq(Notification::getAffirm, SystemConstant.NOTIFICATION_NOT_AFFIRM); - } - if (tab.equals(SystemConstant.FRONTEND_NOTIFICATION_AFFIRM)) { - notificationWrapper.eq(Notification::getAffirm, SystemConstant.NOTIFICATION_AFFIRM); - } - if (tab.equals(SystemConstant.FRONTEND_NOTIFICATION_ALL)) { - //分页 - PageHelper.startPage(currentPage, perPage); - notificationList = list(notificationWrapper); - PageInfo pageInfo = new PageInfo<>(notificationList, perPage); - List notificationListVos = BeanCopyUtils.copyBeanList(notificationList, NotificationListVo.class); - notificationListVos.forEach(notificationListVo -> { - Integer instanceType = notificationListVo.getInstanceType(); - //设置实例的图像、名称等信息 - if (SystemConstant.INSTANCETYPE_HOST.equals(instanceType) || SystemConstant.INSTANCETYPE_VM.equals(instanceType)) { - HostMachine hostMachine = hostMachineService.getById(notificationListVo.getInstanceId()); - notificationListVo.setInstanceName(hostMachine.getName()) - .setInstanceAvatar(hostMachine.getAvatar()); - } - if (SystemConstant.INSTANCETYPE_CONTAINER.equals(instanceType)) { - Container container = containerService.getById(notificationListVo.getInstanceId()); - notificationListVo.setInstanceName(container.getName()) - .setInstanceAvatar(container.getAvatar()); - } - }); - pageInfo.setList(notificationListVos); - return ResponseResult.okResult(pageInfo); - } - if (tab.equals(SystemConstant.FRONTEND_NOTIFICATION_TYPE_OFFLINE)) { - notificationWrapper.eq(Notification::getType, SystemConstant.OFFLINE_NOTIFICATION); - } - if (tab.equals(SystemConstant.FRONTEND_NOTIFICATION_TYPE_STATISTICS)) { - notificationWrapper.eq(Notification::getType, SystemConstant.STATISTICS_NOTIFICATION); - } - //分页 - PageHelper.startPage(currentPage, perPage); - notificationList = list(notificationWrapper); - PageInfo pageInfo = new PageInfo<>(notificationList, perPage); - List notificationListVos = BeanCopyUtils.copyBeanList(notificationList, NotificationListVo.class); - notificationListVos.forEach(notificationListVo -> { - Integer instanceType = notificationListVo.getInstanceType(); - //设置实例的图像、名称等信息 - if (SystemConstant.INSTANCETYPE_HOST.equals(instanceType) || SystemConstant.INSTANCETYPE_VM.equals(instanceType)) { - HostMachine hostMachine = hostMachineService.getById(notificationListVo.getInstanceId()); - notificationListVo.setInstanceName(hostMachine.getName()) - .setInstanceAvatar(hostMachine.getAvatar()); - } - if (SystemConstant.INSTANCETYPE_CONTAINER.equals(instanceType)) { - Container container = containerService.getById(notificationListVo.getInstanceId()); - notificationListVo.setInstanceName(container.getName()) - .setInstanceAvatar(container.getAvatar()); - } - }); - pageInfo.setList(notificationListVos); - return ResponseResult.okResult(pageInfo); - } - - @Override - public ResponseResult affirmNotification(Long id) { - Notification notification = getById(id); - if (SystemConstant.INSTANCETYPE_HOST.equals(notification.getInstanceType())) { - redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_HOST_IDS, notification.getInstanceId().toString()); - } - if (SystemConstant.INSTANCETYPE_VM.equals(notification.getInstanceType())) { - redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_VM_IDS, notification.getInstanceId().toString()); - } - if (SystemConstant.INSTANCETYPE_CONTAINER.equals(notification.getInstanceType())) { - redisTemplate.opsForSet().remove(RedisConstant.NOTIFY_CONTAINER_IDS, notification.getInstanceId().toString()); - } - saveOrUpdate(notification.setAffirm(SystemConstant.NOTIFICATION_AFFIRM)); - return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "处理完成"); - } - - @Override - public ResponseResult getNotificationCount() { - LambdaQueryWrapper notificationLambdaQueryWrapper = new LambdaQueryWrapper<>(); - notificationLambdaQueryWrapper.eq(Notification::getAffirm, SystemConstant.NOTIFICATION_NOT_AFFIRM); - return ResponseResult.okResult(count(notificationLambdaQueryWrapper)); - } - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/OsServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/OsServiceImpl.java deleted file mode 100644 index eaa1024..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/OsServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.entity.Os; -import com.mzaxd.noodles.service.OsService; -import com.mzaxd.noodles.mapper.OsMapper; -import org.springframework.stereotype.Service; - -/** -* @author root -* @description 针对表【os】的数据库操作Service实现 -* @createDate 2023-01-30 13:20:28 -*/ -@Service -public class OsServiceImpl extends ServiceImpl - implements OsService{ - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/ServirContainerServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/ServirContainerServiceImpl.java deleted file mode 100644 index 081a07d..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/ServirContainerServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.entity.ServirContainer; -import com.mzaxd.noodles.service.ServirContainerService; -import com.mzaxd.noodles.mapper.ServirContainerMapper; -import org.springframework.stereotype.Service; - -/** -* @author 13439 -* @description 针对表【servir_container】的数据库操作Service实现 -* @createDate 2023-02-11 20:48:45 -*/ -@Service -public class ServirContainerServiceImpl extends ServiceImpl - implements ServirContainerService{ - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/ServirHostServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/ServirHostServiceImpl.java deleted file mode 100644 index d3813ee..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/ServirHostServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.entity.ServirHost; -import com.mzaxd.noodles.service.ServirHostService; -import com.mzaxd.noodles.mapper.ServirHostMapper; -import org.springframework.stereotype.Service; - -/** -* @author 13439 -* @description 针对表【servir_host】的数据库操作Service实现 -* @createDate 2023-02-11 20:48:51 -*/ -@Service -public class ServirHostServiceImpl extends ServiceImpl - implements ServirHostService{ - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/ServirServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/ServirServiceImpl.java deleted file mode 100644 index 1aae92a..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/ServirServiceImpl.java +++ /dev/null @@ -1,291 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.domain.message.Server; -import com.mzaxd.noodles.domain.vo.*; -import com.mzaxd.noodles.mapper.ServirMapper; -import com.mzaxd.noodles.mapper.UserMapper; -import com.mzaxd.noodles.service.*; -import com.mzaxd.noodles.util.BeanCopyUtils; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import javax.annotation.Resource; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @author root - * @description - * @createDate 2022-11-26 12:24:08 - */ -@Service -@Slf4j -public class ServirServiceImpl extends ServiceImpl implements ServirService { - - @Resource - private HostMachineService hostMachineService; - - @Resource - private ContainerService containerService; - - @Resource - private TagService tagService; - - @Resource - private ServirTagService servirTagService; - - @Resource - private ServirHostService servirHostService; - - @Resource - private ServirContainerService servirContainerService; - - @Resource - private ServirMapper servirMapper; - - @Override - public ResponseResult servirListWithCondition(String nameLike, List selectedTags, Integer perPage, Integer currentPage) { - //先查出所有选中标签的servir id - LambdaQueryWrapper servirTagLambdaQueryWrapper = new LambdaQueryWrapper<>(); - servirTagLambdaQueryWrapper.in(Objects.nonNull(selectedTags), ServirTag::getTagId, selectedTags); - List list = servirTagService.list(servirTagLambdaQueryWrapper); - List servirIds = null; - if (!CollectionUtils.isEmpty(list)) { - servirIds = list.stream().map(ServirTag::getServirId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList()); - } - - //设置查询条件 - LambdaQueryWrapper servirLambdaQueryWrapper = new LambdaQueryWrapper<>(); - servirLambdaQueryWrapper.like(StringUtils.hasText(nameLike), Servir::getDescription, nameLike); - servirLambdaQueryWrapper.in(Objects.nonNull(servirIds), Servir::getId, servirIds); - //分页 - PageHelper.startPage(currentPage, perPage); - //查询 - List servirs = list(servirLambdaQueryWrapper); - //封装分页信息 - PageInfo pageInfo = new PageInfo<>(servirs, perPage); - //封装结果返回 - List servirListVos = BeanCopyUtils.copyBeanList(servirs, ServirListVo.class); - //关联的host 关联的容器 所有标签 - servirListVos.forEach(servirListVo -> { - //关联的host - LambdaQueryWrapper servirHostWrapper = new LambdaQueryWrapper<>(); - servirHostWrapper.eq(ServirHost::getServirId, servirListVo.getId()); - List servirHosts = servirHostService.list(servirHostWrapper); - if (!CollectionUtils.isEmpty(servirHosts)) { - List hostIds = servirHosts.stream().map(ServirHost::getHostId).collect(Collectors.toList()); - LambdaQueryWrapper hostMachineWrapper = new LambdaQueryWrapper<>(); - hostMachineWrapper.in(HostMachine::getId, hostIds); - List hostMachines = hostMachineService.list(hostMachineWrapper); - servirListVo.setHosts(BeanCopyUtils.copyBeanList(hostMachines, ServirHostVo.class)); - } - //关联的容器 - LambdaQueryWrapper servirContainerWrapper = new LambdaQueryWrapper<>(); - servirContainerWrapper.eq(ServirContainer::getServirId, servirListVo.getId()); - List servirContainers = servirContainerService.list(servirContainerWrapper); - if (!CollectionUtils.isEmpty(servirContainers)) { - List containerIds = servirContainers.stream().map(ServirContainer::getContainerId).collect(Collectors.toList()); - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - containerWrapper.in(Container::getId, containerIds); - List containers = containerService.list(containerWrapper); - servirListVo.setContainers(BeanCopyUtils.copyBeanList(containers, ServirContainerVo.class)); - } - //关联的标签 - LambdaQueryWrapper servirTagWrapper = new LambdaQueryWrapper<>(); - servirTagWrapper.eq(ServirTag::getServirId, servirListVo.getId()); - List servirTags = servirTagService.list(servirTagWrapper); - if (!CollectionUtils.isEmpty(servirTags)) { - List tagIds = servirTags.stream().map(ServirTag::getTagId).collect(Collectors.toList()); - LambdaQueryWrapper tagWrapper = new LambdaQueryWrapper<>(); - tagWrapper.in(Tag::getId, tagIds); - List tags = tagService.list(tagWrapper); - servirListVo.setTags(BeanCopyUtils.copyBeanList(tags, TagVo.class)); - } - }); - pageInfo.setList(servirListVos); - return ResponseResult.okResult(pageInfo); - } - - @Override - @Transactional - public ResponseResult addServir(SaveOrUpdateServirVo saveOrUpdateServirVo) { - Servir servir = BeanCopyUtils.copyBean(saveOrUpdateServirVo, Servir.class); - save(servir); - //关联host - if (Objects.nonNull(saveOrUpdateServirVo.getHostIds())) { - List servirHosts = saveOrUpdateServirVo.getHostIds().stream().map(id -> { - ServirHost servirHost = new ServirHost(); - servirHost.setServirId(servir.getId()); - servirHost.setHostId(Long.valueOf(id)); - return servirHost; - }).collect(Collectors.toList()); - servirHostService.saveBatch(servirHosts); - } - - //关联Container - if (Objects.nonNull(saveOrUpdateServirVo.getContainerIds())) { - List servirContainers = saveOrUpdateServirVo.getContainerIds().stream().map(id -> { - ServirContainer servirContainer = new ServirContainer(); - servirContainer.setServirId(servir.getId()); - servirContainer.setContainerId(Long.valueOf(id)); - return servirContainer; - }).collect(Collectors.toList()); - servirContainerService.saveBatch(servirContainers); - } - - //关联Tag - List servirTags = saveOrUpdateServirVo.getTagIds().stream().map(id -> { - ServirTag servirTag = new ServirTag(); - servirTag.setServirId(servir.getId()); - servirTag.setTagId(Long.valueOf(id)); - return servirTag; - }).collect(Collectors.toList()); - servirTagService.saveBatch(servirTags); - - return ResponseResult.okResult(); - } - - @Override - @Transactional - public ResponseResult updateServir(SaveOrUpdateServirVo saveOrUpdateServirVo) { - Servir servir = BeanCopyUtils.copyBean(saveOrUpdateServirVo, Servir.class); - saveOrUpdate(servir); - - if (Objects.nonNull(saveOrUpdateServirVo.getHostIds())) { - //删除所有服务关联的host - LambdaQueryWrapper servirHostWrapper = new LambdaQueryWrapper<>(); - servirHostWrapper.eq(ServirHost::getServirId, servir.getId()); - servirHostService.getBaseMapper().delete(servirHostWrapper); - //关联新的host - List servirHosts = saveOrUpdateServirVo.getHostIds().stream().map(id -> { - ServirHost servirHost = new ServirHost(); - servirHost.setServirId(servir.getId()); - servirHost.setHostId(Long.valueOf(id)); - return servirHost; - }).collect(Collectors.toList()); - servirHostService.saveBatch(servirHosts); - } - - if (Objects.nonNull(saveOrUpdateServirVo.getContainerIds())) { - //删除所有服务关联的容器 - LambdaQueryWrapper servirContainerWrapper = new LambdaQueryWrapper<>(); - servirContainerWrapper.eq(ServirContainer::getServirId, servir.getId()); - servirContainerService.getBaseMapper().delete(servirContainerWrapper); - //关联新的容器 - List servirContainers = saveOrUpdateServirVo.getContainerIds().stream().map(id -> { - ServirContainer servirContainer = new ServirContainer(); - servirContainer.setServirId(servir.getId()); - servirContainer.setContainerId(Long.valueOf(id)); - return servirContainer; - }).collect(Collectors.toList()); - servirContainerService.saveBatch(servirContainers); - } - - if (!CollectionUtils.isEmpty(saveOrUpdateServirVo.getTagIds())) { - //删除所有服务关联的标签 - LambdaQueryWrapper servirTagWrapper = new LambdaQueryWrapper<>(); - servirTagWrapper.eq(ServirTag::getServirId, servir.getId()); - servirTagService.getBaseMapper().delete(servirTagWrapper); - //关联新的标签 - List servirTags = saveOrUpdateServirVo.getTagIds().stream().map(id -> { - ServirTag servirTag = new ServirTag(); - servirTag.setServirId(servir.getId()); - servirTag.setTagId(Long.valueOf(id)); - return servirTag; - }).collect(Collectors.toList()); - servirTagService.saveBatch(servirTags); - } - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getRemarkById(Integer id) { - Servir servir = getById(id); - return ResponseResult.okResult(servir.getRemark()); - } - - @Override - @Transactional - public ResponseResult deleteServirById(Integer id) { - log.info("删除id为{}的服务", id); - - //删除所有服务关联的host - LambdaQueryWrapper servirHostLambdaQueryWrapper = new LambdaQueryWrapper<>(); - servirHostLambdaQueryWrapper.eq(ServirHost::getServirId, id); - servirHostService.getBaseMapper().delete(servirHostLambdaQueryWrapper); - - //删除所有服务关联的容器 - LambdaQueryWrapper containerLambdaQueryWrapper = new LambdaQueryWrapper<>(); - containerLambdaQueryWrapper.eq(ServirContainer::getServirId, id); - servirContainerService.getBaseMapper().delete(containerLambdaQueryWrapper); - - //删除所有服务关联的标签 - LambdaQueryWrapper servirTagLambdaQueryWrapper = new LambdaQueryWrapper<>(); - servirTagLambdaQueryWrapper.eq(ServirTag::getServirId, id); - servirTagService.getBaseMapper().delete(servirTagLambdaQueryWrapper); - - //删除本体 - servirMapper.deleteById(id); - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getServirById(Integer id) { - Servir servir = getById(id); - ServirListVo servirVo = BeanCopyUtils.copyBean(servir, ServirListVo.class); - - LambdaQueryWrapper servirHostWrapper = new LambdaQueryWrapper<>(); - servirHostWrapper.eq(ServirHost::getServirId, id); - List servirHosts = servirHostService.list(servirHostWrapper); - if (!CollectionUtils.isEmpty(servirHosts)) { - List hostIds = servirHosts.stream().map(ServirHost::getHostId).collect(Collectors.toList()); - LambdaQueryWrapper hostMachineWrapper = new LambdaQueryWrapper<>(); - hostMachineWrapper.in(HostMachine::getId, hostIds); - List hostMachines = hostMachineService.list(hostMachineWrapper); - servirVo.setHosts(BeanCopyUtils.copyBeanList(hostMachines, ServirHostVo.class)); - } - //关联的容器 - LambdaQueryWrapper servirContainerWrapper = new LambdaQueryWrapper<>(); - servirContainerWrapper.eq(ServirContainer::getServirId, id); - List servirContainers = servirContainerService.list(servirContainerWrapper); - if (!CollectionUtils.isEmpty(servirContainers)) { - List containerIds = servirContainers.stream().map(ServirContainer::getContainerId).collect(Collectors.toList()); - LambdaQueryWrapper containerWrapper = new LambdaQueryWrapper<>(); - containerWrapper.in(Container::getId, containerIds); - List containers = containerService.list(containerWrapper); - servirVo.setContainers(BeanCopyUtils.copyBeanList(containers, ServirContainerVo.class)); - } - //关联的标签 - LambdaQueryWrapper servirTagWrapper = new LambdaQueryWrapper<>(); - servirTagWrapper.eq(ServirTag::getServirId, id); - List servirTags = servirTagService.list(servirTagWrapper); - if (!CollectionUtils.isEmpty(servirTags)) { - List tagIds = servirTags.stream().map(ServirTag::getTagId).collect(Collectors.toList()); - LambdaQueryWrapper tagWrapper = new LambdaQueryWrapper<>(); - tagWrapper.in(Tag::getId, tagIds); - List tags = tagService.list(tagWrapper); - servirVo.setTags(BeanCopyUtils.copyBeanList(tags, TagVo.class)); - } - return ResponseResult.okResult(servirVo); - } - - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/ServirTagServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/ServirTagServiceImpl.java deleted file mode 100644 index 76f7969..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/ServirTagServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.entity.ServirTag; -import com.mzaxd.noodles.service.ServirTagService; -import com.mzaxd.noodles.mapper.ServirTagMapper; -import org.springframework.stereotype.Service; - -/** -* @author 13439 -* @description 针对表【servir_tag】的数据库操作Service实现 -* @createDate 2023-02-11 19:40:35 -*/ -@Service -public class ServirTagServiceImpl extends ServiceImpl - implements ServirTagService{ - -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/SshLinkServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/SshLinkServiceImpl.java deleted file mode 100644 index 170568f..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/SshLinkServiceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.entity.SshLink; -import com.mzaxd.noodles.domain.vo.ContainerVo; -import com.mzaxd.noodles.domain.vo.HostMachineVo; -import com.mzaxd.noodles.service.ContainerService; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.service.SshLinkService; -import com.mzaxd.noodles.mapper.SshLinkMapper; -import com.mzaxd.noodles.util.BeanCopyUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.Objects; - -/** - * @author 13439 - * @description 针对表【ssh_link】的数据库操作Service实现 - * @createDate 2023-02-24 20:30:25 - */ -@Service -public class SshLinkServiceImpl extends ServiceImpl - implements SshLinkService { - - @Lazy - @Resource - private HostMachineService hostMachineService; - - @Lazy - @Resource - private ContainerService containerService; - - @Override - public ResponseResult getInstanceInfo(Long sshId) { - return ResponseResult.okResult(getInstanceInfoBySshId(sshId)); - } - - @Override - public Object getInstanceInfoBySshId(Long sshId) { - LambdaQueryWrapper hostMachineLambdaQueryWrapper = new LambdaQueryWrapper<>(); - hostMachineLambdaQueryWrapper.eq(HostMachine::getSshId, sshId); - HostMachine hostMachine = hostMachineService.getOne(hostMachineLambdaQueryWrapper); - if (Objects.nonNull(hostMachine)) { - HostMachineVo hostMachineVo = BeanCopyUtils.copyBean(hostMachine, HostMachineVo.class); - return hostMachineVo; - } - LambdaQueryWrapper containerLambdaQueryWrapper = new LambdaQueryWrapper<>(); - containerLambdaQueryWrapper.eq(Container::getSshId, sshId); - Container container = containerService.getOne(containerLambdaQueryWrapper); - if (Objects.nonNull(container)) { - ContainerVo containerVo = BeanCopyUtils.copyBean(container, ContainerVo.class); - return containerVo; - } - return null; - } -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/TagServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/TagServiceImpl.java deleted file mode 100644 index e177365..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/TagServiceImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.Tag; -import com.mzaxd.noodles.domain.vo.TagVo; -import com.mzaxd.noodles.service.TagService; -import com.mzaxd.noodles.mapper.TagMapper; -import com.mzaxd.noodles.util.BeanCopyUtils; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** -* @author 13439 -* @description 针对表【tag】的数据库操作Service实现 -* @createDate 2023-02-11 18:26:12 -*/ -@Service -public class TagServiceImpl extends ServiceImpl - implements TagService{ - - @Override - public ResponseResult getAllTag() { - List tagList = list(); - List tagVos = BeanCopyUtils.copyBeanList(tagList, TagVo.class); - return ResponseResult.okResult(tagVos); - } -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/service/impl/UserServiceImpl.java b/src/main/java/com/mzaxd/noodles/service/impl/UserServiceImpl.java deleted file mode 100644 index 952efe6..0000000 --- a/src/main/java/com/mzaxd/noodles/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.mzaxd.noodles.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.domain.ResponseResult; -import com.mzaxd.noodles.domain.entity.HostMachine; -import com.mzaxd.noodles.domain.entity.User; -import com.mzaxd.noodles.domain.vo.ProfileHeaderVo; -import com.mzaxd.noodles.domain.vo.ProfileVo; -import com.mzaxd.noodles.domain.vo.UserInfoVo; -import com.mzaxd.noodles.enums.AppHttpCodeEnum; -import com.mzaxd.noodles.mapper.UserMapper; -import com.mzaxd.noodles.service.ContainerService; -import com.mzaxd.noodles.service.HostMachineService; -import com.mzaxd.noodles.service.ServirService; -import com.mzaxd.noodles.service.UserService; -import com.mzaxd.noodles.util.BeanCopyUtils; -import com.mzaxd.noodles.util.IpUtil; -import com.mzaxd.noodles.util.SecurityUtils; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.io.IOException; -import java.util.Objects; - -/** -* @author root -* @description 针对表【user】的数据库操作Service实现 -* @createDate 2023-01-28 09:16:07 -*/ -@Service -public class UserServiceImpl extends ServiceImpl - implements UserService{ - - @Resource - private PasswordEncoder passwordEncoder; - - @Resource - private HostMachineService hostMachineService; - - @Resource - private ContainerService containerService; - - @Resource - private ServirService servirService; - - @Override - public ResponseResult userInfo() { - //获取当前用户id - Long userId = SecurityUtils.getUserId(); - //根据id查询用户信息 - User user = getById(userId); - //将用户信息封装Vo并返回 - UserInfoVo userInfoVo = BeanCopyUtils.copyBean(user, UserInfoVo.class); - return ResponseResult.okResult(userInfoVo); - } - - @Override - public ResponseResult updateUserInfo(User user) { - updateById(user); - return ResponseResult.okResult(); - } - - @Override - public ResponseResult getProfileHeader(Integer id, String ip) { - User user = getById(id); - ProfileHeaderVo profileHeaderVo = BeanCopyUtils.copyBean(user, ProfileHeaderVo.class); - try { - profileHeaderVo.setLocation(IpUtil.getRegionByIp(ip)); - } catch (Exception e) { - throw new RuntimeException(e); - } - return ResponseResult.okResult(profileHeaderVo); - } - - @Override - public ResponseResult getProfile() { - //获取当前用户id - Long userId = SecurityUtils.getUserId(); - User user = getById(userId); - ProfileVo profile = BeanCopyUtils.copyBean(user, ProfileVo.class); - //查物理机数量 - LambdaQueryWrapper hostMachineWrapper = new LambdaQueryWrapper<>(); - hostMachineWrapper.eq(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - profile.setHostNumber(hostMachineService.count(hostMachineWrapper)); - //查虚拟机数量 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - profile.setVmNumber(hostMachineService.count(vmWrapper)); - //查容器数量 - profile.setContainerNumber(containerService.count()); - //查服务数量 - profile.setServirNumber(servirService.count()); - return ResponseResult.okResult(profile); - } - - @Override - public ResponseResult isFirstUse() { - User user = getById(1); - if (user.getUserState() == 0) { - return ResponseResult.okResult(true); - } else { - return ResponseResult.okResult(false); - } - } - - @Override - public ResponseResult changePassword(String password) { - Long userId = SecurityUtils.getUserId(); - User user = getById(userId); - user.setPassword(passwordEncoder.encode(password)); - saveOrUpdate(user); - return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "密码修改成功"); - } - - @Override - public ResponseResult getUserInfo(Integer id) { - User user = getById(id); - UserInfoVo userInfoVo = BeanCopyUtils.copyBean(user, UserInfoVo.class); - return ResponseResult.okResult(userInfoVo); - } - - @Override - public ResponseResult updateUserInfo(UserInfoVo userData) { - Long userId = SecurityUtils.getUserId(); - User user = getById(userId); - user.setEmail(userData.getEmail()).setUserName(userData.getUserName()).setNickName(userData.getNickName()).setAvatar(userData.getAvatar()); - saveOrUpdate(user); - return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS.getCode(), "账号信息修改成功"); - } -} - - - - diff --git a/src/main/java/com/mzaxd/noodles/util/IpUtil.java b/src/main/java/com/mzaxd/noodles/util/IpUtil.java deleted file mode 100644 index e882a63..0000000 --- a/src/main/java/com/mzaxd/noodles/util/IpUtil.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.mzaxd.noodles.util; - -import cn.hutool.core.net.NetUtil; -import lombok.extern.slf4j.Slf4j; -import org.lionsoul.ip2region.xdb.Searcher; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - -import javax.servlet.http.HttpServletRequest; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * ip2region封装工具类 - * - * @author 13439 - */ - -@Slf4j -public class IpUtil { - - /** - * 获取客户端IP地址 - * - * @param request - * @return - */ - public static String getIpAddr(HttpServletRequest request) { - String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("X-Real-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("WL-Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getRemoteAddr(); - } - if ("0:0:0:0:0:0:0:1".equals(ip)) { - ip = "127.0.0.1"; - } - if (ip.split(",").length > 1) { - ip = ip.split(",")[0]; - } - return ip; - } - - public static String getRegionByIp(String ip) throws IOException { - if (NetUtil.isInnerIP(ip)) { - return "用户当前为内网访问"; - } - URL url = IpUtil.class.getClassLoader().getResource("ip2region.db"); - File file; - if (url != null) { - file = new File(url.getFile()); - } else { - return null; - } - if (!file.exists()) { - System.out.println("Error: Invalid ip2region.db file, filePath:" + file.getPath()); - return null; - } - String dbPath = file.getPath(); - // 1、创建 searcher 对象 - Searcher searcher = null; - try { - searcher = Searcher.newWithFileOnly(dbPath); - } catch (IOException e) { - log.error("failed to create searcher with `%s`: %s\n", dbPath, e); - return "无法识别用户地址"; - } - - // 2、查询 - try { - long sTime = System.nanoTime(); - String region = searcher.search(ip); - long cost = TimeUnit.NANOSECONDS.toMicros((long) (System.nanoTime() - sTime)); - log.info("{region: %s, ioCount: %d, took: %d μs}\n", region, searcher.getIOCount(), cost); - if (!StringUtils.hasText(region)) { - region = "无法识别用户地址"; - } - return region; - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 3、关闭资源 - searcher.close(); - } - return "无法识别用户地址"; - } -} diff --git a/src/main/java/com/mzaxd/noodles/util/SshLinkUtil.java b/src/main/java/com/mzaxd/noodles/util/SshLinkUtil.java deleted file mode 100644 index 1e39b51..0000000 --- a/src/main/java/com/mzaxd/noodles/util/SshLinkUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.mzaxd.noodles.util; - -import com.mzaxd.noodles.domain.vo.ContainerVo; -import com.mzaxd.noodles.domain.vo.HostVo; -import com.mzaxd.noodles.domain.vo.VmVo; -import org.springframework.util.StringUtils; - -/** - * @author 13439 - */ -public class SshLinkUtil { - - public static boolean isHostSshLinkParamValid(HostVo hostVo) { - try { - if (StringUtils.hasText(hostVo.getSshHost()) || StringUtils.hasText(hostVo.getSshUser()) || - StringUtils.hasText(hostVo.getSshPwd()) || StringUtils.hasText(hostVo.getSshPort().toString())) { - return true; - } - } catch (Exception e) { - return false; - } - return false; - } - - public static boolean isVmSshLinkParamValid(VmVo vmVo) { - try { - if (StringUtils.hasText(vmVo.getSshHost()) || StringUtils.hasText(vmVo.getSshUser()) || - StringUtils.hasText(vmVo.getSshPwd()) || StringUtils.hasText(vmVo.getSshPort().toString())) { - return true; - } - } catch (Exception e) { - return false; - } - return false; - } - - public static boolean isContainerSshLinkParamValid(ContainerVo containerVo) { - try { - if (StringUtils.hasText(containerVo.getSshHost()) || StringUtils.hasText(containerVo.getSshUser()) || - StringUtils.hasText(containerVo.getSshPwd()) || StringUtils.hasText(containerVo.getSshPort().toString())) { - return true; - } - } catch (Exception e) { - return false; - } - return false; - } - - -} diff --git a/src/main/java/com/mzaxd/noodles/util/StringUtil.java b/src/main/java/com/mzaxd/noodles/util/StringUtil.java deleted file mode 100644 index 4dd1de2..0000000 --- a/src/main/java/com/mzaxd/noodles/util/StringUtil.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.mzaxd.noodles.util; - -import cn.hutool.core.date.DateField; -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.lang.Validator; -import cn.hutool.core.util.StrUtil; -import cn.hutool.system.SystemUtil; -import com.alibaba.fastjson.JSON; - -import java.io.File; -import java.util.List; - -/** - * @ProjectName StringUtil - * @author qingfeng - * @version 1.0.0 - * @Description 方法运行参数工具 - * @createTime 2022/5/2 0002 15:29 - */ -public class StringUtil { - - /** - * 支持的压缩包格式 - */ - public static final String[] PACKAGE_EXT = new String[]{"tar.bz2", "tar.gz", "tar", "bz2", "zip", "gz"}; - - /** - * 获取启动参数 - * @param args 所有参数 - * @param name 参数名 - * @return 值 - */ - public static String getArgsValue(String[] args, String name) { - if (args == null) { - return null; - } - for (String item : args) { - item = StrUtil.trim(item); - if (item.startsWith("--" + name + "=")) { - return item.substring(name.length() + 3); - } - } - return null; - } - - /** - * id输入规则 - * - * @param value 值 - * @param min 最短 - * @param max 最长 - * @return true - */ - public static boolean isGeneral(CharSequence value, int min, int max) { - String reg = "^[a-zA-Z0-9_-]{" + min + StrUtil.COMMA + max + "}$"; - return Validator.isMatchRegex(reg, value); - } - - /** - * 删除文件开始的路径 - * - * @param file 要删除的文件 - * @param startPath 开始的路径 - * @param inName 是否返回文件名 - * @return /test/a.txt /test/ a.txt - */ - public static String delStartPath(File file, String startPath, boolean inName) { - String newWhitePath; - if (inName) { - newWhitePath = FileUtil.getAbsolutePath(file.getAbsolutePath()); - } else { - newWhitePath = FileUtil.getAbsolutePath(file.getParentFile()); - } - String itemAbsPath = FileUtil.getAbsolutePath(new File(startPath)); - itemAbsPath = FileUtil.normalize(itemAbsPath); - newWhitePath = FileUtil.normalize(newWhitePath); - String path = StrUtil.removePrefix(newWhitePath, itemAbsPath); - //newWhitePath.substring(newWhitePath.indexOf(itemAbsPath) + itemAbsPath.length()); - path = FileUtil.normalize(path); - if (path.startsWith(StrUtil.SLASH)) { - path = path.substring(1); - } - return path; - } - - /** - * 获取jdk 中的tools jar文件路径 - * - * @return file - */ - public static File getToolsJar() { - File file = new File(SystemUtil.getJavaRuntimeInfo().getHomeDir()); - return new File(file.getParentFile(), "lib/tools.jar"); - } - - /** - * 指定时间的下一个刻度 - * - * @return String - */ - public static String getNextScaleTime(String time, Long millis) { - DateTime dateTime = DateUtil.parse(time); - if (millis == null) { - millis = 30 * 1000L; - } - DateTime newTime = dateTime.offsetNew(DateField.SECOND, (int) (millis / 1000)); - return DateUtil.formatTime(newTime); - } - - /** - * json 字符串转 bean,兼容普通json和字符串包裹情况 - * - * @param jsonStr json 字符串 - * @param cls 要转为bean的类 - * @param 泛型 - * @return data - */ - public static T jsonConvert(String jsonStr, Class cls) { - if (StrUtil.isEmpty(jsonStr)) { - return null; - } - try { - return JSON.parseObject(jsonStr, cls); - } catch (Exception e) { - return JSON.parseObject(JSON.parse(jsonStr).toString(), cls); - } - } - - /** - * json 字符串转 bean,兼容普通json和字符串包裹情况 - * - * @param jsonStr json 字符串 - * @param cls 要转为bean的类 - * @param 泛型 - * @return data - */ - public static List jsonConvertArray(String jsonStr, Class cls) { - try { - if (StrUtil.isEmpty(jsonStr)) { - return null; - } - return JSON.parseArray(jsonStr, cls); - } catch (Exception e) { - Object parse = JSON.parse(jsonStr); - return JSON.parseArray(parse.toString(), cls); - } - } -} diff --git a/src/main/java/com/mzaxd/noodles/websocket/AllHostDynamicDataServer.java b/src/main/java/com/mzaxd/noodles/websocket/AllHostDynamicDataServer.java deleted file mode 100644 index 29cf071..0000000 --- a/src/main/java/com/mzaxd/noodles/websocket/AllHostDynamicDataServer.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.mzaxd.noodles.websocket; - -import com.alibaba.fastjson.JSONObject; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.service.HostDetectorService; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author Mzaxd - * @since 2023-02-05 15:37 - */ -@Component -@ServerEndpoint("/ws/getDynamicData/") -@Slf4j -@Data -public class AllHostDynamicDataServer { - - private static HostDetectorService hostDetectorService; - - @Autowired - public void setHostDetectorService(HostDetectorService hostDetectorService) { - AllHostDynamicDataServer.hostDetectorService = hostDetectorService; - } - - /** - * 实例一个session,这个session是websocket的session - */ - private Session session; - - /** - * 存放websocket的集合(本次demo不会用到,聊天室的demo会用到) - * - * @author mzaxd - * @date 2023/2/5 15:39 - * @param null - */ - private static CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet<>(); - - /** - * 前端请求时一个websocket时 - * - * @param session - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnOpen - public void onOpen(Session session) { - this.session = session; - webSocketSet.add(this); - log.info("【websocket消息】有新的连接, 总数:{}", webSocketSet.size()); - - List allALiveDetectors = hostDetectorService.getAllALiveDetectors(); - - // 执行逻辑 - long initialDelay = 0; - long period = 6L; - - ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, - new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build()); - executorService.scheduleAtFixedRate(() -> { - Map dynamicData = hostDetectorService.getDynamicData(allALiveDetectors); - - String message = JSONObject.toJSONString(dynamicData); - AllHostDynamicDataServer.sendMessage(message); - }, initialDelay, period, TimeUnit.SECONDS); - } - - /** - * 前端关闭时一个websocket时 - * - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnClose - public void onClose() { - webSocketSet.remove(this); - log.info("【websocket消息】连接断开, 总数:{}", webSocketSet.size()); - } - - /** - * 前端向后端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - @OnMessage - public void onMessage(String message) { - log.info("【websocket消息】收到客户端发来的消息:{}", message); - } - - /** - * 新增一个方法用于主动向客户端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - public static void sendMessage(String message) { - for (AllHostDynamicDataServer webSocket : webSocketSet) { - log.info("【websocket消息】广播消息, message={}", message); - try { - webSocket.session.getBasicRemote().sendText(message); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - -} diff --git a/src/main/java/com/mzaxd/noodles/websocket/HostDynamicDataServer.java b/src/main/java/com/mzaxd/noodles/websocket/HostDynamicDataServer.java deleted file mode 100644 index b36aa13..0000000 --- a/src/main/java/com/mzaxd/noodles/websocket/HostDynamicDataServer.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.mzaxd.noodles.websocket; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.service.HostDetectorService; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author Mzaxd - * @since 2023-02-05 15:37 - */ -@Component -@ServerEndpoint("/ws/getHostDynamicData/{hostId}") -@Slf4j -@Data -public class HostDynamicDataServer { - - private static HostDetectorService hostDetectorService; - - @Autowired - public void setHostDetectorService(HostDetectorService hostDetectorService) { - HostDynamicDataServer.hostDetectorService = hostDetectorService; - } - - /** - * 实例一个session,这个session是websocket的session - */ - private Session session; - - /** - * 存放websocket的集合(本次demo不会用到,聊天室的demo会用到) - * - * @author mzaxd - * @date 2023/2/5 15:39 - * @param null - */ - private static CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet<>(); - - /** - * 前端请求时一个websocket时 - * - * @param session - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnOpen - public void onOpen(Session session, @PathParam("hostId") Integer hostId) { - this.session = session; - webSocketSet.add(this); - log.info("【websocket消息】有新的连接, 总数:{}", webSocketSet.size()); - - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(HostDetector::getHostMachineId, hostId); - HostDetector hostDetector = hostDetectorService.getOne(lambdaQueryWrapper); - - // 执行逻辑 - long initialDelay = 0; - long period = 6L; - - ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, - new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build()); - executorService.scheduleAtFixedRate(() -> { - Map dynamicData = hostDetectorService.getDynamicDataByDetector(hostDetector); - - String message = JSONObject.toJSONString(dynamicData); - HostDynamicDataServer.sendMessage(message); - }, initialDelay, period, TimeUnit.SECONDS); - } - - /** - * 前端关闭时一个websocket时 - * - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnClose - public void onClose() { - webSocketSet.remove(this); - log.info("【websocket消息】连接断开, 总数:{}", webSocketSet.size()); - } - - /** - * 前端向后端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - @OnMessage - public void onMessage(String message) { - log.info("【websocket消息】收到客户端发来的消息:{}", message); - } - - /** - * 新增一个方法用于主动向客户端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - public static void sendMessage(String message) { - for (HostDynamicDataServer webSocket : webSocketSet) { - log.info("【websocket消息】广播消息, message={}", message); - try { - webSocket.session.getBasicRemote().sendText(message); - } catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/com/mzaxd/noodles/websocket/NoodlesJvmInfoServer.java b/src/main/java/com/mzaxd/noodles/websocket/NoodlesJvmInfoServer.java deleted file mode 100644 index e389e77..0000000 --- a/src/main/java/com/mzaxd/noodles/websocket/NoodlesJvmInfoServer.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.mzaxd.noodles.websocket; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.domain.entity.HostDetector; -import com.mzaxd.noodles.domain.message.DynamicData; -import com.mzaxd.noodles.service.HostDetectorService; -import com.mzaxd.noodles.util.SystemInfoUtils; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author Mzaxd - * @since 2023-02-05 15:37 - */ -@Component -@ServerEndpoint("/ws/getNoodlesJvmInfo") -@Slf4j -@Data -public class NoodlesJvmInfoServer { - - private static HostDetectorService hostDetectorService; - - @Autowired - public void setHostDetectorService(HostDetectorService hostDetectorService) { - NoodlesJvmInfoServer.hostDetectorService = hostDetectorService; - } - - /** - * 实例一个session,这个session是websocket的session - */ - private Session session; - - /** - * 存放websocket的集合(本次demo不会用到,聊天室的demo会用到) - * - * @author mzaxd - * @date 2023/2/5 15:39 - * @param null - */ - private static CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet<>(); - - /** - * 前端请求时一个websocket时 - * - * @param session - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnOpen - public void onOpen(Session session) { - this.session = session; - webSocketSet.add(this); - log.info("【websocket消息】有新的连接, 总数:{}", webSocketSet.size()); - - // 执行逻辑 - long initialDelay = 0; - long period = 5L; - - ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, - new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build()); - executorService.scheduleAtFixedRate(() -> { - JSONObject jvmInfo = SystemInfoUtils.getJvmInfo(); - NoodlesJvmInfoServer.sendMessage(jvmInfo.toJSONString()); - }, initialDelay, period, TimeUnit.SECONDS); - } - - /** - * 前端关闭时一个websocket时 - * - * @author mzaxd - * @date 2023/2/5 16:11 - */ - @OnClose - public void onClose() { - webSocketSet.remove(this); - log.info("【websocket消息】连接断开, 总数:{}", webSocketSet.size()); - } - - /** - * 前端向后端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - @OnMessage - public void onMessage(String message) { - log.info("【websocket消息】收到客户端发来的消息:{}", message); - } - - /** - * 新增一个方法用于主动向客户端发送消息 - * - * @param message - * @author mzaxd - * @date 2023/2/5 16:12 - */ - public static synchronized void sendMessage(String message) { - for (NoodlesJvmInfoServer webSocket : webSocketSet) { - log.info("【websocket消息】广播消息, message={}", message); - try { - webSocket.session.getBasicRemote().sendText(message); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - -} diff --git a/src/main/java/com/mzaxd/noodles/websocket/SshHandler.java b/src/main/java/com/mzaxd/noodles/websocket/SshHandler.java deleted file mode 100644 index c7bdb58..0000000 --- a/src/main/java/com/mzaxd/noodles/websocket/SshHandler.java +++ /dev/null @@ -1,288 +0,0 @@ -package com.mzaxd.noodles.websocket; - -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.thread.ThreadUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.ssh.ChannelType; -import cn.hutool.extra.ssh.JschUtil; -import cn.hutool.json.JSONUtil; -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.jcraft.jsch.ChannelShell; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import com.mzaxd.noodles.domain.entity.Container; -import com.mzaxd.noodles.domain.entity.SshLink; -import com.mzaxd.noodles.domain.ssh.SshModel; -import com.mzaxd.noodles.domain.ssh.SshMessage; -import com.mzaxd.noodles.service.ContainerService; -import com.mzaxd.noodles.service.SshLinkService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.websocket.*; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author qingfeng - * @version 1.0.0 - * @ProjectName SshHandler - * @Description ssh 处理 - * @createTime 2022/5/2 0002 15:26 - */ -@ServerEndpoint(value = "/ws/ssh/{sshId}") -@Component -@Slf4j -public class SshHandler { - - private static SshLinkService sshLinkService; - - private static ContainerService containerService; - - @Autowired - public void setSshLinkService(SshLinkService sshLinkService) { - SshHandler.sshLinkService = sshLinkService; - } - - @Autowired - public void ContainerService(ContainerService containerService) { - SshHandler.containerService = containerService; - } - - - private static final ConcurrentHashMap HANDLER_ITEM_CONCURRENT_HASH_MAP = new ConcurrentHashMap<>(); - - @PostConstruct - public void init() { - log.info("websocket 加载"); - } - - - private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0); - - /** - * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 - */ - private static final CopyOnWriteArraySet sessionSet = new CopyOnWriteArraySet(); - - - /** - * 连接建立成功调用的方法 - */ - @OnOpen - public void onOpen(javax.websocket.Session session, @PathParam("sshId") Long sshId) { - sessionSet.add(session); - SshLink sshLink = sshLinkService.getById(sshId); - SshModel sshItem = new SshModel(); - sshItem.setHost(sshLink.getHost()); - sshItem.setPort(sshLink.getPort()); - sshItem.setUser(sshLink.getName()); - sshItem.setPassword(sshLink.getPassword()); - // 在线数加1 - int cnt = ONLINE_COUNT.incrementAndGet(); - log.info("有连接加入,当前连接数为:{},sessionId={}", cnt, session.getId()); - HandlerItem handlerItem = null; - try { - handlerItem = new HandlerItem(session, sshItem); - handlerItem.startRead(); - HANDLER_ITEM_CONCURRENT_HASH_MAP.put(session.getId(), handlerItem); - if (Objects.nonNull(sshLink.getConsoleType())) { - //找出docker id - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Container::getSshId, sshId); - Container container = containerService.getOne(wrapper); - sendBinary(session,"docker exec -it " + container.getContainerId() + " /bin/" + sshLink.getConsoleType() + "\n"); - } - } catch (Exception exception) { - sendMessage(session, "连接失败,请检查连接信息是否配置正确\n"); - sessionSet.remove(session); - } - } - - /** - * 连接关闭调用的方法 - */ - @OnClose - public void onClose(javax.websocket.Session session) { - destroy(session); - sessionSet.remove(session); - int cnt = ONLINE_COUNT.decrementAndGet(); - log.info("有连接关闭,当前连接数为:{}", cnt); - } - - /** - * 收到客户端消息后调用的方法 - * - * @param message 客户端发送过来的消息 - */ - @OnMessage - public void onMessage(String message, javax.websocket.Session session) throws Exception { - try { - if (JSONUtil.isJson(message)) { - SshMessage sshData = JSON.parseObject(message, SshMessage.class); - HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId()); - handlerItem.channel.setPty(true); - handlerItem.channel.setPtySize(sshData.getCols(), sshData.getRows(), 640, 480); - } else { - HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId()); - this.sendCommand(handlerItem, message); - } - } catch (Exception e) { - //吃掉Hutool JSONUtil产生的异常 - HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId()); - this.sendCommand(handlerItem, message); - } - - } - - /** - * 出现错误 - * - * @param session - * @param error - */ - @OnError - public void onError(javax.websocket.Session session, Throwable error) { - log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId()); - error.printStackTrace(); - } - - private void sendCommand(HandlerItem handlerItem, String data) throws Exception { - if (handlerItem.checkInput(data)) { - handlerItem.outputStream.write(data.getBytes()); - } else { - handlerItem.outputStream.write("没有执行相关命令权限".getBytes()); - handlerItem.outputStream.flush(); - handlerItem.outputStream.write(new byte[]{3}); - } - handlerItem.outputStream.flush(); - } - - /** - * 发送消息,实践表明,每次浏览器刷新,session会发生变化。 - * - * @param session - * @param message - */ - public static void sendMessage(javax.websocket.Session session, String message) { - try { - synchronized (session) { - session.getBasicRemote().sendText(message); - } - } catch (IOException e) { - log.error("发送消息出错:{}", e.getMessage()); - e.printStackTrace(); - } - } - - private class HandlerItem implements Runnable { - private final javax.websocket.Session session; - private final InputStream inputStream; - private final OutputStream outputStream; - private final Session openSession; - private final ChannelShell channel; - private final SshModel sshItem; - private final StringBuilder nowLineInput = new StringBuilder(); - - HandlerItem(javax.websocket.Session session, SshModel sshItem) throws IOException { - this.session = session; - this.sshItem = sshItem; - this.openSession = JschUtil.openSession(sshItem.getHost(), sshItem.getPort(), sshItem.getUser(), sshItem.getPassword()); - this.channel = (ChannelShell) JschUtil.createChannel(openSession, ChannelType.SHELL); - this.inputStream = channel.getInputStream(); - this.outputStream = channel.getOutputStream(); - } - - void startRead() throws JSchException { - this.channel.connect(); - ThreadUtil.execute(this); - } - - - /** - * 添加到命令队列 - * - * @param msg 输入 - * @return 当前待确认待所有命令 - */ - private String append(String msg) { - char[] x = msg.toCharArray(); - if (x.length == 1 && x[0] == 127) { - // 退格键 - int length = nowLineInput.length(); - if (length > 0) { - nowLineInput.delete(length - 1, length); - } - } else { - nowLineInput.append(msg); - } - return nowLineInput.toString(); - } - - public boolean checkInput(String msg) { - String allCommand = this.append(msg); - boolean refuse; - if (StrUtil.equalsAny(msg, StrUtil.CR, StrUtil.TAB)) { - String join = nowLineInput.toString(); - if (StrUtil.equals(msg, StrUtil.CR)) { - nowLineInput.setLength(0); - } - refuse = SshModel.checkInputItem(sshItem, join); - } else { - // 复制输出 - refuse = SshModel.checkInputItem(sshItem, msg); - } - return refuse; - } - - - @Override - public void run() { - try { - byte[] buffer = new byte[1024]; - int i; - //如果没有数据来,线程会一直阻塞在这个地方等待数据。 - while ((i = inputStream.read(buffer)) != -1) { - sendBinary(session, new String(Arrays.copyOfRange(buffer, 0, i), sshItem.getCharsetT())); - } - } catch (Exception e) { - if (!this.openSession.isConnected()) { - return; - } - SshHandler.this.destroy(this.session); - } - } - } - - public void destroy(javax.websocket.Session session) { - HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId()); - if (handlerItem != null) { - IoUtil.close(handlerItem.inputStream); - IoUtil.close(handlerItem.outputStream); - JschUtil.close(handlerItem.channel); - JschUtil.close(handlerItem.openSession); - } - IoUtil.close(session); - HANDLER_ITEM_CONCURRENT_HASH_MAP.remove(session.getId()); - } - - private static void sendBinary(javax.websocket.Session session, String msg) { - try { - System.out.println("#####:" + msg); - session.getBasicRemote().sendText(msg); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 8056f13..5f573a7 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: url: jdbc:mysql://localhost:3306/noodles?characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: rootroot - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: com.alibaba.druid.proxy.DruidDriver #Redis配置 redis: host: 192.168.1.103 @@ -35,5 +35,5 @@ pagehelper: page-size-zero: true logging: level: - com.mzaxd.noodles: debug + com.mzaxd.bps: debug diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 52f3d20..c698230 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -3,14 +3,14 @@ server: spring: #MySQL配置 datasource: - url: jdbc:mysql://192.168.1.103:3307/noodles?characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://localhost:3306/noodles?characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: rootroot - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: com.alibaba.druid.proxy.DruidDriver #Redis配置 redis: host: 192.168.1.103 - database: 3 + database: 5 #RabbitMq配置 rabbitmq: host: 192.168.1.103 @@ -35,4 +35,4 @@ pagehelper: page-size-zero: true logging: level: - com.mzaxd.noodles: info \ No newline at end of file + com.mzaxd.bps: info diff --git a/src/main/resources/config/mail.setting b/src/main/resources/config/mail.setting deleted file mode 100644 index 2b2a2d6..0000000 --- a/src/main/resources/config/mail.setting +++ /dev/null @@ -1,16 +0,0 @@ -#使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。 -startttlsEnable = true - -# 使用SSL安全连接 -sslEnable = true -# 指定实现javax.net.SocketFactory接口的类的名称,这个类将被用于创建SMTP的套接字 -socketFactoryClass = javax.net.ssl.SSLSocketFactory -# 如果设置为true,未能创建一个套接字使用指定的套接字工厂类将导致使用java.net.Socket创建的套接字类, 默认值为true -socketFactoryFallback = true -# 指定的端口连接到在使用指定的套接字工厂。如果没有设置,将使用默认端口456 -socketFactoryPort = 465 - -# SMTP超时时长,单位毫秒,缺省值不超时 -timeout = 0 -# Socket连接超时值,单位毫秒,缺省值不超时 -connectionTimeout = 0 \ No newline at end of file diff --git a/src/main/resources/ip2region.xdb b/src/main/resources/ip2region.xdb deleted file mode 100644 index c78b792..0000000 Binary files a/src/main/resources/ip2region.xdb and /dev/null differ diff --git a/src/main/resources/mapper/HostMachineMapper.xml b/src/main/resources/mapper/HostMachineMapper.xml deleted file mode 100644 index a742999..0000000 --- a/src/main/resources/mapper/HostMachineMapper.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - hm - . - id - ,hm.name,hm.description, - hm.avatar,hm.ssh_id,hm.os_id,hm.server_address, - hm.manage_ip,hm.host_machine_id,hm.threads, - hm.memory,hm.host_machine_state,notify, - hm.create_time,hm.create_by,hm.update_time, - hm.update_by,hm.del_flag - - - diff --git a/src/test/java/com/mzaxd/noodles/EncodePassword.java b/src/test/java/com/mzaxd/bps/EncodePasswordTest.java similarity index 78% rename from src/test/java/com/mzaxd/noodles/EncodePassword.java rename to src/test/java/com/mzaxd/bps/EncodePasswordTest.java index 53848c4..48c93f1 100644 --- a/src/test/java/com/mzaxd/noodles/EncodePassword.java +++ b/src/test/java/com/mzaxd/bps/EncodePasswordTest.java @@ -1,7 +1,5 @@ -package com.mzaxd.noodles; +package com.mzaxd.bps; -import com.alibaba.fastjson.JSONObject; -import com.mzaxd.noodles.util.SystemInfoUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.crypto.password.PasswordEncoder; @@ -9,7 +7,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import javax.annotation.Resource; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class EncodePassword { +public class EncodePasswordTest { @Resource private PasswordEncoder passwordEncoder; diff --git a/src/test/java/com/mzaxd/noodles/NoodlesApplicationTests.java b/src/test/java/com/mzaxd/noodles/NoodlesApplicationTests.java deleted file mode 100644 index 06b4d67..0000000 --- a/src/test/java/com/mzaxd/noodles/NoodlesApplicationTests.java +++ /dev/null @@ -1,776 +0,0 @@ -package com.mzaxd.noodles; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.DateUtil; -import cn.hutool.extra.mail.MailAccount; -import cn.hutool.extra.mail.MailUtil; -import cn.hutool.http.HttpException; -import cn.hutool.http.HttpRequest; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.mzaxd.noodles.constant.RedisConstant; -import com.mzaxd.noodles.constant.SystemConstant; -import com.mzaxd.noodles.constant.UrlConstant; -import com.mzaxd.noodles.domain.entity.*; -import com.mzaxd.noodles.mapper.OsMapper; -import com.mzaxd.noodles.service.*; -import com.mzaxd.noodles.util.*; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; -import org.springframework.web.client.RestTemplate; - -import java.io.IOException; -import java.net.*; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.*; -import java.util.concurrent.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@Slf4j -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class NoodlesApplicationTests { - - @Resource - private OsMapper osMapper; - - @Resource - private RedisCache redisCache; - - @Resource - private RedisTemplate redisTemplate; - - @Resource - private SystemSettingService systemSettingService; - - @Resource - private NotificationService notificationService; - - @Resource - private HostDetectorService hostDetectorService; - - @Resource - private PasswordEncoder passwordEncoder; - - @Test - void contextLoads() { - try { - HttpRequest.get("https://elizaveta.top:71/").setConnectionTimeout(1000).execute(true); - } catch (HttpException exception) { - log.info("建立连接失败"); - } - } - - @Test - void test() { - Set containerNotifyIds = redisCache.getCacheSet("ContainerNotifyIds"); - redisTemplate.boundSetOps("setKey"); - redisTemplate.boundSetOps("Notify:ContainerIds").remove(1); - containerNotifyIds.remove(1); - redisCache.setCacheSet("ContainerNotifyIds", containerNotifyIds); - } - - @Test - void emailTest() { - SystemSetting systemSetting = systemSettingService.getById(1); - MailAccount account = new MailAccount(); - account.setFrom(systemSetting.getNotificationEmail()); - account.setUser(systemSetting.getNotificationEmail()); - account.setPass(systemSetting.getEmailPass()); - MailUtil.send(account, CollUtil.newArrayList("mzaxd0712@gmail.com"), "测试5", "邮件来自测试", false); - } - - @Test - public void testJVMInfo() { - JSONObject jvmInfo = SystemInfoUtils.getJvmInfo(); - System.out.println(jvmInfo); - } - - @Resource - private HostMachineService hostMachineService; - - @Resource - private ContainerService containerService; - - @Resource - private ServirService servirService; - - @Resource - private AuditLogService auditLogService; - - @Resource - private EveryDayDataService everyDayDataService; - - @Resource - private SystemSettingUtils systemSettingUtils; - - /** - * 每天晚上收集今日数据 - */ - @Test - public void everyDayDataCollect() { - EveryDayData everyDayData = new EveryDayData(); - LambdaQueryWrapper auditLogWrapper = new LambdaQueryWrapper<>(); - Map hostStateInfo = hostMachineService.getHostStateInfo(); - Map vmStateInfo = hostMachineService.getVmStateInfo(); - Map containerStateInfo = containerService.getContainerStateInfo(); - //设置主机总数 - everyDayData.setHostCount(hostStateInfo.get("hostCount")); - //设置主机在线总数 - everyDayData.setHostOnlineCount(hostStateInfo.get("hostOnlineCount")); - //设置主机离线总数 - everyDayData.setHostOfflineCount(hostStateInfo.get("hostOfflineCount")); - //设置主机未知总数 - everyDayData.setHostUnknownCount(hostStateInfo.get("hostUnknownCount")); - //设置虚拟机总数 - everyDayData.setVmCount(vmStateInfo.get("vmCount")); - //设置虚拟机在线总数 - everyDayData.setVmOnlineCount(vmStateInfo.get("vmOnlineCount")); - //设置虚拟机离线总数 - everyDayData.setVmOfflineCount(vmStateInfo.get("vmOfflineCount")); - //设置虚拟机未知总数 - everyDayData.setVmUnknownCount(vmStateInfo.get("vmUnknownCount")); - //设置容器总数 - everyDayData.setContainerCount(containerStateInfo.get("containerCount")); - //设置容器在线总数 - everyDayData.setContainerOnlineCount(containerStateInfo.get("containerOnlineCount")); - //设置容器离线总数 - everyDayData.setContainerOfflineCount(containerStateInfo.get("containerOfflineCount")); - //设置容器未知总数 - everyDayData.setContainerUnknownCount(containerStateInfo.get("containerUnknownCount")); - //设置服务总数 - everyDayData.setServirCount(servirService.count()); - //设置操作总数 - auditLogWrapper.ge(AuditLog::getCreateTime, DateUtil.beginOfDay(DateUtil.date())); - auditLogWrapper.lt(AuditLog::getCreateTime, DateUtil.endOfDay(DateUtil.date())); - everyDayData.setAuditCount(auditLogService.count(auditLogWrapper)); - - System.out.println(everyDayData); - } - - @Test - public void checkInstanceStatus() { - long startTime = System.nanoTime(); // 记录开始时间 - - //检测容器在线状态 - List containers = containerService.list(); - containers.forEach(container -> { - try { - if (!StringUtils.hasText(container.getWebUi())) { - container.setContainerState(SystemConstant.CONTAINER_STATE_UNKNOWN); - return; - } - HttpRequest.get(container.getWebUi()).setConnectionTimeout(1000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_EXITED); - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(container.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (container.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendContainerOfflineNotification(container.getId()); - } - } - } - //存入redis - set.add(container.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS, set); - } - }); - containerService.saveOrUpdateBatch(containers); - - //检测虚拟机在线状态 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - List vms = hostMachineService.list(vmWrapper); - vms.forEach(vm -> { - try { - if (!StringUtils.hasText(vm.getManageIp())) { - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - return; - } - HttpRequest.get(vm.getManageIp()).setConnectionTimeout(1000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_VM_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(vm.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (vm.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendVmOfflineNotification(vm.getId()); - } - } - } - //存入redis - set.add(vm.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_VM_IDS, set); - } - }); - hostMachineService.saveOrUpdateBatch(vms); - - //检测物理机在线状态(检测物理机要用探测器的isTureUrl接口) - LambdaQueryWrapper detectorWrapper = new LambdaQueryWrapper<>(); - List hostDetectors = hostDetectorService.list(detectorWrapper); - List hostMachines = new ArrayList<>(); - hostDetectors.forEach(detector -> { - try { - HttpRequest.get(detector.getDetectorIpAddress() + UrlConstant.DETECTOR_IS_TRUE_URL).setConnectionTimeout(1000).execute(true); - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachines.add(hostMachine); - } - } catch (Exception exception) { - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - hostMachines.add(hostMachine); - } - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_HOST_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(hostMachine.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendHostOfflineNotification(hostMachine.getId()); - } - } - } - //存入redis - set.add(hostMachine.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_HOST_IDS, set); - } - }); - hostMachineService.saveOrUpdateBatch(hostMachines); - - long endTime = System.nanoTime(); // 记录结束时间 - long elapsedTime = endTime - startTime; - double seconds = (double) elapsedTime / 1_000_000_000.0; // 将纳秒转换为秒 - System.out.println("代码执行时间:" + seconds + " 秒"); - } - - @Test - public void checkContainerStatusMultiThread() { - long startTime = System.nanoTime(); // 记录开始时间 - - List containers = containerService.list(); - int thread = CpuUtil.getLogicProcessorCount(); - int containerCount = containerService.count(); - - int corePoolSize = Math.min(thread + 1, containerCount); - int maxPoolSize = Math.max(thread + 1, containerCount); - - // 创建一个包含10个线程的线程池 - ExecutorService executor = new ThreadPoolExecutor( - corePoolSize, - maxPoolSize, - 1, - TimeUnit.SECONDS, - new LinkedBlockingQueue<>(), - new ThreadPoolExecutor.AbortPolicy()); - - // 创建一个 Future 列表,用于存储每个容器检查的结果 - List> futures = new ArrayList<>(); - - for (Container container : containers) { - futures.add(executor.submit(() -> { - try { - if (!StringUtils.hasText(container.getWebUi())) { - container.setContainerState(SystemConstant.CONTAINER_STATE_UNKNOWN); - return container; - } - HttpRequest.get(container.getWebUi()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_EXITED); - // 判断 Redis 里面有没有,如果有就不需要提醒,如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (!CollectionUtils.isEmpty(set)) { - // 如果 Redis 里面有,说明已经发送过了未 check 的通知,所以不需要发送,直接返回 - if (set.contains(container.getId().toString())) { - return container; - } else { - // 根据实例对应的提醒方式进行提醒 - if (container.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return container; - } else { - notificationService.sendContainerOfflineNotification(container.getId()); - } - } - } - // 存入 Redis - set.add(container.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS, set); - } - return container; - })); - } - - // 等待所有线程执行完成,并收集更新后的容器列表 - List updatedContainers = new ArrayList<>(); - for (Future future : futures) { - try { - Container container = future.get(); - updatedContainers.add(container); - } catch (InterruptedException | ExecutionException e) { - log.error("检查容器状态时出错:{}", e.getMessage()); - } - } - - // 将更新后的容器列表保存到数据库中 - containerService.saveOrUpdateBatch(updatedContainers); - - // 关闭线程池 - executor.shutdown(); - - long endTime = System.nanoTime(); // 记录结束时间 - long elapsedTime = endTime - startTime; - double seconds = (double) elapsedTime / 1_000_000_000.0; // 将纳秒转换为秒 - System.out.println("代码执行时间:" + seconds + " 秒"); - } - - - @Test - public void checkVmStatus() { - long startTime = System.nanoTime(); // 记录开始时间 - - //检测虚拟机在线状态 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - List vms = hostMachineService.list(vmWrapper); - vms.forEach(vm -> { - try { - if (!StringUtils.hasText(vm.getManageIp())) { - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - return; - } - HttpRequest.get(vm.getManageIp()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_VM_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(vm.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (vm.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendVmOfflineNotification(vm.getId()); - } - } - } - //存入redis - set.add(vm.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_VM_IDS, set); - } - }); - hostMachineService.saveOrUpdateBatch(vms); - - long endTime = System.nanoTime(); // 记录结束时间 - long elapsedTime = endTime - startTime; - double seconds = (double) elapsedTime / 1_000_000_000.0; // 将纳秒转换为秒 - System.out.println("代码执行时间:" + seconds + " 秒"); - } - - - @Test - public void checkVmStatusMultiThread() throws InterruptedException { - long startTime = System.nanoTime(); // 记录开始时间 - - List containers = containerService.list(); - int thread = CpuUtil.getLogicProcessorCount(); - int containerCount = containerService.count(); - int corePoolSize = Math.min(thread + 1, containerCount); - int maxPoolSize = Math.max(thread + 1, containerCount); - - ExecutorService executor = new ThreadPoolExecutor( - corePoolSize, - maxPoolSize, - 1, - TimeUnit.SECONDS, - new LinkedBlockingQueue<>(), - new ThreadPoolExecutor.AbortPolicy()); - - // 创建一个 Future 列表,用于存储每个容器检查的结果 - List> futures = new ArrayList<>(); - - for (Container container : containers) { - futures.add(executor.submit(() -> { - try { - if (!StringUtils.hasText(container.getWebUi()) && !StringUtils.hasText(container.getServerAddress())) { - container.setContainerState(SystemConstant.CONTAINER_STATE_UNKNOWN); - return container; - } - //通过Socket(IP+端口)判断是否在线 - if (StringUtils.hasText(container.getServerAddress())) { - if (UrlUtil.isServiceOnline(UrlUtil.getHostname(container.getServerAddress()), UrlUtil.getPort(container.getServerAddress()))) { - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - return container; - } - } - //通过HTTP请求判断是否在线 - HttpRequest.get(container.getWebUi()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_EXITED); - // 判断 Redis 里面有没有,如果有就不需要提醒,如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (!CollectionUtils.isEmpty(set)) { - // 如果 Redis 里面有,说明已经发送过了未 check 的通知,所以不需要发送,直接返回 - if (set.contains(container.getId().toString())) { - return container; - } else { - // 根据实例对应的提醒方式进行提醒 - if (container.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return container; - } else { - notificationService.sendContainerOfflineNotification(container.getId()); - } - } - } - // 存入 Redis - set.add(container.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS, set); - } - return container; - })); - } - - // 等待所有线程执行完成,并收集更新后的容器列表 - List updatedContainers = new ArrayList<>(); - for (Future future : futures) { - try { - Container container = future.get(); - updatedContainers.add(container); - } catch (InterruptedException | ExecutionException e) { - log.error("检查容器状态时出错:{}", e.getMessage()); - } - } - - // 将更新后的容器列表保存到数据库中 - containerService.saveOrUpdateBatch(updatedContainers); - // 关闭线程池 - executor.shutdown(); - - //检测虚拟机在线状态 - LambdaQueryWrapper vmWrapper = new LambdaQueryWrapper<>(); - vmWrapper.ne(HostMachine::getHostMachineId, SystemConstant.HOST_MACHINE_ID_HOST); - List vms = hostMachineService.list(vmWrapper); - vms.forEach(vm -> { - try { - if (!StringUtils.hasText(vm.getServerAddress()) && !StringUtils.hasText(vm.getServerAddress())) { - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_UNKNOWN); - return; - } - //通过Ping的方式判断是否在线 - if (StringUtils.hasText(vm.getServerAddress())) { - if (UrlUtil.isHostOnline(vm.getServerAddress())) { - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - return; - } - } - //通过HTTP请求的方式判断是否在线 - HttpRequest.get(vm.getManageIp()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", vm.getName()); - vm.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_VM_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(vm.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (vm.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendVmOfflineNotification(vm.getId()); - } - } - } - //存入redis - set.add(vm.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_VM_IDS, set); - } - }); - hostMachineService.saveOrUpdateBatch(vms); - - //检测物理机在线状态(检测物理机要用探测器的isTureUrl接口) - LambdaQueryWrapper detectorWrapper = new LambdaQueryWrapper<>(); - List hostDetectors = hostDetectorService.list(detectorWrapper); - List hostMachines = new ArrayList<>(); - hostDetectors.forEach(detector -> { - try { - HttpRequest.get(detector.getDetectorIpAddress() + UrlConstant.DETECTOR_IS_TRUE_URL).setConnectionTimeout(5000).execute(true); - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_ONLINE); - hostMachines.add(hostMachine); - } - } catch (Exception exception) { - HostMachine hostMachine = hostMachineService.getById(detector.getHostMachineId()); - if (Objects.nonNull(hostMachine)) { - hostMachine.setHostMachineState(SystemConstant.HOST_MACHINE_STATE_OFFLINE); - hostMachines.add(hostMachine); - } - //判断Redis里面有没有 如果有就不需要提醒 如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_HOST_IDS); - if (!CollectionUtils.isEmpty(set)) { - //如果redis里面有 说明已经发送过了未check的通知 所以不需要发送 直接返回 - if (set.contains(hostMachine.getId().toString())) { - return; - } else { - //根据实例对应的提醒方式进行提醒 - if (hostMachine.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } else { - notificationService.sendHostOfflineNotification(hostMachine.getId()); - } - } - } - //存入redis - set.add(hostMachine.getId().toString()); - redisCache.setCacheSet(RedisConstant.NOTIFY_HOST_IDS, set); - } - }); - hostMachineService.saveOrUpdateBatch(hostMachines); - - long endTime = System.nanoTime(); // 记录结束时间 - long elapsedTime = endTime - startTime; - double seconds = (double) elapsedTime / 1_000_000_000.0; // 将纳秒转换为秒 - System.out.println("代码执行时间:" + seconds + " 秒"); - } - - @Test - public void pingTest() { - String ipAddress = "192.168.1.90"; // 要检查的IP地址 - try { - InetAddress inetAddress = InetAddress.getByName(ipAddress); - boolean isReachable = inetAddress.isReachable(5000); // 超时时间为5秒 - if (isReachable) { - System.out.println("虚拟机在线"); - } else { - System.out.println("虚拟机不在线"); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Test - public void serviceTest() { - try { - String serverName = "wiz.elizaveta.top"; - int port = 700; - Socket socket = new Socket(serverName, port); - System.out.println("MySQL服务已经开启"); - socket.close(); - } catch (Exception e) { - System.out.println("MySQL服务没有开启或者远程服务器无法访问"); - } - } - - @Test - public void hostnameTest() { - String hostname = UrlUtil.getHostname("192.168.1.90:8080"); - System.out.println(hostname); - } - - @Test - public void portTest() { - String address = "192.168.1.103:3306"; - String regex = ":(\\d+)$"; // 匹配冒号后面的数字 - Pattern pattern = Pattern.compile(regex); - Matcher matcher = pattern.matcher(address); - if (matcher.find()) { - System.out.println(matcher.group(1)); - } else { - System.out.println("解析失败"); - } - } - - - @Test - public void containerCheck() throws InterruptedException { - long startTime = System.nanoTime(); // 记录开始时间 - - List containers = containerService.list(); - - // Create a thread pool with a fixed number of threads - ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - - // Submit each container to the thread pool for processing - for (Container container : containers) { - executor.submit(() -> { - try { - if (!StringUtils.hasText(container.getWebUi()) && !StringUtils.hasText(container.getServerAddress())) { - container.setContainerState(SystemConstant.CONTAINER_STATE_UNKNOWN); - containerService.saveOrUpdate(container); - return; - } - //通过Socket(IP+端口)判断是否在线 - if (StringUtils.hasText(container.getServerAddress())) { - if (UrlUtil.isServiceOnline(UrlUtil.getHostname(container.getServerAddress()), UrlUtil.getPort(container.getServerAddress()))) { - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - containerService.saveOrUpdate(container); - return; - } - } - //通过HTTP请求判断是否在线 - HttpRequest.get(container.getWebUi()).setConnectionTimeout(5000).execute(true); - log.info("[实例状态检测]:与{}建立连接成功", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_RUNNING); - containerService.saveOrUpdate(container); - } catch (Exception exception) { - log.info("[实例状态检测]:与{}建立连接失败,状态转为离线", container.getName()); - container.setContainerState(SystemConstant.CONTAINER_STATE_EXITED); - containerService.saveOrUpdate(container); - // 判断 Redis 里面有没有,如果有就不需要提醒,如果没有就提醒 - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (CollectionUtils.isEmpty(set)) { - set = new HashSet<>(); - } - // 如果 Redis 里面有,说明已经发送过了未 check 的通知,所以不需要发送,直接返回 - if (set.contains(container.getId().toString())) { - return; - } else { - // 根据实例对应的提醒方式进行提醒 - if (container.getNotify().equals(SystemConstant.NOTIFY_NO)) { - return; - } - if (container.getNotify().equals(SystemConstant.NOTIFY_BROWSER)) { - notificationService.sendContainerOfflineNotification(container.getId()); - set.add(container.getId().toString()); - } - if (container.getNotify().equals(SystemConstant.NOTIFY_EMAIL)) { - notificationService.sendContainerOfflineEmail(container.getId()); - } - if (container.getNotify().equals(SystemConstant.NOTIFY_BROWSER_EMAIL)) { - notificationService.sendContainerOfflineNotificationEmail(container.getId()); - set.add(container.getId().toString()); - } - } - redisCache.setCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS, set); - } - }); - } - - // Shutdown the thread pool and wait for all tasks to complete - executor.shutdown(); - executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - - long endTime = System.nanoTime(); // 记录结束时间 - long elapsedTime = endTime - startTime; - double seconds = (double) elapsedTime / 1_000_000_000.0; // 将纳秒转换为秒 - System.out.println("代码执行时间:" + seconds + " 秒"); - } - - - @Test - public void testRedis() { - Set set = redisCache.getCacheSet(RedisConstant.NOTIFY_CONTAINER_IDS); - if (CollectionUtils.isEmpty(set)) { - set = new HashSet<>(); - } - System.out.println(set); - set.add("1"); - redisCache.setCacheSet(RedisConstant.NOTIFY_HOST_IDS, set); - } - - - @Test - public void passwordEncode() { - String encodePassword = passwordEncoder.encode("changeme"); - System.out.println(encodePassword); - } - - @LocalServerPort - int port; - - @Resource - private RestTemplate restTemplate; - - @Test - public void getBackendAddress() throws UnknownHostException { - // 获取本地IP地址 - InetAddress inetAddress = InetAddress.getLocalHost(); - String ipAddress = inetAddress.getHostAddress(); - - // 获取当前后端服务器的端口号 - String portNumber = Integer.toString(port); - - // 返回后端服务器的地址,格式为:http://ipAddress:portNumber - System.out.println("http://" + ipAddress + ":" + portNumber); - } - - @Test - public void sendEmailTest() { - // 获取本机IP地址和端口号 - String ipAddress; - int port; - try (ServerSocket serverSocket = new ServerSocket(0)) { - port = serverSocket.getLocalPort(); - ipAddress = InetAddress.getLocalHost().getHostAddress(); - } catch (Exception e) { - e.printStackTrace(); - return; - } - - // 创建邮件内容 - String yourString = "这是您的字符串"; - String yourUrl = "http://" + ipAddress + ":" + port + "/api"; - String emailBody = "

您好,以下是您的字符串:

" + - yourString + "

发送HTTP请求

"; - String time = LocalDateTime.now().toString(); - String content = String.format("发现容器[ %s ]掉线---- %s", "测试测试", time); - // 发送邮件... - MailUtil.send(systemSettingUtils.getMailAccount(), CollUtil.newArrayList(systemSettingUtils.getMailTarget()), "Noodles掉线提醒", emailBody, true); - - - } -}