feat(shared): add BaseEntity and ApiResponse
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<artifactId>mybatis-plus-annotation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
package com.sino.mci.shared.entity;
|
||||
|
||||
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.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public abstract class BaseEntity {
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
package com.sino.mci.shared.web;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ApiResponse<T> {
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
private T data;
|
||||
private String requestId;
|
||||
private static final int SUCCESS_CODE = 0;
|
||||
private static final String SUCCESS_MESSAGE = "ok";
|
||||
|
||||
private static final int DEFAULT_FAIL_CODE = -1;
|
||||
private static final String DEFAULT_FAIL_MESSAGE = "fail";
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
private final T data;
|
||||
|
||||
public static <T> ApiResponse<T> ok() {
|
||||
return ok(null);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> ok(T data) {
|
||||
ApiResponse<T> response = new ApiResponse<>();
|
||||
response.setCode(0);
|
||||
response.setMessage("ok");
|
||||
response.setData(data);
|
||||
return response;
|
||||
return new ApiResponse<>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> fail() {
|
||||
return fail(DEFAULT_FAIL_CODE, DEFAULT_FAIL_MESSAGE);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> fail(int code, String message) {
|
||||
ApiResponse<T> response = new ApiResponse<>();
|
||||
response.setCode(code);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
return new ApiResponse<>(code, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,21 @@
|
||||
<description>Message & Customer Interaction Platform</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mybatis-plus.version>3.5.7</mybatis-plus.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>mci-shared</module>
|
||||
<module>mci-server</module>
|
||||
<module>mci-channel-common</module>
|
||||
<module>mci-channel-wecom</module>
|
||||
<module>mci-channel-dingtalk</module>
|
||||
<module>mci-channel-feishu</module>
|
||||
<module>mci-channel-ivr</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -47,6 +53,11 @@
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-annotation</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user