19 changed files with 360 additions and 236 deletions
@ -0,0 +1,50 @@ |
|||
package com.huaxing.common.result; |
|||
|
|||
import com.huaxing.common.constant.AppConstant; |
|||
import lombok.Getter; |
|||
import lombok.ToString; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
@Getter |
|||
@ToString |
|||
public abstract class BaseException extends RuntimeException { |
|||
|
|||
private static final Logger Logger = LoggerFactory.getLogger(BizException.class); |
|||
|
|||
protected final String code; |
|||
|
|||
protected Object data; |
|||
|
|||
protected BaseException(String code, String message) { |
|||
super(message); |
|||
if (code == null){ |
|||
this.code = AppConstant.CODE_BIZ; |
|||
}else { |
|||
this.code = code; |
|||
} |
|||
} |
|||
|
|||
public final void print(){ |
|||
Logger.error("exception info print: start"); |
|||
Logger.error(this.getMessage(),this); |
|||
Logger.error("data:{}", data); |
|||
Logger.error("exception info print: end"); |
|||
} |
|||
|
|||
public final BaseException setData(Object data){ |
|||
this.data = data; |
|||
return this; |
|||
} |
|||
|
|||
public final <D> D getData(){ |
|||
return (D)data; |
|||
} |
|||
|
|||
protected static String buildMsg(String msg,String hint){ |
|||
if (hint != null){ |
|||
msg = msg + ":" + hint; |
|||
} |
|||
return msg; |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.huaxing.common.result; |
|||
|
|||
import com.huaxing.common.constant.AppConstant; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
public class BizException extends BaseException { |
|||
|
|||
private BizException(String msg) { |
|||
super(AppConstant.CODE_BIZ, msg); |
|||
} |
|||
|
|||
/** tag!(msg:hint) */ |
|||
public static BizException custom(String tag, String msg, String hint){ |
|||
return BizException.custom(tag,BaseException.buildMsg(msg,hint)); |
|||
} |
|||
/** tag!(msg) */ |
|||
public static BizException custom(String tag, String msg){ |
|||
if (!StringUtils.isEmpty(msg)){ |
|||
tag += "!(" + msg + ")"; |
|||
} |
|||
return new BizException(tag); |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
package com.huaxing.common.result; |
|||
|
|||
import com.huaxing.common.constant.AppConstant; |
|||
import lombok.Getter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@Getter |
|||
public class ResultVo<T> implements Serializable { |
|||
|
|||
final String code; |
|||
|
|||
final String msg; |
|||
|
|||
final T data; |
|||
|
|||
private ResultVo(String code, String msg, T data) { |
|||
this.code = code; |
|||
this.msg = msg; |
|||
this.data = data; |
|||
} |
|||
|
|||
private ResultVo(BaseException exception) { |
|||
this.code = exception.getCode(); |
|||
this.msg = exception.getMessage(); |
|||
this.data = exception.getData(); |
|||
} |
|||
|
|||
public static ResultVo<?> ok() { |
|||
return ResultVo.ok(null); |
|||
} |
|||
|
|||
public static <D> ResultVo<D> ok(D data) { |
|||
return new ResultVo<>(AppConstant.REQUEST_SUCCESS_CODE,"操作成功!",data); |
|||
} |
|||
|
|||
public static <D> ResultVo<D> ok(String msg,D data) { |
|||
return new ResultVo<>(AppConstant.REQUEST_SUCCESS_CODE,msg,data); |
|||
} |
|||
|
|||
public static ResultVo<?> fail(String msg) { |
|||
return ResultVo.fail(msg,null); |
|||
} |
|||
|
|||
public static <D> ResultVo<D> fail(String msg,D data) { |
|||
return new ResultVo<>(AppConstant.REQUEST_CODE_FAIL,msg,data); |
|||
} |
|||
|
|||
public static <D> ResultVo<D> fail(BaseException exception) { |
|||
return new ResultVo<>(exception); |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.huaxing.data.api.controller; |
|||
|
|||
import com.huaxing.data.api.domain.DataQueryDTO; |
|||
import com.huaxing.common.result.ResultVo; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ProjectName: data-bridge |
|||
* @Package: com.huaxing.data.api.controller |
|||
* @ClassName: DataQueryController |
|||
* @Author: swordmeng8@163.com |
|||
* @Description: 数据查询控制器 |
|||
* @Date: 2025/1/20 16:02 |
|||
* @Version: 1.0 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/data") |
|||
public class DataQueryController { |
|||
|
|||
// TODO 查询方法
|
|||
@PostMapping("/query") |
|||
public ResultVo<Map<String, Object>> query(DataQueryDTO queryDTO) { |
|||
return ResultVo.ok(null); |
|||
} |
|||
|
|||
|
|||
} |
@ -1,10 +1,9 @@ |
|||
package com.huaxing.data.storage.domain; |
|||
package com.huaxing.data.api.domain; |
|||
|
|||
import lombok.Data; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ProjectName: iot-data-bridge |
@ -1,5 +1,7 @@ |
|||
server: |
|||
port: 8088 |
|||
servlet: |
|||
context-path: /api |
|||
spring: |
|||
profiles: |
|||
active: dev |
@ -1,7 +1,9 @@ |
|||
######## ### ######## ### ###### ######## ####### ######## ### ###### ######## |
|||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
## ## ## ## ## ## ## ####### ###### ## ## ## ######## ## ## ## #### ###### |
|||
## ## ######### ## ######### ## ## ## ## ## ## ######### ## ## ## |
|||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
######## ## ## ## ## ## ###### ## ####### ## ## ## ## ###### ######## |
|||
${AnsiColor.BLUE} ######## ### ######## ### ###### ######## ####### ######## ### ###### ######## |
|||
${AnsiColor.BLUE} ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
${AnsiColor.BLUE} ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
${AnsiColor.BLUE} ## ## ## ## ## ## ## ####### ###### ## ## ## ######## ## ## ## #### ###### |
|||
${AnsiColor.BLUE} ## ## ######### ## ######### ## ## ## ## ## ## ######### ## ## ## |
|||
${AnsiColor.BLUE} ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## |
|||
${AnsiColor.BLUE} ######## ## ## ## ## ## ###### ## ####### ## ## ## ## ###### ######## |
|||
${AnsiColor.BRIGHT_GREEN}Spring Boot Version: ${spring-boot.version} |
|||
${AnsiColor.BRIGHT_YELLOW}Application Version: ${application.version} |
Loading…
Reference in new issue