[init]
0 parents
Showing
63 changed files
with
2343 additions
and
0 deletions
.gitignore
0 → 100644
| 1 | # maven | ||
| 2 | target/ | ||
| 3 | .mvn/ | ||
| 4 | mvnw | ||
| 5 | mvnw.cmd | ||
| 6 | .flattened-pom.xml | ||
| 7 | |||
| 8 | # gradle | ||
| 9 | .gradle/ | ||
| 10 | bin/ | ||
| 11 | build/ | ||
| 12 | *.class | ||
| 13 | classes/ | ||
| 14 | out/ | ||
| 15 | |||
| 16 | # eclipse | ||
| 17 | .settings/ | ||
| 18 | .project | ||
| 19 | .classpath | ||
| 20 | |||
| 21 | # idea | ||
| 22 | .idea/ | ||
| 23 | *.ipr | ||
| 24 | *.iml | ||
| 25 | *.iws | ||
| 26 | *.http | ||
| 27 | |||
| 28 | # temp | ||
| 29 | *.log | ||
| 30 | *.cache | ||
| 31 | *.diff | ||
| 32 | *.patch | ||
| 33 | *.tmp | ||
| 34 | |||
| 35 | # system | ||
| 36 | .DS_Store | ||
| 37 | Thumbs.db | ||
| 38 | |||
| 39 | # other | ||
| 40 | *.jar | ||
| 41 | *.war | ||
| 42 | *.zip | ||
| 43 | *.tar | ||
| 44 | *.tar.gz | ||
| 45 | |||
| 46 | # apollo | ||
| 47 | .apollo/ | ||
| 48 | log/ | ||
| 49 | logs/ | ||
| 50 | |||
| 51 | # auto | ||
| 52 | gen/ |
pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <modelVersion>4.0.0</modelVersion> | ||
| 6 | |||
| 7 | <groupId>com.pl.backend</groupId> | ||
| 8 | <artifactId>ql-backend</artifactId> | ||
| 9 | <packaging>pom</packaging> | ||
| 10 | <version>1.0.0-SNAPSHOT</version> | ||
| 11 | <modules> | ||
| 12 | <module>ql-backend-parent</module> | ||
| 13 | <module>ql-backend-taskmanager</module> | ||
| 14 | <module>ql-backend-service</module> | ||
| 15 | <module>ql-backend-ploycenter</module> | ||
| 16 | <module>ql-backend-core</module> | ||
| 17 | <module>ql-backend-taskmanager-common</module> | ||
| 18 | </modules> | ||
| 19 | |||
| 20 | <properties> | ||
| 21 | <maven.compiler.source>8</maven.compiler.source> | ||
| 22 | <maven.compiler.target>8</maven.compiler.target> | ||
| 23 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 24 | </properties> | ||
| 25 | |||
| 26 | <build> | ||
| 27 | <plugins> | ||
| 28 | <plugin> | ||
| 29 | <groupId>org.apache.maven.plugins</groupId> | ||
| 30 | <artifactId>maven-compiler-plugin</artifactId> | ||
| 31 | <version>3.8.1</version> | ||
| 32 | <configuration> | ||
| 33 | <parameters>true</parameters> | ||
| 34 | <source>${maven.compiler.source}</source> | ||
| 35 | <target>${maven.compiler.target}</target> | ||
| 36 | </configuration> | ||
| 37 | </plugin> | ||
| 38 | </plugins> | ||
| 39 | </build> | ||
| 40 | </project> |
ql-backend-core/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <parent> | ||
| 6 | <artifactId>ql-backend-parent</artifactId> | ||
| 7 | <groupId>com.pl.backend</groupId> | ||
| 8 | <version>1.0.0-SNAPSHOT</version> | ||
| 9 | <relativePath>../ql-backend-parent/pom.xml</relativePath> <!-- lookup parent from repository --> | ||
| 10 | </parent> | ||
| 11 | <modelVersion>4.0.0</modelVersion> | ||
| 12 | |||
| 13 | <artifactId>ql-backend-core</artifactId> | ||
| 14 | <version>1.0.0-SNAPSHOT</version> | ||
| 15 | |||
| 16 | <properties> | ||
| 17 | <maven.compiler.source>8</maven.compiler.source> | ||
| 18 | <maven.compiler.target>8</maven.compiler.target> | ||
| 19 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 20 | </properties> | ||
| 21 | |||
| 22 | <dependencies> | ||
| 23 | <dependency> | ||
| 24 | <groupId>org.springframework.boot</groupId> | ||
| 25 | <artifactId>spring-boot-starter</artifactId> | ||
| 26 | </dependency> | ||
| 27 | |||
| 28 | <dependency> | ||
| 29 | <groupId>org.springframework.boot</groupId> | ||
| 30 | <artifactId>spring-boot-starter-web</artifactId> | ||
| 31 | </dependency> | ||
| 32 | |||
| 33 | <dependency> | ||
| 34 | <groupId>org.projectlombok</groupId> | ||
| 35 | <artifactId>lombok</artifactId> | ||
| 36 | </dependency> | ||
| 37 | |||
| 38 | <dependency> | ||
| 39 | <groupId>org.mapstruct</groupId> | ||
| 40 | <artifactId>mapstruct</artifactId> | ||
| 41 | </dependency> | ||
| 42 | |||
| 43 | <dependency> | ||
| 44 | <groupId>org.mapstruct</groupId> | ||
| 45 | <artifactId>mapstruct-processor</artifactId> | ||
| 46 | </dependency> | ||
| 47 | |||
| 48 | <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> | ||
| 49 | <dependency> | ||
| 50 | <groupId>com.fasterxml.jackson.core</groupId> | ||
| 51 | <artifactId>jackson-databind</artifactId> | ||
| 52 | </dependency> | ||
| 53 | |||
| 54 | <dependency> | ||
| 55 | <groupId>com.baomidou</groupId> | ||
| 56 | <artifactId>mybatis-plus-boot-starter</artifactId> | ||
| 57 | </dependency> | ||
| 58 | |||
| 59 | <dependency> | ||
| 60 | <groupId>com.baomidou</groupId> | ||
| 61 | <artifactId>mybatis-plus-generator</artifactId> | ||
| 62 | </dependency> | ||
| 63 | |||
| 64 | <dependency> | ||
| 65 | <groupId>com.baomidou</groupId> | ||
| 66 | <artifactId>mybatis-plus-extension</artifactId> | ||
| 67 | </dependency> | ||
| 68 | |||
| 69 | <dependency> | ||
| 70 | <groupId>com.alibaba</groupId> | ||
| 71 | <artifactId>fastjson</artifactId> | ||
| 72 | </dependency> | ||
| 73 | |||
| 74 | <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> | ||
| 75 | <dependency> | ||
| 76 | <groupId>cn.hutool</groupId> | ||
| 77 | <artifactId>hutool-all</artifactId> | ||
| 78 | </dependency> | ||
| 79 | </dependencies> | ||
| 80 | </project> |
ql-backend-core/src/main/java/com/ql/backend/core/infrastructure/config/MybatisPlusConfig.java
0 → 100644
| 1 | package com.ql.backend.core.infrastructure.config; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.DbType; | ||
| 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
| 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
| 6 | import org.springframework.context.annotation.Bean; | ||
| 7 | import org.springframework.context.annotation.Configuration; | ||
| 8 | import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/7 10:31 | ||
| 13 | */ | ||
| 14 | @EnableTransactionManagement | ||
| 15 | @Configuration | ||
| 16 | public class MybatisPlusConfig { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除) | ||
| 20 | */ | ||
| 21 | @Bean | ||
| 22 | public MybatisPlusInterceptor mybatisPlusInterceptor() { | ||
| 23 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||
| 24 | //向Mybatis过滤器链中添加分页拦截器 | ||
| 25 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||
| 26 | //还可以添加i他的拦截器 | ||
| 27 | return interceptor; | ||
| 28 | } | ||
| 29 | |||
| 30 | // @Bean | ||
| 31 | // public ConfigurationCustomizer configurationCustomizer() { | ||
| 32 | // return configuration -> configuration.setUseDeprecatedExecutor(false); | ||
| 33 | // } | ||
| 34 | } |
| 1 | package com.ql.backend.core.interfaces.vo; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.Data; | ||
| 6 | |||
| 7 | import java.io.Serializable; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/8/31 18:04 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 15 | public class ApiResponse<VO> implements Serializable { | ||
| 16 | |||
| 17 | private int code; | ||
| 18 | |||
| 19 | private String message; | ||
| 20 | |||
| 21 | private VO data; | ||
| 22 | |||
| 23 | public ApiResponse() { | ||
| 24 | } | ||
| 25 | |||
| 26 | private ApiResponse(int code, String message, VO data) { | ||
| 27 | this.code = code; | ||
| 28 | this.message = message; | ||
| 29 | this.data = data; | ||
| 30 | } | ||
| 31 | |||
| 32 | public boolean isOk() { | ||
| 33 | return code == 0; | ||
| 34 | } | ||
| 35 | |||
| 36 | public static <VO> ApiResponse<VO> of(int code, String message, VO data) { | ||
| 37 | return new ApiResponse<>(code, message, data); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static <VO> ApiResponse<VO> ok(String message, VO data) { | ||
| 41 | return new ApiResponse<>(0, message, data); | ||
| 42 | } | ||
| 43 | |||
| 44 | public static <VO> ApiResponse<VO> ok(VO data) { | ||
| 45 | return ok("OK", data); | ||
| 46 | } | ||
| 47 | |||
| 48 | public static <VO> ApiResponse<VO> ok() { | ||
| 49 | return ok("OK", null); | ||
| 50 | } | ||
| 51 | |||
| 52 | public static <VO> ApiResponse<VO> fail(String message, VO data) { | ||
| 53 | return new ApiResponse<>(-1, message, data); | ||
| 54 | } | ||
| 55 | |||
| 56 | public static <VO> ApiResponse<VO> fail(VO data) { | ||
| 57 | return ok("NETWORK ERROR", data); | ||
| 58 | } | ||
| 59 | |||
| 60 | public static <VO> ApiResponse<VO> fail() { | ||
| 61 | return ok("NETWORK ERROR", null); | ||
| 62 | } | ||
| 63 | } |
| 1 | package com.ql.backend.core.interfaces.vo; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Builder; | ||
| 5 | import lombok.Data; | ||
| 6 | import lombok.NoArgsConstructor; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/4 20:45 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @Builder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | public class PageVO<T> { | ||
| 19 | |||
| 20 | private int page; | ||
| 21 | |||
| 22 | private int size; | ||
| 23 | |||
| 24 | private long total; | ||
| 25 | |||
| 26 | private List<T> list; | ||
| 27 | } |
ql-backend-parent/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <parent> | ||
| 6 | <groupId>org.springframework.boot</groupId> | ||
| 7 | <artifactId>spring-boot-starter-parent</artifactId> | ||
| 8 | <version>2.7.3</version> | ||
| 9 | <relativePath/> <!-- lookup parent from repository --> | ||
| 10 | </parent> | ||
| 11 | <modelVersion>4.0.0</modelVersion> | ||
| 12 | |||
| 13 | <groupId>com.pl.backend</groupId> | ||
| 14 | <artifactId>ql-backend-parent</artifactId> | ||
| 15 | <version>1.0.0-SNAPSHOT</version> | ||
| 16 | <packaging>pom</packaging> | ||
| 17 | |||
| 18 | <properties> | ||
| 19 | <maven.compiler.source>8</maven.compiler.source> | ||
| 20 | <maven.compiler.target>8</maven.compiler.target> | ||
| 21 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 22 | </properties> | ||
| 23 | |||
| 24 | <dependencyManagement> | ||
| 25 | <dependencies> | ||
| 26 | <dependency> | ||
| 27 | <groupId>org.springframework.boot</groupId> | ||
| 28 | <artifactId>spring-boot-starter</artifactId> | ||
| 29 | <version>2.7.3</version> | ||
| 30 | </dependency> | ||
| 31 | |||
| 32 | <dependency> | ||
| 33 | <groupId>org.springframework.boot</groupId> | ||
| 34 | <artifactId>spring-boot-starter-web</artifactId> | ||
| 35 | <version>2.7.3</version> | ||
| 36 | </dependency> | ||
| 37 | |||
| 38 | <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter --> | ||
| 39 | <dependency> | ||
| 40 | <groupId>com.baomidou</groupId> | ||
| 41 | <artifactId>mybatis-plus-boot-starter</artifactId> | ||
| 42 | <version>3.5.2</version> | ||
| 43 | </dependency> | ||
| 44 | |||
| 45 | <dependency> | ||
| 46 | <groupId>com.baomidou</groupId> | ||
| 47 | <artifactId>mybatis-plus-generator</artifactId> | ||
| 48 | <version>3.5.2</version> | ||
| 49 | </dependency> | ||
| 50 | |||
| 51 | <dependency> | ||
| 52 | <groupId>com.baomidou</groupId> | ||
| 53 | <artifactId>mybatis-plus-extension</artifactId> | ||
| 54 | <version>3.5.2</version> | ||
| 55 | </dependency> | ||
| 56 | |||
| 57 | <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
| 58 | <dependency> | ||
| 59 | <groupId>org.projectlombok</groupId> | ||
| 60 | <artifactId>lombok</artifactId> | ||
| 61 | <version>1.18.24</version> | ||
| 62 | <scope>provided</scope> | ||
| 63 | </dependency> | ||
| 64 | |||
| 65 | <dependency> | ||
| 66 | <groupId>org.mapstruct</groupId> | ||
| 67 | <artifactId>mapstruct</artifactId> | ||
| 68 | <version>1.4.2.Final</version> | ||
| 69 | </dependency> | ||
| 70 | |||
| 71 | <dependency> | ||
| 72 | <groupId>org.mapstruct</groupId> | ||
| 73 | <artifactId>mapstruct-processor</artifactId> | ||
| 74 | <version>1.4.2.Final</version> | ||
| 75 | </dependency> | ||
| 76 | |||
| 77 | <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> | ||
| 78 | <dependency> | ||
| 79 | <groupId>com.fasterxml.jackson.core</groupId> | ||
| 80 | <artifactId>jackson-databind</artifactId> | ||
| 81 | <version>2.13.3</version> | ||
| 82 | </dependency> | ||
| 83 | |||
| 84 | <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> | ||
| 85 | <dependency> | ||
| 86 | <groupId>com.alibaba</groupId> | ||
| 87 | <artifactId>fastjson</artifactId> | ||
| 88 | <version>2.0.12</version> | ||
| 89 | </dependency> | ||
| 90 | |||
| 91 | <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> | ||
| 92 | <dependency> | ||
| 93 | <groupId>cn.hutool</groupId> | ||
| 94 | <artifactId>hutool-all</artifactId> | ||
| 95 | <version>5.8.5</version> | ||
| 96 | </dependency> | ||
| 97 | |||
| 98 | </dependencies> | ||
| 99 | </dependencyManagement> | ||
| 100 | </project> |
ql-backend-ploycenter/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <parent> | ||
| 6 | <artifactId>ql-backend-parent</artifactId> | ||
| 7 | <groupId>com.pl.backend</groupId> | ||
| 8 | <version>1.0.0-SNAPSHOT</version> | ||
| 9 | <relativePath>../ql-backend-parent/pom.xml</relativePath> <!-- lookup parent from repository --> | ||
| 10 | </parent> | ||
| 11 | <modelVersion>4.0.0</modelVersion> | ||
| 12 | |||
| 13 | <artifactId>ql-backend-ploycenter</artifactId> | ||
| 14 | <version>1.0.0-SNAPSHOT</version> | ||
| 15 | |||
| 16 | <properties> | ||
| 17 | <maven.compiler.source>8</maven.compiler.source> | ||
| 18 | <maven.compiler.target>8</maven.compiler.target> | ||
| 19 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 20 | <easy.rules.version>4.1.0</easy.rules.version> | ||
| 21 | <aviator.version>5.3.1</aviator.version> | ||
| 22 | </properties> | ||
| 23 | |||
| 24 | <dependencies> | ||
| 25 | <dependency> | ||
| 26 | <groupId>com.pl.backend</groupId> | ||
| 27 | <artifactId>ql-backend-core</artifactId> | ||
| 28 | <version>1.0.0-SNAPSHOT</version> | ||
| 29 | </dependency> | ||
| 30 | |||
| 31 | <dependency> | ||
| 32 | <groupId>com.pl.backend</groupId> | ||
| 33 | <artifactId>ql-backend-taskmanager-common</artifactId> | ||
| 34 | <version>1.0.0-SNAPSHOT</version> | ||
| 35 | </dependency> | ||
| 36 | |||
| 37 | <!-- easy-rules 执行引擎 --> | ||
| 38 | <dependency> | ||
| 39 | <groupId>org.jeasy</groupId> | ||
| 40 | <artifactId>easy-rules-core</artifactId> | ||
| 41 | <version>${easy.rules.version}</version> | ||
| 42 | </dependency> | ||
| 43 | <dependency> | ||
| 44 | <groupId>org.jeasy</groupId> | ||
| 45 | <artifactId>easy-rules-support</artifactId> | ||
| 46 | <version>${easy.rules.version}</version> | ||
| 47 | </dependency> | ||
| 48 | |||
| 49 | <!-- 表达式引擎 Aviator --> | ||
| 50 | <dependency> | ||
| 51 | <groupId>com.googlecode.aviator</groupId> | ||
| 52 | <artifactId>aviator</artifactId> | ||
| 53 | <version>${aviator.version}</version> | ||
| 54 | </dependency> | ||
| 55 | |||
| 56 | <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
| 57 | <dependency> | ||
| 58 | <groupId>org.projectlombok</groupId> | ||
| 59 | <artifactId>lombok</artifactId> | ||
| 60 | <scope>provided</scope> | ||
| 61 | </dependency> | ||
| 62 | |||
| 63 | <dependency> | ||
| 64 | <groupId>org.mapstruct</groupId> | ||
| 65 | <artifactId>mapstruct</artifactId> | ||
| 66 | </dependency> | ||
| 67 | |||
| 68 | <dependency> | ||
| 69 | <groupId>org.mapstruct</groupId> | ||
| 70 | <artifactId>mapstruct-processor</artifactId> | ||
| 71 | <scope>provided</scope> | ||
| 72 | </dependency> | ||
| 73 | </dependencies> | ||
| 74 | |||
| 75 | <build> | ||
| 76 | <plugins> | ||
| 77 | <plugin> | ||
| 78 | <groupId>org.apache.maven.plugins</groupId> | ||
| 79 | <artifactId>maven-compiler-plugin</artifactId> | ||
| 80 | <version>3.8.1</version> | ||
| 81 | <configuration> | ||
| 82 | <source>1.8</source> | ||
| 83 | <target>1.8</target> | ||
| 84 | </configuration> | ||
| 85 | </plugin> | ||
| 86 | </plugins> | ||
| 87 | </build> | ||
| 88 | </project> |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/application/DeviceService.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.application; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.PageVO; | ||
| 4 | import com.ql.backend.ploycenter.domain.condition.DeviceCondition; | ||
| 5 | import com.ql.backend.ploycenter.interfaces.request.DeviceReportRequest; | ||
| 6 | import com.ql.backend.ploycenter.interfaces.vo.DeviceVO; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/4 11:34 | ||
| 11 | */ | ||
| 12 | public interface DeviceService { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * 上报设备状态 | ||
| 16 | */ | ||
| 17 | void reportDeviceStatus(DeviceReportRequest request); | ||
| 18 | |||
| 19 | PageVO<DeviceVO> findDevice(DeviceCondition condition); | ||
| 20 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/application/PloyService.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.application; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | ||
| 5 | import com.ql.backend.taskmanager.common.dto.TaskDTO; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/9/2 17:09 | ||
| 10 | */ | ||
| 11 | public interface PloyService { | ||
| 12 | |||
| 13 | String createPloy(PloyCreateRequest request); | ||
| 14 | |||
| 15 | ApiResponse<String> fire(TaskDTO taskDTO); | ||
| 16 | } |
| 1 | package com.ql.backend.ploycenter.application.impl; | ||
| 2 | |||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 5 | import com.ql.backend.core.interfaces.vo.PageVO; | ||
| 6 | import com.ql.backend.ploycenter.application.DeviceService; | ||
| 7 | import com.ql.backend.ploycenter.domain.condition.DeviceCondition; | ||
| 8 | import com.ql.backend.ploycenter.domain.po.DevicePO; | ||
| 9 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.DeviceConverter; | ||
| 10 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.DeviceDao; | ||
| 11 | import com.ql.backend.ploycenter.interfaces.request.DeviceReportRequest; | ||
| 12 | import com.ql.backend.ploycenter.interfaces.vo.DeviceVO; | ||
| 13 | import lombok.extern.slf4j.Slf4j; | ||
| 14 | import org.springframework.stereotype.Service; | ||
| 15 | |||
| 16 | import javax.annotation.Resource; | ||
| 17 | import java.util.Date; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @author lirenhao | ||
| 21 | * date: 2022/9/4 11:35 | ||
| 22 | */ | ||
| 23 | @Slf4j | ||
| 24 | @Service | ||
| 25 | public class DeviceServiceImpl implements DeviceService { | ||
| 26 | |||
| 27 | @Resource | ||
| 28 | private DeviceDao deviceDao; | ||
| 29 | |||
| 30 | @Override | ||
| 31 | public void reportDeviceStatus(DeviceReportRequest request) { | ||
| 32 | /* todo 加锁 */ | ||
| 33 | |||
| 34 | log.info("[ReportDeviceStatus] request -> [{}]", JSON.toJSONString(request)); | ||
| 35 | DevicePO newOrUpdateDevice = DeviceConverter.INSTANCE.convertRequest2Po(request); | ||
| 36 | |||
| 37 | /* 查询是否存在设备 */ | ||
| 38 | DevicePO oldPo = deviceDao.getByDeviceId(request.getDeviceId()); | ||
| 39 | if (oldPo == null) { | ||
| 40 | /* 新增设备 */ | ||
| 41 | newOrUpdateDevice.setGmtCreated(new Date()); | ||
| 42 | newOrUpdateDevice.setGmtModified(new Date()); | ||
| 43 | newOrUpdateDevice.setIsDeleted(Boolean.FALSE); | ||
| 44 | deviceDao.save(newOrUpdateDevice); | ||
| 45 | } else if (oldPo.getGmtModified().getTime() < request.getTimestamp()) { | ||
| 46 | /* 更新设备状态 */ | ||
| 47 | newOrUpdateDevice.setDeviceId(oldPo.getDeviceId()); | ||
| 48 | newOrUpdateDevice.setGmtModified(new Date(request.getTimestamp())); | ||
| 49 | deviceDao.updateById(oldPo); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public PageVO<DeviceVO> findDevice(DeviceCondition condition) { | ||
| 55 | Page<DevicePO> page = deviceDao.findDevice(condition); | ||
| 56 | return PageVO.<DeviceVO>builder() | ||
| 57 | .page(condition.getPage()) | ||
| 58 | .size(condition.getSize()) | ||
| 59 | .total(page.getPages()) | ||
| 60 | .list(DeviceConverter.INSTANCE.convertPo2Vo(page.getRecords())) | ||
| 61 | .build(); | ||
| 62 | } | ||
| 63 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/application/impl/PloyServiceImpl.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.application.impl; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.application.PloyService; | ||
| 5 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; | ||
| 7 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; | ||
| 8 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | ||
| 9 | import com.ql.backend.taskmanager.common.dto.TaskDTO; | ||
| 10 | import lombok.extern.slf4j.Slf4j; | ||
| 11 | import org.springframework.stereotype.Service; | ||
| 12 | import org.springframework.util.ObjectUtils; | ||
| 13 | |||
| 14 | import javax.annotation.Resource; | ||
| 15 | import java.util.Date; | ||
| 16 | import java.util.UUID; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @author lirenhao | ||
| 20 | * date: 2022/9/3 16:16 | ||
| 21 | */ | ||
| 22 | @Slf4j | ||
| 23 | @Service | ||
| 24 | public class PloyServiceImpl implements PloyService { | ||
| 25 | |||
| 26 | @Resource | ||
| 27 | private PloyDao ployDao; | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public String createPloy(PloyCreateRequest request) { | ||
| 31 | PloyPO po = PloyConverter.INSTANCE.convertRequest2Po(request); | ||
| 32 | po.setPloyId(UUID.randomUUID().toString()); | ||
| 33 | po.setGmtCreated(new Date()); | ||
| 34 | po.setGmtModified(new Date()); | ||
| 35 | po.setIsDeleted(Boolean.FALSE); | ||
| 36 | ployDao.save(po); | ||
| 37 | return po.getPloyId(); | ||
| 38 | } | ||
| 39 | |||
| 40 | @Override | ||
| 41 | public ApiResponse<String> fire(TaskDTO taskDTO) { | ||
| 42 | /* todo 执行策略, 创建任务 */ | ||
| 43 | if (!ObjectUtils.isEmpty(taskDTO.getPloyId())) { | ||
| 44 | /* 查询策略 */ | ||
| 45 | |||
| 46 | /* 创建任务 */ | ||
| 47 | |||
| 48 | } | ||
| 49 | return ApiResponse.fail("未查询到策略", null); | ||
| 50 | } | ||
| 51 | } |
| 1 | package com.ql.backend.ploycenter.common.dto; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Builder; | ||
| 5 | import lombok.Data; | ||
| 6 | import lombok.NoArgsConstructor; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/5 17:47 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | @Builder | ||
| 14 | @NoArgsConstructor | ||
| 15 | @AllArgsConstructor | ||
| 16 | public class PloyDTO { | ||
| 17 | |||
| 18 | private String ployId; | ||
| 19 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/common/enums/DeviceStatus.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.common.enums; | ||
| 2 | |||
| 3 | import lombok.Getter; | ||
| 4 | |||
| 5 | import java.util.stream.Stream; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/9/4 10:52 | ||
| 10 | */ | ||
| 11 | public enum DeviceStatus { | ||
| 12 | |||
| 13 | CONNECTING(0, "connecting", "连线中"), | ||
| 14 | IDLE(1, "idle", "空闲"), | ||
| 15 | BUSY(2, "busy", "忙碌"), | ||
| 16 | OFFLINE(3, "offline", "下线"); | ||
| 17 | |||
| 18 | @Getter | ||
| 19 | private final int code; | ||
| 20 | |||
| 21 | @Getter | ||
| 22 | private final String type; | ||
| 23 | |||
| 24 | @Getter | ||
| 25 | private final String desc; | ||
| 26 | |||
| 27 | DeviceStatus(int code, String type, String desc) { | ||
| 28 | this.code = code; | ||
| 29 | this.type = type; | ||
| 30 | this.desc = desc; | ||
| 31 | } | ||
| 32 | |||
| 33 | public static DeviceStatus convert(String type) { | ||
| 34 | return Stream.of(values()) | ||
| 35 | .filter(status -> status.getType().equalsIgnoreCase(type)) | ||
| 36 | .findFirst() | ||
| 37 | .orElse(null); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static DeviceStatus convert(Integer code) { | ||
| 41 | return Stream.of(values()) | ||
| 42 | .filter(status -> status.getCode() == code) | ||
| 43 | .findFirst() | ||
| 44 | .orElse(null); | ||
| 45 | } | ||
| 46 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/domain/condition/DeviceCondition.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.domain.condition; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import com.ql.backend.ploycenter.common.enums.DeviceStatus; | ||
| 6 | import lombok.AllArgsConstructor; | ||
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.NoArgsConstructor; | ||
| 10 | |||
| 11 | import java.util.Set; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/5 11:18 | ||
| 16 | */ | ||
| 17 | @Data | ||
| 18 | @Builder | ||
| 19 | @NoArgsConstructor | ||
| 20 | @AllArgsConstructor | ||
| 21 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 22 | public class DeviceCondition { | ||
| 23 | |||
| 24 | private int page; | ||
| 25 | |||
| 26 | private int size; | ||
| 27 | |||
| 28 | private Set<DeviceStatus> deviceStatuses; | ||
| 29 | } |
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | import com.ql.backend.ploycenter.common.enums.DeviceStatus; | ||
| 8 | import lombok.AllArgsConstructor; | ||
| 9 | import lombok.Builder; | ||
| 10 | import lombok.Data; | ||
| 11 | import lombok.NoArgsConstructor; | ||
| 12 | |||
| 13 | import java.io.Serializable; | ||
| 14 | import java.util.Date; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * 设备信息 | ||
| 18 | * | ||
| 19 | * @author lirenhao | ||
| 20 | * date: 2022/9/4 10:47 | ||
| 21 | */ | ||
| 22 | @Data | ||
| 23 | @Builder | ||
| 24 | @NoArgsConstructor | ||
| 25 | @AllArgsConstructor | ||
| 26 | @TableName("t_device") | ||
| 27 | public class DevicePO implements Serializable { | ||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * 设备ID | ||
| 33 | */ | ||
| 34 | @TableId(value = "device_id", type = IdType.ASSIGN_ID) | ||
| 35 | private String deviceId; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * 设备名称 | ||
| 39 | */ | ||
| 40 | @TableField(value = "device_name") | ||
| 41 | private String deviceName; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * 设备系统版本 | ||
| 45 | */ | ||
| 46 | @TableField(value = "device_operate_system") | ||
| 47 | private String deviceOperateSystem; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * 设备IP | ||
| 51 | */ | ||
| 52 | @TableField(value = "device_ip") | ||
| 53 | private String deviceIp; | ||
| 54 | |||
| 55 | /** | ||
| 56 | * 设备Bot版本 | ||
| 57 | */ | ||
| 58 | @TableField(value = "device_bot_version") | ||
| 59 | private String deviceBotVersion; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * 上次登录时间 | ||
| 63 | */ | ||
| 64 | @TableField(value = "lasted_login_time") | ||
| 65 | private Date lastedLoginTime; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * 设备状态 | ||
| 69 | */ | ||
| 70 | @TableField(value = "device_status") | ||
| 71 | private DeviceStatus deviceStatus; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * 机器上运行的任务数量 | ||
| 75 | */ | ||
| 76 | @TableField(value = "task_num") | ||
| 77 | private Long taskNum; | ||
| 78 | |||
| 79 | @TableField(value = "is_deleted") | ||
| 80 | private Boolean isDeleted; | ||
| 81 | |||
| 82 | @TableField(value = "gmt_created") | ||
| 83 | private Date gmtCreated; | ||
| 84 | |||
| 85 | @TableField(value = "gmt_modified") | ||
| 86 | private Date gmtModified; | ||
| 87 | } |
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | import lombok.AllArgsConstructor; | ||
| 8 | import lombok.Builder; | ||
| 9 | import lombok.Data; | ||
| 10 | import lombok.NoArgsConstructor; | ||
| 11 | |||
| 12 | import java.io.Serializable; | ||
| 13 | import java.util.Date; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * 策略 | ||
| 17 | * | ||
| 18 | * @author lirenhao | ||
| 19 | * date: 2022/9/2 16:50 | ||
| 20 | */ | ||
| 21 | @Data | ||
| 22 | @Builder | ||
| 23 | @NoArgsConstructor | ||
| 24 | @AllArgsConstructor | ||
| 25 | @TableName("t_ploy") | ||
| 26 | public class PloyPO implements Serializable { | ||
| 27 | |||
| 28 | private static final long serialVersionUID = 1L; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * 策略ID | ||
| 32 | */ | ||
| 33 | @TableId(value = "poly_id", type = IdType.ASSIGN_ID) | ||
| 34 | private String ployId; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * 策略名称 | ||
| 38 | */ | ||
| 39 | @TableField(value = "ploy_name") | ||
| 40 | private String ployName; | ||
| 41 | |||
| 42 | @TableField(value = "process_detail_uuid") | ||
| 43 | private String processDetailUUID; | ||
| 44 | |||
| 45 | @TableField(value = "process_channel") | ||
| 46 | private String processChannel; | ||
| 47 | |||
| 48 | @TableField(value = "execute_times") | ||
| 49 | private Integer executeTimes; | ||
| 50 | |||
| 51 | @TableField(value = "execute_type") | ||
| 52 | private String executeType; | ||
| 53 | |||
| 54 | @TableField(value = "cron_expression") | ||
| 55 | private String cronExpression; | ||
| 56 | |||
| 57 | @TableField(value = "input_param") | ||
| 58 | private String inputParam; | ||
| 59 | |||
| 60 | @TableField(value = "priority") | ||
| 61 | private Integer priority; | ||
| 62 | |||
| 63 | @TableField(value = "distribution_type") | ||
| 64 | private Integer distributionType; | ||
| 65 | |||
| 66 | @TableField(value = "is_deleted") | ||
| 67 | private Boolean isDeleted; | ||
| 68 | |||
| 69 | @TableField(value = "gmt_created") | ||
| 70 | private Date gmtCreated; | ||
| 71 | |||
| 72 | @TableField(value = "gmt_modified") | ||
| 73 | private Date gmtModified; | ||
| 74 | } |
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | import lombok.AllArgsConstructor; | ||
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.NoArgsConstructor; | ||
| 10 | |||
| 11 | import java.io.Serializable; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/4 10:44 | ||
| 16 | */ | ||
| 17 | @Data | ||
| 18 | @Builder | ||
| 19 | @NoArgsConstructor | ||
| 20 | @AllArgsConstructor | ||
| 21 | @TableName("t_shop_group") | ||
| 22 | public class ShopGroupPO implements Serializable { | ||
| 23 | |||
| 24 | private static final long serialVersionUID = 1L; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 店铺ID | ||
| 28 | */ | ||
| 29 | @TableId(value = "shop_group_id", type = IdType.ASSIGN_ID) | ||
| 30 | private String shopGroupId; | ||
| 31 | } |
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | import lombok.AllArgsConstructor; | ||
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.NoArgsConstructor; | ||
| 10 | |||
| 11 | import java.io.Serializable; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/4 10:38 | ||
| 16 | */ | ||
| 17 | @Data | ||
| 18 | @Builder | ||
| 19 | @NoArgsConstructor | ||
| 20 | @AllArgsConstructor | ||
| 21 | @TableName("t_shop") | ||
| 22 | public class ShopPO implements Serializable { | ||
| 23 | |||
| 24 | private static final long serialVersionUID = 1L; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 店铺ID | ||
| 28 | */ | ||
| 29 | @TableId(value = "shop_id", type = IdType.ASSIGN_ID) | ||
| 30 | private String shopId; | ||
| 31 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.converter.mapper; | ||
| 2 | |||
| 3 | import cn.hutool.core.date.DateUtil; | ||
| 4 | import com.ql.backend.ploycenter.common.enums.DeviceStatus; | ||
| 5 | import com.ql.backend.ploycenter.domain.po.DevicePO; | ||
| 6 | import com.ql.backend.ploycenter.interfaces.request.DeviceReportRequest; | ||
| 7 | import com.ql.backend.ploycenter.interfaces.vo.DeviceVO; | ||
| 8 | import org.mapstruct.*; | ||
| 9 | import org.mapstruct.factory.Mappers; | ||
| 10 | |||
| 11 | import java.util.Date; | ||
| 12 | import java.util.List; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @author lirenhao | ||
| 16 | * date: 2022/9/4 11:54 | ||
| 17 | */ | ||
| 18 | @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, | ||
| 19 | nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, | ||
| 20 | nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) | ||
| 21 | public interface DeviceConverter { | ||
| 22 | |||
| 23 | DeviceConverter INSTANCE = Mappers.getMapper(DeviceConverter.class); | ||
| 24 | |||
| 25 | @Mapping(source = "deviceStatus", target = "deviceStatus", qualifiedByName = "convertDeviceStatus") | ||
| 26 | DevicePO convertRequest2Po(DeviceReportRequest request); | ||
| 27 | |||
| 28 | List<DeviceVO> convertPo2Vo(List<DevicePO> pos); | ||
| 29 | |||
| 30 | @Named("convertDeviceStatus") | ||
| 31 | default DeviceStatus convertDeviceStatus(Integer deviceStatus) { | ||
| 32 | return DeviceStatus.convert(deviceStatus); | ||
| 33 | } | ||
| 34 | |||
| 35 | default Integer convertDeviceStatus(DeviceStatus deviceStatus) { | ||
| 36 | return deviceStatus == null ? null : deviceStatus.getCode(); | ||
| 37 | } | ||
| 38 | |||
| 39 | default Date convertStr2Date(String date) { | ||
| 40 | return DateUtil.parse(date); | ||
| 41 | } | ||
| 42 | |||
| 43 | default String convertDate2Str(Date date) { | ||
| 44 | return DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"); | ||
| 45 | } | ||
| 46 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.converter.mapper; | ||
| 2 | |||
| 3 | import com.ql.backend.ploycenter.common.dto.PloyDTO; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | ||
| 6 | import com.ql.backend.ploycenter.interfaces.vo.PloyVO; | ||
| 7 | import org.mapstruct.Mapper; | ||
| 8 | import org.mapstruct.NullValueCheckStrategy; | ||
| 9 | import org.mapstruct.NullValuePropertyMappingStrategy; | ||
| 10 | import org.mapstruct.ReportingPolicy; | ||
| 11 | import org.mapstruct.factory.Mappers; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/5 17:45 | ||
| 16 | */ | ||
| 17 | @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, | ||
| 18 | nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, | ||
| 19 | nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) | ||
| 20 | public interface PloyConverter extends CommonConverter<PloyPO, PloyDTO, PloyVO> { | ||
| 21 | |||
| 22 | PloyConverter INSTANCE = Mappers.getMapper(PloyConverter.class); | ||
| 23 | |||
| 24 | PloyPO convertRequest2Po(PloyCreateRequest request); | ||
| 25 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import com.googlecode.aviator.AviatorEvaluator; | ||
| 4 | import com.googlecode.aviator.Expression; | ||
| 5 | import org.jeasy.rules.api.Action; | ||
| 6 | import org.jeasy.rules.api.Facts; | ||
| 7 | |||
| 8 | import java.util.Map; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/1/12 11:36 上午 | ||
| 13 | */ | ||
| 14 | public class AviatorAction implements Action { | ||
| 15 | |||
| 16 | private final Expression compliedExpression; | ||
| 17 | |||
| 18 | public AviatorAction(String expression) { | ||
| 19 | this.compliedExpression = AviatorEvaluator.compile(expression); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public void execute(Facts facts) throws Exception { | ||
| 24 | Map<String, Object> env = facts.asMap(); | ||
| 25 | compliedExpression.execute(env); | ||
| 26 | } | ||
| 27 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import com.googlecode.aviator.AviatorEvaluator; | ||
| 4 | import com.googlecode.aviator.Expression; | ||
| 5 | import org.jeasy.rules.api.Condition; | ||
| 6 | import org.jeasy.rules.api.Facts; | ||
| 7 | |||
| 8 | import java.util.Map; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/1/12 11:39 上午 | ||
| 13 | */ | ||
| 14 | public class AviatorCondition implements Condition { | ||
| 15 | |||
| 16 | private final Expression compliedExpression; | ||
| 17 | |||
| 18 | public AviatorCondition(String expression) { | ||
| 19 | this.compliedExpression = AviatorEvaluator.compile(expression); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public boolean evaluate(Facts facts) { | ||
| 24 | Map<String, Object> env = facts.asMap(); | ||
| 25 | return (boolean) compliedExpression.execute(env); | ||
| 26 | } | ||
| 27 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import com.googlecode.aviator.runtime.function.AbstractFunction; | ||
| 4 | import org.jeasy.rules.support.reader.JsonRuleDefinitionReader; | ||
| 5 | import org.springframework.context.annotation.Bean; | ||
| 6 | import org.springframework.context.annotation.Configuration; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/3 16:05 | ||
| 13 | */ | ||
| 14 | @Configuration | ||
| 15 | public class AviatorConfiguration { | ||
| 16 | |||
| 17 | @Bean | ||
| 18 | public AviatorRuleFactory aviatorRuleFactory(List<AbstractFunction> functions) { | ||
| 19 | return new AviatorRuleFactory(new JsonRuleDefinitionReader(), functions); | ||
| 20 | } | ||
| 21 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import org.jeasy.rules.api.Action; | ||
| 4 | import org.jeasy.rules.api.Condition; | ||
| 5 | import org.jeasy.rules.api.Facts; | ||
| 6 | import org.jeasy.rules.core.BasicRule; | ||
| 7 | |||
| 8 | import java.util.ArrayList; | ||
| 9 | import java.util.List; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author lirenhao | ||
| 13 | * date: 2022/1/12 11:39 上午 | ||
| 14 | */ | ||
| 15 | public class AviatorRule extends BasicRule { | ||
| 16 | |||
| 17 | private int ruleType; | ||
| 18 | private Condition condition = Condition.FALSE; | ||
| 19 | private final List<Action> actions = new ArrayList<>(); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Set rule type. | ||
| 23 | * | ||
| 24 | * @param ruleType of the rule | ||
| 25 | * @return this rule | ||
| 26 | */ | ||
| 27 | public AviatorRule ruleType(int ruleType) { | ||
| 28 | this.ruleType = ruleType; | ||
| 29 | return this; | ||
| 30 | } | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Set rule name. | ||
| 34 | * | ||
| 35 | * @param name of the rule | ||
| 36 | * @return this rule | ||
| 37 | */ | ||
| 38 | public AviatorRule name(String name) { | ||
| 39 | this.name = name; | ||
| 40 | return this; | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Set rule description. | ||
| 45 | * | ||
| 46 | * @param description of the rule | ||
| 47 | * @return this rule | ||
| 48 | */ | ||
| 49 | public AviatorRule description(String description) { | ||
| 50 | this.description = description; | ||
| 51 | return this; | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Set rule priority. | ||
| 56 | * | ||
| 57 | * @param priority of the rule | ||
| 58 | * @return this rule | ||
| 59 | */ | ||
| 60 | public AviatorRule priority(int priority) { | ||
| 61 | this.priority = priority; | ||
| 62 | return this; | ||
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Specify the rule's condition as SpEL expression. | ||
| 67 | * | ||
| 68 | * @param condition of the rule | ||
| 69 | * @return this rule | ||
| 70 | */ | ||
| 71 | public AviatorRule when(String condition) { | ||
| 72 | this.condition = new AviatorCondition(condition); | ||
| 73 | return this; | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Add an action specified as an SpEL expression to the rule. | ||
| 78 | * | ||
| 79 | * @param action to add to the rule | ||
| 80 | * @return this rule | ||
| 81 | */ | ||
| 82 | public AviatorRule then(String action) { | ||
| 83 | this.actions.add(new AviatorAction(action)); | ||
| 84 | return this; | ||
| 85 | } | ||
| 86 | |||
| 87 | public int getRuleType() { | ||
| 88 | return ruleType; | ||
| 89 | } | ||
| 90 | |||
| 91 | @Override | ||
| 92 | public boolean evaluate(Facts facts) { | ||
| 93 | return condition.evaluate(facts); | ||
| 94 | } | ||
| 95 | |||
| 96 | @Override | ||
| 97 | public void execute(Facts facts) throws Exception { | ||
| 98 | for (Action action : actions) { | ||
| 99 | action.execute(facts); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | import lombok.EqualsAndHashCode; | ||
| 5 | import org.jeasy.rules.support.RuleDefinition; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/4/6 3:45 下午 | ||
| 10 | */ | ||
| 11 | @EqualsAndHashCode(callSuper = true) | ||
| 12 | @Data | ||
| 13 | public class AviatorRuleDefinition extends RuleDefinition { | ||
| 14 | |||
| 15 | /** | ||
| 16 | * 规则ID | ||
| 17 | */ | ||
| 18 | private String ruleId; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * 规则类型 | ||
| 22 | */ | ||
| 23 | private int ruleType; | ||
| 24 | |||
| 25 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.easyrule; | ||
| 2 | |||
| 3 | import com.googlecode.aviator.AviatorEvaluator; | ||
| 4 | import com.googlecode.aviator.runtime.function.AbstractFunction; | ||
| 5 | import org.jeasy.rules.api.Rule; | ||
| 6 | import org.jeasy.rules.api.Rules; | ||
| 7 | import org.jeasy.rules.support.AbstractRuleFactory; | ||
| 8 | import org.jeasy.rules.support.RuleDefinition; | ||
| 9 | import org.jeasy.rules.support.reader.RuleDefinitionReader; | ||
| 10 | import org.springframework.util.CollectionUtils; | ||
| 11 | |||
| 12 | import java.io.Reader; | ||
| 13 | import java.util.List; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author lirenhao | ||
| 17 | * date: 2022/1/12 11:40 上午 | ||
| 18 | */ | ||
| 19 | public class AviatorRuleFactory extends AbstractRuleFactory { | ||
| 20 | |||
| 21 | private final RuleDefinitionReader reader; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Create a new {@link AviatorRuleFactory} with a given reader. | ||
| 25 | * | ||
| 26 | * @param reader used to read rule definitions | ||
| 27 | */ | ||
| 28 | public AviatorRuleFactory(RuleDefinitionReader reader, List<AbstractFunction> functions) { | ||
| 29 | this.reader = reader; | ||
| 30 | if (!CollectionUtils.isEmpty(functions)) { | ||
| 31 | functions.forEach(AviatorEvaluator::addFunction); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Create a set of {@link AviatorRule} from a Reader. | ||
| 37 | * | ||
| 38 | * @param rulesDescriptor descriptor of rule definitions | ||
| 39 | * @return a set of rules | ||
| 40 | * @throws Exception if unable to create rules from the descriptor | ||
| 41 | */ | ||
| 42 | public Rules createRules(Reader rulesDescriptor) throws Exception { | ||
| 43 | Rules rules = new Rules(); | ||
| 44 | List<RuleDefinition> ruleDefinitions = reader.read(rulesDescriptor); | ||
| 45 | for (RuleDefinition ruleDefinition : ruleDefinitions) { | ||
| 46 | rules.register(createRule(ruleDefinition)); | ||
| 47 | } | ||
| 48 | return rules; | ||
| 49 | } | ||
| 50 | |||
| 51 | public Rules createRules(List<RuleDefinition> ruleDefinitions) throws Exception { | ||
| 52 | Rules rules = new Rules(); | ||
| 53 | for (RuleDefinition ruleDefinition : ruleDefinitions) { | ||
| 54 | rules.register(createRule(ruleDefinition)); | ||
| 55 | } | ||
| 56 | return rules; | ||
| 57 | } | ||
| 58 | |||
| 59 | @Override | ||
| 60 | protected Rule createSimpleRule(RuleDefinition ruleDefinition) { | ||
| 61 | int ruleType = 0; | ||
| 62 | if (ruleDefinition instanceof AviatorRuleDefinition) { | ||
| 63 | ruleType = ((AviatorRuleDefinition) ruleDefinition).getRuleType(); | ||
| 64 | } | ||
| 65 | |||
| 66 | AviatorRule aviatorRule = new AviatorRule() | ||
| 67 | .ruleType(ruleType) | ||
| 68 | .name(ruleDefinition.getName()) | ||
| 69 | .description(ruleDefinition.getDescription()) | ||
| 70 | .priority(ruleDefinition.getPriority()) | ||
| 71 | .when(ruleDefinition.getCondition()); | ||
| 72 | for (String action : ruleDefinition.getActions()) { | ||
| 73 | aviatorRule.then(action); | ||
| 74 | } | ||
| 75 | return aviatorRule; | ||
| 76 | } | ||
| 77 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 4 | import com.baomidou.mybatisplus.extension.service.IService; | ||
| 5 | import com.ql.backend.ploycenter.domain.condition.DeviceCondition; | ||
| 6 | import com.ql.backend.ploycenter.domain.po.DevicePO; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/4 11:41 | ||
| 11 | */ | ||
| 12 | public interface DeviceDao extends IService<DevicePO> { | ||
| 13 | |||
| 14 | DevicePO getByDeviceId(String deviceId); | ||
| 15 | |||
| 16 | Page<DevicePO> findDevice(DeviceCondition condition); | ||
| 17 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/5 16:41 | ||
| 9 | */ | ||
| 10 | public interface PloyDao extends IService<PloyPO> { | ||
| 11 | |||
| 12 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 6 | import com.ql.backend.ploycenter.domain.condition.DeviceCondition; | ||
| 7 | import com.ql.backend.ploycenter.domain.po.DevicePO; | ||
| 8 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.DeviceDao; | ||
| 9 | import com.ql.backend.ploycenter.infrastructure.persistence.mapper.DeviceMapper; | ||
| 10 | import org.springframework.stereotype.Service; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/4 11:41 | ||
| 15 | */ | ||
| 16 | @Service | ||
| 17 | public class DeviceDaoImpl extends ServiceImpl<DeviceMapper, DevicePO> implements DeviceDao { | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public DevicePO getByDeviceId(String deviceId) { | ||
| 21 | return this.getById(deviceId); | ||
| 22 | } | ||
| 23 | |||
| 24 | @Override | ||
| 25 | public Page<DevicePO> findDevice(DeviceCondition condition) { | ||
| 26 | Page<DevicePO> page = new Page<>(condition.getPage(), condition.getSize()); | ||
| 27 | return this.baseMapper.selectPage(page, new QueryWrapper<>()); | ||
| 28 | } | ||
| 29 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.persistence.mapper.PloyMapper; | ||
| 7 | import org.springframework.stereotype.Service; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/9/5 16:41 | ||
| 12 | */ | ||
| 13 | @Service | ||
| 14 | public class PloyDaoImpl extends ServiceImpl<PloyMapper, PloyPO> implements PloyDao { | ||
| 15 | |||
| 16 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.mapper; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.DevicePO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/7 10:10 | ||
| 9 | */ | ||
| 10 | public interface DeviceMapper extends BaseMapper<DevicePO> { | ||
| 11 | |||
| 12 | DevicePO getDevicePOByDeviceId(String deviceId); | ||
| 13 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.mapper; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/7 10:10 | ||
| 9 | */ | ||
| 10 | public interface PloyMapper extends BaseMapper<PloyPO> { | ||
| 11 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/interfaces/facade/DeviceFacade.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.interfaces.facade; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.core.interfaces.vo.PageVO; | ||
| 5 | import com.ql.backend.ploycenter.application.DeviceService; | ||
| 6 | import com.ql.backend.ploycenter.domain.condition.DeviceCondition; | ||
| 7 | import com.ql.backend.ploycenter.interfaces.request.DeviceReportRequest; | ||
| 8 | import com.ql.backend.ploycenter.interfaces.vo.DeviceVO; | ||
| 9 | import org.springframework.web.bind.annotation.*; | ||
| 10 | |||
| 11 | import javax.annotation.Resource; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/4 11:06 | ||
| 16 | */ | ||
| 17 | @RestController | ||
| 18 | @RequestMapping("/ploy-center/v1/devices") | ||
| 19 | public class DeviceFacade { | ||
| 20 | |||
| 21 | @Resource | ||
| 22 | private DeviceService deviceService; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 上报设备状态 | ||
| 26 | */ | ||
| 27 | @PostMapping | ||
| 28 | public ApiResponse<Void> reportDeviceStatus(@RequestBody DeviceReportRequest request) { | ||
| 29 | deviceService.reportDeviceStatus(request); | ||
| 30 | return ApiResponse.ok(); | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 查询设备状态 | ||
| 35 | */ | ||
| 36 | @GetMapping | ||
| 37 | public ApiResponse<PageVO<DeviceVO>> findDevice(DeviceCondition condition) { | ||
| 38 | return ApiResponse.ok( | ||
| 39 | deviceService.findDevice(condition) | ||
| 40 | ); | ||
| 41 | } | ||
| 42 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/interfaces/facade/PloyFacade.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.interfaces.facade; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.application.PloyService; | ||
| 5 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | ||
| 6 | import org.springframework.web.bind.annotation.PostMapping; | ||
| 7 | import org.springframework.web.bind.annotation.RequestBody; | ||
| 8 | import org.springframework.web.bind.annotation.RequestMapping; | ||
| 9 | import org.springframework.web.bind.annotation.RestController; | ||
| 10 | |||
| 11 | import javax.annotation.Resource; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/5 15:54 | ||
| 16 | */ | ||
| 17 | @RestController | ||
| 18 | @RequestMapping("/ploy-center/v1/ploys") | ||
| 19 | public class PloyFacade { | ||
| 20 | |||
| 21 | @Resource | ||
| 22 | private PloyService ployService; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 创建策略 | ||
| 26 | */ | ||
| 27 | @PostMapping | ||
| 28 | public ApiResponse<String> createPloy(@RequestBody PloyCreateRequest request) { | ||
| 29 | return ApiResponse.ok( | ||
| 30 | ployService.createPloy(request) | ||
| 31 | ); | ||
| 32 | } | ||
| 33 | |||
| 34 | /* todo 更新策略 */ | ||
| 35 | |||
| 36 | /* todo 查询策略列表 */ | ||
| 37 | |||
| 38 | /* todo 查询策略详情 */ | ||
| 39 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/interfaces/facade/ShopFacade.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.interfaces.facade; | ||
| 2 | |||
| 3 | import org.springframework.web.bind.annotation.RequestMapping; | ||
| 4 | import org.springframework.web.bind.annotation.RestController; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/5 15:56 | ||
| 9 | */ | ||
| 10 | @RestController | ||
| 11 | @RequestMapping("/ploy-center/v1/shops") | ||
| 12 | public class ShopFacade { | ||
| 13 | |||
| 14 | /* todo 创建店铺 */ | ||
| 15 | |||
| 16 | /* todo 更新店铺信息 */ | ||
| 17 | |||
| 18 | /* todo 查询店铺列表 */ | ||
| 19 | |||
| 20 | /* todo 查询店铺详情 */ | ||
| 21 | } |
| 1 | package com.ql.backend.ploycenter.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/9/4 11:11 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @NoArgsConstructor | ||
| 15 | @AllArgsConstructor | ||
| 16 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 17 | public class DeviceReportRequest { | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 设备ID | ||
| 21 | */ | ||
| 22 | private String deviceId; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 设备名称 | ||
| 26 | */ | ||
| 27 | private String deviceName; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 设备系统版本 | ||
| 31 | */ | ||
| 32 | private String deviceOperateSystem; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * 设备IP | ||
| 36 | */ | ||
| 37 | private String deviceIp; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * 设备Bot版本 | ||
| 41 | */ | ||
| 42 | private String deviceBotVersion; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * 上次登录时间 | ||
| 46 | */ | ||
| 47 | private String lastedLoginTime; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * 设备状态 | ||
| 51 | */ | ||
| 52 | private Integer deviceStatus; | ||
| 53 | |||
| 54 | /** | ||
| 55 | * 设备任务数量 | ||
| 56 | */ | ||
| 57 | private Long taskNum; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * 上报的时间 | ||
| 61 | */ | ||
| 62 | private long timestamp; | ||
| 63 | } |
| 1 | package com.ql.backend.ploycenter.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/9/5 17:40 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @NoArgsConstructor | ||
| 15 | @AllArgsConstructor | ||
| 16 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 17 | public class PloyCreateRequest { | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 策略名称 | ||
| 21 | */ | ||
| 22 | private String ployName; | ||
| 23 | |||
| 24 | private String processDetailUUID; | ||
| 25 | |||
| 26 | private String processChannel; | ||
| 27 | |||
| 28 | private Integer executeTimes; | ||
| 29 | |||
| 30 | private String executeType; | ||
| 31 | |||
| 32 | private String cronExpression; | ||
| 33 | |||
| 34 | private String inputParam; | ||
| 35 | |||
| 36 | private Integer priority; | ||
| 37 | |||
| 38 | private Integer distributionType; | ||
| 39 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/interfaces/vo/DeviceVO.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.interfaces.vo; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Builder; | ||
| 7 | import lombok.Data; | ||
| 8 | import lombok.NoArgsConstructor; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/4 20:44 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @Builder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class DeviceVO { | ||
| 20 | |||
| 21 | /** | ||
| 22 | * 设备ID | ||
| 23 | */ | ||
| 24 | private String deviceId; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 设备名称 | ||
| 28 | */ | ||
| 29 | private String deviceName; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * 设备系统版本 | ||
| 33 | */ | ||
| 34 | private String deviceOperateSystem; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * 设备状态 | ||
| 38 | */ | ||
| 39 | private Integer deviceStatus; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * 设备IP | ||
| 43 | */ | ||
| 44 | private String deviceIp; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * 设备Bot版本 | ||
| 48 | */ | ||
| 49 | private String deviceBotVersion; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * 上次登录时间 | ||
| 53 | */ | ||
| 54 | private String lastedLoginTime; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * 机器上运行的任务数量 | ||
| 58 | */ | ||
| 59 | private Long taskNum; | ||
| 60 | |||
| 61 | private String gmtModified; | ||
| 62 | } |
| 1 | package com.ql.backend.ploycenter.interfaces.vo; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Builder; | ||
| 7 | import lombok.Data; | ||
| 8 | import lombok.NoArgsConstructor; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/5 17:49 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @Builder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class PloyVO { | ||
| 20 | |||
| 21 | private String ployId; | ||
| 22 | } |
ql-backend-service/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <parent> | ||
| 6 | <artifactId>ql-backend-parent</artifactId> | ||
| 7 | <groupId>com.pl.backend</groupId> | ||
| 8 | <version>1.0.0-SNAPSHOT</version> | ||
| 9 | <relativePath>../ql-backend-parent/pom.xml</relativePath> <!-- lookup parent from repository --> | ||
| 10 | </parent> | ||
| 11 | <modelVersion>4.0.0</modelVersion> | ||
| 12 | |||
| 13 | <artifactId>ql-backend-service</artifactId> | ||
| 14 | <version>1.0.0-SNAPSHOT</version> | ||
| 15 | |||
| 16 | <properties> | ||
| 17 | <maven.compiler.source>8</maven.compiler.source> | ||
| 18 | <maven.compiler.target>8</maven.compiler.target> | ||
| 19 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 20 | </properties> | ||
| 21 | |||
| 22 | <dependencies> | ||
| 23 | <dependency> | ||
| 24 | <groupId>com.pl.backend</groupId> | ||
| 25 | <artifactId>ql-backend-taskmanager</artifactId> | ||
| 26 | <version>1.0.0-SNAPSHOT</version> | ||
| 27 | </dependency> | ||
| 28 | |||
| 29 | <dependency> | ||
| 30 | <groupId>org.springframework.boot</groupId> | ||
| 31 | <artifactId>spring-boot-starter</artifactId> | ||
| 32 | </dependency> | ||
| 33 | |||
| 34 | <dependency> | ||
| 35 | <groupId>org.springframework.boot</groupId> | ||
| 36 | <artifactId>spring-boot-starter-web</artifactId> | ||
| 37 | </dependency> | ||
| 38 | |||
| 39 | <dependency> | ||
| 40 | <groupId>mysql</groupId> | ||
| 41 | <artifactId>mysql-connector-java</artifactId> | ||
| 42 | <scope>runtime</scope> | ||
| 43 | </dependency> | ||
| 44 | </dependencies> | ||
| 45 | |||
| 46 | <build> | ||
| 47 | <plugins> | ||
| 48 | <plugin> | ||
| 49 | <groupId>org.springframework.boot</groupId> | ||
| 50 | <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 51 | <version>2.7.3</version> | ||
| 52 | </plugin> | ||
| 53 | <plugin> | ||
| 54 | <groupId>org.apache.maven.plugins</groupId> | ||
| 55 | <artifactId>maven-compiler-plugin</artifactId> | ||
| 56 | <version>3.8.1</version> | ||
| 57 | </plugin> | ||
| 58 | </plugins> | ||
| 59 | </build> | ||
| 60 | </project> |
| 1 | package com.ql.backend.service; | ||
| 2 | |||
| 3 | import org.mybatis.spring.annotation.MapperScan; | ||
| 4 | import org.springframework.boot.SpringApplication; | ||
| 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/8/31 11:35 | ||
| 10 | */ | ||
| 11 | @SpringBootApplication(scanBasePackages = "com.ql.backend") | ||
| 12 | @MapperScan("com.ql.backend.*.infrastructure.persistence.mapper") | ||
| 13 | public class QLBackendServiceApplication { | ||
| 14 | |||
| 15 | public static void main(String[] args) { | ||
| 16 | SpringApplication.run(QLBackendServiceApplication.class, args); | ||
| 17 | } | ||
| 18 | } |
| 1 | server: | ||
| 2 | port: 9999 | ||
| 3 | |||
| 4 | spring: | ||
| 5 | datasource: | ||
| 6 | url: jdbc:mysql://localhost:3306/ql-backend?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false | ||
| 7 | username: root | ||
| 8 | password: a15728006904 | ||
| 9 | driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 10 | mybatis: | ||
| 11 | #开启驼峰命名法 | ||
| 12 | configuration: | ||
| 13 | map-underscore-to-camel-case: true | ||
| 14 | mybatis-plus: | ||
| 15 | # xml地址 | ||
| 16 | mapper-locations: classpath:mapper/*Mapper.xml | ||
| 17 | # 实体扫描,多个package用逗号或者分号分隔 | ||
| 18 | type-aliases-package: com.ql.backend.*.domain.po #自己的实体类地址 | ||
| 19 | configuration: | ||
| 20 | # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 | ||
| 21 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
ql-backend-taskmanager-common/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | |||
| 6 | <modelVersion>4.0.0</modelVersion> | ||
| 7 | |||
| 8 | <groupId>com.pl.backend</groupId> | ||
| 9 | <artifactId>ql-backend-taskmanager-common</artifactId> | ||
| 10 | <version>1.0.0-SNAPSHOT</version> | ||
| 11 | |||
| 12 | <properties> | ||
| 13 | <maven.compiler.source>8</maven.compiler.source> | ||
| 14 | <maven.compiler.target>8</maven.compiler.target> | ||
| 15 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 16 | </properties> | ||
| 17 | |||
| 18 | <dependencies> | ||
| 19 | <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
| 20 | <dependency> | ||
| 21 | <groupId>org.projectlombok</groupId> | ||
| 22 | <artifactId>lombok</artifactId> | ||
| 23 | <version>1.18.24</version> | ||
| 24 | <scope>provided</scope> | ||
| 25 | </dependency> | ||
| 26 | |||
| 27 | <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> | ||
| 28 | <dependency> | ||
| 29 | <groupId>com.fasterxml.jackson.core</groupId> | ||
| 30 | <artifactId>jackson-databind</artifactId> | ||
| 31 | <version>2.13.3</version> | ||
| 32 | </dependency> | ||
| 33 | </dependencies> | ||
| 34 | </project> |
ql-backend-taskmanager-common/src/main/java/com/ql/backend/taskmanager/common/dto/TaskDTO.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.common.dto; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 6 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 7 | import lombok.AllArgsConstructor; | ||
| 8 | import lombok.Builder; | ||
| 9 | import lombok.Data; | ||
| 10 | import lombok.NoArgsConstructor; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/3 16:21 | ||
| 15 | */ | ||
| 16 | @Data | ||
| 17 | @Builder | ||
| 18 | @NoArgsConstructor | ||
| 19 | @AllArgsConstructor | ||
| 20 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 21 | public class TaskDTO { | ||
| 22 | |||
| 23 | /** | ||
| 24 | * 任务ID | ||
| 25 | */ | ||
| 26 | private String taskId; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * 任务状态 | ||
| 30 | */ | ||
| 31 | private TaskStatus taskStatus; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 任务子状态 | ||
| 35 | */ | ||
| 36 | private TaskSubStatus taskSubStatus; | ||
| 37 | |||
| 38 | private String shopId; | ||
| 39 | |||
| 40 | private String ployId; | ||
| 41 | |||
| 42 | private String taskParam; | ||
| 43 | } |
ql-backend-taskmanager-common/src/main/java/com/ql/backend/taskmanager/common/enums/TaskStatus.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.common.enums; | ||
| 2 | |||
| 3 | import lombok.Getter; | ||
| 4 | |||
| 5 | import java.util.stream.Stream; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/8/31 17:46 | ||
| 10 | */ | ||
| 11 | public enum TaskStatus { | ||
| 12 | |||
| 13 | CREATED(0, "created", "创建"), | ||
| 14 | EXECUTED(1, "executed", "执行"), | ||
| 15 | DONE(2, "done", "完成"); | ||
| 16 | |||
| 17 | @Getter | ||
| 18 | private final int code; | ||
| 19 | |||
| 20 | @Getter | ||
| 21 | private final String type; | ||
| 22 | |||
| 23 | @Getter | ||
| 24 | private final String desc; | ||
| 25 | |||
| 26 | TaskStatus(int code, String type, String desc) { | ||
| 27 | this.code = code; | ||
| 28 | this.type = type; | ||
| 29 | this.desc = desc; | ||
| 30 | } | ||
| 31 | |||
| 32 | public static TaskStatus convert(String type) { | ||
| 33 | return Stream.of(values()) | ||
| 34 | .filter(taskStatus -> taskStatus.getType().equalsIgnoreCase(type)) | ||
| 35 | .findFirst() | ||
| 36 | .orElse(null); | ||
| 37 | } | ||
| 38 | } |
| 1 | package com.ql.backend.taskmanager.common.enums; | ||
| 2 | |||
| 3 | import lombok.Getter; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * @author lirenhao | ||
| 7 | * date: 2022/8/31 19:55 | ||
| 8 | */ | ||
| 9 | public enum TaskSubStatus { | ||
| 10 | |||
| 11 | PENDING(0, "pending", "等待中"), | ||
| 12 | DOING(1, "doing", "执行中"), | ||
| 13 | DONE_SUCCESS(2, "done_success", "成功"), | ||
| 14 | DONE_FAIL(3, "done_fail", "失败"), | ||
| 15 | DONE_TIMEOUT(4, "done_timeout", "超时"); | ||
| 16 | |||
| 17 | @Getter | ||
| 18 | private final int code; | ||
| 19 | |||
| 20 | @Getter | ||
| 21 | private final String type; | ||
| 22 | |||
| 23 | @Getter | ||
| 24 | private final String desc; | ||
| 25 | |||
| 26 | TaskSubStatus(int code, String type, String desc) { | ||
| 27 | this.code = code; | ||
| 28 | this.type = type; | ||
| 29 | this.desc = desc; | ||
| 30 | } | ||
| 31 | } |
ql-backend-taskmanager/pom.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | <parent> | ||
| 6 | <artifactId>ql-backend-parent</artifactId> | ||
| 7 | <groupId>com.pl.backend</groupId> | ||
| 8 | <version>1.0.0-SNAPSHOT</version> | ||
| 9 | <relativePath>../ql-backend-parent/pom.xml</relativePath> <!-- lookup parent from repository --> | ||
| 10 | </parent> | ||
| 11 | <modelVersion>4.0.0</modelVersion> | ||
| 12 | |||
| 13 | <artifactId>ql-backend-taskmanager</artifactId> | ||
| 14 | <version>1.0.0-SNAPSHOT</version> | ||
| 15 | |||
| 16 | <properties> | ||
| 17 | <maven.compiler.source>8</maven.compiler.source> | ||
| 18 | <maven.compiler.target>8</maven.compiler.target> | ||
| 19 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 20 | </properties> | ||
| 21 | |||
| 22 | <dependencies> | ||
| 23 | <dependency> | ||
| 24 | <groupId>com.pl.backend</groupId> | ||
| 25 | <artifactId>ql-backend-core</artifactId> | ||
| 26 | <version>1.0.0-SNAPSHOT</version> | ||
| 27 | </dependency> | ||
| 28 | |||
| 29 | <dependency> | ||
| 30 | <groupId>com.pl.backend</groupId> | ||
| 31 | <artifactId>ql-backend-taskmanager-common</artifactId> | ||
| 32 | <version>1.0.0-SNAPSHOT</version> | ||
| 33 | </dependency> | ||
| 34 | |||
| 35 | <dependency> | ||
| 36 | <groupId>com.pl.backend</groupId> | ||
| 37 | <artifactId>ql-backend-ploycenter</artifactId> | ||
| 38 | <version>1.0.0-SNAPSHOT</version> | ||
| 39 | </dependency> | ||
| 40 | |||
| 41 | <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
| 42 | <dependency> | ||
| 43 | <groupId>org.projectlombok</groupId> | ||
| 44 | <artifactId>lombok</artifactId> | ||
| 45 | <scope>provided</scope> | ||
| 46 | </dependency> | ||
| 47 | </dependencies> | ||
| 48 | |||
| 49 | <build> | ||
| 50 | <plugins> | ||
| 51 | <plugin> | ||
| 52 | <groupId>org.apache.maven.plugins</groupId> | ||
| 53 | <artifactId>maven-compiler-plugin</artifactId> | ||
| 54 | <version>3.8.1</version> | ||
| 55 | </plugin> | ||
| 56 | </plugins> | ||
| 57 | </build> | ||
| 58 | </project> |
ql-backend-taskmanager/src/main/java/com/ql/backend/taskmanager/application/TaskService.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.application; | ||
| 2 | |||
| 3 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; | ||
| 4 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/1 10:10 | ||
| 9 | */ | ||
| 10 | public interface TaskService { | ||
| 11 | |||
| 12 | String createTask(TaskCreateRequest request); | ||
| 13 | |||
| 14 | TaskVO getTask(String taskId); | ||
| 15 | } |
| 1 | package com.ql.backend.taskmanager.application.impl; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.application.PloyService; | ||
| 5 | import com.ql.backend.taskmanager.application.TaskService; | ||
| 6 | import com.ql.backend.taskmanager.common.dto.TaskDTO; | ||
| 7 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 8 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 9 | import com.ql.backend.taskmanager.domain.po.TaskPO; | ||
| 10 | import com.ql.backend.taskmanager.infrastructure.converter.mapper.TaskConverter; | ||
| 11 | import com.ql.backend.taskmanager.infrastructure.persistence.dao.TaskDao; | ||
| 12 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; | ||
| 13 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; | ||
| 14 | import lombok.extern.slf4j.Slf4j; | ||
| 15 | import org.springframework.stereotype.Service; | ||
| 16 | import org.springframework.transaction.annotation.Transactional; | ||
| 17 | |||
| 18 | import javax.annotation.Resource; | ||
| 19 | import java.util.UUID; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * @author lirenhao | ||
| 23 | * date: 2022/9/1 10:11 | ||
| 24 | */ | ||
| 25 | @Slf4j | ||
| 26 | @Service | ||
| 27 | public class TaskServiceImpl implements TaskService { | ||
| 28 | |||
| 29 | @Resource | ||
| 30 | private TaskDao taskDao; | ||
| 31 | |||
| 32 | @Resource | ||
| 33 | private PloyService ployService; | ||
| 34 | |||
| 35 | @Override | ||
| 36 | @Transactional | ||
| 37 | public String createTask(TaskCreateRequest request) { | ||
| 38 | TaskPO taskPO = TaskConverter.INSTANCE.convertRequest2Po(request); | ||
| 39 | taskPO.setTaskId(UUID.randomUUID().toString()); | ||
| 40 | taskPO.setTaskStatus(TaskStatus.CREATED); | ||
| 41 | taskPO.setTaskSubStatus(TaskSubStatus.PENDING); | ||
| 42 | taskDao.save(taskPO); | ||
| 43 | |||
| 44 | /* 执行策略 */ | ||
| 45 | TaskDTO taskDTO = TaskConverter.INSTANCE.convertPo2Dto(taskPO); | ||
| 46 | ApiResponse<String> response = ployService.fire(taskDTO); | ||
| 47 | |||
| 48 | TaskPO update = new TaskPO(); | ||
| 49 | if (response.isOk()) { | ||
| 50 | update.setTaskStatus(TaskStatus.CREATED); | ||
| 51 | update.setTaskSubStatus(TaskSubStatus.DONE_SUCCESS); | ||
| 52 | } else { | ||
| 53 | update.setTaskStatus(TaskStatus.CREATED); | ||
| 54 | update.setTaskSubStatus(TaskSubStatus.DONE_FAIL); | ||
| 55 | update.setFailReason(response.getMessage()); | ||
| 56 | } | ||
| 57 | |||
| 58 | taskDao.updateByTaskId(taskPO.getTaskId(), update); | ||
| 59 | |||
| 60 | return taskPO.getTaskId(); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | public TaskVO getTask(String taskId) { | ||
| 65 | return TaskConverter.INSTANCE.convertPo2Vo(taskDao.getByTaskId(taskId)); | ||
| 66 | } | ||
| 67 | } |
| 1 | package com.ql.backend.taskmanager.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 8 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 9 | import lombok.AllArgsConstructor; | ||
| 10 | import lombok.Builder; | ||
| 11 | import lombok.Data; | ||
| 12 | import lombok.NoArgsConstructor; | ||
| 13 | |||
| 14 | import java.io.Serializable; | ||
| 15 | import java.util.Date; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * 任务表 | ||
| 19 | * | ||
| 20 | * @author lirenhao | ||
| 21 | * date: 2022/8/31 15:23 | ||
| 22 | */ | ||
| 23 | @Data | ||
| 24 | @Builder | ||
| 25 | @NoArgsConstructor | ||
| 26 | @AllArgsConstructor | ||
| 27 | @TableName("t_task") | ||
| 28 | public class TaskPO implements Serializable { | ||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 任务ID | ||
| 34 | */ | ||
| 35 | @TableId(value = "task_id", type = IdType.ASSIGN_ID) | ||
| 36 | private String taskId; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * 任务状态 | ||
| 40 | */ | ||
| 41 | @TableField(value = "task_status") | ||
| 42 | private TaskStatus taskStatus; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * 任务子状态 | ||
| 46 | */ | ||
| 47 | @TableField(value = "task_sub_status") | ||
| 48 | private TaskSubStatus taskSubStatus; | ||
| 49 | |||
| 50 | @TableField(value = "shop_id") | ||
| 51 | private String shopId; | ||
| 52 | |||
| 53 | @TableField(value = "ploy_id") | ||
| 54 | private String ployId; | ||
| 55 | |||
| 56 | @TableField(value = "task_param") | ||
| 57 | private String taskParam; | ||
| 58 | |||
| 59 | @TableField(value = "fail_reason") | ||
| 60 | private String failReason; | ||
| 61 | |||
| 62 | @TableField(value = "is_deleted") | ||
| 63 | private Boolean isDeleted; | ||
| 64 | |||
| 65 | @TableField(value = "gmt_created") | ||
| 66 | private Date gmtCreated; | ||
| 67 | |||
| 68 | @TableField(value = "gmt_modified") | ||
| 69 | private Date gmtModified; | ||
| 70 | } |
| 1 | package com.ql.backend.taskmanager.infrastructure.converter.mapper; | ||
| 2 | |||
| 3 | import com.ql.backend.taskmanager.common.dto.TaskDTO; | ||
| 4 | import com.ql.backend.taskmanager.domain.po.TaskPO; | ||
| 5 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; | ||
| 6 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; | ||
| 7 | import org.mapstruct.Mapper; | ||
| 8 | import org.mapstruct.NullValueCheckStrategy; | ||
| 9 | import org.mapstruct.NullValuePropertyMappingStrategy; | ||
| 10 | import org.mapstruct.ReportingPolicy; | ||
| 11 | import org.mapstruct.factory.Mappers; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * @author lirenhao | ||
| 15 | * date: 2022/9/3 17:08 | ||
| 16 | */ | ||
| 17 | @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, | ||
| 18 | nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, | ||
| 19 | nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) | ||
| 20 | public interface TaskConverter { | ||
| 21 | |||
| 22 | TaskConverter INSTANCE = Mappers.getMapper(TaskConverter.class); | ||
| 23 | |||
| 24 | TaskPO convertRequest2Po(TaskCreateRequest request); | ||
| 25 | |||
| 26 | TaskDTO convertPo2Dto(TaskPO po); | ||
| 27 | |||
| 28 | TaskVO convertPo2Vo(TaskPO po); | ||
| 29 | } |
| 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao; | ||
| 2 | |||
| 3 | import com.ql.backend.taskmanager.domain.po.TaskPO; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * @author lirenhao | ||
| 7 | * date: 2022/9/1 11:02 | ||
| 8 | */ | ||
| 9 | public interface TaskDao { | ||
| 10 | |||
| 11 | TaskPO save(TaskPO po); | ||
| 12 | |||
| 13 | boolean updateByTaskId(String taskId, TaskPO update); | ||
| 14 | |||
| 15 | TaskPO getByTaskId(String taskId); | ||
| 16 | } |
| 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao.impl; | ||
| 2 | |||
| 3 | import com.ql.backend.taskmanager.domain.po.TaskPO; | ||
| 4 | import com.ql.backend.taskmanager.infrastructure.persistence.dao.TaskDao; | ||
| 5 | import org.springframework.stereotype.Service; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/9/1 11:02 | ||
| 10 | */ | ||
| 11 | @Service | ||
| 12 | public class TaskDaoImpl implements TaskDao { | ||
| 13 | @Override | ||
| 14 | public TaskPO save(TaskPO po) { | ||
| 15 | return null; | ||
| 16 | } | ||
| 17 | |||
| 18 | @Override | ||
| 19 | public boolean updateByTaskId(String taskId, TaskPO update) { | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public TaskPO getByTaskId(String taskId) { | ||
| 25 | return null; | ||
| 26 | } | ||
| 27 | } |
| 1 | package com.ql.backend.taskmanager.infrastructure.persistence.mapper; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | import com.ql.backend.taskmanager.domain.po.TaskPO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/7 10:11 | ||
| 9 | */ | ||
| 10 | public interface TaskMapper extends BaseMapper<TaskPO> { | ||
| 11 | } |
ql-backend-taskmanager/src/main/java/com/ql/backend/taskmanager/interfaces/facade/TaskFacade.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.interfaces.facade; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.taskmanager.application.TaskService; | ||
| 5 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; | ||
| 6 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; | ||
| 7 | import org.springframework.web.bind.annotation.*; | ||
| 8 | |||
| 9 | import javax.annotation.Resource; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author lirenhao | ||
| 13 | * date: 2022/8/31 17:53 | ||
| 14 | */ | ||
| 15 | @RestController | ||
| 16 | @RequestMapping("/task-manager/v1/tasks") | ||
| 17 | public class TaskFacade { | ||
| 18 | |||
| 19 | @Resource | ||
| 20 | private TaskService taskService; | ||
| 21 | |||
| 22 | @PostMapping | ||
| 23 | public ApiResponse<String> createTask(@RequestBody TaskCreateRequest request) { | ||
| 24 | return ApiResponse.ok(taskService.createTask(request)); | ||
| 25 | } | ||
| 26 | |||
| 27 | @GetMapping("/{taskId}") | ||
| 28 | public ApiResponse<TaskVO> getTask(@PathVariable("taskId") String taskId) { | ||
| 29 | return ApiResponse.ok(taskService.getTask(taskId)); | ||
| 30 | } | ||
| 31 | |||
| 32 | /* todo 设备上报任务状态 */ | ||
| 33 | } |
| 1 | package com.ql.backend.taskmanager.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.Data; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author lirenhao | ||
| 9 | * date: 2022/8/31 18:13 | ||
| 10 | */ | ||
| 11 | @Data | ||
| 12 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 13 | public class TaskCreateRequest { | ||
| 14 | |||
| 15 | /** | ||
| 16 | * 店铺ID | ||
| 17 | */ | ||
| 18 | private String shopId; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * 策略ID | ||
| 22 | */ | ||
| 23 | private String ployId; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 任务参数 | ||
| 27 | */ | ||
| 28 | private String taskParam; | ||
| 29 | } |
ql-backend-taskmanager/src/main/java/com/ql/backend/taskmanager/interfaces/vo/TaskVO.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.interfaces.vo; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Builder; | ||
| 7 | import lombok.Data; | ||
| 8 | import lombok.NoArgsConstructor; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/8/31 18:17 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @Builder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class TaskVO { | ||
| 20 | |||
| 21 | private String taskId; | ||
| 22 | } |
-
Please register or sign in to post a comment