diff --git a/jcommon/infra-common/pom.xml b/jcommon/infra-common/pom.xml new file mode 100644 index 000000000..1f60d6bda --- /dev/null +++ b/jcommon/infra-common/pom.xml @@ -0,0 +1,18 @@ + + + + jcommon + run.mone + 1.4-SNAPSHOT + + 4.0.0 + + infra-common + + + UTF-8 + + + \ No newline at end of file diff --git a/jcommon/infra-common/src/main/java/run/mone/common/ErrorCode.java b/jcommon/infra-common/src/main/java/run/mone/common/ErrorCode.java new file mode 100644 index 000000000..80693a212 --- /dev/null +++ b/jcommon/infra-common/src/main/java/run/mone/common/ErrorCode.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Xiaomi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package run.mone.common; + +/** + * @author shanwb + * @date 2023-08-16 + */ +public class ErrorCode { + public static final int SUCCESS = 0; + + public static final int PARAM_ERROR = 400; + public static final int INTERNAL_ERROR = 500; + + public ErrorCode() { + } +} diff --git a/jcommon/infra-common/src/main/java/run/mone/common/Result.java b/jcommon/infra-common/src/main/java/run/mone/common/Result.java new file mode 100644 index 000000000..aedec4f9d --- /dev/null +++ b/jcommon/infra-common/src/main/java/run/mone/common/Result.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020 Xiaomi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package run.mone.common; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author shanwb + * @date 2023-08-16 + */ +@Data +public class Result implements Serializable { + private int code; + private String message; + private T data; + private String traceId; + private Map attributes; + + public Result(int code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + public Result(int code, String message, T data, String traceId) { + this.code = code; + this.message = message; + this.data = data; + this.traceId = traceId; + } + + public static Result success(T data) { + return new Result(ErrorCode.SUCCESS, "success", data); + } + + public static Result fail(int code, String message) { + return new Result(code, message, null); + } + + public static Result fromException(Throwable e) { + return fail(ErrorCode.INTERNAL_ERROR, e.getMessage()); + } + + @Override + public String toString() { + return "Result{" + + "code=" + code + + ", message='" + message + '\'' + + ", data=" + data + + ", traceId='" + traceId + '\'' + + ", attributes=" + attributes + + '}'; + } +} diff --git a/jcommon/pom.xml b/jcommon/pom.xml index 337323d66..624e2dd70 100644 --- a/jcommon/pom.xml +++ b/jcommon/pom.xml @@ -96,6 +96,7 @@ openai excel match + infra-common diff --git a/jcommon/test/src/main/java/com/xiaomi/youpin/test/codefilter/c/test-1.4-SNAPSHOT.jar b/jcommon/test/src/main/java/com/xiaomi/youpin/test/codefilter/c/test-1.4-SNAPSHOT.jar deleted file mode 100644 index 5f0bb22b4..000000000 --- a/jcommon/test/src/main/java/com/xiaomi/youpin/test/codefilter/c/test-1.4-SNAPSHOT.jar +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f9df4eae49d52c33425d54fd6351ee7d7928fa91f37c87189408f44411348ffc -size 41064