Skip to content

Commit

Permalink
开始启动自用的脚手架和Enable集合
Browse files Browse the repository at this point in the history
  • Loading branch information
vector4wang committed Sep 14, 2023
1 parent 058517d commit e3accf3
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 4 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module>quick-sse</module>
<module>quick-multi-api-invoker</module>
<module>quick-abstract-template</module>
<module>quick-platform-component</module>
</modules>
<packaging>pom</packaging>
<description>使用springboot框架做的一些例子,做个记录,以后方便即拿即用</description>
Expand Down
7 changes: 7 additions & 0 deletions quick-log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.quick.component</groupId>
<artifactId>quick-platform-component</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions quick-log/src/main/java/com/quick/log/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quick.log;

import com.quick.component.enables.EnableGlobalExceptionHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
Expand All @@ -13,6 +14,7 @@
*/
@SpringBootApplication
@EnableScheduling
@EnableGlobalExceptionHandler
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.quick.log.controller;

import com.quick.log.service.LoggerService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
Expand Down Expand Up @@ -52,5 +49,11 @@ public String ss() {
return "123";
}

@GetMapping("/exception")
public String exce() {
System.out.println("异常");
throw new IllegalArgumentException("异常了");
}


}
38 changes: 38 additions & 0 deletions quick-platform-component/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
40 changes: 40 additions & 0 deletions quick-platform-component/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>quick-platform</artifactId>
<groupId>com.quick</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../quick-platform/pom.xml</relativePath>
</parent>

<groupId>com.quick.component</groupId>
<artifactId>quick-platform-component</artifactId>
<packaging>jar</packaging>

<name>quick-platform-component</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.quick.component;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.quick.component.common;

import java.util.Date;

