mirror of
https://github.com/qiurunze123/miaosha.git
synced 2023-11-19 22:41:03 +08:00
提交规范
This commit is contained in:
parent
7d326a0f64
commit
5c54a07abd
|
@ -14,6 +14,8 @@
|
|||
|
||||
### 秒杀高并发架构 -- 架构图
|
||||
|
||||
> 软件环境 : 请选择稳定版
|
||||
|
||||
![整体流程](https://raw.githubusercontent.com/qiurunze123/imageall/master/miaosha.png)
|
||||
|
||||
#### [提交合并代码规范](/docs/code-criterion.md)
|
||||
|
|
|
@ -94,3 +94,15 @@
|
|||
void garnish(List<Strawberry> strawberries) { ... }
|
||||
}
|
||||
13.**类名应该是名词不应该是动词,使用普遍的被大众理解的词**<br>
|
||||
14.**请勿抛异常直接返回**<br>
|
||||
|
||||
类似如下规范
|
||||
Result result=Result.build();
|
||||
boolean isChecking = redisServiceUtil.getIsCheckingOfAutomatedLoanService();
|
||||
result.setValue(isChecking);
|
||||
if (isChecking) {
|
||||
logger.info("--- isSystemChecking ---系统清算中-----");
|
||||
result.withError(ResultMsgStatus.SYSTEM_CHECKING.getMessage());
|
||||
}
|
||||
return result;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.geekq.miaosha.common.resultbean;
|
||||
|
||||
import com.geekq.miaosha.common.enums.ResultStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Result<T> 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 <T> Result<T> build() {
|
||||
return new Result(ResultStatus.SUCCESS, (String)null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user