Commit 1e9b3f69 authored by ysongq's avatar ysongq

Merge branch 'dm_dev' of http://gitlab.ioubuy.cn/yaobenzhang/dm_project into dm_dev

parents eb20785a 29646613
......@@ -45,6 +45,24 @@ CREATE TABLE `t_api_interface_custom` (
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='api自定义信息表';
#api api文件表
DROP TABLE IF EXISTS `t_api_interface_file`;
CREATE TABLE `t_api_interface_file` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api文件表自增ID',
`api_interface_id` bigint(20) NOT NULL COMMENT 'api表自增id',
`api_key` varchar(200) NOT NULL COMMENT 'api唯一标识',
`file_type` varchar(50) DEFAULT NULL COMMENT '文件类型',
`file_name` varchar(50) DEFAULT NULL COMMENT '文件名称',
`file_en_name` varchar(50) DEFAULT NULL COMMENT '文件英文名称',
`status` varchar(50) DEFAULT NULL COMMENT 'VALID 有效,UNVALID 无效',
`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组织信息表
DROP TABLE IF EXISTS `t_api_org`;
......
......@@ -49,11 +49,7 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!--lang3工具类-->
<dependency>
......
package com.jz.dm.common.enums;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums
* @PROJECT_NAME: jz-dm-parent
* @NAME: GeneralStatusTypeEnum
* @DATE: 2020-12-30/20:08
* @DAY_NAME_SHORT: 周三
* @Description: 通用状态枚举
**/
public enum GeneralStatusTypeEnum {
/**
* 启用
*/
ENABLE("启用"),
/**
* 停用
*/
UNABLE("停用"),
/**
* 有效'
*/
VALID("有效"),
/**
* 无效
*/
UN_VALID("无效");
private String text;
GeneralStatusTypeEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
......@@ -124,7 +124,7 @@ public class RandomUtil {
String userNum = addZeroForNum(userId, 8);
builder.append(userNum);
}
coding = getCodeInfo(orgCode, coding, builder, month, day, hour, minute, second);
coding = getCodeInfo(userId, coding, builder, month, day, hour, minute, second);
}
return coding;
......
......@@ -28,6 +28,18 @@ public class ProducerController {
@Autowired
private ProducerService producerService;
/**
* @Description:Api制作(自定义)
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation("Api制作(获取文件夹列表)")
@GetMapping(value = "/getFileCatalog")
public Mono<Result> getFileCatalog(@RequestParam(name = "pageNum",defaultValue = "1",required = false)String pageNum,
@RequestParam(name = "pageSize",defaultValue = "10",required = false)String pageSize) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getFileCatalog(pageNum,pageSize)));
}
/**
* @Description:Api制作(自定义)
* @Author: Mr.zhang
......
package com.jz.dm.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.dm.models.domian.ApiInterfaceFile;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.mapper
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiInterfaceFileMapper
* @DATE: 2020-12-30/20:34
* @DAY_NAME_SHORT: 周三
* @Description:
**/
public interface ApiInterfaceFileMapper extends BaseMapper<ApiInterfaceFile> {
}
package com.jz.dm.models.domian;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jz.dm.common.base.BaseObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @Description:
* @Author: Mr.zhang
* @Date: 2020-12-23
*/
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@Accessors(chain = true)
@TableName("t_api_interface_file")
public class ApiInterfaceFile extends BaseObject implements Serializable {
/**
* api唯一标识
*/
@TableField("api_key")
private String apiKey;
/**
* apiInterfaceId
*/
@TableField("api_interface_id")
private Long apiInterfaceId;
/**
* 文件类型
*/
@TableField("file_type")
private String apiType;
/**
* 文件名称
*/
@TableField("file_name")
private String fileName;
/**
* 文件英文名称
*/
@TableField("file_en_name")
private String fileEnName;
/**
* 'VALID 有效,UNVALID 无效'
*/
@TableField("status")
private String status;
}
......@@ -26,9 +26,13 @@ public class AuthDmpUserApiReq implements Serializable {
@NotNull(message = "apiKey唯一标识不能为空")
private String apiKey;
@ApiModelProperty(value = "组织id",required = true)
@NotNull(message = "组织id不能为空")
private Long orgId;
@ApiModelProperty(value = "组织编码",required = true)
@NotNull(message = "组织编码不能为空")
private String orgCode;
@ApiModelProperty(value = "组织类型: INT 内部, OUT 外部",required = true)
@NotNull(message = "组织类型不能为空")
private String orgType;
@ApiModelProperty(value = "授权类型:DATA_BANK_AUTH 数据银行 , DMP_AUTH dmp授权",required = true)
@NotNull(message = "授权类型不能为空")
......
......@@ -26,9 +26,16 @@ public class AuthMallUserApiReq implements Serializable {
@NotNull(message = "apiKey唯一标识不能为空")
private String apiKey;
@ApiModelProperty(value = "组织id",required = true)
@NotNull(message = "组织id不能为空")
private Long orgId;
@ApiModelProperty(value = "组织类型: INT 内部, OUT 外部",required = true)
@NotNull(message = "组织类型不能为空")
private String orgType;
@ApiModelProperty(value = "用户id",required = false)
private String userId;
@ApiModelProperty(value = "组织编码",required = true)
@NotNull(message = "组织编码不能为空")
private String orgCode;
@ApiModelProperty(value = "授权类型:DATA_BANK_AUTH 数据银行 , DMP_AUTHdmp 授权",required = true)
@NotNull(message = "授权类型不能为空")
......
package com.jz.dm.models.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.resp
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthMallUserResponse
* @DATE: 2020-12-30/19:35
* @DAY_NAME_SHORT: 周三
* @Description:
**/
@Data
@ApiModel
public class AuthMallUserResponse implements Serializable {
@ApiModelProperty(value ="授权码")
public String authCode;
@ApiModelProperty(value ="盐值")
public String salt;
}
package com.jz.dm.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.common.utils.Result;
import com.jz.dm.models.domian.ApiInterfaceFile;
import com.jz.dm.models.req.make.*;
/**
......@@ -86,4 +88,12 @@ public interface ProducerService {
* @return
*/
Result saveInterfaceAPi(ApiInterfaceReq req);
/**
* 获取文件列表
* @param pageNum
* @param pageSize
* @return
*/
IPage<ApiInterfaceFile> getFileCatalog( String pageNum, String pageSize);
}
......@@ -6,8 +6,10 @@ 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.constant.Constants;
import com.jz.dm.common.enums.auth.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum;
import com.jz.dm.common.util.RandomUtil;
import com.jz.dm.mapper.ApiAuthMapper;
import com.jz.dm.mapper.ApiInterfaceMapper;
import com.jz.dm.mapper.ApiOrgMapper;
......@@ -16,6 +18,7 @@ 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.models.resp.AuthMallUserResponse;
import com.jz.dm.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -84,7 +87,7 @@ public class AuthServiceImpl implements AuthService {
if (null == apiInterface) {
return Result.of_error("api授权信息不存在!");
}
ApiOrg apiOrg = apiOrgMapper.selectById(req.getOrgId());
ApiOrg apiOrg = apiOrgMapper.selectOne(new QueryWrapper<ApiOrg>().eq("org_code",req.getOrgCode()));
if (null == apiOrg) {
return Result.of_error("组织信息不存在!");
}
......@@ -103,11 +106,21 @@ public class AuthServiceImpl implements AuthService {
AuthModeEnum.POWER_CALL_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!");
}
String authCode = "";
ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码
apiAuth.setSalt("");//盐值
if (StringUtils.isNotBlank(req.getOrgType()) //内部组织
&& Constants.AUTH_INT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode(apiOrg.getOrgCode(),"",Constants.AUTH_INT);
}
/*else if (StringUtils.isNotBlank(req.getOrgType()) //外部组织
&& Constants.AUTH_OUT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode("", req.getUserId(),Constants.AUTH_OUT);
}*/
apiAuth.setAuthCode(authCode);//授权码
String salt = RandomUtil.getStringRandom(8);
apiAuth.setSalt(salt);//盐值
apiAuth.setStatus("1");//授权状态
if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS);
......@@ -123,17 +136,18 @@ public class AuthServiceImpl implements AuthService {
*/
@Override
public Result addMallUserApiAuth(AuthMallUserApiReq req) {
AuthMallUserResponse response = new AuthMallUserResponse();
ApiInterface apiInterface = getInterface(req.getApiKey());
if (null == apiInterface) {
return Result.of_error("api授权信息不存在!");
}
ApiOrg apiOrg = apiOrgMapper.selectById(req.getOrgId());
ApiOrg apiOrg = apiOrgMapper.selectOne(new QueryWrapper<ApiOrg>().eq("org_code",req.getOrgCode()));
if (null == apiOrg) {
return Result.of_error("组织信息不存在!");
}
//授权验证
if (StringUtils.isNotBlank(req.getAuthType().name()) &&
!AuthTypeEnum.DATA_BANK_AUTH.name().equals(req.getAuthType())) {
!AuthTypeEnum.DATA_BANK_AUTH.name().equals(req.getAuthType())) {
return Result.of_error("授权类型错误!");
}
//认证类型
......@@ -143,19 +157,49 @@ public class AuthServiceImpl implements AuthService {
}
}
if (StringUtils.isNotBlank(req.getAuthMode().name()) &&
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!");
}
String authCode = "";
ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码
apiAuth.setSalt("");//盐值
if (StringUtils.isNotBlank(req.getOrgType()) //内部组织
&& Constants.AUTH_INT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode(apiOrg.getOrgCode(),"",Constants.AUTH_INT);
} else if (StringUtils.isNotBlank(req.getOrgType()) //外部组织
&& Constants.AUTH_OUT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode("", req.getUserId(),Constants.AUTH_OUT);
}
apiAuth.setAuthCode(authCode);//授权码
String salt = RandomUtil.getStringRandom(8);
apiAuth.setSalt(salt);//盐值
apiAuth.setStatus("1");//授权状态
response.setAuthCode(authCode);
response.setSalt(salt);
if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS);
return Result.of_success(ResultMsg.SUCCESS,response);
}
return Result.of_success(ResultMsg.FAILURE);
return Result.of_success(ResultMsg.FAILURE,response);
}
/**
* 获取授权码
* @param type
* @param userId
* @param apiOrgCode
* @return
*/
private String getAuthCode(String apiOrgCode,String userId,String type) {
String authCode = "";
authCode = RandomUtil.generateTokenCode(type, apiOrgCode, userId);
QueryWrapper<ApiAuth> query = new QueryWrapper<>();
query.eq("auth_code", authCode);
ApiAuth auth = apiAuthMapper.selectOne(query);
if (null != auth) {
authCode = RandomUtil.generateTokenCode(type, apiOrgCode, userId);
}
return authCode;
}
/**
......@@ -194,11 +238,12 @@ public class AuthServiceImpl implements AuthService {
}
return Result.of_success(ResultMsg.UPDATE_FAIL);
}
private ApiInterface getInterface(String apiKey){
private ApiInterface getInterface(String apiKey) {
QueryWrapper<ApiInterface> queryInface = new QueryWrapper<>();
queryInface.last("where is_deleted=0 and api_key ="+apiKey+"");
queryInface.last("where is_deleted=0 and api_key =" + apiKey + "");
ApiInterface apiInterface = apiInterfaceMapper.selectOne(queryInface);
if (null != apiInterface){
if (null != apiInterface) {
return apiInterface;
}
return null;
......
......@@ -3,6 +3,8 @@ package com.jz.dm.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.bean.SysUserDto;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result;
import com.jz.dm.common.constant.Constants;
......@@ -74,10 +76,10 @@ 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);
//}
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) {
......@@ -98,7 +100,7 @@ public class OrganizationManageImpl implements OrganizationManageService {
}
apiOrg.setOrgCode(coding);//组织编码需要生成
apiOrg.setStatus("1");//正常
//apiOrg.setCreateUser(currentUser.getUserName());
apiOrg.setCreateUser(currentUser.getUserName());
if (apiOrgMapper.insert(apiOrg) > 0) {
return Result.of_success(ResultMsg.INSERT_SUCCESS);
}
......@@ -130,10 +132,10 @@ 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);
//}
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("组织信息不存在!");
......@@ -148,7 +150,7 @@ public class OrganizationManageImpl implements OrganizationManageService {
apiOrgUpdate.setId(apiOrg.getId());
BeanUtils.copyProperties(req, apiOrgUpdate);
apiOrgUpdate.setUpdateDate(new Date());
//apiOrgUpdate.setUpdateUser(currentUser.getUserName());
apiOrgUpdate.setUpdateUser(currentUser.getUserName());
if (apiOrgMapper.updateById(apiOrgUpdate) > 0) {
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
}
......
......@@ -3,7 +3,9 @@ package com.jz.dm.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.bean.SysUserDto;
import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.RedisUtils;
......@@ -54,6 +56,8 @@ public class ProducerServiceImpl implements ProducerService {
private ApiOpenApiEsTagconfigMapper apiOpenApiEsTagconfigMapper;
@Resource
private ApiInterfaceCustomMapper apiInterfaceCustomMapper;
@Resource
private ApiInterfaceFileMapper apiInterfaceFileMapper;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
......@@ -68,6 +72,21 @@ public class ProducerServiceImpl implements ProducerService {
@Value("${dmp.ignoreRedis}")
protected boolean ignoreRedis;
/**
* 获取文件列表
* @param pageSize
* @param pageNum
* @return
*/
@Override
public IPage<ApiInterfaceFile> getFileCatalog(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.orderByDesc("create_time");
return apiInterfaceFileMapper.selectPage(page, query);
}
/**
* 制作自定义Api
......@@ -251,6 +270,8 @@ public class ProducerServiceImpl implements ProducerService {
return Result.of_success(ResultMsg.INSERT_SUCCESS);
}
/**
* 保存修改的api信息
*
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jz.dm.mapper.ApiInterfaceMapper">
<mapper namespace="com.jz.dm.mapper.ApiInterfaceCustomMapper">
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jz.dm.mapper.ApiInterfaceFileMapper">
</mapper>
\ No newline at end of file
......@@ -34,7 +34,12 @@
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<!--httpclient包-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
......@@ -57,11 +62,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- swagger2接口文档 -->
<dependency>
......
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