forked from rayoy/seckill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
588 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.seckill.dto; | ||
|
||
/** | ||
* 暴露秒杀地址DTO | ||
* Created by wchb7 on 16-5-13. | ||
*/ | ||
public class Exposer { | ||
|
||
/** | ||
* 秒杀是否开启 | ||
*/ | ||
private boolean exposed; | ||
|
||
|
||
private String md5; | ||
|
||
private long seckillId; | ||
|
||
/** | ||
* 系统时间(毫秒) | ||
*/ | ||
private long now; | ||
|
||
private long start; | ||
|
||
private long end; | ||
|
||
public Exposer(boolean exposed, String md5, long seckillId) { | ||
this.exposed = exposed; | ||
this.md5 = md5; | ||
this.seckillId = seckillId; | ||
} | ||
|
||
public Exposer(boolean exposed, long seckillId, long now, long start, long end) { | ||
this.exposed = exposed; | ||
this.seckillId = seckillId; | ||
this.now = now; | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public Exposer(boolean exposed, long seckillId) { | ||
this.exposed = exposed; | ||
this.seckillId = seckillId; | ||
} | ||
|
||
public boolean isExposed() { | ||
return exposed; | ||
} | ||
|
||
public void setExposed(boolean exposed) { | ||
this.exposed = exposed; | ||
} | ||
|
||
public String getMd5() { | ||
return md5; | ||
} | ||
|
||
public void setMd5(String md5) { | ||
this.md5 = md5; | ||
} | ||
|
||
public long getSeckillId() { | ||
return seckillId; | ||
} | ||
|
||
public void setSeckillId(long seckillId) { | ||
this.seckillId = seckillId; | ||
} | ||
|
||
public long getNow() { | ||
return now; | ||
} | ||
|
||
public void setNow(long now) { | ||
this.now = now; | ||
} | ||
|
||
public long getStart() { | ||
return start; | ||
} | ||
|
||
public void setStart(long start) { | ||
this.start = start; | ||
} | ||
|
||
public long getEnd() { | ||
return end; | ||
} | ||
|
||
public void setEnd(long end) { | ||
this.end = end; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Exposer{" + | ||
"exposed=" + exposed + | ||
", md5='" + md5 + '\'' + | ||
", seckillId=" + seckillId + | ||
", now=" + now + | ||
", start=" + start + | ||
", end=" + end + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.seckill.dto; | ||
|
||
import org.seckill.entity.SuccessKilled; | ||
import org.seckill.enums.SeckillStatEnum; | ||
|
||
/** | ||
* 封装秒杀执行后的结果 | ||
* Created by wchb7 on 16-5-13. | ||
*/ | ||
public class SeckillExecution { | ||
|
||
|
||
private long seckillId; | ||
|
||
/** | ||
* 秒杀执行结果状态 | ||
*/ | ||
private int state; | ||
|
||
/** | ||
* 状态表示 | ||
*/ | ||
private String stateInfo; | ||
|
||
private SuccessKilled successKilled; | ||
|
||
public long getSeckillId() { | ||
return seckillId; | ||
} | ||
|
||
public void setSeckillId(long seckillId) { | ||
this.seckillId = seckillId; | ||
} | ||
|
||
public int getState() { | ||
return state; | ||
} | ||
|
||
public void setState(int state) { | ||
this.state = state; | ||
} | ||
|
||
public String getStateInfo() { | ||
return stateInfo; | ||
} | ||
|
||
public void setStateInfo(String stateInfo) { | ||
this.stateInfo = stateInfo; | ||
} | ||
|
||
public SuccessKilled getSuccessKilled() { | ||
return successKilled; | ||
} | ||
|
||
public void setSuccessKilled(SuccessKilled successKilled) { | ||
this.successKilled = successKilled; | ||
} | ||
|
||
|
||
public SeckillExecution(long seckillId, SeckillStatEnum statEnum, String stateInfo) { | ||
this.seckillId = seckillId; | ||
this.state = statEnum.getState(); | ||
this.stateInfo = statEnum.getStateInfo(); | ||
this.stateInfo = stateInfo; | ||
} | ||
|
||
public SeckillExecution(long seckillId, SeckillStatEnum statEnum, SuccessKilled successKilled) { | ||
this.seckillId = seckillId; | ||
this.state = statEnum.getState(); | ||
this.stateInfo = statEnum.getStateInfo(); | ||
this.successKilled = successKilled; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SeckillExecution{" + | ||
"seckillId=" + seckillId + | ||
", state=" + state + | ||
", stateInfo='" + stateInfo + '\'' + | ||
", successKilled=" + successKilled + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.seckill.enums; | ||
|
||
/** | ||
* Created by wchb7 on 16-5-14. | ||
*/ | ||
public enum SeckillStatEnum { | ||
SUCCESS(1, "秒杀成功"), | ||
END(0, "秒杀结束"), | ||
REPEAT_KILL(-1, "重复秒杀"), | ||
INNER_ERROR(-2, "系统异常"), | ||
DATA_REWRITE(-3, "数据篡改"); | ||
|
||
private int state; | ||
|
||
private String stateInfo; | ||
|
||
SeckillStatEnum(int state, String stateInfo) { | ||
this.state = state; | ||
this.stateInfo = stateInfo; | ||
} | ||
|
||
public int getState() { | ||
return state; | ||
} | ||
|
||
public String getStateInfo() { | ||
return stateInfo; | ||
} | ||
|
||
public static SeckillStatEnum stateOf(int index) { | ||
for (SeckillStatEnum state : values()) { | ||
if (state.getState() == index) { | ||
return state; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/seckill/exception/RepeatKillException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.seckill.exception; | ||
|
||
/** | ||
* 重复秒杀异常(运行期异常) | ||
* RuntimeException 不需要try/catch 而且Spring 的声明式事务只接收RuntimeException回滚策略. | ||
* Created by wchb7 on 16-5-14. | ||
*/ | ||
public class RepeatKillException extends SeckillException { | ||
|
||
public RepeatKillException(String message) { | ||
super(message); | ||
} | ||
|
||
public RepeatKillException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/seckill/exception/SeckillCloseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.seckill.exception; | ||
|
||
/** | ||
* Created by wchb7 on 16-5-14. | ||
*/ | ||
public class SeckillCloseException extends SeckillException { | ||
|
||
public SeckillCloseException(String message) { | ||
super(message); | ||
} | ||
|
||
public SeckillCloseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.seckill.exception; | ||
|
||
/** | ||
* 秒杀相关业务异常 | ||
* Created by wchb7 on 16-5-14. | ||
*/ | ||
public class SeckillException extends RuntimeException { | ||
|
||
public SeckillException(String message) { | ||
super(message); | ||
} | ||
|
||
public SeckillException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.