/**
* @param <T>
*/
public class BaseResp<T> {
/**
* 返回码
*/
private int code;

/**
* 返回信息描述
*/
private String message;

/**
* 返回数据
*/
private T data;

private long currentTime;

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Object getData() {
return data;
}

public void setData(T data) {
this.data = data;
}

public long getCurrentTime() {
return currentTime;
}

public void setCurrentTime(long currentTime) {
this.currentTime = currentTime;
}

public BaseResp(){}

/**
*
* @param code 错误码
* @param message 信息
* @param data 数据
*/
public BaseResp(int code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
this.currentTime = new Date().getTime();
}

/**
* 不带数据的返回结果
* @param resultStatus
*/
public BaseResp(ResultStatus resultStatus) {
this.code = resultStatus.getErrorCode();
this.message = resultStatus.getErrorMsg();
this.data = data;
this.currentTime = new Date().getTime();
}

/**
* 带数据的返回结果
* @param resultStatus
* @param data
*/
public BaseResp(ResultStatus resultStatus, T data) {
this.code = resultStatus.getErrorCode();
this.message = resultStatus.getErrorMsg();
this.data = data;
this.currentTime = new Date().getTime();
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.quick.component.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
错误码
* @author vector
*
*/
public enum ResultStatus {

// -1为通用失败(根据ApiResult.java中的构造方法注释而来)
FAIL(-1, "common fail"),
// 0为成功
SUCCESS(0, "success"),

error_pic_file(3,"非法图片文件"),
error_pic_upload(4,"图片上传失败"),
error_record_not_found(5, "没有找到对应的数据"),
error_max_page_size(6, "请求记录数超出每次请求最大允许值"),
error_create_failed(7,"新增失败"),
error_update_failed(8,"修改失败"),
error_delete_failed(9,"删除失败"),
error_search_failed(10,"查询失败"),
error_count_failed(11,"查询数据总数失败"),
error_string_to_obj(12,"字符串转java对象失败"),
error_invalid_argument(13,"参数不合法"),
error_update_not_allowed(14,"更新失败:%s"),
error_duplicated_data(15,"数据已存在"),
error_unknown_database_operation(16,"未知数据库操作失败,请联系管理员解决"),
error_column_unique(17,"字段s%违反唯一约束性条件"),
error_file_download(18,"文件下载失败"),
error_file_upload(19,"文件上传失败"),

//100-511为http 状态码
// --- 4xx Client Error ---
http_status_bad_request(400, "Bad Request"),
http_status_unauthorized(401, "Unauthorized"),
http_status_payment_required(402, "Payment Required"),
http_status_forbidden(403, "Forbidden"),
http_status_not_found(404, "Not Found"),
http_status_method_not_allowed(405, "Method Not Allowed"),
http_status_not_acceptable(406, "Not Acceptable"),
http_status_proxy_authentication_required(407, "Proxy Authentication Required"),
http_status_request_timeout(408, "Request Timeout"),
http_status_conflict(409, "Conflict"),
http_status_gone(410, "Gone"),
http_status_length_required(411, "Length Required"),
http_status_precondition_failed(412, "Precondition Failed"),
http_status_payload_too_large(413, "Payload Too Large"),
http_status_uri_too_long(414, "URI Too Long"),
http_status_unsupported_media_type(415, "Unsupported Media Type"),
http_status_requested_range_not_satisfiable(416, "Requested range not satisfiable"),
http_status_expectation_failed(417, "Expectation Failed"),
http_status_im_a_teapot(418, "I'm a teapot"),
http_status_unprocessable_entity(422, "Unprocessable Entity"),
http_status_locked(423, "Locked"),
http_status_failed_dependency(424, "Failed Dependency"),
http_status_upgrade_required(426, "Upgrade Required"),
http_status_precondition_required(428, "Precondition Required"),
http_status_too_many_requests(429, "Too Many Requests"),
http_status_request_header_fields_too_large(431, "Request Header Fields Too Large"),

// --- 5xx Server Error ---
http_status_internal_server_error(500, "系统错误"),
http_status_not_implemented(501, "Not Implemented"),
http_status_bad_gateway(502, "Bad Gateway"),
http_status_service_unavailable(503, "Service Unavailable"),
http_status_gateway_timeout(504, "Gateway Timeout"),
http_status_http_version_not_supported(505, "HTTP Version not supported"),
http_status_variant_also_negotiates(506, "Variant Also Negotiates"),
http_status_insufficient_storage(507, "Insufficient Storage"),
http_status_loop_detected(508, "Loop Detected"),
http_status_bandwidth_limit_exceeded(509, "Bandwidth Limit Exceeded"),
http_status_not_extended(510, "Not Extended"),
http_status_network_authentication_required(511, "Network Authentication Required"),

// --- 8xx common error ---
EXCEPTION(800, "exception"),
INVALID_PARAM(801, "invalid.param"),
INVALID_PRIVI(802, "invalid.privi"),

//1000以内是系统错误,
no_login(1000,"没有登录"),
config_error(1001,"参数配置表错误"),
user_exist(1002,"用户名已存在"),
userpwd_not_exist(1003,"用户名不存在或者密码错误"),




;
private static final Logger LOGGER = LoggerFactory.getLogger(ResultStatus.class);


private int code;
private String msg;

ResultStatus(int code, String msg){
this.code = code;
this.msg = msg;
}

public static int getCode(String define){
try {
return ResultStatus.valueOf(define).code;
} catch (IllegalArgumentException e) {
LOGGER.error("undefined error code: {}", define);
return FAIL.getErrorCode();
}
}

public static String getMsg(String define){
try {
return ResultStatus.valueOf(define).msg;
} catch (IllegalArgumentException e) {
LOGGER.error("undefined error code: {}", define);
return FAIL.getErrorMsg();
}

}

public static String getMsg(int code){
for(ResultStatus err : ResultStatus.values()){
if(err.code==code){
return err.msg;
}
}
return "errorCode not defined ";
}

public int getErrorCode(){
return code;
}

public String getErrorMsg(){
return msg;
}

}

Loading

0 comments on commit e3accf3

Please sign in to comment.