Commit ff9c5002 authored by zhangc's avatar zhangc

commit 删除gateway服务

parent 9e276215
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jz-dm-apigateway</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>jz-dm-parent</artifactId>
<groupId>com.jz.dm</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jz-dm-apigateway</artifactId>
<dependencies>
<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatis-plus自动的维护了mybatis以及mybatis-spring的依赖,
在springboot中这三者不能同时的出现,避免版本的冲突,表示:跳进过这个坑-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.20</version>
</dependency>
<!-- 提供mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--lang3工具类-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!--fastJson包-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>compile</scope>
</dependency>
<!-- swagger2接口文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<dependency>
<groupId>com.jz.common</groupId>
<artifactId>jz-dm-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- validation校验-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!--Sentinel 限流框架依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<!-- <version>0.9.0.RELEASE</version>-->
</dependency>
<!-- 客户端需要引入 Transport 模块来与 Sentinel 控制台进行通信 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parameter-flow-control</artifactId>
</dependency>
<!-- 开启注解 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-annotation-aspectj</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-webmvc-adapter</artifactId>
<version>1.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<classifier>jdk15</classifier><!-- jdk版本 -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<!-- 代码自动生成依赖 begin -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.1</version>
</dependency>
<!-- velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<!-- 代码自动生成依赖 end-->
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>static/**</exclude>
<exclude>xls/**</exclude>
<exclude>conf/**</exclude>
<exclude>emails/**</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>static/**</include>
<include>xls/**</include>
<include>conf/**</include>
<include>emails/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<!-- 过滤后缀为pem、pfx的证书文件 -->
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
<nonFilteredFileExtension>pem</nonFilteredFileExtension>
<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.jz.dm;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiGatewayApplication
* @DATE: 2020-12-2/16:03
* @DAY_NAME_SHORT: 周三
* @Description:
**/
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
@ComponentScan(basePackages = {"com.jz"})
@MapperScan("com.jz.dm.mapper")
@EnableTransactionManagement
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
package com.jz.dm.common.base;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.enity
* @PROJECT_NAME: jz-dm-parent
* @NAME: BaseObject
* @DATE: 2020-12-22/14:03
* @DAY_NAME_SHORT: 周二
* @Description: 日期处理公共类
**/
@Data
public class BaseObject implements Serializable {
/**
* 主健ID
*/
@ApiModelProperty("主健ID")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 创建日期
*/
@ApiModelProperty("创建日期")
@TableField("create_date")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createDate;
/**
* 创建人
*/
@ApiModelProperty("创建人")
@TableField("create_user")
private String createUser;
/**
* 更新人
*/
@ApiModelProperty("更新人")
@TableField("update_user")
private String updateUser;
/**
* 更新日期
*/
@ApiModelProperty("更新日期")
@TableField("update_date")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateDate;
/**
* 是否删除
*/
@TableField("is_deleted")
private Integer isDeleted;
/**
* 备注
*/
@TableField("remark")
private String remark;
}
package com.jz.dm.common.constant;
/**
* 常量
*
*/
public class Constants {
public static final String SIGN_TYPE_RSA = "RSA";
/**
* sha256WithRsa 算法请求类型
*/
public static final String SIGN_TYPE_RSA2 = "RSA2";
public static final String ENCRYPT_TYPE_AES = "AES";
public static final String APP_KEY = "app_key";
public static final String FORMAT = "format";
public static final String METHOD = "method";
public static final String TIMESTAMP = "timestamp";
public static final String VERSION = "version";
public static final String SIGN_TYPE = "sign_type";
public static final String SIGN = "sign";
public static final String CHARSET = "charset";
public static final String ENCRYPT_TYPE = "encrypt_type";
public static final String PARAMS = "params";
public static final String RESPONSE = "response";
public static final String SUCCESS = "SUCCESS";
/** 默认时间格式 **/
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/** Date默认时区 **/
public static final String DATE_TIMEZONE = "GMT+8";
/** UTF-8字符集 **/
public static final String CHARSET_UTF8 = "UTF-8";
/** GBK字符集 **/
public static final String CHARSET_GBK = "GBK";
/** JSON 应格式 */
public static final String FORMAT_JSON = "JSON";
/** 生成内部授权码格式 */
public static final String AUTH_INT = "INT";
/** 生成外部授权码格式 */
public static final String AUTH_OUT = "OUT";
/** XML 应格式 */
public static final String FORMAT_XML = "XML";
/** 默认版本 */
public static final String DEFAULT_VERSION = "1.0.0";
public static final int FILTER_ORDER_0 = 0;
public static final int FILTER_ORDER_1 = 1;
public static final int FILTER_ORDER_2 = 2;
public static final int FILTER_ORDER_3 = 3;
public static final int FILTER_ORDER_4 = 4;
public static final int FILTER_ORDER_5 = 5;
public static final int FILTER_ORDER_6 = 6;
}
package com.jz.dm.common.constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 日志常量
*
*/
public class LoggingConstants {
/** 业务摘要日志 */
public static final Logger DIGEST_LOGGER = LoggerFactory.getLogger("GATEWAY-DIGEST");
/** 报警日志,内容关键字用##号包括,便于报警信息归类 */
public static final Logger ALERT_LOGGER = LoggerFactory.getLogger("GATEWAY-ALERT");
/** 网关路由分发 */
public static final Logger DISPATCHER_LOGGER = LoggerFactory
.getLogger("GATEWAY-DISPATCHER");
public static final Logger REGISTRY_LOGGER = LoggerFactory.getLogger("GATEWAY-REGISTRY");
/** 分隔符*/
public static final String SEP = ",";
/** 点分割符*/
public static final String DOT_SEP = ".";
/** 默认值*/
public static final String DEFAULT_STR = "-";
/** 冒号 */
public static final String COLON = ":";
/** 金额币种分隔 */
public static final String AMOUNT_CURRENCY_SPLIT = "^";
/** 左中括号 */
public static final String LBRACKET = "[";
/** 右中括号 */
public static final String RBRACKET = "]";
/** "@" 符号*/
public static final String MONKEYS_AT = "@";
/** "&" 符号*/
public static final String AND_SPILT = "&";
/** "=" 符号*/
public static final String AND_EQUAL = "=";
}
package com.jz.dm.common.constant;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.constant
* @PROJECT_NAME: jz-dm-parent
* @NAME: TagConstants
* @DATE: 2020-12-28/18:40
* @DAY_NAME_SHORT: 周一
* @Description:
**/
public class TagConstants {
//远程shell脚本存放路径
public static final String remoteShellFilePath = "/opt/shell";
//远程sql脚本存放路径
public static final String remoteSqlFilePath = "/opt/sql";
//kafka handler 相关
public static final String OPEN_API_HANDLER_LIST_INFO_NAMESPACE = "jz:openapi:handler:list";
public static final String OPEN_API_HANDLER_INFO_NAMESPACE = "jz:openapi:handler:";
public static final String OPEN_API_SCHEMA_INFO_NAMESPACE = "jz:openapi:schema:";
public static final String OPEN_API_SERVERS_INFO_NAMESPACE = "jz:openapi:kafka:servers:";
// es handler 相关
public static final String OPEN_API_ESTAG_INFO_NAMESPACE = "jz:openapi:handler:estag:";
public static final String OPEN_API_ESTAG_JDBC_INFO_NAMESPACE = "jz:openapi:handler:estag:jdbc:";
//redis限流相关
public static final String OPEN_API_REDIS_LIMIT_KEY = "jz:openapi:redis:limit:";
//API缓存Key
public static final String OPEN_API_CACHE_KEY = "jz:openapi:cache:";
}
package com.jz.dm.common.enums;
/**
* 数据格式
*
* @author zc
*/
public enum Format {
JSON,
XML;
}
package com.jz.dm.common.enums;
import com.jz.dm.common.util.ResultCode;
import java.util.HashMap;
import java.util.Map;
/**
* 网关结果码
*
*/
public enum GatewayResultCode implements ResultCode {
/** 处理成功 */
SUCCESS("SUCCESS", "处理成功"),
/** 处理成功 */
FAIL("FAIL", "处理失败"),
/** 未知异常 */
UNKNOWN_EXCEPTION("UNKNOWN_EXCEPTION", "未知异常"),
/** 无效接口 */
ILLEGAL_INTERFACE("ILLEGAL_INTERFACE", "无效接口"),
/** 无效参数 */
ILLEGAL_ARGUMENT("ILLEGAL_ARGUMENT", "无效参数"),
/** 参数列表为空 */
REQUEST_PARAM_EMPTY("REQUEST_PARAM_EMPTY", "请求参数为空"),
/** 无效请求 */
ILLEGAL_REQUEST("ILLEGAL_REQUEST", "无效请求"),
/** 无效请求 */
ILLEGAL_TIMETEMP("ILLEGAL_TIMETEMP", "无效时间戳"),
/** 无效授权 */
ILLEGAL_AUTHORIZATION("ILLEGAL_AUTHORIZATION", "无效授权"),
/** 请求次数受限 */
REQUEST_LIMIT_EXCEPTION("REQUEST_LIMIT_EXCEPTION", "请求次数受限"),
/** 请求超过限制 */
RATE_LIMIT_EXCEEDED("RATE_LIMIT_EXCEEDED", "请求超过限制"),
/** 提交数据过大 */
POST_DATA_TOO_LARGE("POST_DATA_TOO_LARGE", "提交数据过大"),
/** 签名错误 */
SIGN_ERROR("SIGN_EMPTY", "签名错误"),
/** 请求未授权 */
REQUEST_NOT_AUTH("REQUEST_NOT_AUTH", "请求未授权"),
/** 组织不存在 */
ORG_NOT_EXIST("ORG_NOT_EXIST", "组织不存在"),
/** API状态异常 */
API_STATUS_EXCEPTION("API_STATUS_EXCEPTION", "API状态异常"),
/** API类型错误 */
API_TYPE_ERROR("API_TYPE_ERROR", "API类型错误"),
/** 文件地址不存在 */
DATA_BIG_ADDR_UNEXIST("DATA_BIG_ADDR_UNEXIST", "文件地址不存在!"),
/** 组织状态异常 */
ORG_STATE_EXCEPTION("ORG_STATE_EXCEPTION", "组织状态异常"),
/** 请求信息不存在 */
REQUEST_INFO_UNEXIST("REQUEST_INFO_UNEXIST", "请求信息不存在"),
/** 远程请求异常 */
DISTANCE_REQUEST_EXCEPTION("DISTANCE_REQUEST_EXCEPTION", "远程请求异常"),
/** 单次调用金额不足 */
CALL_AMOUNT_NOT_ENOUGH("CALL_AMOUNT_NOT_ENOUGH", "单次调用金额不足"),
/** 认证API已过有效期 */
AUTH_EXCEED_TIME("AUTH_EXCEED_TIME", "认证API已过有效期"),
/** 输出类型错误 */
OUTPUT_TYPE_EXCEPTION("OUTPUT_TYPE_EXCEPTION", "输出类型错误!");
/**
* 初始化保存到map里方便根据code获取
*/
private static Map<String, GatewayResultCode> RESULT_CODES = new HashMap<String, GatewayResultCode>();
static {
for (GatewayResultCode gatewayResultCode : GatewayResultCode.values()) {
RESULT_CODES.put(gatewayResultCode.code, gatewayResultCode);
}
}
/** 结果码 */
private String code;
/** 结果码信息 */
private String msg;
/**
* 构造函数
*
* @param code 结果码
* @param msg 结果码信息
*/
private GatewayResultCode(String code, String msg) {
this.code = code;
this.msg = msg;
}
/**
* 通过枚举<code>code</code>获得枚举
*
* @param code 结果码
* @return 枚举
*/
public static GatewayResultCode getGatewayResultCode(String code) {
return RESULT_CODES.get(code);
}
/**
* Getter method for property <tt>code</tt>.
*
* @return property value of code
*/
@Override
public String getCode() {
return code;
}
/**
* Setter method for property <tt>code</tt>.
*
* @param code value to be assigned to property code
*/
public void setCode(String code) {
this.code = code;
}
/**
* Getter method for property <tt>msg</tt>.
*
* @return property value of msg
*/
@Override
public String getMsg() {
return msg;
}
/**
* Setter method for property <tt>msg</tt>.
*
* @param msg value to be assigned to property msg
*/
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.jz.dm.common.enums;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums
* @PROJECT_NAME: jz-dm-parent
* @NAME: GeneralStatusTypeEnum
* @DATE: 2020-12-30/20:08
* @DAY_NAME_SHORT: 周三
* @Description: 通用状态枚举
**/
public enum GeneralStatusTypeEnum {
/**
* 启用
*/
ENABLE("启用"),
/**
* 停用
*/
UNABLE("停用"),
/**
* 有效'
*/
VALID("有效"),
/**
* 无效
*/
UN_VALID("无效"),
/**
* 成功'
*/
SUCCEED("成功"),
/**
* 失败'
*/
FAIL("失败");
private String text;
GeneralStatusTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static GeneralStatusTypeEnum fromGeneralStatus(String typeName) {
for (GeneralStatusTypeEnum type : GeneralStatusTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums;
import com.alibaba.fastjson.JSON;
import com.jz.common.constant.ResultMsg;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums
* @PROJECT_NAME: jz-dm-parent
* @NAME: ResultFlowCode
* @DATE: 2021-2-25/14:40
* @DAY_NAME_SHORT: 周四
* @Description:
**/
public enum ResultFlowCode {
/** 限流异常 */
FLOW_EXCEPTION(410, ResultMsg.LIMIT_FLOW_EXCEPTION),
/** 降级异常 */
DEGRADE_EXCEPTION(411, ResultMsg.LIMIT_DEGRADE_EXCEPTION),
/** 热点异常 */
PARAM_EXCEPTION(412, ResultMsg.LIMIT_PARAM_EXCEPTION),
/** 系统规则异常 */
SYSTEM_EXCEPTION(413, ResultMsg.LIMIT_SYSTEM_EXCEPTION),
/** 认证异常 */
AUTHORITY_EXCEPTION(414, ResultMsg.LIMIT_AUTHORITY_EXCEPTION);
private int code;
/**
* 提示信息
*/
private ResultMsg msg;
private ResultFlowCode(int code, ResultMsg msg) {
this.code = code;
this.msg = msg;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
public int getCode() {
return code;
}
public ResultMsg getMsg() {
return this.msg;
}
public void setMsg(ResultMsg msg) {
this.msg = msg;
}
}
package com.jz.dm.common.enums;
/**
* 签名类型
*
*/
public enum SignType {
RSA, RSA2, MD5
}
package com.jz.dm.common.enums.apiInterface;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.apiInterface
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiInfoOutTypeEnum
* @DATE: 2021-1-6/11:14
* @DAY_NAME_SHORT: 周三
* @Description: 输出类型
**/
public enum ApiInfoOutTypeEnum {
JSON,
XML,
FLOW;
}
package com.jz.dm.common.enums.apiInterface;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.constant
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiStatusEnum
* @DATE: 2020-12-29/14:28
* @DAY_NAME_SHORT: 周二
* @Description:
**/
public enum ApiStatusEnum {
/**
* 草稿
*/
DRAFT("草稿"),
/**
* 发布'
*/
ISSUE("发布"),
/**
* 授权
*/
AUTHORIZATION("授权"),
/**
* 冻结
*//*
FREEZE("冻结"),*/
/**
* 下架(下架时可以调用/不可以购买)
*/
SOLDOUT("下架"),
/**
* 失效'
*/
EXPIRY("失效");
private String text;
ApiStatusEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static ApiStatusEnum fromApiStatusName(String typeName) {
for (ApiStatusEnum type : ApiStatusEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.auth;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.auth
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthModeEnum
* @DATE: 2020-12-26/23:53
* @DAY_NAME_SHORT: 周六
* @Description: 认证方式枚举
**/
public enum AuthModeEnum {
/**
* 按次调用
*/
POWER_CALL_MODE("按次调用"),
/**
* 按时间调用'
*/
RECORD_TIME_MODE("按时间调用"),
/**
* 永久有效'
*/
PERMANENT_TIME_MODE("永久有效");
private String text;
AuthModeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static AuthModeEnum fromTypeModeName(String typeName) {
for (AuthModeEnum type : AuthModeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.auth;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.auth
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthReqTypeEnum
* @DATE: 2021-1-8/18:44
* @DAY_NAME_SHORT: 周五
* @Description:
**/
public enum AuthReqTypeEnum {
DAY("天"),
MONTH("月"),
YEAR("年");
private String text;
AuthReqTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static AuthReqTypeEnum fromAuthReqTypeEnum(String typeName) {
for (AuthReqTypeEnum type : AuthReqTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.auth;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.auth
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthTypeEnum
* @DATE: 2020-12-26/23:47
* @DAY_NAME_SHORT: 周六
* @Description: 授权认证枚举类
**/
public enum AuthTypeEnum {
/**
* 数据银行
*/
DATA_BANK_AUTH("数据银行授权"),
/**
* dmp授权'
*/
DMP_AUTH("DMP授权");
private String text;
AuthTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static AuthTypeEnum fromAuthTypeName(String typeName) {
for (AuthTypeEnum type : AuthTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.direction;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums
* @PROJECT_NAME: jz-dm-parent
* @NAME: DirectionTypeEnum
* @DATE: 2020-12-31/18:39
* @DAY_NAME_SHORT: 周四
* @Description:
**/
public enum DirectionTypeEnum {
/**
* API类型
*/
API_TYPE;
public static DirectionTypeEnum fromTypeDirectionName(String typeName) {
for (DirectionTypeEnum type : DirectionTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.org;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.org
* @PROJECT_NAME: jz-dm-parent
* @NAME: OrgStatusEnum
* @DATE: 2021-1-1/11:17
* @DAY_NAME_SHORT: 周五
* @Description:
**/
public enum OrgStatusEnum {
NORMAL("正常"),
FREEZE("冻结"),
CANCEL("注销");
private String text;
OrgStatusEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static OrgStatusEnum fromOrgStatusTypeName(String typeName) {
for (OrgStatusEnum type : OrgStatusEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.org;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.org
* @PROJECT_NAME: jz-dm-parent
* @NAME: OrgTypeEnum
* @DATE: 2021-1-14/16:17
* @DAY_NAME_SHORT: 周四
* @Description:
**/
public enum OrgTypeEnum {
INT("内部组织"),
OUT("外部组织");
private String text;
OrgTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static OrgTypeEnum fromOrgTypeEnumName(String typeName) {
for (OrgTypeEnum type : OrgTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.enums.produce;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.produce
* @PROJECT_NAME: jz-dm-parent
* @NAME: ProducerStatusTypeEnum
* @DATE: 2021-1-1/18:04
* @DAY_NAME_SHORT: 周五
* @Description:
**/
public enum ProducerStatusTypeEnum {
DRAFT("草稿"),
ISSUE("发布"),
OUTMODED("过时"),
FREEZE("冻结"),
EXPIRY("失效");
private String text;
ProducerStatusTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
public static ProducerStatusTypeEnum fromTypeName(String typeName) {
for (ProducerStatusTypeEnum type : ProducerStatusTypeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
}
package com.jz.dm.common.exception;
import com.jz.dm.common.util.ResultCode;
/**
* 网关异常
*
*/
public class GatewayException extends OpenApiException {
/** 序列号 */
private static final long serialVersionUID = 3391018902219700916L;
/**
* 构造函数
*
* @param resultCode
*/
public GatewayException(ResultCode resultCode) {
super(resultCode);
}
/**
* 构造函数
*
* @param resultCode
* @param cause
*/
public GatewayException(ResultCode resultCode, Throwable cause) {
super(resultCode, cause);
}
/**
* 构造函数
*
* @param resultCode
* @param detailMessage
*/
public GatewayException(ResultCode resultCode, String detailMessage) {
super(resultCode, detailMessage);
}
/**
* 构造函数
*
* @param code
* @param msg
*/
public GatewayException(String code, String msg) {
this(code, msg, (Throwable) null);
}
/**
* 构造函数
*
* @param code
* @param msg
* @param cause
*/
public GatewayException(String code, String msg, Throwable cause) {
super(code, msg, cause);
}
/**
* 构造函数
*
* @param code
* @param msg
* @param detailMessage
*/
public GatewayException(String code, String msg, String detailMessage) {
super(code, msg, detailMessage);
}
}
\ No newline at end of file
package com.jz.dm.common.exception;
import com.jz.common.constant.ResultMsg;
import com.jz.dm.common.enums.ResultFlowCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.exception
* @PROJECT_NAME: jz-dm-parent
* @NAME: LimitFlowException
* @DATE: 2021-2-25/14:27
* @DAY_NAME_SHORT: 周四
* @Description: 限流异常处理器
**/
@Data
@EqualsAndHashCode(callSuper = true)
public class LimitFlowException extends RuntimeException {
private static final long serialVersionUID = -3963657380514719229L;
/**
* 错误代码
*/
protected ResultFlowCode code;
/**
* 错误信息
*/
protected String message;
private Throwable cause;
public static LimitFlowException of(ResultMsg errorMsg) {
return LimitFlowException.of(ResultFlowCode.FLOW_EXCEPTION,errorMsg.getMsg());
}
public static LimitFlowException of_error(String errorMsg) {
return LimitFlowException.of(ResultFlowCode.FLOW_EXCEPTION,errorMsg);
}
public static LimitFlowException of(ResultFlowCode code) {
LimitFlowException ufaceException = new LimitFlowException();
ufaceException.setCode(code);
ufaceException.setMessage(code.getMsg().getMsg());
return ufaceException;
}
public static LimitFlowException of(ResultFlowCode code, String message) {
LimitFlowException ufaceException = new LimitFlowException();
ufaceException.setCode(code);
ufaceException.setMessage(message);
return ufaceException;
}
public static LimitFlowException of(ResultFlowCode code, Throwable cause) {
LimitFlowException ufaceException = new LimitFlowException();
ufaceException.setCode(code);
ufaceException.setCause(cause);
ufaceException.setMessage("todo need get from db/properties");
return ufaceException;
}
}
package com.jz.dm.common.exception;
import com.jz.dm.common.util.ResultCode;
/**
* openapi异常
*
*/
public class OpenApiException extends RuntimeException {
private static final long serialVersionUID = -3963657380514719229L;
/**
* 结果码
*/
private ResultCode resultCode;
/**
* 构造函数
*
* @param resultCode
*/
public OpenApiException(ResultCode resultCode) {
this.resultCode = new ResultCodeImpl(resultCode);
}
/**
* 构造函数
*
* @param resultCode
* @param cause
*/
public OpenApiException(ResultCode resultCode, Throwable cause) {
super(cause);
this.resultCode = new ResultCodeImpl(resultCode);
}
/**
* 构造函数
*
* @param resultCode
* @param detailMessage
*/
public OpenApiException(ResultCode resultCode, String detailMessage) {
super(detailMessage);
this.resultCode = new ResultCodeImpl(resultCode);
}
/**
* 构造函数
*
* @param resultCode
* @param detailMessage
* @param cause
*/
public OpenApiException(ResultCode resultCode, String detailMessage, Throwable cause) {
super(detailMessage, cause);
this.resultCode = new ResultCodeImpl(resultCode);
}
/**
* 构造函数
*
* @param code
* @param msg
*/
public OpenApiException(String code, String msg) {
this(new ResultCodeImpl(code, msg));
}
/**
* 构造函数
*
* @param code
* @param msg
* @param cause
*/
public OpenApiException(String code, String msg, Throwable cause) {
this(new ResultCodeImpl(code, msg), cause);
}
/**
* 构造函数
*
* @param code
* @param msg
* @param detailMessage
*/
public OpenApiException(String code, String msg, String detailMessage) {
this(new ResultCodeImpl(code, msg), detailMessage);
}
/**
* Getter method for property <tt>resultCode</tt>.
*
* @return property value of resultCode
*/
public ResultCode getResultCode() {
return resultCode;
}
public static class ResultCodeImpl implements ResultCode {
private String code;
private String msg;
public ResultCodeImpl(ResultCode resultCode) {
this.code = resultCode.getCode();
this.msg = resultCode.getMsg();
}
public ResultCodeImpl(String code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public String getCode() {
return code;
}
@Override
public String getMsg() {
return msg;
}
}
}
package com.jz.dm.common.exception;
import com.jz.dm.common.util.ResultCode;
/**
* 签名异常
*
*/
public class SignatureException extends OpenApiException {
private static final long serialVersionUID = 6551962245794846748L;
/**
* 构造函数
*
* @param resultCode
*/
public SignatureException(ResultCode resultCode) {
super(resultCode);
}
/**
* 构造函数
* @param resultCode
* @param detailMessage
*/
public SignatureException(ResultCode resultCode, String detailMessage) {
super(resultCode, detailMessage);
}
/**
* 构造函数
* @param resultCode
* @param cause
*/
public SignatureException(ResultCode resultCode, Throwable cause) {
super(resultCode, cause);
}
/**
* 构造函数
* @param resultCode
* @param detailMessage
* @param cause
*/
public SignatureException(ResultCode resultCode, String detailMessage, Throwable cause) {
super(resultCode, detailMessage, cause);
}
}
package com.jz.dm.common.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.util
* @PROJECT_NAME: jz-dm-parent
* @NAME: DateUtil
* @DATE: 2021-1-2/21:55
* @DAY_NAME_SHORT: 周六
* @Description: 时间工具类处理时间
**/
public class DateUtil {
/**
* 计算当前距离23:59:59剩余时间
* @return
*/
public static long calculateNowResidueTime(){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
}
/**
* 计算当前距离下月一号剩余时间
* @return
*/
public static long calculateNowMonthTime(){
Calendar c = Calendar.getInstance();//获取一个Calendar对象
c.setTime(new Date() );
c.add(Calendar.MONTH, 1);
c.set(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
return (c.getTimeInMillis() - System.currentTimeMillis()) / 1000;
}
/**
* 获取指定年份的时间
* @param year
* @return
*/
public static Date getAssignYearDate(Integer year){
Calendar cal = Calendar.getInstance();
/* int year =cal.get(Calendar.YEAR)+1;
int month=cal.get(Calendar.MONTH)+1;
cal.add(Calendar.MONTH, 0);*/
//Date date = cal.getTime(); //结果
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cal.set(Calendar.YEAR,cal.get(Calendar.YEAR)+year);
Date date=cal.getTime();
System.out.println(sdf.format(date));
return date;
}
public static void main(String[] args) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//System.out.println(calculateNowResidueTime());
Calendar c = Calendar.getInstance();//获取一个Calendar对象
c.setTime(new Date() );
c.add(Calendar.MONTH, 1);
c.set(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
Date time = c.getTime();
String format = dateFormat.format(time);
System.out.println(format);
Calendar cal = Calendar.getInstance();//获取一个Calendar对象
cal.setTime(new Date() );
cal.add(Calendar.MONTH, 0);//获取当前时间的下一个月
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));//获取下一个月的最后一天
Date preMonth=cal.getTime();//得到下个月的最后一天
String format1 = dateFormat.format(preMonth);
System.out.println(format1);
System.out.println(calculateNowMonthTime()/60/60/24);
}
}
package com.jz.dm.common.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.NameFilter;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* Json工具类
*/
public class JsonUtil {
private static final ParserConfig PARSER_CONFIG = new ParserConfig();
static {
PARSER_CONFIG.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
}
private static final Map<PropertyNamingStrategy, NameFilter> NAME_FILTERS = new HashMap<PropertyNamingStrategy, NameFilter>();
static {
NAME_FILTERS.put(PropertyNamingStrategy.SnakeCase, new SnakeNameFilter());
NAME_FILTERS.put(PropertyNamingStrategy.CamelCase, new CamelNameFilter());
NAME_FILTERS.put(PropertyNamingStrategy.PascalCase, new PascalNameFilter());
NAME_FILTERS.put(PropertyNamingStrategy.KebabCase, new KebabNameFilter());
}
public static class SnakeNameFilter implements NameFilter {
/**
* @see NameFilter#process(Object, String, Object)
*/
@Override
public String process(Object object, String name, Object value) {
return PropertyNamingStrategy.SnakeCase.translate(name);
}
}
public static class CamelNameFilter implements NameFilter {
/**
* @see NameFilter#process(Object, String, Object)
*/
@Override
public String process(Object object, String name, Object value) {
return PropertyNamingStrategy.CamelCase.translate(name);
}
}
public static class PascalNameFilter implements NameFilter {
/**
* @see NameFilter#process(Object, String, Object)
*/
@Override
public String process(Object object, String name, Object value) {
return PropertyNamingStrategy.PascalCase.translate(name);
}
}
public static class KebabNameFilter implements NameFilter {
/**
* @see NameFilter#process(Object, String, Object)
*/
@Override
public String process(Object object, String name, Object value) {
return PropertyNamingStrategy.KebabCase.translate(name);
}
}
/**
* object serialize to string
*
* @param object
* @param strategy
* @return
*/
public static String toJSONString(Object object, PropertyNamingStrategy strategy) {
if (object == null) {
return null;
}
if (strategy == null) {
return JSON.toJSONString(object);
}
NameFilter nameFilter = NAME_FILTERS.get(strategy);
if (nameFilter == null) {
return JSON.toJSONString(object);
} else {
return JSON.toJSONString(object, nameFilter);
}
}
/**
* String转换为JSONObject对象
*
* @param data
* @return
*/
public static JSONObject stringToJsonObject(String data) {
if (StringUtils.isNotEmpty(data)) {
return JSONObject.parseObject(data);
}
return null;
}
}
package com.jz.dm.common.util;
import org.slf4j.Logger;
/**
* 日志打印工具
*
*/
public class LogUtil {
/** 摘要日志的内容分隔符 */
public static final String SEP = ",";
/** 修饰符 */
private static final char RIGHT_TAG = ']';
/** 修饰符 */
private static final char LEFT_TAG = '[';
/**
* 日志信息
*
*/
public interface LogInfo {
/**
* 获取日志信息
*
* @return 日志信息
*/
String getLogInfo();
}
/**
* 打印info日志。
*
* @param logger 日志对象
* @param objs 任意个要输出到日志的参数
*/
public static void info(Logger logger, Object... objs) {
if (logger.isInfoEnabled()) {
logger.info(getLogString(objs));
}
}
/**
* 打印info级别日志
*
* @param logger 日志对象
* @param logInfo 日志信息
*/
public static void info(Logger logger, LogInfo logInfo) {
if (logger.isInfoEnabled()) {
logger.info(logInfo.getLogInfo());
}
}
/**
* 打印info级别日志
*
* @param logger 日志对象
* @param e 异常信息
* @param objs 任意个要输出到日志的参数
*/
public static void info(Logger logger, Throwable e, Object... objs) {
if (logger.isInfoEnabled()) {
logger.info(getLogString(objs), e);
}
}
/**
* 打印warn级别日志
*
* @param logger 日志对象
* @param objs 任意个要输出到日志的参数
*/
public static void warn(Logger logger, Object... objs) {
logger.warn(getLogString(objs));
}
/**
* 打印warn级别日志
*
* @param logger 日志对象
* @param e 异常信息
* @param objs 任意个要输出到日志的参数
*/
public static void warn(Logger logger, Throwable e, Object... objs) {
logger.warn(getLogString(objs), e);
}
/**
* 打印error级别日志
*
* @param logger 日志对象
* @param e 异常信息
* @param objs 任意个要输出到日志的参数
*/
public static void error(Logger logger, Throwable e, Object... objs) {
logger.error(getLogString(objs), e);
}
/**
* 打印error级别日志
*
* @param logger 日志对象
* @param objs 任意个要输出到日志的参数
*/
public static void error(Logger logger, Object... objs) {
logger.error(getLogString(objs));
}
/**
* 打印debug日志。
*
* @param logger 日志对象
* @param objs 任意个要输出到日志的参数
*/
public static void debug(Logger logger, Object... objs) {
if (logger.isDebugEnabled()) {
logger.debug(getLogString(objs));
}
}
/**
* 打印debug日志。
*
* @param logger 日志对象
* @param e 异常信息
* @param objs 任意个要输出到日志的参数
*/
public static void debug(Logger logger, Throwable e, Object... objs) {
if (logger.isDebugEnabled()) {
logger.debug(getLogString(objs), e);
}
}
/**
* 生成输出到日志的字符串
*
* @param objs 任意个要输出到日志的参数
* @return 日志字符串
*/
public static String getLogString(Object... objs) {
StringBuilder log = new StringBuilder();
log.append(LEFT_TAG).append(getThreadId()).append(RIGHT_TAG);
for (Object o : objs) {
log.append(o).append(SEP);
}
return log.toString();
}
/**
* 获取线程id。
*
* @return 线程id
*/
public static String getThreadId() {
return String.valueOf(Thread.currentThread().getId());
}
}
package com.jz.dm.common.util;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.*;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.util
* @PROJECT_NAME: jz-dm-parent
* @NAME: MapUtil
* @DATE: 2021-1-2/14:02
* @DAY_NAME_SHORT: 周六
* @Description:
**/
public class MapUtil {
/**
* 获取签名参数
*
* @param apiKey
* @param method
* @param signType
* @return
*/
//public static String getSignValue(String apiKey, String method, String signType) {
// StringBuilder builder = new StringBuilder();
// builder.append("apiKey=").append(apiKey).append(LoggingConstants.AND_SPILT)
// .append("method=").append(method).append(LoggingConstants.AND_SPILT)
// .append("signType=").append(signType);
// return builder.toString();
//}
/**
* 将对象转成TreeMap,属性名为key,属性值为value
*
* @param object 对象
* @return
* @throws IllegalAccessException
*/
public static TreeMap<String, String> objToMap(Object object) throws IllegalAccessException {
Class clazz = object.getClass();
TreeMap<String, String> treeMap = new TreeMap<String, String>();
while (null != clazz.getSuperclass()) {
Field[] declaredFields1 = clazz.getDeclaredFields();
for (Field field : declaredFields1) {
String name = field.getName();
// 获取原来的访问控制权限
boolean accessFlag = field.isAccessible();
// 修改访问控制权限
field.setAccessible(true);
Object value = field.get(object);
// 恢复访问控制权限
field.setAccessible(accessFlag);
if (null != value && StringUtils.isNotBlank(value.toString())) {
//如果是List,将List转换为json字符串
if (value instanceof List) {
value = JSON.toJSONString(value);
}
treeMap.put(name, String.valueOf(value));
}
}
clazz = clazz.getSuperclass();
}
return treeMap;
}
/**
* 按照指定的分割符将list转换为String
*
* @param list
* @param separator
* @return
*/
public static String listToString(List list, String separator) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
sb.append(list.get(i));
} else {
sb.append(list.get(i));
sb.append(separator);
}
}
return sb.toString();
}
/**
* * 把数组元素按照按照字典倒序排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param params 需要排序并参与字符拼接的参数组
* @return 拼接后字符串
*/
public static String stringInvertSort(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.reverse(keys);
String prestr = "";
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
String value = params.get(key);
try {
value = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符
prestr = prestr + key + "=" + value;
} else {
prestr = prestr + key + "=" + value + "&";
}
}
return prestr;
}
/**
*   * 把数组所有元素字典排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
*   * @param params 需要排序并参与字符拼接的参数组
*   * @return 拼接后字符串 
*/
public static String stringNormalSort(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.sort(keys);
String prestr = "";
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
String value = params.get(key);
try {
value = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符
prestr = prestr + key + "=" + value;
} else {
prestr = prestr + key + "=" + value + "&";
}
}
return prestr;
}
class SpellComparatorUtils implements Comparator {
@Override
public int compare(Object o1, Object o2) {
try {
// 取得比较对象的汉字编码,并将其转换成字符串
String s1 = new String(o1.toString().getBytes("GB2312"), "ISO-8859-1");
String s2 = new String(o2.toString().getBytes("GB2312"), "ISO-8859-1");
// 运用String类的 compareTo()方法对两对象进行比较
return s1.compareTo(s2);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}
public static void main(String[] args) {
//Map<String, String> map = new HashMap();
//map.put("name", "hello");
//map.put("value", "world");
//System.out.println(createLinkStringByGet(map));
StringJoiner joiner = new StringJoiner(",","[","]");
joiner.add("123");
joiner.add("456");
joiner.add("789");
System.out.println(joiner);
}
}
package com.jz.dm.common.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jz.dm.common.exception.OpenApiException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* openapi请求
*
*/
public class OpenApiRequest {
private String apiKey; //apiKey
private String openApiParams;
private JSONObject parameters;
private Object parameterObject;
private Map<String, Object> extAttributes = new HashMap<String, Object>();
public OpenApiRequest(String openApiParams) {
setOpenApiParams(openApiParams);
}
private void setOpenApiParams(String openApiParams) {
this.openApiParams = openApiParams;
try {
parameters = JSON.parseObject(openApiParams, JSONObject.class);
} catch (Exception ex) {
throw new OpenApiException(OpenApiResultCode.ILLEGAL_ARGUMENT,
"parse openapi params error, openApiParams=" + openApiParams, ex);
}
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
@SuppressWarnings("unchecked")
public <T> T getObject(Class<?> clazz) {
if (parameterObject != null) {
return (T) parameterObject;
}
try {
this.parameterObject = JSON.parseObject(openApiParams, clazz);
} catch (Exception ex) {
throw new OpenApiException(OpenApiResultCode.ILLEGAL_ARGUMENT, ex);
}
return (T) parameterObject;
}
public String getOpenApiParams() {
return this.openApiParams;
}
@SuppressWarnings("unchecked")
@Deprecated
public <T> T getParameter(String key) {
return (T) parameters.get(key);
}
public <T> T getObject(String key, Class<T> clazz) {
return parameters.getObject(key, clazz);
}
public byte[] getBytes(String key) {
return parameters.getBytes(key);
}
public Boolean getBoolean(String key) {
return parameters.getBoolean(key);
}
public boolean getBooleanValue(String key) {
return parameters.getBooleanValue(key);
}
public Byte getByte(String key) {
return parameters.getByte(key);
}
public byte getByteValue(String key) {
return parameters.getByteValue(key);
}
public Short getShort(String key) {
return parameters.getShortValue(key);
}
public short getShortValue(String key) {
return parameters.getShortValue(key);
}
public Integer getInteger(String key) {
return parameters.getInteger(key);
}
public int getIntValue(String key) {
return parameters.getIntValue(key);
}
public Long getLong(String key) {
return parameters.getLong(key);
}
public long getLongValue(String key) {
return parameters.getLongValue(key);
}
public Float getFloat(String key) {
return parameters.getFloat(key);
}
public float getFloatValue(String key) {
return parameters.getFloatValue(key);
}
public Double getDouble(String key) {
return parameters.getDouble(key);
}
public double getDoubleValue(String key) {
return parameters.getDoubleValue(key);
}
public BigDecimal getBigDecimal(String key) {
return parameters.getBigDecimal(key);
}
public BigInteger getBigInteger(String key) {
return parameters.getBigInteger(key);
}
public String getString(String key) {
return parameters.getString(key);
}
public Date getDate(String key) {
return parameters.getDate(key);
}
/**
* Get Extend Attribute
*
* @param attributeName
* @return
*/
@SuppressWarnings("unchecked")
public <T> T getExtAttribute(String attributeName) {
return (T) extAttributes.get(attributeName);
}
/**
* Set Extend Attribute
*
* @param attributeName
* @param attributeValue
*/
public void setExtAttribute(String attributeName, String attributeValue) {
this.extAttributes.put(attributeName, attributeValue);
}
/**
* Getter method for property <tt>extAttributes</tt>.
*
* @return property value of extAttributes
*/
public Map<String, Object> getExtAttributes() {
return extAttributes;
}
/**
* Setter method for property <tt>extAttributes</tt>.
*
* @param extAttributes value to be assigned to property extAttributes
*/
public void setExtAttributes(Map<String, Object> extAttributes) {
this.extAttributes = extAttributes;
}
}
package com.jz.dm.common.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
/**
* openapi响应
*
*/
public class OpenApiResponse {
/**
* 结果码
*/
private static final String ATTRIBUTE_NAME_CODE = "code";
/**
* 结果消息
*/
private static final String ATTRIBUTE_NAME_MSG = "msg";
/**
* 属性
*/
private final Map<String, Object> attributes = new HashMap<String, Object>();
/**
* 获取结果码
*
* @return
*/
public String getCode() {
return (String) attributes.get(ATTRIBUTE_NAME_CODE);
}
/**
* 设置结果码
*
* @param code
*/
public void setCode(String code) {
attributes.put(ATTRIBUTE_NAME_CODE, code);
}
/**