Commit b2e74712855c818315b494e5235ee9a2f5ac7c4d
1 parent
ace3690a
fix code use String
Showing
9 changed files
with
37 additions
and
32 deletions
cashier-assistant/src/main/java/com/diligrp/cashier/assistant/exception/AssistantServiceException.java
| ... | ... | @@ -7,7 +7,7 @@ public class AssistantServiceException extends PlatformServiceException { |
| 7 | 7 | super(message); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public AssistantServiceException(int code, String message) { | |
| 10 | + public AssistantServiceException(String code, String message) { | |
| 11 | 11 | super(code, message); |
| 12 | 12 | } |
| 13 | 13 | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/ErrorCode.java
| ... | ... | @@ -5,23 +5,23 @@ package com.diligrp.cashier.shared; |
| 5 | 5 | */ |
| 6 | 6 | public class ErrorCode { |
| 7 | 7 | // 系统未知异常 |
| 8 | - public static final int SYSTEM_UNKNOWN_ERROR = 300000; | |
| 8 | + public static final String SYSTEM_UNKNOWN_ERROR = "300000"; | |
| 9 | 9 | // 无效参数错误 |
| 10 | - public static final int ILLEGAL_ARGUMENT_ERROR = 300001; | |
| 10 | + public static final String ILLEGAL_ARGUMENT_ERROR = "300001"; | |
| 11 | 11 | // 访问未授权 |
| 12 | - public static final int UNAUTHORIZED_ACCESS_ERROR = 300002; | |
| 12 | + public static final String UNAUTHORIZED_ACCESS_ERROR = "300002"; | |
| 13 | 13 | // 操作不允许 |
| 14 | - public static final int OPERATION_NOT_ALLOWED = 300003; | |
| 14 | + public static final String OPERATION_NOT_ALLOWED = "300003"; | |
| 15 | 15 | // 对象不存在 |
| 16 | - public static final int OBJECT_NOT_FOUND = 300004; | |
| 16 | + public static final String OBJECT_NOT_FOUND = "300004"; | |
| 17 | 17 | // 对象已存在 |
| 18 | - public static final int OBJECT_ALREADY_EXISTS = 300005; | |
| 18 | + public static final String OBJECT_ALREADY_EXISTS = "300005"; | |
| 19 | 19 | // 数据并发修改 |
| 20 | - public static final int SYSTEM_BUSY_ERROR = 301000; | |
| 20 | + public static final String SYSTEM_BUSY_ERROR = "301000"; | |
| 21 | 21 | // 无效对象状态 |
| 22 | - public static final int INVALID_OBJECT_STATE = 301001; | |
| 22 | + public static final String INVALID_OBJECT_STATE = "301001"; | |
| 23 | 23 | // 远程服务访问错误 |
| 24 | - public static final int SERVICE_ACCESS_ERROR = 301002; | |
| 24 | + public static final String SERVICE_ACCESS_ERROR = "301002"; | |
| 25 | 25 | |
| 26 | 26 | public static final String MESSAGE_UNKNOWN_ERROR = "收银台系统未知异常,请联系管理员"; |
| 27 | 27 | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/domain/Message.java
| ... | ... | @@ -3,27 +3,27 @@ package com.diligrp.cashier.shared.domain; |
| 3 | 3 | import com.diligrp.cashier.shared.ErrorCode; |
| 4 | 4 | |
| 5 | 5 | public class Message<T> { |
| 6 | - protected static final int CODE_SUCCESS = 200; | |
| 7 | - protected static final int CODE_FAILURE = ErrorCode.SYSTEM_UNKNOWN_ERROR; | |
| 6 | + protected static final String CODE_SUCCESS = "200"; | |
| 7 | + protected static final String CODE_FAILURE = ErrorCode.SYSTEM_UNKNOWN_ERROR; | |
| 8 | 8 | protected static final String MSG_SUCCESS = "success"; |
| 9 | 9 | |
| 10 | - private Integer code; | |
| 10 | + private String code; | |
| 11 | 11 | private String message; |
| 12 | 12 | private T data; |
| 13 | 13 | |
| 14 | 14 | public Message() { |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public Integer getCode() { | |
| 18 | - return this.code; | |
| 17 | + public String getCode() { | |
| 18 | + return code; | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public void setCode(Integer code) { | |
| 21 | + public void setCode(String code) { | |
| 22 | 22 | this.code = code; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public String getMessage() { |
| 26 | - return this.message; | |
| 26 | + return message; | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public void setMessage(String message) { |
| ... | ... | @@ -31,7 +31,7 @@ public class Message<T> { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public T getData() { |
| 34 | - return this.data; | |
| 34 | + return data; | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public void setData(T data) { |
| ... | ... | @@ -40,30 +40,30 @@ public class Message<T> { |
| 40 | 40 | |
| 41 | 41 | public static Message<?> success() { |
| 42 | 42 | Message<?> result = new Message<>(); |
| 43 | - result.code = 200; | |
| 44 | - result.message = "success"; | |
| 43 | + result.code = CODE_SUCCESS; | |
| 44 | + result.message = MSG_SUCCESS; | |
| 45 | 45 | return result; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public static <E> Message<E> success(E data) { |
| 49 | 49 | Message<E> result = new Message<>(); |
| 50 | - result.code = 200; | |
| 50 | + result.code = CODE_SUCCESS; | |
| 51 | 51 | result.data = data; |
| 52 | - result.message = "success"; | |
| 52 | + result.message = MSG_SUCCESS; | |
| 53 | 53 | return result; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public static Message<?> failure(String message) { |
| 57 | 57 | Message<?> result = new Message<>(); |
| 58 | - result.code = 1000; | |
| 58 | + result.code = CODE_FAILURE; | |
| 59 | 59 | result.message = message; |
| 60 | 60 | return result; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - public static Message<?> failure(int code, String message) { | |
| 63 | + public static Message<?> failure(String code, String message) { | |
| 64 | 64 | Message<?> result = new Message<>(); |
| 65 | 65 | result.code = code; |
| 66 | 66 | result.message = message; |
| 67 | 67 | return result; |
| 68 | 68 | } |
| 69 | -} | |
| 70 | 69 | \ No newline at end of file |
| 70 | +} | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/domain/PageMessage.java
| ... | ... | @@ -30,7 +30,7 @@ public class PageMessage<E> extends Message<List<E>>{ |
| 30 | 30 | return failure(CODE_FAILURE, message); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public static PageMessage<?> failure(int code, String message) { | |
| 33 | + public static PageMessage<?> failure(String code, String message) { | |
| 34 | 34 | PageMessage<?> page = new PageMessage<>(); |
| 35 | 35 | page.setCode(code); |
| 36 | 36 | page.setTotal(0); | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/exception/PlatformServiceException.java
| ... | ... | @@ -9,7 +9,7 @@ public class PlatformServiceException extends RuntimeException { |
| 9 | 9 | /** |
| 10 | 10 | * 错误码 |
| 11 | 11 | */ |
| 12 | - private int code = ErrorCode.SYSTEM_UNKNOWN_ERROR; | |
| 12 | + private String code = ErrorCode.SYSTEM_UNKNOWN_ERROR; | |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * 是否打印异常栈 |
| ... | ... | @@ -20,7 +20,7 @@ public class PlatformServiceException extends RuntimeException { |
| 20 | 20 | super(message); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public PlatformServiceException(int code, String message) { | |
| 23 | + public PlatformServiceException(String code, String message) { | |
| 24 | 24 | super(message); |
| 25 | 25 | this.code = code; |
| 26 | 26 | this.stackTrace = false; |
| ... | ... | @@ -35,7 +35,7 @@ public class PlatformServiceException extends RuntimeException { |
| 35 | 35 | return stackTrace ? super.fillInStackTrace() : this; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public int getCode() { | |
| 38 | + public String getCode() { | |
| 39 | 39 | return code; |
| 40 | 40 | } |
| 41 | 41 | } | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/exception/ServiceAccessException.java
| ... | ... | @@ -8,7 +8,7 @@ public class ServiceAccessException extends PlatformServiceException { |
| 8 | 8 | super(message); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | - public ServiceAccessException(int code, String message) { | |
| 11 | + public ServiceAccessException(String code, String message) { | |
| 12 | 12 | super(code, message); |
| 13 | 13 | } |
| 14 | 14 | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/exception/ServiceConnectException.java
| ... | ... | @@ -9,7 +9,7 @@ public class ServiceConnectException extends ServiceAccessException { |
| 9 | 9 | super(message); |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public ServiceConnectException(int code, String message) { | |
| 12 | + public ServiceConnectException(String code, String message) { | |
| 13 | 13 | super(code, message); |
| 14 | 14 | } |
| 15 | 15 | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/exception/ServiceTimeoutException.java
| ... | ... | @@ -9,7 +9,7 @@ public class ServiceTimeoutException extends ServiceAccessException { |
| 9 | 9 | super(message); |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public ServiceTimeoutException(int code, String message) { | |
| 12 | + public ServiceTimeoutException(String code, String message) { | |
| 13 | 13 | super(code, message); |
| 14 | 14 | } |
| 15 | 15 | ... | ... |
cashier-shared/src/main/java/com/diligrp/cashier/shared/util/JsonUtils.java
| ... | ... | @@ -102,6 +102,11 @@ public class JsonUtils { |
| 102 | 102 | return objectMapper.convertValue(value, typeReference); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | + public static <T> T convertValue(Object value, Class<T> type) { | |
| 106 | + return fromJsonString(toJsonString(value), type); | |
| 107 | + } | |
| 108 | + | |
| 109 | + | |
| 105 | 110 | public static <T> String toJsonString(T object) { |
| 106 | 111 | try { |
| 107 | 112 | return objectMapper.writeValueAsString(object); | ... | ... |