Commit ae0d95a2 authored by ysongq's avatar ysongq

commit

parents a1813bf4 e3e340bf
......@@ -8,18 +8,18 @@ CREATE TABLE `t_api_interface` (
`api_protocl` varchar(32) DEFAULT NULL COMMENT 'api请求协议:http,https',
`api_path` varchar(100) DEFAULT NULL COMMENT '请求地址',
`target_url` varchar(100) DEFAULT NULL COMMENT '目标url',
`api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义',
`api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 数据银行制作大数据表 2 数据银行制作数据包,3,数据银行制作自定义API 4 API实时接入 6 标签查询 9自定义',
`api_function` varchar(200) DEFAULT NULL COMMENT '接口功能',
`join_type` varchar(50) NULL DEFAULT NULL COMMENT '接入类型:字典表对应key值',
`test_example` varchar(255) NULL DEFAULT NULL COMMENT '测试实例',
`status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)',
`output_type` varchar(50) NULL DEFAULT 'JSON' COMMENT '输出类型:flow 流形式输出, json格式输出',
`page` tinyint(2) NULL DEFAULT '0' COMMENT '是否分页:0 false ,1 true',
`version` varchar(20) DEFAULT '1.0' COMMENT '版本号',
`version` varchar(20) DEFAULT 'v1.0' COMMENT '版本号',
`sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA',
`timeout` varchar(50) DEFAULT NULL COMMENT '超时时间',
`file_id` bigint(20) NOT NULL COMMENT '文件夹id',
`req_type` varchar(20) DEFAULT NULL COMMENT '限类型:DAY 按天,MONTH 按月, YEAR 按年',
`req_type` varchar(20) DEFAULT NULL COMMENT '限类型:DAY 按天,MONTH 按月, YEAR 按年',
`req_frequency` bigint(20) DEFAULT '100' COMMENT '限制次数',
`is_test` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否测试数据:0 否,1 是',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
......@@ -38,7 +38,11 @@ CREATE TABLE `t_api_interface_custom` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api 信息表自增ID',
`api_key` varchar(200) NOT NULL COMMENT 'api唯一标识',
`api_interface_id` bigint(20) NOT NULL COMMENT 'api表自增id',
`api_type` varchar(50) DEFAULT '' COMMENT 'api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义',
`api_type` varchar(50) DEFAULT '' COMMENT 'api类型:1 数据银行制作大数据表 2 数据银行制作数据包,3,数据银行制作自定义API 4 API实时接入 5 DMP标签查询 6.DMP大数据表查询 7 DMP自定义',
`es_data_source` varchar(100) DEFAULT NULL COMMENT '数据源id',
`es_data_base` varchar(100) DEFAULT NULL COMMENT '源数据库名称',
`es_table` varchar(100) DEFAULT NULL COMMENT '源数据表名称',
`handle_type` varchar(50) DEFAULT NULL COMMENT '处理类型',
`request_param` varchar(300) DEFAULT NULL COMMENT '请求参数',
`response_param` varchar(300) DEFAULT NULL COMMENT '响应参数',
`req_headers` varchar(300) DEFAULT NULL COMMENT '请求头',
......@@ -105,7 +109,7 @@ CREATE TABLE `t_api_auth` (
`api_interface_id` bigint(20) NOT NULL COMMENT 'api信息表id',
`api_org_id` bigint(20) NOT NULL COMMENT 'api组织id',
`auth_type` varchar(20) DEFAULT NULL COMMENT '授权类型:DATA_BANK_AUTH 数据银行购买 DMP_AUTH dmp授权',
`req_type` varchar(20) DEFAULT NULL COMMENT '限类型:DAY 按天,MONTH 按月, YEAR 按年',
`req_type` varchar(20) DEFAULT NULL COMMENT '限类型:DAY 按天,MONTH 按月, YEAR 按年',
`req_frequency` bigint(20) DEFAULT '100' COMMENT '限制次数',
`auth_code` varchar(100) DEFAULT NULL COMMENT '授权码',
`salt` varchar(200) DEFAULT NULL COMMENT '盐值',
......
......@@ -25,4 +25,5 @@ public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
package com.jz.dm.common.base;
import com.jz.common.bean.SysUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.base
* @PROJECT_NAME: jz-dm-parent
* @NAME: BaseCurrentUserObject
* @DATE: 2020-12-30/16:05
* @DAY_NAME_SHORT: 周三
* @Description: 获取当前登录用户
**/
@Component
public class BaseCurrentUserObject {
@Autowired
private RedisTemplate redisTemplate;
/**
* 获取登录用户
*
* @return
*/
public SysUserDto getUserInfo() {
SysUserDto sysUserDto = (SysUserDto) redisTemplate.opsForValue().get("USER" + "004");//RedisMessageConstant.SENDTYPE_LOGIN_SYS);
return sysUserDto;
}
//SysUserDto currentUser = (SysUserDto)
// redisTemplate.opsForValue().get("user" + RedisMessageConstant.SENDTYPE_LOGIN_SYS);
/*public static void main(String[] args) {
System.out.println(new BaseCurrentUserObject().getUserInfo());
}*/
}
......@@ -48,4 +48,13 @@ public enum GeneralStatusTypeEnum {
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;
}
}
......@@ -26,15 +26,13 @@ public class MapUtil {
* @param apiKey
* @param method
* @param signType
* @param timestamp
* @return
*/
public static String getSignValue(String apiKey,String method,String signType,String timestamp){
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).append(LoggingConstants.AND_SPILT)
.append("timestamp=").append(timestamp);
.append("signType=").append(signType);
return builder.toString();
}
......
package com.jz.dm.common.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.util
* @PROJECT_NAME: jz-dm-parent
* @NAME: RedisSerializableUtil
* @DATE: 2021-1-12/18:26
* @DAY_NAME_SHORT: 周二
* @Description:
**/
public class RedisSerializableUtil {
/**
* 序列化
* @param object
*/
public static byte[] serialize(Object object) {
ObjectOutputStream oos = null;
ByteArrayOutputStream baos = null;
try {
// 序列化
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
byte[] bytes = baos.toByteArray();
return bytes;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 反序列化
* @param bytes
*/
public static Object unserialize(byte[] bytes) {
ByteArrayInputStream bais = null;
try {
// 反序列化
bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
......@@ -25,7 +25,6 @@ import java.util.Map;
* @author zc
*/
@RestController
@RequestMapping("api")
@Api(tags = {"api请求controller"})
public class GatewayController {
......
......@@ -74,13 +74,13 @@ public class OrganizationManageController {
return Mono.fromSupplier(() -> organizationManageService.update(req));
}
/**
* @Description:删除组织
* @Description:注销组织
* @Author: Mr.zhang
* @Date: 2020-12-24
*/
@ApiOperation("删除组织")
@GetMapping(value = "/deleted")
@ApiOperation("注销组织")
@GetMapping(value = "/logoutOrg")
public Mono<Result> delete(@RequestParam(name = "id")Long id) {
return Mono.fromSupplier(() -> organizationManageService.delete(id));
return Mono.fromSupplier(() -> organizationManageService.logoutOrg(id));
}
}
......@@ -30,11 +30,11 @@ public class ProducerController {
/**
* @Description:Api制作(自定义)
* @Description:获取文件夹列表
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(获取文件夹列表)")
@ApiOperation("获取文件夹列表")
@GetMapping(value = "/getFileCatalog")
public Mono<Result> getFileCatalog(@RequestParam(name = "projectId")Long projectId,
@RequestParam(name = "pageNum",defaultValue = "1",required = false)String pageNum,
......@@ -42,11 +42,23 @@ public class ProducerController {
return Mono.fromSupplier(() -> Result.of_success(producerService.getFileCatalog(projectId,pageNum,pageSize)));
}
/**
* @Description:Api制作(自定义)
* @Description:创建文件夹
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(自定义)")
@ApiOperation("创建项目文件夹")
@PostMapping(value = "/createProjectFolder")
public Mono<Result> createProjectFolder(@RequestParam(name = "projectId")Long projectId,
@RequestParam(name = "parentId")Long parentId,
@RequestParam(name = "currentUser") String currentUser ) {
return Mono.fromSupplier(() -> producerService.createProjectFolder(projectId,parentId,currentUser));
}
/**
* @Description:Api制作(自定义DMP)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(自定义DMP)")
@PostMapping(value = "/addCustomApi")
public Mono<Result> makeCustomApi(@RequestBody @Valid ApiInterfaceReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.addCustomApi(req)));
......@@ -86,7 +98,7 @@ public class ProducerController {
}
/**
* @Description:保存API基本信息
* @Description:保存API基本信息/自定义API
* @return: (保存API基本信息)
* @Author: Mr.zhang
* @Date: 2020-12-26
......@@ -152,4 +164,17 @@ public class ProducerController {
@RequestParam(name = "id") Long id) {
return Mono.fromSupplier(() -> producerService.getIndicesTypesFields(indices,type,id));
}
@ApiOperation("保存数据到redis中")
@GetMapping(value = "/saveRedis")
public Result saveObjOnRedis() {
return producerService.saveObjOnRedis();
}
@ApiOperation("获取redis中的数据")
@GetMapping(value = "/getRedisObj")
public Result getObjOnRedis() {
return producerService.getObjOnRedis();
}
}
......@@ -21,6 +21,7 @@ import com.jz.dm.service.ApiInterfaceService;
import com.jz.dm.service.AuthService;
import com.jz.dm.service.OrganizationManageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -82,7 +83,7 @@ public class AuthFilter extends AbstractFilter {
JSONObject parameter = JSONObject.parseObject(request.getParams());
if (null != parameter) {
String authCode = parameter.getString("authCode");
ApiAuth authAuth = authService.getAuthUser(authCode,apiInterface.getId());
ApiAuth authAuth = authService.getAuthUser(authCode, apiInterface.getId());
if (null == authAuth) {
throw new GatewayException(GatewayResultCode.REQUEST_NOT_AUTH);
}
......@@ -95,8 +96,8 @@ public class AuthFilter extends AbstractFilter {
}
chain.doFilter(request, response);
} catch (Exception e) {
if (e instanceof GatewayException){
throw(GatewayException) e;
if (e instanceof GatewayException) {
throw (GatewayException) e;
}
log.error("~~~~~~~~~~~~~~~~认证过滤异常~~~~~~~~~~~~~~~~~");
log.error("异常信息:{}", e.getMessage());
......@@ -112,6 +113,7 @@ public class AuthFilter extends AbstractFilter {
/**
* 校验计费信息
*
* @param request
* @param authCode
* @param authAuth
......@@ -127,24 +129,24 @@ public class AuthFilter extends AbstractFilter {
throw new GatewayException(GatewayResultCode.ORG_STATE_EXCEPTION);
}
//查询数据银行银行余额是否充足
getDataAmountResult(request);
//getDataAmountResult(request);
try { //记录请求次数(每天限制请求次数)
String limitKey = request.getApiKey() + LoggingConstants.AND_SPILT + authCode;
String reqKey = redisUtils.get(limitKey);
long timeOut =0;
if (AuthReqTypeEnum.DAY.name().equals(authAuth.getReqType())){ //按天
Integer reqValue = (Integer)redisUtils.getObj(limitKey);
long timeOut = 0;
if (AuthReqTypeEnum.DAY.name().equals(authAuth.getReqType())) { //按天
timeOut = DateUtil.calculateNowResidueTime();
}else if (AuthReqTypeEnum.MONTH.name().equals(authAuth.getReqType())){//按月
timeOut=DateUtil.calculateNowMonthTime();
}else if (AuthReqTypeEnum.YEAR.name().equals(authAuth.getReqType())){//按年
} else if (AuthReqTypeEnum.MONTH.name().equals(authAuth.getReqType())) {//按月
timeOut = DateUtil.calculateNowMonthTime();
} else if (AuthReqTypeEnum.YEAR.name().equals(authAuth.getReqType())) {//按年
//暂时不支持年
}
if (null != reqKey) {
Integer value = Integer.valueOf(reqKey);
if (value > authAuth.getReqFrequency()) {//超出最大请求次数
if (null != reqValue && reqValue != 0) {
// Integer value = Integer.valueOf(reqKey);
if (reqValue > authAuth.getReqFrequency()) {//超出最大请求次数
throw new GatewayException(GatewayResultCode.REQUEST_LIMIT_EXCEPTION);
} else if (value <= authAuth.getReqFrequency()) {
redisUtils.delAndAdd(limitKey, limitKey, value + 1, timeOut);
} else if (reqValue <= authAuth.getReqFrequency()) {
redisUtils.delAndAdd(limitKey, limitKey, reqValue + 1, timeOut);
}
} else {
redisUtils.set(limitKey, 1, timeOut);
......@@ -174,20 +176,27 @@ public class AuthFilter extends AbstractFilter {
/**
* 按次调用检查余额是否充足
*
* @param request
*/
private void getDataAmountResult(GatewayRequest request) {
JSONObject params = JSONObject.parseObject(request.getParams());
if (null != params){
Integer assetsId = params.getInteger("assetsId");
Integer userId = params.getInteger("userId");
String dataPrice = params.getString("dataPrice");
if (null == assetsId || null == userId || StringUtils.isBlank(dataPrice)) {
throw new GatewayException(GatewayResultCode.ILLEGAL_ARGUMENT);
}
if (null != params) {
JSONObject pObject = new JSONObject();
pObject.put("assetsId",params.getInteger("assetsId"));
pObject.put("userId",params.getInteger("userId"));
pObject.put("dataPrice",params.getString("dataPrice"));
pObject.put("assetsId", assetsId);
pObject.put("userId", userId);
pObject.put("dataPrice", dataPrice);
String respResult = httpUtils.submitPost(balanceUrl, pObject.toString());
JSONObject result = JSONObject.parseObject(respResult);
if (null != result){
if (200 !=result.getInteger("code")){
log.info("~~~~~~~~~~~~~~~~~~异常信息为:{}",result.getString("message"));
if (null != result) {
if (200 != result.getInteger("code")) {
log.info("~~~~~~~~~~~~~~~~~~异常信息为:{}", result.getString("message"));
throw new GatewayException(GatewayResultCode.CALL_AMOUNT_NOT_ENOUGH);
}
}
......
package com.jz.dm.filter;
import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.Md5;
import com.jz.dm.common.constant.Constants;
import com.jz.dm.common.enums.GatewayResultCode;
import com.jz.dm.common.exception.GatewayException;
import com.jz.dm.common.exception.SignatureException;
import com.jz.dm.common.util.LogUtil;
import com.jz.dm.common.util.MapUtil;
import com.jz.dm.common.util.Md5;
import com.jz.dm.models.domian.ApiAuth;
import com.jz.dm.models.enity.GatewayRequest;
import com.jz.dm.models.enity.GatewayResponse;
......@@ -42,8 +42,7 @@ public class VerifySignFilter extends AbstractFilter {
FilterChain chain) {
try {
//对签约参数进行字典排序
String signParams = MapUtil.getSignValue(request.getApiKey(),request.getMethod(),
request.getSignType(),String.valueOf(request.getTimestamp()));
String signParams = MapUtil.getSignValue(request.getApiKey(),request.getMethod(),request.getSignType());
if (StringUtils.isNotBlank(signParams)){
JSONObject jsonObject = JSONObject.parseObject(request.getParams());
String authCode = jsonObject.getString("authCode");
......
......@@ -44,7 +44,7 @@ public class ApiAuth extends BaseObject implements Serializable {
@TableField("auth_type")
private String authType;
/**
* 限类型:DAY 按天,MONTH 按月, YEAR 按年
* 限类型:DAY 按天,MONTH 按月, YEAR 按年
*/
@TableField("req_type")
private String reqType;
......
......@@ -49,7 +49,7 @@ public class ApiInterface extends BaseObject implements Serializable {
private String apiProtocl;
/**
* api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义'
* api类型:1 数据银行制作大数据表 2 数据银行制作数据包,3,数据银行制作自定义API 4 API实时接入 5 DMP标签查询 6.DMP大数据表查询 7 DMP自定义'
*/
@TableField("api_type")
private String apiType;
......@@ -109,7 +109,7 @@ public class ApiInterface extends BaseObject implements Serializable {
private String signType;
/**
* 限类型:DAY 按天,MONTH 按月, YEAR 按年
* 限类型:DAY 按天,MONTH 按月, YEAR 按年
*/
@TableField("req_type")
private String reqType;
......
......@@ -37,6 +37,30 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
private Long apiInterfaceId;
/**
* 数据源id
*/
@TableField("es_data_source")
private String esDataSource;
/**
* 源数据库名称
*/
@TableField("es_data_base")
private String esDataBase;
/**
* 源数据表名称
*/
@TableField("es_table")
private String esTable;
/**
* 处理类型
*/
@TableField("handle_type")
private String handleType;
/**
* api请求参数
*/
......
......@@ -52,7 +52,7 @@ public class ApiInterfaceFile extends BaseObject implements Serializable {
* 父类id
*/
@TableField("parent_id")
private String parentId;
private Long parentId;
/**
* 文件英文名称
*/
......
......@@ -2,6 +2,7 @@ package com.jz.dm.models.req;
import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
......@@ -18,4 +19,9 @@ import java.io.Serializable;
@Data
@ApiModel("日志信息列表")
public class LogInfoListReq extends BasePageBean implements Serializable {
@ApiModelProperty(value = "状态:SUCCEED 请求成功, FAIL 请求失败")
private String status;
@ApiModelProperty(value = "ApiKey")
private String apiKey;
}
......@@ -19,9 +19,7 @@ import java.io.Serializable;
@Data
@ApiModel(value = "api基本信息")
public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true)
@NotNull(message = "api类型不能为空")
public String apiType;
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
......@@ -46,19 +44,22 @@ public class ApiInterfaceReq implements Serializable {
@NotNull(message="超时时间不能为空")
public String timeout;
@ApiModelProperty(value = "限类型:DAY 按天,MONTH 按月, YEAR 按年",required = true)
@NotNull(message = "限类型不能为空")
@ApiModelProperty(value = "限类型:DAY 按天,MONTH 按月, YEAR 按年",required = true)
@NotNull(message = "限类型不能为空")
public String reqType;
@ApiModelProperty(value = "限制次数",required = true)
@ApiModelProperty(value = "限制次数",required = false)
public Long reqFrequency;
@ApiModelProperty(value = "api描述",required = false)
public String apiFunction;
@ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = true)
@NotNull(message="父类id文件id不能为空")
@ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = false)
public Long parentId;
@ApiModelProperty(value = "文件id",required = false)
public Long fileId;
@ApiModelProperty(value = "项目id",required = true)
@NotNull(message="项目id不能为空")
public Long projectId;
......@@ -69,5 +70,12 @@ public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "更新时传入api自增id",required = false)
public Long id;
@ApiModelProperty(value = "创建用户",hidden = true)
public String createUser;
@ApiModelProperty(value = "api类型:1.数据银行制作大数据表 " +
"2 数据银行制作数据包,3,数据银行制作自定义API " +
"4 API实时接入 6 标签查询 9自定义",hidden = true)
public String apiType;
}
......@@ -27,12 +27,12 @@ public class MakeBigDataApiReq implements Serializable {
@NotNull(message = "apiType不能为空")
private String apiType;*/
@ApiModelProperty(value = "接入类型:对应字典表key",required = true)
@NotNull(message = "接入类型不能为空")
public String joinType;
@ApiModelProperty(value = "apiKey",required = true)
@NotNull(message = "apiKey不能为空")
public String apiKey;
@ApiModelProperty(value = "是否分页",required = false)
public Integer page;
//@ApiModelProperty(value = "是否分页",required = false)
//public Boolean page;
@ApiModelProperty(value = "数据源Id",required = true)
@NotNull(message = "数据源Id不能为空")
......@@ -40,7 +40,7 @@ public class MakeBigDataApiReq implements Serializable {
@ApiModelProperty(value = "源库名称",required = true)
@NotNull(message = "源库名称不能为空")
private String esDatabase;
private String esDataBase;
@ApiModelProperty(value = "源表名称",required = true)
@NotNull(message = "源表名称不能为空")
......@@ -57,12 +57,24 @@ public class MakeBigDataApiReq implements Serializable {
@ApiModelProperty(value = "返回参数",required = true)
@NotNull(message = "返回参数不能为空")
private String resultParam;
private String responseParam;
@ApiModelProperty(value = "段列表",required = true)
@NotNull(message = "字段列表不能为空")
private String tableFields;
//@ApiModelProperty(value = "项目id",required = true)
//@NotNull(message="项目id不能为空")
//public Long projectId;
//@ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = false)
//public Long parentId;
//
//@ApiModelProperty(value = "文件id",required = false)
//public Long fileId;
}
......@@ -20,13 +20,13 @@ import java.io.Serializable;
@ApiModel("数据银行api制作")
public class MakeDataBankApiReq implements Serializable {
//@ApiModelProperty(value = "api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义",required = true)
//@ApiModelProperty(value = "api类型:1 数据银行制作大数据表 2 数据银行制作数据包,3,数据银行制作自定义API 4 API实时接入 6 标签查询 9自定义",required = true)
//@NotNull(message = "api类型不能为空")
//public String apiType;
@ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true)
@NotNull(message = "传输方式不能为空")
public String apiProtocl;
public String transMode;
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空")
......@@ -44,15 +44,23 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "是否分页不能为空")
public Boolean page;
@ApiModelProperty(value = "限类型:DAY 按天,MONTH 按月",required = true)
@NotNull(message = "限类型不能为空")
@ApiModelProperty(value = "限类型:DAY 按天,MONTH 按月",required = true)
@NotNull(message = "限类型不能为空")
public String reqType;
@ApiModelProperty(value = "目标地址",required = true)
@NotNull(message = "目标地址不能为空")
public String targetUrl;
@ApiModelProperty(value = "文件id",required = true)
@NotNull(message = "文件id不能为空")
public Long fileId;
@ApiModelProperty(value = "限制次数",required = true)
@ApiModelProperty(value = "签名",required = true)
@NotNull(message = "签名不能为空")
public String sign;
@ApiModelProperty(value = "限制次数",required = false)
public Long reqFrequency;
@ApiModelProperty(value = "请求地址",required = false)
......@@ -61,8 +69,7 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
@ApiModelProperty(value = "目标地址",required = false)
public String targetUrl;
@ApiModelProperty(value = "超时时间",required = false)
public String timeout;
......@@ -85,13 +92,12 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty(value = "api样例",required = false)
public String apiExample;
@ApiModelProperty(value = "创建用户",required = false)
public String createUser;
//-------------------------前端无效传参----------------------
//@ApiModelProperty(value = "状态",hidden = true)
//public String status;
//
//@ApiModelProperty(value = "创建用户",hidden = true)
//public String createUser;
}
......@@ -42,4 +42,7 @@ public class OrganizationManageAddReq implements Serializable {
@ApiModelProperty(value = "备注",required = false)
private String remark;
@ApiModelProperty(value = "创建用户",required = false)
private String createUser;
}
......@@ -2,6 +2,7 @@ package com.jz.dm.models.req.organizationManage;
import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
......@@ -18,4 +19,11 @@ import java.io.Serializable;
@Data
@ApiModel("组织管理查询请求体")
public class OrganizationManageListQueryReq extends BasePageBean implements Serializable {
@ApiModelProperty(value = "组织名称")
private String orgName;
@ApiModelProperty(value = "组织编码(组织唯一标识)")
private String orgCode;
}
......@@ -45,4 +45,9 @@ public class OrganizationManageUpdateReq implements Serializable {
@ApiModelProperty(value = "备注",required = false)
private String remark;
@ApiModelProperty(value = "创建用户",required = false)
private String updateUser;
}
......@@ -47,11 +47,11 @@ public interface OrganizationManageService {
Result update(OrganizationManageUpdateReq req);
/**
* 根据id删除组织
* 根据id注销组织
* @param id
* @return
*/
Result delete(Long id);
Result logoutOrg(Long id);
/**
* 获取认证组织信息
......
......@@ -97,4 +97,18 @@ public interface ProducerService {
* @return
*/
IPage<ApiInterfaceFile> getFileCatalog(Long projectId ,String pageNum, String pageSize);
/**
* 创建文件夹
* @param projectId
* @param parentId
* @param currentUser
* @return
*/
Result createProjectFolder(Long projectId, Long parentId,String currentUser);
Result saveObjOnRedis();
Result getObjOnRedis();
}
......@@ -14,6 +14,7 @@ import com.jz.dm.models.req.LogInfoListReq;
import com.jz.dm.service.ApiLogService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -47,6 +48,12 @@ public class ApiLogServiceImpl implements ApiLogService {
public IPage<ApiReqLog> listApiLog(LogInfoListReq req) {
IPage<ApiReqLog> page = new Page<>(req.getPageNum(), req.getPageSize());
QueryWrapper<ApiReqLog> query = new QueryWrapper<>();
if (StringUtils.isNotBlank(req.getApiKey())){
query.eq("api_key",req.getApiKey());
}
if (StringUtils.isNotBlank(req.getStatus())){
query.eq("status",req.getStatus());
}
query.eq("is_deleted",0);
query.orderByDesc("create_date");
return apiReqLogMapper.selectPage(page, query);
......
......@@ -19,7 +19,6 @@ import com.jz.dm.service.OrganizationManageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -42,8 +41,6 @@ public class OrganizationManageImpl implements OrganizationManageService {
@Resource
private ApiOrgMapper apiOrgMapper;
@Resource
private RedisTemplate redisTemplate;
/**
* 组织列表信息查询
......@@ -55,7 +52,14 @@ public class OrganizationManageImpl implements OrganizationManageService {
public IPage<ApiOrg> listOrganization(OrganizationManageListQueryReq req) {
IPage<ApiOrg> page = new Page<>(req.getPageNum(), req.getPageSize());
QueryWrapper<ApiOrg> query = new QueryWrapper<>();
if (StringUtils.isNotBlank(req.getOrgName())){
query.eq("org_name",req.getOrgName());
}
if (StringUtils.isNotBlank(req.getOrgCode())){
query.eq("org_code",req.getOrgCode());
}
query.eq("is_deleted", 0);
query.ne("status",OrgStatusEnum.CANCEL);
query.orderByDesc("create_date");
return apiOrgMapper.selectPage(page, query);
}
......@@ -71,6 +75,7 @@ public class OrganizationManageImpl implements OrganizationManageService {
QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.eq("is_deleted", 0);
query.eq("id", req.getId());
query.ne("status",OrgStatusEnum.CANCEL);
return Result.of_success(apiOrgMapper.selectOne(query));
}
......@@ -82,16 +87,18 @@ public class OrganizationManageImpl implements OrganizationManageService {
*/
@Override
public Result add(OrganizationManageAddReq req) {
/* SysUserDto currentUser = (SysUserDto)redisTemplate.opsForValue().get("user"+ RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser){
return Result.of_error(ResultMsg.USER_NOT_EXIST);
}*/
if (StringUtils.isNotBlank(req.getOrgName())) {
ApiOrg orgNameInfo = getOrgNameInfo(req.getOrgName());
if (null != orgNameInfo) {
return Result.of_error("组织名称已存在!");
}
}
if (StringUtils.isNotBlank(req.getOrgType())) {
if (!Constants.AUTH_INT.equals(req.getOrgType()) ||
!Constants.AUTH_OUT.equals(req.getOrgType())) {
return Result.of_error("组织类型不存在!");
}
}
String coding = "";
ApiOrg apiOrg = new ApiOrg();
BeanUtils.copyProperties(req, apiOrg);
......@@ -106,7 +113,6 @@ public class OrganizationManageImpl implements OrganizationManageService {
}
apiOrg.setOrgCode(coding);//组织编码
apiOrg.setStatus(OrgStatusEnum.NORMAL.name());//正常
//apiOrg.setCreateUser(currentUser.getUserName());
if (apiOrgMapper.insert(apiOrg) > 0) {
return Result.of_success(ResultMsg.INSERT_SUCCESS);
}
......@@ -140,23 +146,22 @@ public class OrganizationManageImpl implements OrganizationManageService {
*/
@Override
public Result update(OrganizationManageUpdateReq req) {
/* SysUserDto currentUser = (SysUserDto) redisTemplate.opsForValue().get("user" + RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) {
return Result.of_error(ResultMsg.USER_NOT_EXIST);
}*/
ApiOrg apiOrg = apiOrgMapper.selectById(req.getId());
if (null == apiOrg) {
return Result.of_error("组织信息不存在!");
}
if (StringUtils.isNotBlank(req.getStatus())) {
if (null == fromTypeName(req.getStatus())){
if (null == fromTypeName(req.getStatus())) {
return Result.of_error("更新组织状态不存在!");
}
}
//原状态为注销状态不可复原
if (OrgStatusEnum.CANCEL.equals(apiOrg.getStatus())){
return Result.of_error("注销状态不可修改");
}
ApiOrg apiOrgUpdate = new ApiOrg();
BeanUtils.copyProperties(req, apiOrgUpdate);
apiOrgUpdate.setUpdateDate(new Date());
//apiOrgUpdate.setUpdateUser(currentUser.getUserName());
if (apiOrgMapper.updateById(apiOrgUpdate) > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
......@@ -164,37 +169,39 @@ public class OrganizationManageImpl implements OrganizationManageService {
}
/**
* 删除组织
* 注销组织
*
* @param id
* @return
*/
@Override
public Result delete(Long id) {
public Result logoutOrg(Long id) {
ApiOrg apiOrg = apiOrgMapper.selectById(id);
if (null == apiOrg) {
return Result.of_error(ResultMsg.DATA_NOT_EXIST);
}
UpdateWrapper<ApiOrg> delete = new UpdateWrapper<>();
delete.set("is_deleted", 1);
delete.set("status",OrgStatusEnum.CANCEL);
delete.eq("id", id);
if (apiOrgMapper.update(null, delete) > 0) {
return Result.of_success(ResultMsg.DELETE_SUCCESS);
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
return Result.of_success(ResultMsg.DELETE_FAIL);
return Result.of_success(ResultMsg.UPDATE_FAIL);
}
/**
* 获取认证组织信息
*
* @param apiOrgId
* @return
*/
@Override
public ApiOrg getAuthOrganization(Long apiOrgId) {
QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.eq("id",apiOrgId);
query.eq("id", apiOrgId);
query.eq("status", OrgStatusEnum.NORMAL.name());
query.eq("is_deleted",0);
query.eq("is_deleted", 0);
return apiOrgMapper.selectOne(query);
}
......
......@@ -11,6 +11,7 @@ import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg;
import com.jz.common.exception.ResponseException;
import com.jz.common.utils.HttpsUtils;
import com.jz.common.utils.Md5;
import com.jz.common.utils.RedisUtils;
import com.jz.common.utils.Result;
import com.jz.dm.common.constant.TagConstants;
......@@ -22,6 +23,7 @@ import com.jz.dm.common.util.RandomUtil;
import com.jz.dm.mapper.*;
import com.jz.dm.models.domian.*;
import com.jz.dm.models.req.make.*;
import com.jz.dm.service.ApiInterfaceService;
import com.jz.dm.service.ProducerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -29,7 +31,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -66,7 +67,7 @@ public class ProducerServiceImpl implements ProducerService {
@Resource
private ApiInterfaceFileMapper apiInterfaceFileMapper;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
private ApiInterfaceService apiInterfaceService;
@Autowired
private RedisUtils redisUtils;
@Autowired
......@@ -79,27 +80,66 @@ public class ProducerServiceImpl implements ProducerService {
//@Value("${dmp.openapi.env.open:false}")
//private boolean envOpen = false;
@Value("${dmp.ignoreRedis}")
protected boolean ignoreRedis;
private boolean ignoreRedis;
/**
* dataBank签名token
*/
@Value("${token.dataBank}")
private String dataBankToken;
/**
* 获取文件列表
*
* @param projectId
* @param pageSize
* @param pageNum
* @return
*/
@Override
public IPage<ApiInterfaceFile> getFileCatalog(Long projectId,String pageNum, String pageSize) {
public IPage<ApiInterfaceFile> getFileCatalog(Long projectId, String pageNum, String pageSize) {
Integer pageN = Integer.valueOf(pageNum);
Integer pageS = Integer.valueOf(pageSize);
IPage<ApiInterfaceFile> page = new Page<>(pageN, pageS);
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("project_id",projectId);
query.eq("project_id", projectId);
query.eq("is_deleted", 0);
query.orderByDesc("create_date");
return apiInterfaceFileMapper.selectPage(page, query);
}
/**
* 创建文件夹
*
* @param projectId
* @param parentId
* @param currentUser
* @return
*/
@Override
public Result createProjectFolder(Long projectId, Long parentId, String currentUser) {
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("id", parentId);
query.eq("is_deleted", 0);
ApiInterfaceFile apiInterfaceFile = apiInterfaceFileMapper.selectOne(query);
if (null == apiInterfaceFile) {
return Result.of_error("父级文件夹不存在!");
}
ApiInterfaceFile instanceFile = new ApiInterfaceFile();
instanceFile.setProjectId(projectId);
instanceFile.setFileSource("1");//文件来源:1 DMP 2 数据银行
instanceFile.setParentId(parentId);
instanceFile.setStatus(GeneralStatusTypeEnum.VALID.name());
instanceFile.setCreateUser(currentUser);
instanceFile.setRemark("DMP创建层级文件夹");
if (apiInterfaceFileMapper.insert(instanceFile) > 0) {
return Result.of_error(ResultMsg.INSERT_SUCCESS);
}
return Result.of_error(ResultMsg.INSERT_FAIL);
}
/**
* DMP制作自定义Api
*
......@@ -112,7 +152,7 @@ public class ProducerServiceImpl implements ProducerService {
}
/**
* 数据银行制作API/数据包
* 数据银行制作API/数据包/自定义
*
* @param req
* @return
......@@ -120,60 +160,100 @@ public class ProducerServiceImpl implements ProducerService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Result addDataBankApiInfo(MakeDataBankApiReq req) {
//SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
//if (null == currentUser) {
// return Result.of_error(ResultMsg.USER_NOT_LOGIN);
//}
List<ApiInterfaceFile> fileSource =
apiInterfaceFileMapper.selectList(new QueryWrapper<ApiInterfaceFile>().eq("file_source", "2"));
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("file_source", "2");
query.eq("is_deleted", 0);
List<ApiInterfaceFile> fileSource = apiInterfaceFileMapper.selectList(query);
if (fileSource.size() == 0 || fileSource.size() >= 2) {
return Result.of_error("文件夹信息异常!");
}
if (StringUtils.isNotBlank(req.getOutputType()) &&
(!req.getOutputType().contains(ApiInfoOutTypeEnum.JSON.name()) ||
!req.getOutputType().contains(ApiInfoOutTypeEnum.FLOW.name()) )){
return Result.of_error("输出类型不存在!");
!req.getOutputType().contains(ApiInfoOutTypeEnum.FLOW.name()))) {
return Result.of_error("输出类型不存在!");
}
if(StringUtils.isNotBlank(req.getReqType()) ){
if (null == fromAuthReqTypeEnum(req.getReqType())){
return Result.of_error("限制类型不存在!");
if (StringUtils.isNotBlank(req.getReqType())) {
if (null == fromAuthReqTypeEnum(req.getReqType())) {
return Result.of_error("限流类型不存在!");
}
}
String apiKey ="";
if (StringUtils.isNotBlank(req.getJoinType())
&& "10006".equals(req.getJoinType())) {//数据银行制作API
apiKey = RandomUtil.getStringRandom(16);
ApiInterface anInterface = new ApiInterface();
//anInterface.setCreateUser(currentUser.getUserName());
anInterface.setApiType("2");//数据银行制作api
anInterface.setStatus(ProducerStatusTypeEnum.ISSUE.name());//发布
anInterface.setApiKey(apiKey);//apiKey
BeanUtils.copyProperties(req, anInterface);
int resIn = apiInterfaceMapper.insert(anInterface);
ApiInterfaceCustom interfaceCustom = new ApiInterfaceCustom();
//interfaceCustom.setCreateUser(currentUser.getUserName());
interfaceCustom.setApiKey(apiKey);
interfaceCustom.setApiInterfaceId(anInterface.getId());
BeanUtils.copyProperties(req, interfaceCustom);
int resOut = apiInterfaceCustomMapper.insert(interfaceCustom);
if (resOut == 0 || resIn == 0) {
throw ResponseException.of_error("保存信息失败!");
}
redisUtils.set(apiKey,req);
} else if (StringUtils.isNotBlank(req.getJoinType())
&& "10007".equals(req.getJoinType())) {//数据银行制作数据包
if (StringUtils.isBlank(req.getTargetUrl())) {//目标地址
return Result.of_error("目标地址为空!");
}
ApiInterfaceReq apiInterfaceReq = new ApiInterfaceReq();
apiInterfaceReq.setApiType("2");
apiInterfaceReq.setTransMode(req.getApiProtocl());//请求方式:https http
BeanUtils.copyProperties(req,apiInterfaceReq);
Result result = saveInterfaceAPi(apiInterfaceReq);
apiKey=(String) result.getData();
redisUtils.set(apiKey,req);
}
return Result.of_success(ResultMsg.INSERT_SUCCESS,apiKey);
String signStr = dataBankToken + req.getJoinType() + System.currentTimeMillis();
String signResult = Md5.encrypt(signStr, "");
if (!signResult.equals(req.getSign())) {
return Result.of_error("签名错误!");
}
String apiKey = getApiKey();
switch (req.getJoinType()) {
case "10006"://数据银行三方上传
saveDataBanker(req, apiKey, "3");
break;
case "10007"://数据银行数据包上传
saveDataBanker(req, apiKey, "2");
break;
case "10008"://数据银行制作大数据表
saveDataBanker(req, apiKey, "1");
break;
default:
return Result.of_error("接入类型不存在!");
}
return Result.of_success(ResultMsg.INSERT_SUCCESS, apiKey);
}
/**
* 保存数据银行api信息并缓存
*
* @param req 请求参数
* @param apiKey apiKey
* @param apiType api类型
*/
private void saveDataBanker(MakeDataBankApiReq req, String apiKey, String apiType) {
ApiInterface apiInterface = saveApiInterFace(req, apiKey, apiType);
saveApiInterFaceCustom(req, apiKey, apiInterface.getId());
JSONObject object = new JSONObject();
object.put("targetUrl",req.getTargetUrl());
object.put("outputType",req.getOutputType());
saveObjOnRedis(apiInterface.getApiKey(),object);
}
/**
* 保存api基本信息
*
* @param req
* @param apiKey
* @param apiType
* @return
*/
private ApiInterface saveApiInterFace(MakeDataBankApiReq req,
String apiKey, String apiType) {
ApiInterface anInterface = new ApiInterface();
anInterface.setApiType(apiType);//数据银行制作大数据表
anInterface.setStatus(ProducerStatusTypeEnum.ISSUE.name());//发布
anInterface.setApiKey(apiKey);//apiKey
BeanUtils.copyProperties(req, anInterface);
if (apiInterfaceMapper.insert(anInterface) == 0) {
throw ResponseException.of(ResultCode.FAILURE, "保存api基本信息异常!");
}
return anInterface;
}
/**
* 保存APi扩展信息
*
* @param req
* @param apiKey
* @param interFaceId
* @return
*/
private ApiInterfaceCustom saveApiInterFaceCustom(MakeDataBankApiReq req, String apiKey,
Long interFaceId) {
ApiInterfaceCustom interfaceCustom = new ApiInterfaceCustom();
interfaceCustom.setApiKey(apiKey);
interfaceCustom.setApiInterfaceId(interFaceId);
BeanUtils.copyProperties(req, interfaceCustom);
if (apiInterfaceCustomMapper.insert(interfaceCustom) == 0) {
throw ResponseException.of(ResultCode.FAILURE, "保存api扩展信息异常!");
}
return interfaceCustom;
}
/**
......@@ -189,7 +269,7 @@ public class ProducerServiceImpl implements ProducerService {
}
/**
* Api制作(大数据查询/标签查询)
* DMP大数据查询/标签查询
*
* @param req
* @return
......@@ -197,18 +277,24 @@ public class ProducerServiceImpl implements ProducerService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Result addBigDataMakeApi(MakeBigDataApiReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
SysUserDto currentUser = getLoginUser("004");
if (null == currentUser) {
return Result.of_error("用户信息不存在");
}
ApiInterface apiInterface = apiInterfaceService.getApiInfo(req.getApiKey());
if (null == apiInterface) {
return Result.of_error("API基本信息为空!");
}
QueryWrapper<ApiOpenApiEsFields> queryOpenApi = new QueryWrapper<>();
queryOpenApi.eq("es_database", req.getEsDatabase());
queryOpenApi.eq("es_database", req.getEsDataBase());
queryOpenApi.eq("es_table", req.getEsTable());
queryOpenApi.eq("is_deleted", 0);
List<ApiOpenApiEsFields> listOpenApiEsFields = apiOpenApiEsFieldsMapper.selectList(queryOpenApi);
//如果存在先根据库,表删除,重新添加
if (CollectionUtils.isNotEmpty(listOpenApiEsFields)) {
Map paMap = new HashMap<>();
paMap.put("es_database", req.getEsDataBase());
paMap.put("es_table", req.getEsTable());
apiOpenApiEsFieldsMapper.deleteByMap(paMap);
}
ArrayList<ApiOpenApiEsFields> listApiEsFields = new ArrayList<>();
......@@ -217,7 +303,7 @@ public class ProducerServiceImpl implements ProducerService {
for (int i = 0; i < json.size(); i++) {
JSONObject jsonObject = (JSONObject) json.get(i);
ApiOpenApiEsFields fields = new ApiOpenApiEsFields();
fields.setEsDatabase(req.getEsDatabase());
fields.setEsDatabase(req.getEsDataBase());
fields.setEsTable(req.getEsTable());
fields.setFieldName(jsonObject.get("name").toString());
fields.setFieldType(jsonObject.get("type").toString());
......@@ -231,24 +317,31 @@ public class ProducerServiceImpl implements ProducerService {
}
ApiSyncingDatasource dataSource = apiSyncingDatasourceMapper.selectById(req.getEsDataSource());
//api信息在redis中的key
String redisValueOfKey = RandomUtil.getStringRandom(16);
String redisValueOfKey = apiInterface.getApiKey();
if (null != dataSource) {
//存入调用的基本ApiKey信息
redisTemplate.opsForValue().set( redisValueOfKey, req);
//esjdbc 连接地址 用于接口中调用获取es数据
redisTemplate.opsForValue().set(TagConstants.OPEN_API_ESTAG_JDBC_INFO_NAMESPACE + redisValueOfKey, dataSource.getJdbcUrl());
redisUtils.set(TagConstants.OPEN_API_ESTAG_JDBC_INFO_NAMESPACE + redisValueOfKey, dataSource.getJdbcUrl());
}
int result = 0;
ApiOpenApiEsTagconfig apiEsTagconfig = new ApiOpenApiEsTagconfig();
ApiInterfaceCustom interfaceCustom = new ApiInterfaceCustom();
//ApiOpenApiEsTagconfig apiEsTagconfig = new ApiOpenApiEsTagconfig();
if (null != req.getId() && !"".equals(req.getId())) {//更新
apiEsTagconfig.setUpdateDate(new Date());
/* apiEsTagconfig.setUpdateDate(new Date());
apiEsTagconfig.setUpdateUser(currentUser.getUserName());
BeanUtils.copyProperties(req, apiEsTagconfig);
result = apiOpenApiEsTagconfigMapper.updateById(apiEsTagconfig);
result = apiOpenApiEsTagconfigMapper.updateById(apiEsTagconfig);*/
BeanUtils.copyProperties(req, interfaceCustom);
interfaceCustom.setUpdateDate(new Date());
interfaceCustom.setUpdateUser(currentUser.getUserName());
result = apiInterfaceCustomMapper.updateById(interfaceCustom);
} else { //保存
apiEsTagconfig.setCreateUser(currentUser.getUserName());
BeanUtils.copyProperties(req, interfaceCustom);
interfaceCustom.setCreateUser(currentUser.getUserName());
interfaceCustom.setApiInterfaceId(apiInterface.getId());
result = apiInterfaceCustomMapper.insert(interfaceCustom);
/* apiEsTagconfig.setCreateUser(currentUser.getUserName());
BeanUtils.copyProperties(req, apiEsTagconfig);
result = apiOpenApiEsTagconfigMapper.insert(apiEsTagconfig);
result = apiOpenApiEsTagconfigMapper.insert(apiEsTagconfig);*/
}
if (result <= 0) {
return Result.of_error(ResultMsg.FAILURE);
......@@ -257,7 +350,7 @@ public class ProducerServiceImpl implements ProducerService {
}
/**
* 保存api基本信息
* DMP保存api基本信息/自定义API
*
* @param req
* @return
......@@ -265,46 +358,27 @@ public class ProducerServiceImpl implements ProducerService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public Result saveInterfaceAPi(ApiInterfaceReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) {
return Result.of_error("用户信息不存在");
}
if(StringUtils.isNotBlank(req.getReqType()) ){
if (null == fromAuthReqTypeEnum(req.getReqType())){
return Result.of_error("限制类型不存在!");
}
}
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("project_id", req.getProjectId());
query.eq("parent_id", req.getParentId());
ApiInterfaceFile file = apiInterfaceFileMapper.selectOne(query);
if (null == file) {
//查询父类是否存在
ApiInterfaceFile parentId = apiInterfaceFileMapper.selectOne(new QueryWrapper<ApiInterfaceFile>().eq("parent_id", req.getParentId()));
if (null == parentId && "0".equals(req.getParentId())){
file= new ApiInterfaceFile();
file.setProjectId(req.getProjectId());
file.setFileSource("1");//dmp
file.setParentId("0");
file.setStatus(GeneralStatusTypeEnum.VALID.name());
file.setCreateUser("");
file.setRemark("创建文件夹");
if ( apiInterfaceFileMapper.insert(file) == 0){
throw ResponseException.of_error("创建文件夹失败!");
}
}else {
throw ResponseException.of(ResultCode.FAILURE,"父类文件信息不存在!");
if (StringUtils.isNotBlank(req.getReqType())) {
if (null == fromAuthReqTypeEnum(req.getReqType())) {
return Result.of_error("限流类型不存在!");
}
}
//生成ApiKey
String apiKey = RandomUtil.getStringRandom(16);
String apiKey = getApiKey();
ApiInterface apiInterface = new ApiInterface();
if (null == req.getFileId()) {//创建下级文件夹
Long fileId = checkFileExist(req.getProjectId(), req.getParentId(), req.getCreateUser());
req.setFileId(fileId);
}
BeanUtils.copyProperties(req, apiInterface);
apiInterface.setApiKey(apiKey);
apiInterface.setApiProtocl(req.getTransMode());//传输方式 https http
apiInterface.setStatus(ApiStatusEnum.ISSUE.name());//发布
apiInterface.setFileId(file.getId());
BeanUtils.copyProperties(req, apiInterface);
apiInterface.setCreateUser(currentUser.getUserName());
if ("10004".equals(req.getJoinType())) {//dmp自定义
apiInterface.setApiType("7");
} else if ("10002".equals(req.getJoinType())) {//大数据表查询
apiInterface.setApiType("6");
}
Long timeout = Long.parseLong(req.getTimeout());
if (timeout == null || timeout == 0) {
apiInterface.setTimeout(String.valueOf(defaultTimeout));
......@@ -316,9 +390,78 @@ public class ProducerServiceImpl implements ProducerService {
if (apiInterfaceMapper.insert(apiInterface) == 0) {
throw ResponseException.of_error("保存Api信息失败!");
}
//缓存到redis中
redisUtils.set(apiKey,req);
return Result.of_success(ResultMsg.INSERT_SUCCESS,apiKey);
JSONObject object = new JSONObject();
object.put("targetUrl",req.getTargetUrl());
object.put("outputType",ApiInfoOutTypeEnum.JSON.name());
saveObjOnRedis(apiInterface.getApiKey(),object);
return Result.of_success(ResultMsg.INSERT_SUCCESS, apiKey);
}
/**
* 缓存数据
*
* @param apiKey
* @param params
*/
private void saveObjOnRedis(String apiKey, JSONObject params) {
if (StringUtils.isBlank(apiKey) || null == params) {
log.info("--------------缓存数据为空");
return;
}
try {
String paramKey = redisUtils.get(apiKey);
if (null != paramKey){
redisUtils.del(apiKey);
}
redisUtils.set(apiKey, params.toString());
} catch (Exception ex) {
log.error("缓存api制作数据异常:{}",ex.getMessage());
ex.printStackTrace();
}
}
/**
* 校验文件夹信息
*
* @param projectId
* @param parentId
* @param userName
* @return
*/
private Long checkFileExist(Long projectId, Long parentId, String userName) {
if (null == parentId) {
throw ResponseException.of_error("父文件id不能为空");
}
if (null == projectId) {
throw ResponseException.of_error("项目id不能为空");
}
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("project_id", projectId);
query.eq("parent_id", parentId);
ApiInterfaceFile file = apiInterfaceFileMapper.selectOne(query);
if (null == file && 0 != parentId) {
throw ResponseException.of(ResultCode.FAILURE, "父类文件夹不存在!");
}
if (null == file) {
//查询父类是否存在
ApiInterfaceFile apiInterfaceFile =
apiInterfaceFileMapper.selectOne(new QueryWrapper<ApiInterfaceFile>().eq("parent_id", parentId));
if (null == apiInterfaceFile && 0 == parentId) {
file = new ApiInterfaceFile();
file.setProjectId(projectId);
file.setFileSource("1");//dmp
file.setParentId(0L);
file.setStatus(GeneralStatusTypeEnum.VALID.name());
file.setCreateUser(userName);
file.setRemark("创建文件夹");
if (apiInterfaceFileMapper.insert(file) == 0) {
throw ResponseException.of_error("创建文件夹失败!");
}
} else {
throw ResponseException.of(ResultCode.FAILURE, "父类文件信息不存在!");
}
}
return file.getId();
}
/**
......@@ -329,10 +472,6 @@ public class ProducerServiceImpl implements ProducerService {
*/
@Override
public Result saveUpdateAPiInfo(ApiInterfaceReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) {
return Result.of_error("用户信息不存在");
}
ApiInterface apiInterface = apiInterfaceMapper.selectById(req.getId());
if (null == apiInterface) {
return Result.of_error(ResultMsg.DATA_NOT_FOUND);
......@@ -340,53 +479,59 @@ public class ProducerServiceImpl implements ProducerService {
if (StringUtils.isBlank(req.getSignType()) || "0".equals(req.getSignType())) {
return Result.of_error("加密类型错误!");
}
if(StringUtils.isNotBlank(req.getReqType()) ){
if (null == fromAuthReqTypeEnum(req.getReqType())){
return Result.of_error("限制类型不存在!");
if (StringUtils.isNotBlank(req.getReqType())) {
if (null == fromAuthReqTypeEnum(req.getReqType())) {
return Result.of_error("限流类型不存在!");
}
}
if (StringUtils.isNotBlank(req.getStatus())) {
if (null == fromApiStatusName(req.getStatus())) {
return Result.of_error("更新状态不存在!");
}
}
if (StringUtils.isNotBlank(req.getStatus())) {
if (!canChange(apiInterface.getStatus(), req.getStatus())) {
String errorMsg = String.format("api当前状态为%s不可变更为%s",
ApiStatusEnum.valueOf(apiInterface.getStatus()).getText(),
ApiStatusEnum.valueOf(req.getStatus()).getText());
return Result.of_error(errorMsg);
}
}
if (null != req.getReqFrequency()) {
if (req.getReqFrequency() <= 0) {
return Result.of_error("限流次数不能小于或者等于零");
}
}
apiInterface.setApiType(req.getApiType());
apiInterface.setApiDesc(req.getApiDesc());
apiInterface.setJoinType(req.getJoinType());
apiInterface.setReqType(req.getReqType());
apiInterface.setReqFrequency(req.getReqFrequency());
apiInterface.setVersion(RandomUtil.generateVersion(apiInterface.getVersion()));//版本自动累加
apiInterface.setSignType(req.getSignType());
apiInterface.setApiFunction(req.getApiFunction());
apiInterface.setStatus(req.getStatus());
apiInterface.setApiProtocl(req.getTransMode());//传输方式 https http
apiInterface.setUpdateDate(new Date());
apiInterface.setUpdateUser(req.getCreateUser());
if (StringUtils.isNotBlank(req.getTargetUrl())) {
apiInterface.setTargetUrl(req.getTargetUrl());
if (StringUtils.isNotBlank(req.getTimeout())) {
apiInterface.setTimeout(req.getTimeout());
}
apiInterface.setApiFunction(req.getApiFunction());
if (StringUtils.isNotBlank(req.getStatus())){
if (null == fromApiStatusName(req.getStatus())){
return Result.of_error("更新状态不存在!");
}
}
apiInterface.setStatus(req.getStatus());
if (StringUtils.isNotBlank(req.getStatus())) {
boolean b = canChange(apiInterface.getStatus(), req.getStatus());
if (!b) {
String errorMsg = String.format("api当前状态为%s不可变更为%s",
ApiStatusEnum.valueOf(apiInterface.getStatus()).getText(), ApiStatusEnum.valueOf(req.getStatus()).getText());
return Result.of_error(errorMsg);
}
}
Long timeout = Long.parseLong(apiInterface.getTimeout());
if (timeout == null || timeout == 0) {
apiInterface.setTimeout(String.valueOf(defaultTimeout));
} else if (timeout < 0) {
return Result.of_error("接口超时时间最小0ms");
} else if (timeout > maxTimeout) {
return Result.of_success("接口超时时间最大5000ms");
}
apiInterface.setUpdateDate(new Date());
apiInterface.setTimeout(req.getTimeout());
apiInterface.setUpdateUser(currentUser.getUserName());
int result = apiInterfaceMapper.updateById(apiInterface);
if (result > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
}
Long timeout = Long.parseLong(req.getTimeout());
if (timeout == null || timeout == 0) {
apiInterface.setTimeout(String.valueOf(defaultTimeout));
} else if (timeout < 0) {
return Result.of_error("接口超时时间最小0ms");
} else if (timeout > maxTimeout) {
return Result.of_success("接口超时时间最大5000ms");
}
apiInterface.setTimeout(req.getTimeout());
if (apiInterfaceMapper.updateById(apiInterface) > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
JSONObject object = new JSONObject();
object.put("targetUrl",req.getTargetUrl());
object.put("outputType",ApiInfoOutTypeEnum.JSON.name());
saveObjOnRedis(apiInterface.getApiKey(),object);
return Result.of_success(ResultMsg.UPDATE_FAIL);
}
......@@ -435,8 +580,8 @@ public class ProducerServiceImpl implements ProducerService {
}
} else {
QueryWrapper<ApiInterface> query = new QueryWrapper<>();
query.eq("api_key",req.getApiKey());
query.eq("is_deleted",0);
query.eq("api_key", req.getApiKey());
query.eq("is_deleted", 0);
ApiInterface apiInterface = apiInterfaceMapper.selectOne(query);
if (null != apiInterface) {
return Result.of_error("存在重复的Apikey");
......@@ -459,15 +604,13 @@ public class ProducerServiceImpl implements ProducerService {
}
JSONArray result = new JSONArray();
log.info("查询es标签类下的索引地址信息:" + datasource.getJdbcUrl() + "/es/get/indicess");
String resp = httpsUtils.doGet(datasource.getJdbcUrl() + "/es/get/indicess", null);
String resp = httpsUtils.doGet(datasource.getJdbcUrl() + "/es/get/indicess", new HashMap<>());
if (resp != null) {
log.info("返回索引信息集合:" + resp);
JSONArray json = JSONArray.parseArray(resp);
for (int i = 0; i < json.size(); i++) {
String database = json.get(i).toString();
/**
* 除去已点开头的索引返回前端
*/
//除去已点开头的索引返回前端
if (!database.startsWith(".")) {
result.add(database);
}
......@@ -492,7 +635,6 @@ public class ProducerServiceImpl implements ProducerService {
return Result.of_error("数据源不存在!");
}
log.info("查询es标签类索引下的type的地址信息:" + datasource.getJdbcUrl() + "/es/get/indices/types");
JSONObject param = new JSONObject();
param.put("indices", indices);
log.info("参数集合:" + param.toString());
......@@ -524,7 +666,7 @@ public class ProducerServiceImpl implements ProducerService {
param.put("type", type);
String resp = null;
try {
resp = httpsUtils.submitPost(datasource.getJdbcUrl() + "/es/get/type/fields", param,herders);
resp = httpsUtils.submitPost(datasource.getJdbcUrl() + "/es/get/type/fields", param, herders);
log.info("索引下type的fields信息集合:" + resp);
} catch (Exception e) {
e.printStackTrace();
......@@ -532,17 +674,75 @@ public class ProducerServiceImpl implements ProducerService {
return Result.of_success(resp);
}
/**
* 获取不重复的apiKey
*
* @return
*/
private String getApiKey() {
String random = RandomUtil.getStringRandom(16);
QueryWrapper<ApiInterface> query = new QueryWrapper<>();
query.eq("api_key", random);
query.eq("is_deleted", 0);
ApiInterface apiInterface = apiInterfaceMapper.selectOne(query);
if (null != apiInterface) {
random = RandomUtil.getStringRandom(16);
}
return random;
}
/**
* 获取当前登录用户
*
* @param userType
* @return
*/
protected SysUserDto getLoginUser(String userType){
SysUserDto currentUser = (SysUserDto)
redisTemplate.opsForValue().get("USER_" + RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null != currentUser){
return currentUser;
}
return null;
protected SysUserDto getLoginUser(String userType) {
SysUserDto currentUser = null;
switch (userType) {
case "004": //平台用户004
currentUser = (SysUserDto) redisUtils.getObj("USER_" + RedisMessageConstant.SENDTYPE_LOGIN_SYS);
break;
case "003": //商城用户 003
currentUser = (SysUserDto) redisUtils.getObj("USER_" + RedisMessageConstant.SENDTYPE_LOGIN_CUSTOMER);
break;
default:
return null;
}
return currentUser;
}
@Override
public Result saveObjOnRedis() {
MakeDataBankApiReq bankApiReq = new MakeDataBankApiReq();
/* bankApiReq.setTransMode("HTTPS");
bankApiReq.setSignType("MD5");
bankApiReq.setJoinType("10004");
bankApiReq.setOutputType("JSON");
bankApiReq.setPage(false);
bankApiReq.setReqType("DAY");
bankApiReq.setTargetUrl("www.baidu.com");
bankApiReq.setFileId(1L);
bankApiReq.setSign("F2A8E3CFE528D6AE5C5B075046653F3E");
bankApiReq.setReqFrequency(0L);
bankApiReq.setApiDesc("4444");
bankApiReq.setTimeout("5000");
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(bankApiReq);
redisUtils.set("apiKeyTest", jsonObject, 300);*/
JSONObject object = new JSONObject();
object.put("targetUrl","www.baidu.common");
object.put("outputType",ApiInfoOutTypeEnum.JSON.name());
saveObjOnRedis("apiKeyTest002",object);
return Result.ok();
}
@Override
public Result getObjOnRedis() {
String apiKeyTest002 = redisUtils.get("apiKeyTest002");
// JSONObject jsonObject = JSONObject.parseObject(apiKeyTest);
JSONObject jsonObject = JSONObject.parseObject(apiKeyTest002);
System.out.println(jsonObject);
return Result.ok();
}
}
......@@ -18,7 +18,6 @@ import com.jz.dm.models.domian.ApiInterface;
import com.jz.dm.service.ApiInterfaceService;
import com.jz.dm.service.AuthService;
import com.jz.dm.web.annotation.AccessLimit;
import com.jz.dm.web.annotation.ApiLogAspect;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -71,7 +70,7 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
* @param response
*/
@Override
@ApiLogAspect(description = "API请求日志")
// @ApiLogAspect(description = "API请求日志")
@AccessLimit(limit = 10000, sec = 1)
@SentinelResource(value = "api.gateway", fallback = "fallbackGateway")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
......@@ -114,6 +113,10 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
}
} catch (Exception ex) {
if (ex instanceof GatewayException) {
//调用失败回调数据银行解冻
if (AuthModeEnum.POWER_CALL_MODE.name().equals(apiAuth.getAuthMode())){
notifierMinusMoney(parameter, bResult);
}
throw (GatewayException) ex;
}
log.error("~~~~~~~~~~~~~~~请求api信息异常~~~~~~~~~~~~~");
......@@ -186,7 +189,7 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
jsonReq.put("assetsId",assetsId);
jsonReq.put("userId",userId);
jsonReq.put("dataPrice",dataPrice);
jsonReq.put("callStatus",bResult);//调用成功 扣款 false 调用失败,解冻金额
jsonReq.put("callStatus",bResult);//true 调用成功 扣款 false 调用失败,解冻金额
String responseResult = httpsUtils.submitPost(withholdUrl, jsonReq.toString());
JSONObject paramsResult = JSONObject.parseObject(responseResult);
if (null != paramsResult){
......
......@@ -83,7 +83,7 @@ public class SystemLogAspect {
String url = UrlUtil.getServerUrl(request);
// 访问项目名
String contextPath = request.getContextPath();
log.info("around请求参数为{}", joinPoint.getArgs());
log.info("around请求参数为{}", params);
//动态修改其参数
//注意,如果调用joinPoint.proceed()方法,则修改的参数值不会生效,必须调用joinPoint.proceed(Object[] args)
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(params);
......
......@@ -92,7 +92,8 @@ sentinel: #sentinel每秒中最大的请求个数
#数据银行调用配置
data:
bank:
balanceUrl: http://localhost:8081/mall/financeCustomerAssets/findAssets #余额信息url
withholdUrl: http://localhost:8081/mall/financeCustomerAssets/unfreezeMoney #扣款信通知url
balanceUrl: http://192.168.1.139:8081/mall/financeCustomerAssets/findAssets #余额信息url
withholdUrl: http://192.168.1.139:8081/mall/financeCustomerAssets/unfreezeMoney #扣款信通知url
token: #dataBank 制作验签
dataBank: dataBank123
......@@ -2,8 +2,8 @@ package com.jz.dm.gateway.api;
import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.HttpsUtils;
import com.jz.common.utils.Md5;
import com.jz.dm.common.util.MapUtil;
import com.jz.dm.common.util.Md5;
import com.jz.dm.gateway.SpringTestCase;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -27,14 +27,14 @@ public class ApiReqTest extends SpringTestCase {
public void TestGatewayReq() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("apiKey", "9jNA1W5Ydn7Stp12");
jsonObject.put("apiKey", "sE862E97j7Yzo049");
jsonObject.put("method", "query");
jsonObject.put("signType", "MD5");
long time = System.currentTimeMillis();
jsonObject.put("timestamp", "1609919983045");
jsonObject.put("timestamp", String.valueOf(time));
JSONObject params = new JSONObject();
params.put("authCode", "20200000000221231111455Jg8ug1621");
params.put("authCode", "202100000001118191258T718d78591J");
params.put("selectType", "10006");
params.put("reqParams", new JSONObject());
jsonObject.put("params",params);
......@@ -42,10 +42,9 @@ public class ApiReqTest extends SpringTestCase {
String apiKey = jsonObject.getString("apiKey");
String method = jsonObject.getString("method");
String signType = jsonObject.getString("signType");
String timestamp= jsonObject.getString("timestamp");
String signature = MapUtil.getSignValue(apiKey, method, signType, timestamp);
String salt = Md5.encrypt(signature, "OOmeF1gh");
String signature = MapUtil.getSignValue(apiKey, method, signType);
String salt = Md5.encrypt(signature, "33tgT3g2");
jsonObject.put("sign", salt);
String response = httpsUtils.submitPost(url, jsonObject.toString());
System.out.println(response);
......
package com.jz.dm.gateway.orther;
import com.jz.dm.common.base.BaseCurrentUserObject;
import com.jz.dm.common.util.RedisSerializableUtil;
import com.jz.dm.gateway.SpringTestCase;
import com.jz.dm.models.req.make.MakeDataBankApiReq;
import net.sf.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -19,17 +21,49 @@ import org.springframework.data.redis.core.RedisTemplate;
public class TestRedisUserSave extends SpringTestCase {
@Autowired
private RedisTemplate redisTemplate;
private RedisTemplate<String, Object> redisTemplate;
/*@Autowired
private RedisUtils redisUtils;*/
@Test
public void saveUser(){
redisTemplate.opsForValue().set("USER004","USER9999");
RedisTemplate template = new RedisTemplate();
template.opsForValue().set("USER004","USER9999");
// this.redisTemplate.opsForValue().set("USER004","USER9999");
}
@Test
public void getUser(){
//String str= (String)redisTemplate.opsForValue().get("USER"+"_99999");
//System.out.println("获取到的用户:"+str);
System.out.println(new BaseCurrentUserObject().getUserInfo());
redisTemplate.opsForValue().get("USER004");
}
@Test
public void saveObject(){
MakeDataBankApiReq bankApiReq = new MakeDataBankApiReq();
bankApiReq.setTransMode("HTTPS");
bankApiReq.setSignType("MD5");
bankApiReq.setJoinType("10004");
bankApiReq.setOutputType("JSON");
bankApiReq.setPage(false);
bankApiReq.setReqType("DAY");
bankApiReq.setTargetUrl("www.baidu.com");
bankApiReq.setFileId(1L);
bankApiReq.setSign("F2A8E3CFE528D6AE5C5B075046653F3E");
bankApiReq.setReqFrequency(0L);
bankApiReq.setApiDesc("4444");
bankApiReq.setTimeout("5000");
String value = String.valueOf(bankApiReq);
System.out.println(value);
// JSONObject jsonObject = JSONObject.parseObject(value);
JSONObject jsonObject = JSONObject.fromObject(bankApiReq);
System.out.println(jsonObject);
// redisTemplate.opsForValue().set(bankApiReq,jsonObject,300, TimeUnit.SECONDS);
/*RedisUtils redisUtilsaa = new RedisUtils();*/
RedisTemplate redisTemplate1 = new RedisTemplate();
byte[] serialize = RedisSerializableUtil.serialize(jsonObject);
// redisUtilsaa.set("bankApiReq",jsonObject,300);
redisTemplate1.opsForValue().set("bankApiReq",jsonObject);
redisTemplate1.opsForValue().get(bankApiReq);
}
}
......@@ -7,4 +7,11 @@ package com.jz.dm.gateway.orther;
* @Version:
*/
public class TestStr {
public static void main(String[] args) {
String str = "/picture/logo/T6gxlv137nFA555z.jpg";
// String[] split = str.split("\\/");
System.out.println(str.substring(0, str.lastIndexOf("/") + 1));
String substring = str.substring(str.lastIndexOf("."));
System.out.println(substring);
}
}
......@@ -85,7 +85,11 @@
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<!--链接FTP服务-->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
......
package com.jz.dm.common.util;
package com.jz.common.utils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......
......@@ -132,6 +132,15 @@ public class RedisUtils {
return (String) redisTemplate.opsForValue().get(key);
}
/**
* 实现命令:GET key,返回 key所关联的值。
*
* @param key
* @return obj
*/
public Object getObj(String key) {
return redisTemplate.opsForValue().get(key);
}
/**
* Hash(哈希表)
* 实现命令:HSET key field value,将哈希表 key中的域 field的值设为 value
......
......@@ -4,7 +4,6 @@ import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
......@@ -33,9 +32,9 @@ public class SMSUtils {
* @param templateCode
* @param phoneNumbers
* @param param
* @throws ClientException
* @throws
*/
public static void sendShortMessage(String templateCode,String phoneNumbers,String param) throws ClientException{
public static void sendShortMessage(String templateCode,String phoneNumbers,String param) throws Exception{
// 设置超时时间-可自行调整
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
......
......@@ -121,6 +121,10 @@
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- common公共模块 -->
<dependency>
<groupId>com.jz.common</groupId>
......
package com.jz.dm.mall.moduls.controller.company;
import com.jz.common.entity.Department;
import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.company.bean.CompanyAddReq;
import com.jz.dm.mall.moduls.controller.company.bean.CompanyUpdateReq;
......
package com.jz.dm.mall.moduls.controller.customer;
import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result;
import com.jz.common.utils.SMSUtils;
import com.jz.common.utils.StatusCode;
import com.jz.common.utils.ValidateCodeUtils;
import io.swagger.annotations.Api;
......@@ -12,8 +10,10 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
......@@ -50,8 +50,8 @@ public class ValidateCodeController {
String code = ValidateCodeUtils.generateValidateCode(6) + "";
// 发送
try {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
// SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!", StatusCode.ERROR);
}
......@@ -81,8 +81,8 @@ public class ValidateCodeController {
String code = ValidateCodeUtils.generateValidateCode(6) + "";
// 发送
try {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
// SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!", StatusCode.ERROR);
}
......
......@@ -5,7 +5,6 @@ import com.jz.common.base.BaseController;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.dm.mall.moduls.controller.goods.bean.dto.DataGoodsApiDto;
import com.jz.dm.mall.moduls.entity.DataGoodsApi;
import com.jz.dm.mall.moduls.service.DataGoodsApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......
package com.jz.manage.moduls.controller.sys;
import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result;
import com.jz.common.utils.SMSUtils;
......@@ -41,7 +40,7 @@ public class ValidateCodeController {
// 发送
try {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
} catch (Exception e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!");
}
......
......@@ -47,6 +47,7 @@
<swagger-bootstrap-ui.version>1.9.6</swagger-bootstrap-ui.version>
<lombok.version>1.18.16</lombok.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<commons-net.version>3.5</commons-net.version>
</properties>
<dependencyManagement>
......@@ -216,6 +217,11 @@
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>${commons-net.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment