Commit 77c6b4d9 authored by zhangc's avatar zhangc

commit

parent 3088ec43
...@@ -7,7 +7,9 @@ CREATE TABLE `t_api_interface` ( ...@@ -7,7 +7,9 @@ CREATE TABLE `t_api_interface` (
`api_desc` varchar(300) DEFAULT NULL COMMENT 'api描述', `api_desc` varchar(300) DEFAULT NULL COMMENT 'api描述',
`api_protocl` varchar(32) DEFAULT NULL COMMENT 'api请求协议:http,https', `api_protocl` varchar(32) DEFAULT NULL COMMENT 'api请求协议:http,https',
`target_url` varchar(100) DEFAULT NULL COMMENT '目标url', `target_url` varchar(100) DEFAULT NULL COMMENT '目标url',
`status` varchar(20) NOT NULL COMMENT '状态(1-草稿 2-发布 3-过时 4-冻结 5-失效)', `api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义',
`api_function` varchar(200) DEFAULT NULL COMMENT '接口功能',
`status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)',
`version` varchar(20) DEFAULT NULL COMMENT '版本号', `version` varchar(20) DEFAULT NULL COMMENT '版本号',
`sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA', `sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA',
`timeout` varchar(50) DEFAULT NULL COMMENT '超时时间', `timeout` varchar(50) DEFAULT NULL COMMENT '超时时间',
...@@ -22,6 +24,26 @@ CREATE TABLE `t_api_interface` ( ...@@ -22,6 +24,26 @@ CREATE TABLE `t_api_interface` (
UNIQUE KEY `api_key_unique` (`api_key`) USING BTREE UNIQUE KEY `api_key_unique` (`api_key`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='api信息表'; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='api信息表';
#api api自定义信息表
DROP TABLE IF EXISTS `t_api_interface_custom`;
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自定义',
`request_param` varchar(300) DEFAULT NULL COMMENT '请求参数',
`response_param` varchar(300) DEFAULT NULL COMMENT '响应参数',
`req_headers` varchar(300) DEFAULT NULL COMMENT '请求头',
`resp_code` varchar(300) DEFAULT NULL COMMENT '响应状态码',
`api_example` varchar(300) DEFAULT NULL COMMENT 'api返回样例',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`create_user` varchar(100) DEFAULT NULL COMMENT '创建人',
`update_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`update_user` varchar(100) DEFAULT NULL COMMENT '更新人',
`is_deleted` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除',
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='api自定义信息表';
#api组织信息表 #api组织信息表
...@@ -32,6 +54,8 @@ CREATE TABLE `t_api_org` ( ...@@ -32,6 +54,8 @@ CREATE TABLE `t_api_org` (
`org_name` varchar(100) DEFAULT NULL COMMENT '组织名称', `org_name` varchar(100) DEFAULT NULL COMMENT '组织名称',
`org_desc` varchar(300) DEFAULT NULL COMMENT '组织描述', `org_desc` varchar(300) DEFAULT NULL COMMENT '组织描述',
`org_cn_name` varchar(100) DEFAULT NULL COMMENT '组织英文名称', `org_cn_name` varchar(100) DEFAULT NULL COMMENT '组织英文名称',
`org_phone` varchar(20) NULL DEFAULT NULL COMMENT '组织电话',
`org_type` varchar(20) NULL DEFAULT NULL COMMENT '组织类型:OUT 外部组织, IN 内部组织',
`status` varchar(100) NOT NULL COMMENT '状态(1-正常 2-冻结 3-下架)', `status` varchar(100) NOT NULL COMMENT '状态(1-正常 2-冻结 3-下架)',
`org_mail` varchar(100) DEFAULT NULL COMMENT '组织邮箱', `org_mail` varchar(100) DEFAULT NULL COMMENT '组织邮箱',
`org_sort` int(10) DEFAULT '999' COMMENT '组织排序', `org_sort` int(10) DEFAULT '999' COMMENT '组织排序',
...@@ -53,10 +77,10 @@ CREATE TABLE `t_api_auth` ( ...@@ -53,10 +77,10 @@ CREATE TABLE `t_api_auth` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api授权信息表自增ID', `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api授权信息表自增ID',
`api_interface_id` bigint(20) NOT NULL COMMENT 'api信息表id', `api_interface_id` bigint(20) NOT NULL COMMENT 'api信息表id',
`api_org_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 '授权类型:1.数据银行购买 2.dmp授权', `auth_type` varchar(20) DEFAULT NULL COMMENT '授权类型:DATA_BANK_AUTH 数据银行购买 DMP_AUTH dmp授权',
`auth_code` varchar(100) DEFAULT NULL COMMENT '授权码', `auth_code` varchar(100) DEFAULT NULL COMMENT '授权码',
`salt` varchar(200) DEFAULT NULL COMMENT '盐值', `salt` varchar(200) DEFAULT NULL COMMENT '盐值',
`auth_mode` varchar(20) DEFAULT NULL COMMENT '授权方式:1.按次调用 2.按月调用 3.按季调用 4.按年调用', `auth_mode` varchar(50) DEFAULT NULL COMMENT '授权方式:POWER_CALL_MODE 按次调用 ,RECORD_TIME_MODE 按时间调用 PERMANENT_TIME_MODE 永久有效',
`valid_start_time` datetime DEFAULT NULL COMMENT '开始时间', `valid_start_time` datetime DEFAULT NULL COMMENT '开始时间',
`valid_end_time` datetime DEFAULT NULL COMMENT '结束时间', `valid_end_time` datetime DEFAULT NULL COMMENT '结束时间',
`status` varchar(100) NOT NULL COMMENT '状态(1-正常 2-作废)', `status` varchar(100) NOT NULL COMMENT '状态(1-正常 2-作废)',
......
...@@ -100,6 +100,11 @@ ...@@ -100,6 +100,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
</dependency> </dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>-->
<dependency> <dependency>
<groupId>net.sf.json-lib</groupId> <groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId> <artifactId>json-lib</artifactId>
......
...@@ -54,6 +54,10 @@ public class Constants { ...@@ -54,6 +54,10 @@ public class Constants {
/** JSON 应格式 */ /** JSON 应格式 */
public static final String FORMAT_JSON = "JSON"; public static final String FORMAT_JSON = "JSON";
/** 生成内部授权码格式 */
public static final String AUTH_INT = "INT";
/** 生成外部授权码格式 */
public static final String AUTH_OUT = "OUT";
/** XML 应格式 */ /** XML 应格式 */
public static final String FORMAT_XML = "XML"; public static final String FORMAT_XML = "XML";
......
package com.jz.dm.common.util; package com.jz.dm.common.util;
import com.jz.dm.common.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Random; import java.util.Random;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -13,15 +18,18 @@ import java.util.regex.Pattern; ...@@ -13,15 +18,18 @@ import java.util.regex.Pattern;
* @DAY_NAME_SHORT: 周三 * @DAY_NAME_SHORT: 周三
* @Description: 生成随机编码工具类 * @Description: 生成随机编码工具类
**/ **/
@Slf4j
public class RandomUtil { public class RandomUtil {
private final static int[] li_SecPosValue = { 1601, 1637, 1833, 2078, 2274, private final static int[] li_SecPosValue = {1601, 1637, 1833, 2078, 2274,
2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858, 2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858,
4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590 }; 4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590};
private final static String[] lc_FirstLetter = { "a", "b", "c", "d", "e", private final static String[] lc_FirstLetter = {"a", "b", "c", "d", "e",
"f", "g", "h", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "f", "g", "h", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "w", "x", "y", "z" }; "t", "w", "x", "y", "z"};
/** /**
* 生成指定长度字母+数字的随机数 * 生成指定长度字母+数字的随机数
*
* @param length 长度 * @param length 长度
* @return * @return
*/ */
...@@ -40,12 +48,125 @@ public class RandomUtil { ...@@ -40,12 +48,125 @@ public class RandomUtil {
val += String.valueOf(random.nextInt(10)); val += String.valueOf(random.nextInt(10));
} }
} }
log.info("生成指定长度字母+数字的随机数为:{}", val);
return val; return val;
} }
/**
* 生成组织(内/外)部编码
*
* @param type 类型
* @param content
* @return
*/
public static String generateOrgCoding(String content, String type) {
String coding = "";
if (null == content || null == type) {
log.info("----------生成组织编码内容或类型不存在--------------");
return "";
}
boolean chineseWord = isChineseWord(content);
if (!chineseWord) {
log.info("----------编码中不能出现英文或者字母--------------");
return "";
}
StringBuilder builder = new StringBuilder();
if (Constants.AUTH_INT.equalsIgnoreCase(type)) {
builder.append("NEI");
} else {
builder.append("WAI");
}
String orgContent = getAllFirstLetter(content);
orgContent = orgContent.toUpperCase();
builder.append(orgContent);
if (builder.length() > 12) {
coding = builder.toString().substring(0, 13);
} else if (builder.length() == 12) {
coding = builder.toString();
} else if (builder.length() < 12) {
String random = getStringRandom(12 - builder.length());
builder.append(random);
coding = builder.toString();
log.info("-----------生成的组织编码为:{}", coding);
}
return coding;
}
/**
* 生成内/外部授权码
*
* @param orgCode
* @param userId
* @param type
* @return
*/
public static String generateTokenCode(String type, String orgCode, String userId) {
String coding = "";
StringBuilder builder = new StringBuilder();
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
builder.append(year);//年
if (StringUtils.isNotBlank(type) && Constants.AUTH_INT.equalsIgnoreCase(type)) {//内部授权码
if (StringUtils.isBlank(orgCode)) {
return "";
}
coding = getCodeInfo(orgCode, coding, builder, month, day, hour, minute, second);
} else if (StringUtils.isNotBlank(type) && Constants.AUTH_OUT.equalsIgnoreCase(type)) { //外部组织
if (StringUtils.isBlank(userId)) {
return "";
}
if (userId.length() < 8) { //补全用户id
String userNum = addZeroForNum(userId, 8);
builder.append(userNum);
}
coding = getCodeInfo(orgCode, coding, builder, month, day, hour, minute, second);
}
return coding;
}
/**
* 拼接内部/外部授权码
* @param orgCode
* @param coding
* @param builder
* @param month
* @param day
* @param hour
* @param minute
* @param second
* @return
*/
private static String getCodeInfo(String orgCode, String coding,
StringBuilder builder, int month,
int day, int hour, int minute, int second) {
builder.append(orgCode);//组织编码
builder.append(month);//月
builder.append(day);//日
builder.append(hour);//时
builder.append(minute);//分
builder.append(second);//秒
if (builder.length() > 32) {
coding = builder.toString().substring(0, 33);
} else if (builder.length() == 32) {
coding = builder.toString();
} else if (builder.length() < 32) {
String random = getStringRandom(32 - builder.length());
builder.append(random);
coding = builder.toString();
log.info("-----------生成的内部授权码为:{}", coding);
}
return coding;
}
/** /**
* 取得给定汉字串的首字母串,即声母串 * 取得给定汉字串的首字母串,即声母串
*
* @param str 给定汉字串 * @param str 给定汉字串
* @return 声母串 * @return 声母串
*/ */
...@@ -62,6 +183,7 @@ public class RandomUtil { ...@@ -62,6 +183,7 @@ public class RandomUtil {
/** /**
* 取得给定汉字的首字母,即声母 * 取得给定汉字的首字母,即声母
*
* @param chinese 给定的汉字 * @param chinese 给定的汉字
* @return 给定汉字的声母 * @return 给定汉字的声母
*/ */
...@@ -70,9 +192,7 @@ public class RandomUtil { ...@@ -70,9 +192,7 @@ public class RandomUtil {
return ""; return "";
} }
chinese = conversionStr(chinese, "GB2312", "ISO8859-1"); chinese = conversionStr(chinese, "GB2312", "ISO8859-1");
if (chinese.length() > 1) { // 判断是不是汉字
if (chinese.length() > 1) // 判断是不是汉字
{
int li_SectorCode = (int) chinese.charAt(0); // 汉字区码 int li_SectorCode = (int) chinese.charAt(0); // 汉字区码
int li_PositionCode = (int) chinese.charAt(1); // 汉字位码 int li_PositionCode = (int) chinese.charAt(1); // 汉字位码
li_SectorCode = li_SectorCode - 160; li_SectorCode = li_SectorCode - 160;
...@@ -92,18 +212,18 @@ public class RandomUtil { ...@@ -92,18 +212,18 @@ public class RandomUtil {
chinese = chinese.substring(0, 1); chinese = chinese.substring(0, 1);
} }
} }
return chinese; return chinese;
} }
/** /**
* 字符串编码转换 * 字符串编码转换
*
* @param str 要转换编码的字符串 * @param str 要转换编码的字符串
* @param charsetName 原来的编码 * @param charsetName 原来的编码
* @param toCharsetName 转换后的编码 * @param toCharsetName 转换后的编码
* @return 经过编码转换后的字符串 * @return 经过编码转换后的字符串
*/ */
private static String conversionStr(String str, String charsetName,String toCharsetName) { private static String conversionStr(String str, String charsetName, String toCharsetName) {
try { try {
str = new String(str.getBytes(charsetName), toCharsetName); str = new String(str.getBytes(charsetName), toCharsetName);
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
...@@ -115,17 +235,41 @@ public class RandomUtil { ...@@ -115,17 +235,41 @@ public class RandomUtil {
/** /**
* 限制只能输入中文 * 限制只能输入中文
*/ */
public static boolean isChineseWord(String str){ public static boolean isChineseWord(String str) {
String pattern = "[\u4e00-\u9fa5]+"; String pattern = "[\u4e00-\u9fa5]+";
boolean isMatch = Pattern.matches(pattern, str); boolean isMatch = Pattern.matches(pattern, str);
return isMatch; return isMatch;
} }
/**
* 生成8位用户id,不够的前面用0补全
*
* @param str
* @param strLength
* @return
*/
public static String addZeroForNum(String str, int strLength) {
int strLen = str.length();
if (strLen < strLength) {
while (strLen < strLength) {
StringBuffer sb = new StringBuffer();
sb.append("0").append(str);// 左补0
// sb.append(str).append("0");//右补0
str = sb.toString();
strLen = str.length();
}
}
return str;
}
public static void main(String[] args) { public static void main(String[] args) {
//System.out.println(getStringRandom(8)); //System.out.println(getStringRandom(8));
// System.out.println("获取拼音首字母:"+getAllFirstLetter("大中国南昌中大china")); // System.out.println("获取拼音首字母:"+getAllFirstLetter("大中国南昌中大china"));
//System.out.println(isChineseWord("大中国南昌中大"));
System.out.println(isChineseWord("大中国南昌中大china")); //System.out.println(generateOrgCoding("九章数据","INT"));
// System.out.println(generateTokenCode("", ""));
//System.out.println(addZeroForNum("1", 8));
System.out.println("内部授权码:"+generateTokenCode("INT","NEIJZSJ900hx",""));//内部授权码
System.out.println("外部授权码:"+generateTokenCode("OUT","","199"));//内部授权码
} }
} }
...@@ -6,6 +6,7 @@ import org.apache.http.client.HttpRequestRetryHandler; ...@@ -6,6 +6,7 @@ import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry; import org.apache.http.config.Registry;
...@@ -144,7 +145,6 @@ public final class WebUtils { ...@@ -144,7 +145,6 @@ public final class WebUtils {
* @return * @return
*/ */
public static String post(String uri, String data) { public static String post(String uri, String data) {
log.info("向银行发起参数:{}", data);
CloseableHttpClient httpClient = getHttpClient(uri); CloseableHttpClient httpClient = getHttpClient(uri);
HttpPost method = new HttpPost(uri); HttpPost method = new HttpPost(uri);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(CONNECT_TIMEOUT) RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(CONNECT_TIMEOUT)
...@@ -192,6 +192,41 @@ public final class WebUtils { ...@@ -192,6 +192,41 @@ public final class WebUtils {
return readContent; return readContent;
} }
/**
* 验证码实时校验
* 无需cookie和referer时请求接口
*
* @param headers 请求头
* @param baseUrl 发送请求的URL
* @return URL 所代表远程资源的响应结果
*/
public static String doGet(String baseUrl, Map<String, String> headers) {
CloseableHttpClient httpClient = getHttpClient(baseUrl);
CloseableHttpResponse response = null;
String body = null;
try {
log.info("接口请求路径:" + baseUrl);
HttpGet httpGet = new HttpGet(baseUrl);
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> e : headers.entrySet()) {
httpGet.addHeader(e.getKey(), e.getValue());
}
}
response = httpClient.execute(httpGet);
body = getBody(response.getEntity());
log.info("获取请求结果为:" + body);
} catch (Exception e) {
log.warn("请求接口时-->" + baseUrl + "发生异常:", e);
} finally {
try {
response.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return body;
}
/** /**
* 关闭连接池 * 关闭连接池
*/ */
...@@ -261,7 +296,7 @@ public final class WebUtils { ...@@ -261,7 +296,7 @@ public final class WebUtils {
public static CloseableHttpClient getHttpClient(String url) { public static CloseableHttpClient getHttpClient(String url) {
int port = 80; int port = 80;
String hostName = url.split("/")[2]; String hostName = url.split("/")[2];
if (hostName.contains(":")){ if (hostName.contains(":")) {
String[] args = hostName.split(":"); String[] args = hostName.split(":");
hostName = args[0]; hostName = args[0];
port = Integer.parseInt(args[1]); port = Integer.parseInt(args[1]);
...@@ -288,7 +323,15 @@ public final class WebUtils { ...@@ -288,7 +323,15 @@ public final class WebUtils {
} }
return httpClient; return httpClient;
} }
public static String getBody(HttpEntity entity) throws ParseException, IOException {
String body = "";
if (entity != null) {
// 按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity, Consts.UTF_8);
}
EntityUtils.consume(entity);
return body;
}
/** /**
* 根据host和port构建httpclient实例 * 根据host和port构建httpclient实例
* *
......
package com.jz.dm.controller; package com.jz.dm.controller;
import com.jz.common.utils.Result;
import com.jz.dm.models.req.auth.*;
import com.jz.dm.service.AuthService; import com.jz.dm.service.AuthService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import javax.validation.Valid;
/** /**
* @author ZC * @author ZC
...@@ -22,4 +30,71 @@ public class AuthController { ...@@ -22,4 +30,71 @@ public class AuthController {
@Autowired @Autowired
private AuthService authService; private AuthService authService;
/**
* @Description:商城用户API认证
* @return: 商城用户API认证
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("商城用户API认证")
@PostMapping(value = "/mall-user-auth-api")
public Mono<Result> authMallUserApi(@RequestBody @Valid AuthMallUserApiReq req) {
return Mono.fromSupplier(() -> authService.addMallUserApiAuth(req));
}
/**
* @Description:DMP用户API认证
* @return: DMP用户API认证
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("商城用户API认证")
@PostMapping(value = "dmp-auth-api")
public Mono<Result> authDmpUserApi(@RequestBody @Valid AuthDmpUserApiReq req) {
return Mono.fromSupplier(() -> authService.addDmpUserApiAuth(req));
}
/**
* @Description: 认证详情查询
* @return: 认证详情查询
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("认证详情查询")
@PostMapping(value = "/auth-detail-info")
public Mono<Result> selectAuthDetailInfo(@RequestBody @Valid AuthDetailInfoReq req) {
return Mono.fromSupplier(() -> authService.getAuthDetailInfo(req));
}
/**
* @Description: 认证列表查询
* @return: 认证列表查询
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("认证列表查询")
@PostMapping(value = "/auth-list")
public Mono<Result> selectAuthListInfo(@RequestBody @Valid AuthListInfoReq req) {
return Mono.fromSupplier(() -> authService.getAuthListInfo(req));
}
/**
* @Description: 认证信息修改
* @return: 认证信息修改
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("认证信息修改")
@PostMapping(value = "/update-auth-info")
public Mono<Result> updateAuthListInfo(@RequestBody @Valid AuthInfoUpdateReq req) {
return Mono.fromSupplier(() -> authService.updateAuthInfo(req));
}
/**
* @Description: 盐值重置接口
* @return: 盐值重置接口
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("盐值重置接口")
@PostMapping(value = "/reset-salt")
public Mono<Result> resetSalt(@RequestBody @Valid SaltResetReq req) {
return Mono.fromSupplier(() -> authService.updateSaltInfo(req));
}
} }
package com.jz.dm.controller; package com.jz.dm.controller;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.models.req.OrganizationManageAddReq; import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
import com.jz.dm.models.req.OrganizationManageDetailQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageDetailQueryReq;
import com.jz.dm.models.req.OrganizationManageListQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq;
import com.jz.dm.models.req.OrganizationManageUpdateReq; import com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq;
import com.jz.dm.service.OrganizationManageService; import com.jz.dm.service.OrganizationManageService;
import com.jz.dm.web.annotation.AccessLimit;
import com.jz.dm.web.annotation.ApiLogAspect;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -50,6 +52,8 @@ public class OrganizationManageController { ...@@ -50,6 +52,8 @@ public class OrganizationManageController {
*/ */
@ApiOperation("组织详情查询") @ApiOperation("组织详情查询")
@PostMapping(value = "/getOrgDetail") @PostMapping(value = "/getOrgDetail")
@AccessLimit(limit = 1000,sec = 1)
@ApiLogAspect
public Mono<Result> getOrganizationDetail(@RequestBody @Valid OrganizationManageDetailQueryReq req) { public Mono<Result> getOrganizationDetail(@RequestBody @Valid OrganizationManageDetailQueryReq req) {
return Mono.fromSupplier(() -> organizationManageService.getOrganizationDetail(req)); return Mono.fromSupplier(() -> organizationManageService.getOrganizationDetail(req));
} }
......
package com.jz.dm.controller; package com.jz.dm.controller;
import com.jz.common.utils.Result;
import com.jz.dm.models.req.make.*;
import com.jz.dm.service.ProducerService; import com.jz.dm.service.ProducerService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono;
import javax.validation.Valid;
/** /**
* @author ZC * @author ZC
...@@ -22,4 +27,116 @@ public class ProducerController { ...@@ -22,4 +27,116 @@ public class ProducerController {
@Autowired @Autowired
private ProducerService producerService; private ProducerService producerService;
/**
* @Description:Api制作(自定义)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(自定义)")
@PostMapping(value = "/addCustomApi")
public Mono<Result> makeCustomApi(@RequestBody @Valid MakeCustomApiReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.addCustomApi(req)));
}
/**
* @Description:Api制作(数据银行)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(数据银行)")
@PostMapping(value = "/addDataBankApiInfo")
public Mono<Result> addDataBankApiInfo(@RequestBody @Valid MakeDataBankApiReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.addDataBankApiInfo(req)));
}
/**
* @Description:Api制作(实时接入)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(实时接入)")
@PostMapping(value = "/realMakeApi")
public Mono<Result> realCustomApi(@RequestBody @Valid MakeRealCustomApiReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.addRealCustomApi(req)));
}
/**
* @Description:Api制作(大数据查询/标签查询)
* @return:
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(大数据查询/标签查询)")
@PostMapping(value = "/makeBigDataApi")
public Mono<Result> bigDataMakeApi(@RequestBody @Valid MakeBigDataApiReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.addBigDataMakeApi(req)));
}
/**
* @Description:保存API基本信息
* @return: (保存API基本信息)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("保存API基本信息")
@PostMapping(value = "/saveInterface")
public Mono<Result> saveInsetInterface(@RequestBody @Valid ApiInterfaceReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.saveInterfaceAPi(req)));
}
/**
* @Description:Api制作(大数据查询/标签查询)保存修改的api信息
* @return: (自定义更新同时使用)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("保存修改的api信息")
@PostMapping(value = "/保存修改的api信息")
public Mono<Result> saveUpdateAPiInfo(@RequestBody @Valid MakeApiSaveInfoReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.saveUpdateAPiInfo(req)));
}
/**
* @Description:获取数据源配置
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("获取数据源配置")
@PostMapping(value = "/getSourceConfig")
public Mono<Result> getSourceConfig(@RequestBody @Valid SourceConfigReq req) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getSourceConfig(req)));
}
/**
* @Description:获取索引
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("获取索引")
@GetMapping(value = "/getIndicess")
public Mono<Result> getSourceWarehouseList(@RequestParam(name = "id") Long id) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getSourceWarehouseList(id)));
}
/**
* @Description:获取某个索引下的type
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("获取某个索引下的type")
@GetMapping(value = "/getIndicesTypes")
public Mono<Result> getIndicesTypes(@RequestParam(name = "indices") String indices,
@RequestParam(name = "id") Long id) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getIndicesTypes(indices,id)));
}
/**
* @Description:获取某个索引 type的fields
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("获取某个索引 type的fields")
@GetMapping(value = "/getIndicesTypesFields")
public Mono<Result> getIndicesTypesFields(@RequestParam(name = "indices") String indices,
@RequestParam(name = "type") String type,
@RequestParam(name = "id") Long id) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getIndicesTypesFields(indices,type,id)));
}
} }
package com.jz.dm.mapper; package com.jz.dm.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.dm.models.domian.ApiAuth; import com.jz.dm.models.domian.ApiAuth;
import com.jz.dm.models.dto.AuthInfoDto;
import com.jz.dm.models.req.auth.AuthDetailInfoReq;
import org.apache.ibatis.annotations.Param;
/**api授权信息表 mapper /**api授权信息表 mapper
* @author zc * @author zc
...@@ -9,4 +14,18 @@ import com.jz.dm.models.domian.ApiAuth; ...@@ -9,4 +14,18 @@ import com.jz.dm.models.domian.ApiAuth;
*/ */
public interface ApiAuthMapper extends BaseMapper<ApiAuth> { public interface ApiAuthMapper extends BaseMapper<ApiAuth> {
/**
* 查询认证详情信息
* @param req
* @return
*/
AuthInfoDto selectAuthDetail(AuthDetailInfoReq req);
/**
* 分页查询认证列表
* @param page
* @param query
* @return
*/
IPage<AuthInfoDto> listSelectApiAuth(IPage<AuthInfoDto> page, @Param("ew") Wrapper<AuthInfoDto> query);
} }
...@@ -2,6 +2,9 @@ package com.jz.dm.mapper; ...@@ -2,6 +2,9 @@ package com.jz.dm.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jz.dm.models.domian.ApiOpenApiEsFields; import com.jz.dm.models.domian.ApiOpenApiEsFields;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
/**apiEs字段信息表 mapper /**apiEs字段信息表 mapper
* @author ybz * @author ybz
...@@ -9,4 +12,9 @@ import com.jz.dm.models.domian.ApiOpenApiEsFields; ...@@ -9,4 +12,9 @@ import com.jz.dm.models.domian.ApiOpenApiEsFields;
*/ */
public interface ApiOpenApiEsFieldsMapper extends BaseMapper<ApiOpenApiEsFields> { public interface ApiOpenApiEsFieldsMapper extends BaseMapper<ApiOpenApiEsFields> {
/**
* 批量插入字段信息
* @param lists
*/
void insetBatch(@Param("lists") ArrayList<ApiOpenApiEsFields> lists);
} }
...@@ -2,10 +2,18 @@ package com.jz.dm.mapper; ...@@ -2,10 +2,18 @@ package com.jz.dm.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jz.dm.models.domian.ApiReqLog; import com.jz.dm.models.domian.ApiReqLog;
import org.apache.ibatis.annotations.Select;
/**api请求日志表 mapper /**api请求日志表 mapper
* @author ybz * @author ybz
*/ */
public interface ApiReqLogMapper extends BaseMapper<ApiReqLog> { public interface ApiReqLogMapper extends BaseMapper<ApiReqLog> {
/**
* 查询出最大id数据
* @param id
* @return
*/
@Select("SELECT * FROM t_api_req_log WHERE id =(SELECT MAX(id) FROM t_api_req_log)")
ApiReqLog maxId(Long id);
} }
...@@ -48,6 +48,11 @@ public class ApiInterface extends BaseObject implements Serializable { ...@@ -48,6 +48,11 @@ public class ApiInterface extends BaseObject implements Serializable {
@TableField("api_protocl") @TableField("api_protocl")
private String apiProtocl; private String apiProtocl;
/**
* api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义'
*/
@TableField("api_type")
private String apiType;
/** /**
* 目标url * 目标url
*/ */
...@@ -59,6 +64,11 @@ public class ApiInterface extends BaseObject implements Serializable { ...@@ -59,6 +64,11 @@ public class ApiInterface extends BaseObject implements Serializable {
*/ */
@TableField("status") @TableField("status")
private String status; private String status;
/**
* 接口功能
*/
@TableField("api_function")
private String apiFunction;
/** /**
* 版本号 * 版本号
......
...@@ -45,6 +45,16 @@ public class ApiOrg extends BaseObject implements Serializable { ...@@ -45,6 +45,16 @@ public class ApiOrg extends BaseObject implements Serializable {
*/ */
@TableField("org_cn_name") @TableField("org_cn_name")
private String orgCnName; private String orgCnName;
/**
* 组织电话
*/
@TableField("org_phone")
private String orgPhone;
/**
* 组织类型 OUT 外部组织 IN 内部组织
*/
@TableField("org_type")
private String orgType;
/** /**
* 状态(1-正常 2-冻结 3-下架) * 状态(1-正常 2-冻结 3-下架)
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import com.jz.dm.common.enums.auth.AuthModeEnum; import com.jz.dm.common.enums.auth.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum; import com.jz.dm.common.enums.auth.AuthTypeEnum;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import com.jz.common.bean.BasePageBean; import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import com.jz.dm.common.enums.auth.AuthModeEnum; import com.jz.dm.common.enums.auth.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum; import com.jz.dm.common.enums.auth.AuthTypeEnum;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.auth;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
......
...@@ -18,9 +18,9 @@ import javax.validation.constraints.NotNull; ...@@ -18,9 +18,9 @@ import javax.validation.constraints.NotNull;
@Data @Data
@ApiModel(value = "api基本信息") @ApiModel(value = "api基本信息")
public class ApiInterfaceReq { public class ApiInterfaceReq {
@ApiModelProperty(value = "api类型",required = true) @ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true)
@NotNull(message = "api类型不能为空") @NotNull(message = "api类型不能为空")
public String apiInterfaceType; public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true) @ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空") @NotNull(message = "apiId不能为空")
...@@ -54,10 +54,13 @@ public class ApiInterfaceReq { ...@@ -54,10 +54,13 @@ public class ApiInterfaceReq {
@ApiModelProperty(value = "列",required = false) @ApiModelProperty(value = "列",required = false)
public String columnCode; public String columnCode;
@ApiModelProperty(value = "api名称",required = false)
public String apiName;
@ApiModelProperty(value = "状态",required = false) @ApiModelProperty(value = "状态",required = false)
public String status; public String status;
@ApiModelProperty(value = "更新时传入api自增id",required = false) //@ApiModelProperty(value = "更新时传入api自增id",required = false)
public Long id; //public Long id;
} }
...@@ -20,6 +20,10 @@ import java.io.Serializable; ...@@ -20,6 +20,10 @@ import java.io.Serializable;
@ApiModel("保存API基本信息请求体") @ApiModel("保存API基本信息请求体")
public class MakeApiSaveInfoReq implements Serializable { public class MakeApiSaveInfoReq implements Serializable {
@ApiModelProperty(value = "id",required = true)
@NotNull(message = "id不能为空")
public Long id;
@ApiModelProperty(value = "api类型",required = true) @ApiModelProperty(value = "api类型",required = true)
@NotNull(message = "api类型不能为空") @NotNull(message = "api类型不能为空")
public String apiType; public String apiType;
...@@ -63,4 +67,5 @@ public class MakeApiSaveInfoReq implements Serializable { ...@@ -63,4 +67,5 @@ public class MakeApiSaveInfoReq implements Serializable {
@ApiModelProperty(value = "状态",required = false) @ApiModelProperty(value = "状态",required = false)
public String status; public String status;
} }
package com.jz.dm.models.req; package com.jz.dm.models.req.make;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -17,4 +19,49 @@ import java.io.Serializable; ...@@ -17,4 +19,49 @@ import java.io.Serializable;
@Data @Data
@ApiModel("Api制作大数据查询/标签查询请求体") @ApiModel("Api制作大数据查询/标签查询请求体")
public class MakeBigDataApiReq implements Serializable { public class MakeBigDataApiReq implements Serializable {
@ApiModelProperty(value = "id--更新时id不能为空",required = false)
private Long id;
@ApiModelProperty(value = "数据类型:api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 8 查询hive数据源 9自定义",required = true)
@NotNull(message = "apiType不能为空")
private String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;
@ApiModelProperty(value = "数据源Id",required = true)
@NotNull(message = "数据源Id不能为空")
private String esDataSource;
@ApiModelProperty(value = "源库名称",required = true)
@NotNull(message = "源库名称不能为空")
private String esDatabase;
@ApiModelProperty(value = "源表名称",required = true)
@NotNull(message = "源表名称不能为空")
private String esTable;
@ApiModelProperty(value = "处理类型",required = true)
@NotNull(message = "处理类型不能为空")
private String handleType;
@ApiModelProperty(value = "是否分页",required = false)
private long page;
@ApiModelProperty(value = "请求参数",required = true)
@NotNull(message = "请求参数不能为空")
private String requestParam;
@ApiModelProperty(value = "返回参数",required = true)
@NotNull(message = "返回参数不能为空")
private String resultParam;
@ApiModelProperty(value = "段列表",required = true)
@NotNull(message = "字段列表不能为空")
private String tableFields;
} }
package com.jz.dm.models.req; package com.jz.dm.models.req.make;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -17,4 +19,45 @@ import java.io.Serializable; ...@@ -17,4 +19,45 @@ import java.io.Serializable;
@Data @Data
@ApiModel("制作自定义Api") @ApiModel("制作自定义Api")
public class MakeCustomApiReq implements Serializable { public class MakeCustomApiReq implements Serializable {
@ApiModelProperty(value = "api类型",required = true)
@NotNull(message = "api类型不能为空")
public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
@ApiModelProperty(value = "api版本",required = false)
public String version;
@ApiModelProperty(value = "传输方式",required = true)
@NotNull(message = "传输方式不能为空")
public String transMode;
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空")
public String type;
@ApiModelProperty(value = "目标地址",required = true)
@NotNull(message="目标地址不能为空")
public String targetUrl;
@ApiModelProperty(value = "超时时间",required = true)
@NotNull(message="超时时间不能为空")
public String timeout;
@ApiModelProperty(value = "api描述",required = false)
public String apiFunction;
@ApiModelProperty(value = "列",required = false)
public String columnCode;
@ApiModelProperty(value = "状态",required = false)
public String status;
@ApiModelProperty(value = "更新时传入api自增id",required = false)
public Long id;
} }
package com.jz.dm.models.req; package com.jz.dm.models.req.make;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.organizationManage;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -37,6 +37,13 @@ public class OrganizationManageAddReq implements Serializable { ...@@ -37,6 +37,13 @@ public class OrganizationManageAddReq implements Serializable {
@ApiModelProperty(value = "组织邮箱",required = false) @ApiModelProperty(value = "组织邮箱",required = false)
private String orgMail; private String orgMail;
@ApiModelProperty(value = "组织电话",required = false)
private String orgPhone;
@ApiModelProperty(value = "组织类型",required = true)
@NotNull(message = "组织类型不能为空!")
private String orgType;
@ApiModelProperty(value = "备注",required = false) @ApiModelProperty(value = "备注",required = false)
private String remark; private String remark;
} }
package com.jz.dm.models.req; package com.jz.dm.models.req.organizationManage;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.organizationManage;
import com.jz.common.bean.BasePageBean; import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
......
package com.jz.dm.models.req; package com.jz.dm.models.req.organizationManage;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
......
package com.jz.dm.service; package com.jz.dm.service;
import com.jz.common.utils.Result;
import com.jz.dm.models.req.auth.*;
/** /**
* @author ZC * @author ZC
* @PACKAGE_NAME: com.jz.dm.service * @PACKAGE_NAME: com.jz.dm.service
...@@ -10,4 +13,45 @@ package com.jz.dm.service; ...@@ -10,4 +13,45 @@ package com.jz.dm.service;
* @Description: * @Description:
**/ **/
public interface AuthService { public interface AuthService {
/**
* 认证列表
* @param req
* @return
*/
Result getAuthListInfo(AuthListInfoReq req);
/**
* 获取认证详情信息
* @param req
* @return
*/
Result getAuthDetailInfo(AuthDetailInfoReq req);
/**
* 添加Dmp用户认证
* @param req
* @return
*/
Result addDmpUserApiAuth(AuthDmpUserApiReq req);
/**
* 添加商城用户api认证
* @param req
* @return
*/
Result addMallUserApiAuth(AuthMallUserApiReq req);
/**
* 修改认证信息
* @param req
* @return
*/
Result updateAuthInfo(AuthInfoUpdateReq req);
/**
* 盐值重置
* @param req
* @return
*/
Result updateSaltInfo(SaltResetReq req);
} }
...@@ -3,10 +3,10 @@ package com.jz.dm.service; ...@@ -3,10 +3,10 @@ package com.jz.dm.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.models.domian.ApiOrg; import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.req.OrganizationManageAddReq; import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
import com.jz.dm.models.req.OrganizationManageDetailQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageDetailQueryReq;
import com.jz.dm.models.req.OrganizationManageListQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq;
import com.jz.dm.models.req.OrganizationManageUpdateReq; import com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq;
/** /**
* @author ZC * @author ZC
......
package com.jz.dm.service; package com.jz.dm.service;
import com.jz.common.utils.Result;
import com.jz.dm.models.req.make.*;
/** /**
* @author ZC * @author ZC
* @PACKAGE_NAME: com.jz.dm.service * @PACKAGE_NAME: com.jz.dm.service
...@@ -10,4 +13,77 @@ package com.jz.dm.service; ...@@ -10,4 +13,77 @@ package com.jz.dm.service;
* @Description: * @Description:
**/ **/
public interface ProducerService { public interface ProducerService {
/**
* 制作自定义APi
* @param req
* @return
*/
Result addCustomApi(MakeCustomApiReq req);
/**
* Api制作(实时接入)
* @param req
* @return
*/
Result addRealCustomApi(MakeRealCustomApiReq req);
/**
* Api制作(大数据查询/标签查询)
* @param req
* @return
*/
Result addBigDataMakeApi(MakeBigDataApiReq req);
/**
* 获取数据源配置
* @param req
* @return
*/
Result getSourceConfig(SourceConfigReq req);
/**
* 获取数据库列表
* @param id
* @return
*/
Result getSourceWarehouseList(Long id);
/**
* 获取某个索引下的type
* @param indices
* @param id
* @return
*/
Result getIndicesTypes(String indices, Long id);
/**
* 获取某个索引 type的fields
* @param indices
* @param type
* @param id
* @return
*/
Result getIndicesTypesFields(String indices, String type, Long id);
/**
* 保存修改的api信息
* @param req
* @return
*/
Result saveUpdateAPiInfo(MakeApiSaveInfoReq req);
/**
* 数据银行制作API/数据包
* @param req
* @return
*/
Result addDataBankApiInfo(MakeDataBankApiReq req);
/**
* 保存 API基本信息
* @param req
* @return
*/
Result saveInterfaceAPi(ApiInterfaceReq req);
} }
...@@ -3,8 +3,12 @@ package com.jz.dm.service.apirequest; ...@@ -3,8 +3,12 @@ package com.jz.dm.service.apirequest;
import com.jz.dm.common.util.OpenApiRequest; import com.jz.dm.common.util.OpenApiRequest;
import com.jz.dm.common.util.OpenApiResponse; import com.jz.dm.common.util.OpenApiResponse;
import com.jz.dm.gateway.OpenApiService; import com.jz.dm.gateway.OpenApiService;
import com.jz.dm.web.annotation.AccessLimit;
import com.jz.dm.web.annotation.ApiLogAspect;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @author ZC * @author ZC
...@@ -29,6 +33,9 @@ public class ApiQueryService implements OpenApiService { ...@@ -29,6 +33,9 @@ public class ApiQueryService implements OpenApiService {
} }
@Override @Override
@ApiLogAspect
@AccessLimit(limit = 10000,sec = 1)
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
public void doService(OpenApiRequest request, OpenApiResponse response) { public void doService(OpenApiRequest request, OpenApiResponse response) {
} }
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.config.ReentrantRedisLock;
import com.jz.dm.mapper.ApiReqLogMapper; import com.jz.dm.mapper.ApiReqLogMapper;
import com.jz.dm.models.domian.ApiReqLog; import com.jz.dm.models.domian.ApiReqLog;
import com.jz.dm.models.req.LogInfoDetailReq; import com.jz.dm.models.req.LogInfoDetailReq;
...@@ -11,6 +12,7 @@ import com.jz.dm.models.req.LogInfoListReq; ...@@ -11,6 +12,7 @@ import com.jz.dm.models.req.LogInfoListReq;
import com.jz.dm.service.ApiLogService; import com.jz.dm.service.ApiLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -31,7 +33,9 @@ public class ApiLogServiceImpl implements ApiLogService { ...@@ -31,7 +33,9 @@ public class ApiLogServiceImpl implements ApiLogService {
@Resource @Resource
private ApiReqLogMapper apiReqLogMapper; private ApiReqLogMapper apiReqLogMapper;
// 加锁
@Autowired
private ReentrantRedisLock lock;
/** /**
* 日志信息列表 * 日志信息列表
* @param req * @param req
...@@ -72,15 +76,26 @@ public class ApiLogServiceImpl implements ApiLogService { ...@@ -72,15 +76,26 @@ public class ApiLogServiceImpl implements ApiLogService {
*/ */
@Override @Override
public void updateLog(Long id, JSONObject jsonObject) { public void updateLog(Long id, JSONObject jsonObject) {
ApiReqLog apiReqLog = apiReqLogMapper.selectById(id); //if (!lock.tryLock("apiLog")){
// return;
//}
try {
ApiReqLog apiReqLog = apiReqLogMapper.maxId(id);
if (null != apiReqLog){ if (null != apiReqLog){
ApiReqLog reqLog = new ApiReqLog(); ApiReqLog reqLog = new ApiReqLog();
reqLog.setId(id); reqLog.setId(apiReqLog.getId());
reqLog.setResponseParams(jsonObject.toString()); reqLog.setResponseParams(jsonObject.toString());
reqLog.setUpdateDate(new Date()); reqLog.setUpdateDate(new Date());
apiReqLogMapper.updateById(reqLog); apiReqLogMapper.updateById(reqLog);
}else { }else {
log.info("id为:{}",id+"-----------------日志信息不存在"); log.info("id为:{}",id+"-----------------日志信息不存在");
} }
}catch (Exception ex){
log.error("更新日志返回信息异常:{}",ex.getMessage());
}
//finally {
// lock.unlock("apiLog");
//}
} }
} }
package com.jz.dm.service.impl; package com.jz.dm.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result;
import com.jz.dm.common.enums.auth.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum;
import com.jz.dm.mapper.ApiAuthMapper;
import com.jz.dm.mapper.ApiInterfaceMapper;
import com.jz.dm.mapper.ApiOrgMapper;
import com.jz.dm.models.domian.ApiAuth;
import com.jz.dm.models.domian.ApiInterface;
import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.dto.AuthInfoDto;
import com.jz.dm.models.req.auth.*;
import com.jz.dm.service.AuthService; import com.jz.dm.service.AuthService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/** /**
* @author ZC * @author ZC
* @PACKAGE_NAME: com.jz.dm.service.impl * @PACKAGE_NAME: com.jz.dm.service.impl
...@@ -16,4 +37,170 @@ import org.springframework.stereotype.Service; ...@@ -16,4 +37,170 @@ import org.springframework.stereotype.Service;
@Service("authService") @Service("authService")
@Slf4j @Slf4j
public class AuthServiceImpl implements AuthService { public class AuthServiceImpl implements AuthService {
@Resource
private ApiAuthMapper apiAuthMapper;
@Resource
private ApiInterfaceMapper apiInterfaceMapper;
@Resource
private ApiOrgMapper apiOrgMapper;
/**
* 认证信息列表
*
* @param req
* @return
*/
@Override
public Result getAuthListInfo(AuthListInfoReq req) {
IPage<AuthInfoDto> page = new Page<>(req.getPageNum(), req.getPageSize());
QueryWrapper<AuthInfoDto> query = new QueryWrapper<>();
query.orderByDesc("create_date");
IPage<AuthInfoDto> listSelectApiAuth = apiAuthMapper.listSelectApiAuth(page, query);
return Result.of_success(listSelectApiAuth);
}
/**
* 认证信息详情
*
* @param req
* @return
*/
@Override
public Result getAuthDetailInfo(AuthDetailInfoReq req) {
return Result.of_success(apiAuthMapper.selectAuthDetail(req));
}
/**
* 添加dmp认证信息
*
* @param req
* @return
*/
@Override
public Result addDmpUserApiAuth(AuthDmpUserApiReq req) {
ApiInterface apiInterface = getInterface(req.getApiKey());
if (null == apiInterface) {
return Result.of_error("api授权信息不存在!");
}
ApiOrg apiOrg = apiOrgMapper.selectById(req.getOrgId());
if (null == apiOrg) {
return Result.of_error("组织信息不存在!");
}
//授权验证
if (StringUtils.isNotBlank(req.getAuthType().name()) &&
!AuthTypeEnum.DMP_AUTH.name().equals(req.getAuthType())) {
return Result.of_error("授权类型错误!");
}
//认证类型
if (StringUtils.isNotBlank(req.getAuthMode().name()) && AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
if (StringUtils.isBlank(req.getValidStartTime()) || StringUtils.isBlank(req.getValidEndTime())) {
return Result.of_error("开始或结束时间不能为空!");
}
}
if (StringUtils.isNotBlank(req.getAuthMode().name()) &&
AuthModeEnum.POWER_CALL_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!");
}
ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码
apiAuth.setSalt("");//盐值
apiAuth.setStatus("1");//授权状态
if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS);
}
return Result.of_success(ResultMsg.FAILURE);
}
/**
* 添加商城用户认证信息
*
* @param req
* @return
*/
@Override
public Result addMallUserApiAuth(AuthMallUserApiReq req) {
ApiInterface apiInterface = getInterface(req.getApiKey());
if (null == apiInterface) {
return Result.of_error("api授权信息不存在!");
}
ApiOrg apiOrg = apiOrgMapper.selectById(req.getOrgId());
if (null == apiOrg) {
return Result.of_error("组织信息不存在!");
}
//授权验证
if (StringUtils.isNotBlank(req.getAuthType().name()) &&
!AuthTypeEnum.DATA_BANK_AUTH.name().equals(req.getAuthType())) {
return Result.of_error("授权类型错误!");
}
//认证类型
if (StringUtils.isNotBlank(req.getAuthMode().name()) && AuthModeEnum.RECORD_TIME_MODE.name().equals(req.getAuthMode())) {
if (StringUtils.isBlank(req.getValidStartTime()) || StringUtils.isBlank(req.getValidEndTime())) {
return Result.of_error("开始或结束时间不能为空!");
}
}
if (StringUtils.isNotBlank(req.getAuthMode().name()) &&
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!");
}
ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码
apiAuth.setSalt("");//盐值
apiAuth.setStatus("1");//授权状态
if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS);
}
return Result.of_success(ResultMsg.FAILURE);
}
/**
* 修改用户认证信息
*
* @param req
* @return
*/
@Override
public Result updateAuthInfo(AuthInfoUpdateReq req) {
//TODO 认证后是否可以修改
return null;
}
/**
* 盐值重置
*
* @param req
* @return
*/
@Override
public Result updateSaltInfo(SaltResetReq req) {
ApiAuth apiAuth = apiAuthMapper.selectById(req.getId());
if (null == apiAuth) {
return Result.of_error("认证用户不存在");
}
if (StringUtils.isNotBlank(req.getSalt())) {
UpdateWrapper<ApiAuth> update = new UpdateWrapper<>();
update.set("salt", req.getSalt());
update.set("create_time", new Date());
update.set("create_user", "");
update.eq("id", req.getId());
if (apiAuthMapper.update(null, update) > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
}
return Result.of_success(ResultMsg.UPDATE_FAIL);
}
private ApiInterface getInterface(String apiKey){
QueryWrapper<ApiInterface> queryInface = new QueryWrapper<>();
queryInface.last("where is_deleted=0 and api_key ="+apiKey+"");
ApiInterface apiInterface = apiInterfaceMapper.selectOne(queryInface);
if (null != apiInterface){
return apiInterface;
}
return null;
}
} }
...@@ -5,15 +5,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -5,15 +5,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.constant.ResultMsg; import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.common.constant.Constants;
import com.jz.dm.common.util.RandomUtil;
import com.jz.dm.mapper.ApiOrgMapper; import com.jz.dm.mapper.ApiOrgMapper;
import com.jz.dm.models.domian.ApiOrg; import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.req.OrganizationManageAddReq; import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
import com.jz.dm.models.req.OrganizationManageDetailQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageDetailQueryReq;
import com.jz.dm.models.req.OrganizationManageListQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq;
import com.jz.dm.models.req.OrganizationManageUpdateReq; import com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq;
import com.jz.dm.service.OrganizationManageService; import com.jz.dm.service.OrganizationManageService;
import com.jz.dm.web.annotation.ApiBeforeLog;
import com.jz.dm.web.annotation.ApiReturnLog;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -40,8 +40,10 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -40,8 +40,10 @@ public class OrganizationManageImpl implements OrganizationManageService {
private ApiOrgMapper apiOrgMapper; private ApiOrgMapper apiOrgMapper;
@Resource @Resource
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
/** /**
* 组织列表信息查询 * 组织列表信息查询
*
* @param req * @param req
* @return * @return
*/ */
...@@ -50,23 +52,23 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -50,23 +52,23 @@ public class OrganizationManageImpl implements OrganizationManageService {
IPage<ApiOrg> page = new Page<>(req.getPageNum(), req.getPageSize()); IPage<ApiOrg> page = new Page<>(req.getPageNum(), req.getPageSize());
QueryWrapper<ApiOrg> query = new QueryWrapper<>(); QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.orderByDesc("create_date"); query.orderByDesc("create_date");
return apiOrgMapper.selectPage(page,query); return apiOrgMapper.selectPage(page, query);
} }
/** /**
* 获取组织详情 * 获取组织详情
*
* @param req * @param req
* @return * @return
*/ */
@Override @Override
@ApiBeforeLog
@ApiReturnLog
public Result getOrganizationDetail(OrganizationManageDetailQueryReq req) { public Result getOrganizationDetail(OrganizationManageDetailQueryReq req) {
return Result.of_success(apiOrgMapper.selectById(req.getId())); return Result.of_success(apiOrgMapper.selectById(req.getId()));
} }
/** /**
* 添加组织 * 添加组织
*
* @param req * @param req
* @return * @return
*/ */
...@@ -76,23 +78,51 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -76,23 +78,51 @@ public class OrganizationManageImpl implements OrganizationManageService {
//if (null == currentUser){ //if (null == currentUser){
// return Result.of_error(ResultMsg.USER_NOT_EXIST); // return Result.of_error(ResultMsg.USER_NOT_EXIST);
//} //}
if (StringUtils.isNotBlank(req.getOrgName())){ if (StringUtils.isNotBlank(req.getOrgName())) {
ApiOrg orgNameInfo = getOrgNameInfo(req.getOrgName()); ApiOrg orgNameInfo = getOrgNameInfo(req.getOrgName());
if (null != orgNameInfo){ if (null != orgNameInfo) {
return Result.of_error("组织名称已存在"); return Result.of_error("组织名称已存在");
} }
} }
String coding = "";
ApiOrg apiOrg = new ApiOrg(); ApiOrg apiOrg = new ApiOrg();
BeanUtils.copyProperties(req,apiOrg); BeanUtils.copyProperties(req, apiOrg);
apiOrg.setOrgCode("111eef33");//组织编码需要生成 if (StringUtils.isNotBlank(req.getOrgType()) //内部组织
&& Constants.AUTH_INT.equals(req.getOrgType())) {
coding = generateCode(req.getOrgName(), Constants.AUTH_INT);
} else {
coding = generateCode(req.getOrgName(), Constants.AUTH_OUT);
}
if (StringUtils.isBlank(coding)) {
return Result.of_error("生成组织编码异常!");
}
apiOrg.setOrgCode(coding);//组织编码需要生成
apiOrg.setStatus("1");//正常 apiOrg.setStatus("1");//正常
//apiOrg.setCreateUser(currentUser.getUserName()); //apiOrg.setCreateUser(currentUser.getUserName());
if (apiOrgMapper.insert(apiOrg) > 0){ if (apiOrgMapper.insert(apiOrg) > 0) {
return Result.of_success(ResultMsg.INSERT_SUCCESS); return Result.of_success(ResultMsg.INSERT_SUCCESS);
} }
return Result.of_error(ResultMsg.INSERT_FAIL); return Result.of_error(ResultMsg.INSERT_FAIL);
} }
/**
* 获取组织编码(去重)
* @param orgName 组织名称
* @param type 生成类型
* @return
*/
private String generateCode(String orgName, String type) {
String coding = "";
coding = RandomUtil.generateOrgCoding(orgName, type);
QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.eq("org_code", coding);
ApiOrg org = apiOrgMapper.selectOne(query);
if (null != org) {
coding = RandomUtil.generateOrgCoding(orgName, type);
}
return coding;
}
/** /**
* 更新组织 * 更新组织
* @param req * @param req
...@@ -105,21 +135,21 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -105,21 +135,21 @@ public class OrganizationManageImpl implements OrganizationManageService {
// return Result.of_error(ResultMsg.USER_NOT_EXIST); // return Result.of_error(ResultMsg.USER_NOT_EXIST);
//} //}
ApiOrg apiOrg = apiOrgMapper.selectById(req.getId()); ApiOrg apiOrg = apiOrgMapper.selectById(req.getId());
if (null == apiOrg){ if (null == apiOrg) {
return Result.of_error("组织信息不存在!"); return Result.of_error("组织信息不存在!");
} }
if (StringUtils.isNotBlank(req.getOrgName())){ if (StringUtils.isNotBlank(req.getOrgName())) {
ApiOrg orgNameInfo = getOrgNameInfo(req.getOrgName()); ApiOrg orgNameInfo = getOrgNameInfo(req.getOrgName());
if (null != orgNameInfo){ if (null != orgNameInfo) {
return Result.of_error("组织名称已存在"); return Result.of_error("组织名称已存在");
} }
} }
ApiOrg apiOrgUpdate = new ApiOrg(); ApiOrg apiOrgUpdate = new ApiOrg();
apiOrgUpdate.setId(apiOrg.getId()); apiOrgUpdate.setId(apiOrg.getId());
BeanUtils.copyProperties(req,apiOrgUpdate); BeanUtils.copyProperties(req, apiOrgUpdate);
apiOrgUpdate.setUpdateDate(new Date()); apiOrgUpdate.setUpdateDate(new Date());
//apiOrgUpdate.setUpdateUser(currentUser.getUserName()); //apiOrgUpdate.setUpdateUser(currentUser.getUserName());
if (apiOrgMapper.updateById(apiOrgUpdate) > 0){ if (apiOrgMapper.updateById(apiOrgUpdate) > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS); return Result.of_success(ResultMsg.UPDATE_SUCCESS);
} }
return Result.of_success(ResultMsg.UPDATE_FAIL); return Result.of_success(ResultMsg.UPDATE_FAIL);
...@@ -133,10 +163,10 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -133,10 +163,10 @@ public class OrganizationManageImpl implements OrganizationManageService {
@Override @Override
public Result delete(Long id) { public Result delete(Long id) {
ApiOrg apiOrg = apiOrgMapper.selectById(id); ApiOrg apiOrg = apiOrgMapper.selectById(id);
if (null == apiOrg){ if (null == apiOrg) {
return Result.of_error(ResultMsg.DATA_NOT_EXIST); return Result.of_error(ResultMsg.DATA_NOT_EXIST);
} }
if (apiOrgMapper.deleteById(id) >0){ if (apiOrgMapper.deleteById(id) > 0) {
return Result.of_success(ResultMsg.DELETE_SUCCESS); return Result.of_success(ResultMsg.DELETE_SUCCESS);
} }
return Result.of_success(ResultMsg.DELETE_FAIL); return Result.of_success(ResultMsg.DELETE_FAIL);
...@@ -144,16 +174,17 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -144,16 +174,17 @@ public class OrganizationManageImpl implements OrganizationManageService {
/** /**
* 根据名称获取组织信息 * 根据名称获取组织信息
*
* @param orgName 组织名称 * @param orgName 组织名称
* @return * @return
*/ */
private ApiOrg getOrgNameInfo(String orgName){ private ApiOrg getOrgNameInfo(String orgName) {
QueryWrapper<ApiOrg> query = new QueryWrapper<>(); QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.eq("org_name",orgName); query.eq("org_name", orgName);
query.eq("is_deleted",0); query.eq("is_deleted", 0);
query.eq("status","3"); query.eq("status", "3");
ApiOrg apiOrg = apiOrgMapper.selectOne(query); ApiOrg apiOrg = apiOrgMapper.selectOne(query);
if (null != apiOrg){ if (null != apiOrg) {
return apiOrg; return apiOrg;
} }
return null; return null;
......
...@@ -6,7 +6,7 @@ import java.lang.annotation.*; ...@@ -6,7 +6,7 @@ import java.lang.annotation.*;
* @author ZC * @author ZC
* @PACKAGE_NAME: com.jz.dm.web.annotation * @PACKAGE_NAME: com.jz.dm.web.annotation
* @PROJECT_NAME: jz-dm-parent * @PROJECT_NAME: jz-dm-parent
* @NAME: ApiBeforeLog * @NAME: ApiLogAspect
* @DATE: 2020-12-25/15:50 * @DATE: 2020-12-25/15:50
* @DAY_NAME_SHORT: 周五 * @DAY_NAME_SHORT: 周五
* @Description: api全局切面日志 * @Description: api全局切面日志
...@@ -14,6 +14,6 @@ import java.lang.annotation.*; ...@@ -14,6 +14,6 @@ import java.lang.annotation.*;
@Target({ElementType.PARAMETER, ElementType.METHOD})//作用在参数和方法上 @Target({ElementType.PARAMETER, ElementType.METHOD})//作用在参数和方法上
@Retention(RetentionPolicy.RUNTIME)//运行时注解 @Retention(RetentionPolicy.RUNTIME)//运行时注解
@Documented//表明这个注解应该被 javadoc工具记录 @Documented//表明这个注解应该被 javadoc工具记录
public @interface ApiBeforeLog { public @interface ApiLogAspect {
String description() default ""; String description() default "";
} }
...@@ -15,10 +15,8 @@ import javassist.bytecode.MethodInfo; ...@@ -15,10 +15,8 @@ import javassist.bytecode.MethodInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.*;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
...@@ -49,25 +47,77 @@ public class SystemLogAspect { ...@@ -49,25 +47,77 @@ public class SystemLogAspect {
@Resource @Resource
private ApiLogService apiLogService; private ApiLogService apiLogService;
//Service层切 /* //前置通知切入
@Pointcut("@annotation(com.jz.dm.web.annotation.ApiLogAspect)") @Pointcut("@annotation(com.jz.dm.web.annotation.ApiLogAspect)")
public void serviceAspect() { public void beforeAspect() {
} }
//Controller层切点
//最终通知切入点
@Pointcut("@annotation(com.jz.dm.web.annotation.ApiLogAspect)")
public void lastAspect() {
}*/
//环绕通知切入点
@Pointcut("@annotation(com.jz.dm.web.annotation.ApiLogAspect)") @Pointcut("@annotation(com.jz.dm.web.annotation.ApiLogAspect)")
public void controllerAspect(){ public void aroundAspect() {
} }
@Before("serviceAspect()")
@Around("aroundAspect()")
public void doAround(ProceedingJoinPoint joinPoint) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = IpUtils.getIpAddr(request);
//获取用户请求方法的参数并序列化为JSON格式字符串
String params = "";
if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) {
for (int i = 0; i < joinPoint.getArgs().length; i++) {
params += JsonUtils.objectToJson(joinPoint.getArgs()[i]) + ";";
}
}
//获取请求路径
String url = UrlUtil.getServerUrl(request);
// 访问项目名
String contextPath = request.getContextPath();
log.info("around请求参数为{}", joinPoint.getArgs());
//动态修改其参数
//注意,如果调用joinPoint.proceed()方法,则修改的参数值不会生效,必须调用joinPoint.proceed(Object[] args)
try {
ApiReqLog reqLog = new ApiReqLog();
reqLog.setRequestIp(ip);
// reqLog.setApiKey(jsonObject.getString("apiKey"));
reqLog.setRequestParams(params);
reqLog.setResponseParams("");//响应参数
reqLog.setRequestUrl(url);
reqLog.setRequestMethod(contextPath);
reqLog.setEncryMode(SignType.MD5.name()); //加密方式:MD5,RSA
reqLog.setTransMode(request.getMethod());//传输方式 GET POST
// reqLog.setRequestToken(token);
reqLog.setRequestTime(new Date());
reqLog.setRemark(getServiceMethodDescription(joinPoint));
System.out.println(reqLog);
if (null != reqLog) {
apiLogService.insetLogInfo(reqLog);
}
Object result = joinPoint.proceed(joinPoint.getArgs());
JSONObject jsonObject = JSONObject.fromObject(result);
log.info("around响应结果为{}", jsonObject);
apiLogService.updateLog(reqLog.getId(), jsonObject);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
/*@Before("beforeAspect()")
public void doBefore(JoinPoint joinPoint) { public void doBefore(JoinPoint joinPoint) {
//日志信息收集切面 //日志信息收集切面
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = IpUtils.getIpAddr(request); String ip = IpUtils.getIpAddr(request);
//获取用户请求方法的参数并序列化为JSON格式字符串 //获取用户请求方法的参数并序列化为JSON格式字符串
String params =""; String params = "";
if (joinPoint.getArgs()!=null&&joinPoint.getArgs().length>0){ if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) {
for (int i = 0; i < joinPoint.getArgs().length; i++) { for (int i = 0; i < joinPoint.getArgs().length; i++) {
params+= JsonUtils.objectToJson(joinPoint.getArgs()[i])+";"; params += JsonUtils.objectToJson(joinPoint.getArgs()[i]) + ";";
} }
} }
//获取请求路径 //获取请求路径
...@@ -93,21 +143,21 @@ public class SystemLogAspect { ...@@ -93,21 +143,21 @@ public class SystemLogAspect {
reqLog.setRequestTime(new Date()); reqLog.setRequestTime(new Date());
reqLog.setRemark(getServiceMethodDescription(joinPoint)); reqLog.setRemark(getServiceMethodDescription(joinPoint));
System.out.println(reqLog); System.out.println(reqLog);
if (null != reqLog){ if (null != reqLog) {
apiLogService.insetLogInfo(reqLog); apiLogService.insetLogInfo(reqLog);
} }
} catch(Exception e) { } catch (Exception e) {
log.error("~~~~~~~~~~~~~~~~~~~~~~~前置通知异常~~~~~~~~~~~~~~~~~~~~~~~"); log.error("~~~~~~~~~~~~~~~~~~~~~~~前置通知异常~~~~~~~~~~~~~~~~~~~~~~~");
log.error("异常信息{}",e.getMessage()); log.error("异常信息{}", e.getMessage());
} }
} }*/
/** /**
* 返回异常通知,返回抛出异常的时候执行的通知,可以获得返回的异常 * 返回异常通知,返回抛出异常的时候执行的通知,可以获得返回的异常
* 可以访问到异常对象,且可以指定在出现特定异常的时候再执行通知代码 * 可以访问到异常对象,且可以指定在出现特定异常的时候再执行通知代码
*/ */
@AfterReturning(value = "controllerAspect()",returning = "result") /*@AfterReturning(value = "lastAspect()", returning = "result")
public void afterReturn(JoinPoint joinPoint,Object result){ public void afterReturn(JoinPoint joinPoint, Object result) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest(); .getRequest();
log.info("~~~~~~~~~~~~~~~~~~~~~~最终通知执行~~~~~~~~~~~~~~~~~~~~~~~~"); log.info("~~~~~~~~~~~~~~~~~~~~~~最终通知执行~~~~~~~~~~~~~~~~~~~~~~~~");
...@@ -132,16 +182,17 @@ public class SystemLogAspect { ...@@ -132,16 +182,17 @@ public class SystemLogAspect {
Map<String, Object> res = (Map<String, Object>) mapResult.get("data"); Map<String, Object> res = (Map<String, Object>) mapResult.get("data");
Integer id = (Integer) res.get("id"); Integer id = (Integer) res.get("id");
JSONObject data = jsonObject.getJSONObject("data"); JSONObject data = jsonObject.getJSONObject("data");
// apiLogService.updateLog(id.longValue(),data); // apiLogService.updateLog(id.longValue(), data);
} catch(Exception e) { } catch (Exception e) {
log.error("~~~~~~~~~~~~~~~~~~~~~~~最终通知异常~~~~~~~~~~~~~~~~~~~~~~~"); log.error("~~~~~~~~~~~~~~~~~~~~~~~最终通知异常~~~~~~~~~~~~~~~~~~~~~~~");
log.error("异常信息{}",e.getMessage()); log.error("异常信息{}", e.getMessage());
} }
} }*/
/** /**
* 获取注解中对方法的描述信息 用于service层注解 * 获取注解中对方法的描述信息 用于service层注解
*
* @param joinPoint * @param joinPoint
* @return * @return
* @throws Exception * @throws Exception
...@@ -165,7 +216,7 @@ public class SystemLogAspect { ...@@ -165,7 +216,7 @@ public class SystemLogAspect {
return description; return description;
} }
public static Map<String, Object> getFieldsName(Class cls, String clazzName, String methodName, Object[] args)throws Exception { public static Map<String, Object> getFieldsName(Class cls, String clazzName, String methodName, Object[] args) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
ClassPool pool = ClassPool.getDefault(); ClassPool pool = ClassPool.getDefault();
......
...@@ -73,3 +73,13 @@ spring: ...@@ -73,3 +73,13 @@ spring:
aop: aop:
proxy-target-class: true proxy-target-class: true
auto: true auto: true
#rePrefix redis存储的前缀
#ignoreRedis true存入 false不存 api.timeout.default
dmp:
ignoreRedis: true
rePrefix: test
openapi:
timeout:
default: 5000
max: 5000
...@@ -7,5 +7,43 @@ ...@@ -7,5 +7,43 @@
status, remark, create_date, create_user, update_date, status, remark, create_date, create_user, update_date,
update_user, is_deleted update_user, is_deleted
</sql> </sql>
<select id="selectAuthDetail" resultType="com.jz.dm.models.dto.AuthInfoDto">
SELECT au.id AS id,
au.api_org_id AS apiOrgId,
au.api_interface_id AS apiInterFace,
au.auth_mode AS authMode,
au.valid_start_time AS validStartTime,
au.valid_end_time AS validEndTime,
au.status AS status,
au.remark AS remark,
au.create_time AS createDate,
au.create_user AS createUser,
ao.org_name AS orgName,
ai.api_key AS apiKey
FROM t_api_auth AS au
JOIN t_api_interface AS ai ON au.api_interface_id = ai.id AND ai.is_deleted =0 AND ai.`status` ='2'
JOIN t_api_org AS ao ON au.api_org_id = ao.id AND ao.`status` ='1' AND ao.is_deleted =0
WHERE au.is_deleted =0
AND au.id =#{req.getId}
</select>
<select id="listSelectApiAuth" resultType="com.jz.dm.models.dto.AuthInfoDto">
SELECT au.id AS id,
au.api_org_id AS apiOrgId,
au.api_interface_id AS apiInterFace,
au.auth_mode AS authMode,
au.valid_start_time AS validStartTime,
au.valid_end_time AS validEndTime,
au.status AS status,
au.remark AS remark,
au.create_time AS createDate,
au.create_user AS createUser,
ao.org_name AS orgName,
ai.api_key AS apiKey
FROM t_api_auth AS au
JOIN t_api_interface AS ai ON au.api_interface_id = ai.id AND ai.is_deleted =0 AND ai.`status` ='2'
JOIN t_api_org AS ao ON au.api_org_id = ao.id AND ao.`status` ='1' AND ao.is_deleted =0
${ew.customSqlSegment}
</select>
</mapper> </mapper>
...@@ -8,4 +8,16 @@ ...@@ -8,4 +8,16 @@
update_user, is_deleted update_user, is_deleted
</sql> </sql>
<insert id="insetBatch">
INSERT INTO `t_api_open_api_es_fields`
(`es_database`, `es_table`, `field_name`, `field_type`, `field_desc`, `create_user`)
VALUES
<if test="lists != null and lists.size >0">
<foreach collection="lists" item="item" separator=",">
( #{item.esDatabase}, #{item.esTable}, #{item.fieldName},#{item.fieldType},
#{item.fieldDesc},#{item.createUser})
</foreach>
</if>
</insert>
</mapper> </mapper>
...@@ -36,7 +36,7 @@ public class TestApplicationContextInitializer implements ApplicationContextInit ...@@ -36,7 +36,7 @@ public class TestApplicationContextInitializer implements ApplicationContextInit
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = null; Resource[] resources = null;
try { try {
resources = resolver.getResources("classpath:properties/*.properties"); resources = resolver.getResources("classpath*:/**/*.yml");
for (Resource res : resources) { for (Resource res : resources) {
Properties properties = PropertiesLoaderUtils.loadProperties(res); Properties properties = PropertiesLoaderUtils.loadProperties(res);
CollectionUtils.mergePropertiesIntoMap(properties, props); CollectionUtils.mergePropertiesIntoMap(properties, props);
......
...@@ -4,10 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -4,10 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.gateway.SpringTestCase; import com.jz.dm.gateway.SpringTestCase;
import com.jz.dm.models.domian.ApiOrg; import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.req.OrganizationManageAddReq; import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
import com.jz.dm.models.req.OrganizationManageDetailQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageDetailQueryReq;
import com.jz.dm.models.req.OrganizationManageListQueryReq; import com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq;
import com.jz.dm.models.req.OrganizationManageUpdateReq; import com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq;
import com.jz.dm.service.OrganizationManageService; import com.jz.dm.service.OrganizationManageService;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -43,7 +43,7 @@ public class TestOrganizationManage extends SpringTestCase { ...@@ -43,7 +43,7 @@ public class TestOrganizationManage extends SpringTestCase {
@Test @Test
public void getOrgDetail(){ public void getOrgDetail(){
OrganizationManageDetailQueryReq req = new OrganizationManageDetailQueryReq(); OrganizationManageDetailQueryReq req = new OrganizationManageDetailQueryReq();
req.setId(5L); req.setId(1L);
Result detail = organizationManageService.getOrganizationDetail(req); Result detail = organizationManageService.getOrganizationDetail(req);
ApiOrg apiOrg = (ApiOrg)detail.getData(); ApiOrg apiOrg = (ApiOrg)detail.getData();
System.out.println(apiOrg); System.out.println(apiOrg);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
...@@ -62,6 +61,7 @@ ...@@ -62,6 +61,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<!-- swagger2接口文档 --> <!-- swagger2接口文档 -->
<dependency> <dependency>
......
...@@ -104,7 +104,22 @@ public class RedisUtils { ...@@ -104,7 +104,22 @@ public class RedisUtils {
public void set(String key, Object value, long timeout) { public void set(String key, Object value, long timeout) {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
} }
/**
* 实现命令:SET key value EX seconds,设置key-value和超时时间(分钟)
*
* @param key
* @param value
* @param timeout (以分钟为单位)
*/
public Boolean setIfAbsent(String key, String value, long timeout) {
try {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MINUTES);
} catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/** /**
* 实现命令:GET key,返回 key所关联的字符串值。 * 实现命令:GET key,返回 key所关联的字符串值。
* *
...@@ -217,7 +232,7 @@ public class RedisUtils { ...@@ -217,7 +232,7 @@ public class RedisUtils {
/** /**
* *
* @param rid * @param
*/ */
public List<Object> range(String key) { public List<Object> range(String key) {
return redisTemplate.opsForList().range(key, 0, 500); return redisTemplate.opsForList().range(key, 0, 500);
......
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