feat: 新增资产授权

master
031026 2024-05-03 09:48:08 +08:00
commit f51991b5d5
13 changed files with 368 additions and 5 deletions

View File

@ -0,0 +1,79 @@
package com.muyu.data.source.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.data.source.domain.req.AssetAuthInfoQueryReq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Date;
import java.util.function.Supplier;
/**
*
*
* @ClassName asset_authInfo
* @Author AnNan.Wang
* @Date 2024/5/5 15:28
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "asset_auth_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "AssetAuthInfo",description = "资产授权")
public class AssetAuthInfo extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 授权主键 */
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty(name = "授权主键",value = "授权主键")
private Long id;
/** 授权编号 */
@ApiModelProperty(name = "授权编号",value = "授权编号")
private Long authId;
/** 编号类型 dept/user */
@ApiModelProperty(name = "编号类型 dept/user",value = "编号类型 dept/user")
private String idType;
/** 授权数据 */
@ApiModelProperty(name = "授权数据",value = "授权数据")
private String authData;
/** 授权类型 datasource/database/table */
@ApiModelProperty(name = "授权类型 datasource/database/table",value = "授权类型 datasource/database/table")
private String authType;
public static AssetAuthInfo queryBuild(AssetAuthInfoQueryReq assetAuthInfoQueryReq) {
return AssetAuthInfo.builder()
.authId(assetAuthInfoQueryReq.getAuthId())
.idType(assetAuthInfoQueryReq.getIdType())
.authData(assetAuthInfoQueryReq.getAuthData())
.authType(assetAuthInfoQueryReq.getAuthType())
.build();
}
public static AssetAuthInfo saveBuild(AssetAuthInfoQueryReq assetAuthInfoQueryReq, Supplier<String> getUsername) {
return AssetAuthInfo.builder()
.authId(assetAuthInfoQueryReq.getAuthId())
.idType(assetAuthInfoQueryReq.getIdType())
.authData(assetAuthInfoQueryReq.getAuthData())
.authType(assetAuthInfoQueryReq.getAuthType())
.createBy(getUsername.get())
.createTime(new Date())
.build();
}
}

View File

@ -0,0 +1,41 @@
package com.muyu.data.source.domain.req;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* asset_auth_info
*
* @author wan
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "AssetAuthInfoQueryReq", description = "资产授权")
public class AssetAuthInfoQueryReq extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 授权编号 */
@ApiModelProperty(name = "授权编号", value = "授权编号")
private Long authId;
/** 编号类型 dept/user */
@ApiModelProperty(name = "编号类型 dept/user", value = "编号类型 dept/user")
private String idType;
/** 授权数据 */
@ApiModelProperty(name = "授权数据", value = "授权数据")
private String authData;
/** 授权类型 datasource/database/table */
@ApiModelProperty(name = "授权类型 datasource/database/table", value = "授权类型 datasource/database/table")
private String authType;
}

View File

@ -0,0 +1,50 @@
package com.muyu.data.source.domain.req;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* asset_auth_info
*
* @author wan
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "AssetAuthInfoSaveReq", description = "资产授权")
public class AssetAuthInfoSaveReq extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 编号 */
@ApiModelProperty(name = "编号", value = "编号")
private Long id;
/** 授权编号 */
@ApiModelProperty(name = "授权编号", value = "授权编号", required = true)
private Long authId;
/** 编号类型 dept/user */
@ApiModelProperty(name = "编号类型 dept/user", value = "编号类型 dept/user", required = true)
private String idType;
/** 授权数据 */
@ApiModelProperty(name = "授权数据", value = "授权数据", required = true)
private String authData;
/** 授权类型 datasource/database/table */
@ApiModelProperty(name = "授权类型 datasource/database/table", value = "授权类型 datasource/database/table", required = true)
private String authType;
}

View File

