diff --git a/README.md b/README.md index 550d0cf..363aa04 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ ### 秒杀高并发架构 -- 架构图 +> 软件环境 : 请选择稳定版 + ![整体流程](https://raw.githubusercontent.com/qiurunze123/imageall/master/miaosha.png) #### [提交合并代码规范](/docs/code-criterion.md) diff --git a/docs/code-criterion.md b/docs/code-criterion.md index cb50693..5af8f0f 100644 --- a/docs/code-criterion.md +++ b/docs/code-criterion.md @@ -94,3 +94,15 @@ void garnish(List strawberries) { ... } } 13.**类名应该是名词不应该是动词,使用普遍的被大众理解的词**
+14.**请勿抛异常直接返回**
+ + 类似如下规范 + Result result=Result.build(); + boolean isChecking = redisServiceUtil.getIsCheckingOfAutomatedLoanService(); + result.setValue(isChecking); + if (isChecking) { + logger.info("--- isSystemChecking ---系统清算中-----"); + result.withError(ResultMsgStatus.SYSTEM_CHECKING.getMessage()); + } + return result; + diff --git a/src/main/java/com/geekq/miaosha/common/enums/ResultStatus.java b/src/main/java/com/geekq/miaosha/common/enums/ResultStatus.java new file mode 100644 index 0000000..170a0fa --- /dev/null +++ b/src/main/java/com/geekq/miaosha/common/enums/ResultStatus.java @@ -0,0 +1,52 @@ +package com.geekq.miaosha.common.enums; + +public enum ResultStatus { + SUCCESS(0, "成功"), + FAILD(-1, "失败"), + EXCEPTION(-1, "系统异常"), + PARAM_ERROR(1000, "参数错误"), + SYSTEM_ERROR(1001, "系统错误"), + FILE_NOT_EXIST(1001, "文件不存在"), + FILE_NOT_DOWNLOAD(1002, "文件没有下载"), + FILE_NOT_GENERATE(1003, "文件没有生成"), + FILE_NOT_STORAGE(1004, "文件没有入库"), + SYSTEM_DB_ERROR(1005, "数据库系统错误"), + FILE_ALREADY_DOWNLOAD(1003, "文件已经下载"), + DATA_ALREADY_PEXISTS(1006, "数据已经存在"); + + private int code; + private String message; + + private ResultStatus(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return this.code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return this.message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getName() { + return this.name(); + } + + public String getOutputName() { + return this.name(); + } + + public String toString() { + return this.getName(); + } +} diff --git a/src/main/java/com/geekq/miaosha/common/resultbean/AbstractResult.java b/src/main/java/com/geekq/miaosha/common/resultbean/AbstractResult.java new file mode 100644 index 0000000..31b2ea2 --- /dev/null +++ b/src/main/java/com/geekq/miaosha/common/resultbean/AbstractResult.java @@ -0,0 +1,56 @@ +package com.geekq.miaosha.common.resultbean; + +import com.geekq.miaosha.common.enums.ResultStatus; + +public class AbstractResult { + private ResultStatus status; + private int code; + private String message; + + protected AbstractResult(ResultStatus status, String message) { + this.status = status; + this.message = message; + } + + public static boolean isSuccess(AbstractResult result) { + return result != null && result.status == ResultStatus.SUCCESS && result.getCode() == ResultStatus.SUCCESS.getCode(); + } + + public AbstractResult withError(ResultStatus status) { + this.status = status; + return this; + } + + public AbstractResult withError(String message) { + this.status = ResultStatus.SYSTEM_ERROR; + this.message = message; + return this; + } + + public AbstractResult withError(int code, String message) { + this.code = code; + this.message = message; + return this; + } + + public AbstractResult success() { + this.status = ResultStatus.SUCCESS; + return this; + } + + public ResultStatus getStatus() { + return this.status; + } + + public String getMessage() { + return this.message == null ? this.status.getMessage() : this.message; + } + + public int getCode() { + return this.code; + } + + public void setCode(int code) { + this.code = code; + } +} diff --git a/src/main/java/com/geekq/miaosha/common/resultbean/Result.java b/src/main/java/com/geekq/miaosha/common/resultbean/Result.java new file mode 100644 index 0000000..87ecdc2 --- /dev/null +++ b/src/main/java/com/geekq/miaosha/common/resultbean/Result.java @@ -0,0 +1,45 @@ +package com.geekq.miaosha.common.resultbean; + +import com.geekq.miaosha.common.enums.ResultStatus; + +import java.io.Serializable; + +public class Result extends AbstractResult implements Serializable { + private static final long serialVersionUID = 867933019328199779L; + private T value; + private Integer count; + + protected Result(ResultStatus status, String message) { + super(status, message); + } + + public static Result build() { + return new Result(ResultStatus.SUCCESS, (String)null); + } + + public static Result build(String message) { + return new Result(ResultStatus.SUCCESS, message); + } + + public T getValue() { + return this.value; + } + + public void setValue(T value) { + this.value = value; + } + + public Integer getCount() { + return this.count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public void success(T value) { + this.success(); + this.value = value; + this.count = 0; + } +}