@ -0,0 +1,60 @@
package com.muyu.data.source.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.data.source.domain.AssetAuthInfo;
import com.muyu.data.source.domain.req.AssetAuthInfoQueryReq;
import com.muyu.data.source.service.AssetAuthInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Controller
*
* @ClassName AssetAuthInfoController
* @Author AnNan.Wang
* @Date 2024/5/5 15:38
*/
@Api(tags = "资产授权")
@RestController
@RequestMapping("/auth")
public class AssetAuthInfoController extends BaseController {
@Autowired
private AssetAuthInfoService assetAuthInfoService;
@ApiOperation("获取资产授权列表")
@RequiresPermissions("source:auth:list")
@GetMapping("/list")
public Result<TableDataInfo<AssetAuthInfo>> list(AssetAuthInfoQueryReq assetAuthInfoQueryReq) {
startPage();
List<AssetAuthInfo> list = assetAuthInfoService.list(AssetAuthInfo.queryBuild(assetAuthInfoQueryReq));
return getDataTable(list);
}
@RequiresPermissions("source:auth:add")
@Log(title = "资产授权", businessType = BusinessType.DELETE)
@RequestMapping
@ApiOperation("新增资产授权")
public Result<String> add(@RequestBody AssetAuthInfoQueryReq assetAuthInfoQueryReq){
return toAjax(assetAuthInfoService.save(AssetAuthInfo.saveBuild(assetAuthInfoQueryReq, SecurityUtils::getUsername)));
}
@RequiresPermissions("source:auth:remove")
@Log(title = "资产授权", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ApiOperation("删除资产授权")
public Result<String> remove(@RequestBody AssetAuthInfoQueryReq assetAuthInfoQueryReq){
return assetAuthInfoService.removeList(assetAuthInfoQueryReq);
}
}

View File

@ -111,6 +111,7 @@ public class DataSourceController extends BaseController {
return Result.success(accessTypeList);
}
/** 测试连接 */
@PostMapping("/testConnection")
public Result testConnection(@RequestBody DataSourceSaveReq dataSourceSaveReq){
return dataSourceService.testConnection(dataSourceSaveReq);

View File

@ -0,0 +1,14 @@
package com.muyu.data.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.data.source.domain.AssetAuthInfo;
/**
* AssetAuthInfo Mapper
*
* @author AnNan.Wang
* @ClassName: AssetAuthInfoMapper
* @createTime: 2024/5/5 18:30
*/
public interface AssetAuthInfoMapper extends BaseMapper<AssetAuthInfo> {
}

View File

@ -0,0 +1,27 @@
package com.muyu.data.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.data.source.domain.AssetAuthInfo;
import com.muyu.data.source.domain.req.AssetAuthInfoQueryReq;
import java.util.List;
/**
* AssetAuthInfo Service
*
* @author AnNan.Wang
* @ClassName: AssetAuthInfoService
* @createTime: 2024/5/5 15:40
*/
public interface AssetAuthInfoService extends IService<AssetAuthInfo> {
/**
*
*
* @param assetAuthInfo
* @return
*/
public List<AssetAuthInfo> list(AssetAuthInfo assetAuthInfo);
Result<String> removeList(AssetAuthInfoQueryReq assetAuthInfoQueryReq);
}

View File

@ -0,0 +1,62 @@
package com.muyu.data.source.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.exception.ServiceException;
import com.muyu.data.source.domain.AssetAuthInfo;
import com.muyu.data.source.domain.req.AssetAuthInfoQueryReq;
import com.muyu.data.source.mapper.AssetAuthInfoMapper;
import com.muyu.data.source.service.AssetAuthInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* AssetAuthInfo Impl
*
* @ClassName AssetAuthInfoServiceImpl
* @Author AnNan.Wang
* @Date 2024/5/5 18:29
*/
@Service
public class AssetAuthInfoServiceImpl extends ServiceImpl<AssetAuthInfoMapper, AssetAuthInfo>
implements AssetAuthInfoService{
@Autowired
private AssetAuthInfoMapper assetAuthInfoMapper;
@Override
public List<AssetAuthInfo> list(AssetAuthInfo assetAuthInfo) {
if (Objects.isNull(assetAuthInfo.getIdType())){
throw new ServiceException("id类型不能为空");
}
if (Objects.isNull(assetAuthInfo.getAuthType())){
throw new ServiceException("授权类型不能为空");
}
return list(new LambdaQueryWrapper<AssetAuthInfo>()
.eq(AssetAuthInfo::getIdType, assetAuthInfo.getIdType())
.eq(AssetAuthInfo::getAuthType, assetAuthInfo.getAuthType()));
}
@Override
public Result<String> removeList(AssetAuthInfoQueryReq assetAuthInfoQueryReq) {
int delete = assetAuthInfoMapper.delete(
new LambdaQueryWrapper<AssetAuthInfo>() {{
eq(AssetAuthInfo::getAuthId, assetAuthInfoQueryReq.getAuthId());
eq(AssetAuthInfo::getIdType, assetAuthInfoQueryReq.getIdType());
eq(AssetAuthInfo::getAuthData, assetAuthInfoQueryReq.getAuthData());
eq(AssetAuthInfo::getAuthType, assetAuthInfoQueryReq.getAuthType());
}}
);
if (delete>0) {
return Result.success("删除成功");
}else {
return Result.success("删除失败");
}
}
}

View File

@ -105,8 +105,6 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
if (con!=null){
return Result.success("连接成功");
}
Statement stmt = con.createStatement();
} catch (SQLException e) {
log.error("连接失败:"+e.getMessage());
return Result.error("连接失败");

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/muyu-system"/>
<property name="log.path" value="logs/muyu-data-source"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>

View File

@ -102,12 +102,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`comment`,
`is_primary_key`,
`type`,
`detail_kype`,
`detail_type`,
`length`,
`decimal_places`,
`is_null`,
`default_value`,
`database_name`)
`database_name`)
VALUES
<foreach collection="databaseTables" item="databaseTable" separator=",">
(
@ -124,6 +124,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{databaseTable.databaseName}
)
</foreach>
</insert>
<select id="findAccessType" resultType="com.muyu.data.source.domain.AccessType">
select * from access_type

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,28 @@
# Tomcat
server:
port: 9599
# Spring
spring:
application:
# 应用名称
name: ruoyi-rule
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 101.34.243.166:8848
config:
# 配置中心地址
server-addr: 101.34.243.166:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.data.source.mapper: DEBUG