api最新一版
parent
ddc882e00e
commit
ce78b4e3fd
|
@ -0,0 +1,40 @@
|
||||||
|
package net.srt;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@EnableFeignClients
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class DataServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(DataServiceApplication.class, args);
|
||||||
|
System.out.println("\n" +
|
||||||
|
"/**\n" +
|
||||||
|
" * _ooOoo_\n" +
|
||||||
|
" * o8888888o\n" +
|
||||||
|
" * 88\" . \"88\n" +
|
||||||
|
" * (| -_- |)\n" +
|
||||||
|
" * O\\ = /O\n" +
|
||||||
|
" * ____/`---'\\____\n" +
|
||||||
|
" * . ' \\\\| |// `.\n" +
|
||||||
|
" * / \\\\||| : |||// \\\n" +
|
||||||
|
" * / _||||| -:- |||||- \\\n" +
|
||||||
|
" * | | \\\\\\ - /// | |\n" +
|
||||||
|
" * | \\_| ''\\---/'' | |\n" +
|
||||||
|
" * \\ .-\\__ `-` ___/-. /\n" +
|
||||||
|
" * ___`. .' /--.--\\ `. . __\n" +
|
||||||
|
" * .\"\" '< `.___\\_<|>_/___.' >'\"\".\n" +
|
||||||
|
" * | | : `- \\`.;`\\ _ /`;.`/ - ` : | |\n" +
|
||||||
|
" * \\ \\ `-. \\_ __\\ /__ _/ .-` / /\n" +
|
||||||
|
" * ======`-.____`-.___\\_____/___.-`____.-'======\n" +
|
||||||
|
" * `=---='\n" +
|
||||||
|
" *\n" +
|
||||||
|
" * .............................................\n" +
|
||||||
|
" * 佛祖保佑 代码 启动 永无BUG\n" +
|
||||||
|
" */\n" +
|
||||||
|
"————————代码——启动————————");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package net.srt.constants;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiConstants {
|
||||||
|
public static final String API_PREFIX = "/api/v1"; // 例如,这里定义了一个API的前缀
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package net.srt.constants;
|
||||||
|
|
||||||
|
import net.srt.dao.ApiConfigDao;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/api")
|
||||||
|
public class ApiController {
|
||||||
|
|
||||||
|
private boolean isOnline = true;
|
||||||
|
|
||||||
|
@GetMapping("/status")
|
||||||
|
public ResponseEntity<String> getStatus() {
|
||||||
|
String status = isOnline ? "online" : "offline";
|
||||||
|
return ResponseEntity.ok("API status: " + status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/resource/{id}")
|
||||||
|
public ResponseEntity<String> getResource(@PathVariable Long id) {
|
||||||
|
if (!isOnline) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理获取资源的逻辑...
|
||||||
|
|
||||||
|
String resource = ""; // 假设这里是获取资源的代码
|
||||||
|
|
||||||
|
if (resource != null) {
|
||||||
|
return ResponseEntity.ok("Resource: " + resource);
|
||||||
|
} else {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/offline")
|
||||||
|
public ResponseEntity<String> offline() {
|
||||||
|
isOnline = false;
|
||||||
|
return ResponseEntity.ok("API is now offline");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/online")
|
||||||
|
public ResponseEntity<String> online() {
|
||||||
|
isOnline = true;
|
||||||
|
return ResponseEntity.ok("API is now online");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package net.srt.constants;
|
||||||
|
|
||||||
|
public enum ApiGroupType {
|
||||||
|
FOLDER(1,"数据库"),
|
||||||
|
API(2,"数据库");
|
||||||
|
private final Integer value;
|
||||||
|
private final String longValue;
|
||||||
|
|
||||||
|
ApiGroupType(Integer value, String longValue) {
|
||||||
|
this.value = value;
|
||||||
|
this.longValue = longValue;
|
||||||
|
}
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
public String getLongValue() {
|
||||||
|
return longValue;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
package net.srt.controller;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.convert.ApiConfigConvert;
|
||||||
|
import net.srt.dto.SqlDto;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.common.utils.Result;
|
||||||
|
import net.srt.query.ApiConfigQuery;
|
||||||
|
import net.srt.service.ApiConfigService;
|
||||||
|
import net.srt.vo.ApiConfigVo;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api-config")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiConfigController {
|
||||||
|
private final ApiConfigService apiConfigService;
|
||||||
|
|
||||||
|
@GetMapping("page")
|
||||||
|
@Operation(summary = "分页")
|
||||||
|
@PreAuthorize("hasAuthority('data-service:api-config:page')")
|
||||||
|
public Result<PageResult<ApiConfigVo>> page(@Valid ApiConfigQuery query) {
|
||||||
|
PageResult<ApiConfigVo> page = apiConfigService.page(query);
|
||||||
|
|
||||||
|
return Result.ok(page);
|
||||||
|
}
|
||||||
|
@GetMapping("page-resource")
|
||||||
|
@Operation(summary = "根据resourceId分页获取")
|
||||||
|
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
|
||||||
|
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query);
|
||||||
|
|
||||||
|
return Result.ok(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @GetMapping("{id}")
|
||||||
|
// @Operation(summary = "信息")
|
||||||
|
// public ResponseEntity<?> get(@PathVariable("id") Long id) {
|
||||||
|
// ApiConfigEntity entity = apiConfigService.getById(id);
|
||||||
|
// if (entity != null && entity.getStatus() == 1) {
|
||||||
|
// return ResponseEntity.ok(ApiConfigConvert.INSTANCE.convert(entity));
|
||||||
|
// } else {
|
||||||
|
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Resource not found");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
@GetMapping("{id}")
|
||||||
|
@Operation(summary = "信息")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:info')")
|
||||||
|
public Result<ApiConfigVo> get(@PathVariable("id") Long id){
|
||||||
|
ApiConfigEntity entity=apiConfigService.getById(id);
|
||||||
|
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "保存")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
|
||||||
|
public Result<String> save(@RequestBody ApiConfigVo vo) {
|
||||||
|
apiConfigService.save(vo);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
@PutMapping
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
|
||||||
|
public Result<String> update(@RequestBody ApiConfigVo vo){
|
||||||
|
apiConfigService.update(vo);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
@DeleteMapping
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
|
||||||
|
public Result<String> delete(@RequestBody List<Long> idList){
|
||||||
|
apiConfigService.delete(idList);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
@GetMapping("getIpPort")
|
||||||
|
public Result<String> getIpPort() {
|
||||||
|
return Result.ok(apiConfigService.getIpPort());
|
||||||
|
}
|
||||||
|
@Operation(summary = "获取服务的ip和端口号")
|
||||||
|
@GetMapping("/ip-port")
|
||||||
|
public Result<String> ipPort() {
|
||||||
|
return Result.ok(apiConfigService.ipPort());
|
||||||
|
}
|
||||||
|
@Operation(summary = "上线")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')")
|
||||||
|
@PutMapping("/{id}/online")
|
||||||
|
public Result<String> online(@PathVariable Long id) {
|
||||||
|
apiConfigService.online(id);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
@Operation(summary = "下线")
|
||||||
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
|
||||||
|
@PutMapping("/{id}/offline")
|
||||||
|
public Result<String> offline(@PathVariable Long id){
|
||||||
|
apiConfigService.offline(id);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "执行sql")
|
||||||
|
@PostMapping("/sql/execute")
|
||||||
|
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) {
|
||||||
|
return Result.ok(apiConfigService.sqlExecute(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "导出 api 文档")
|
||||||
|
@PostMapping(value = "/export-docs")
|
||||||
|
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
|
||||||
|
apiConfigService.exportDocs(ids, response);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package net.srt.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.convert.ApiGroupConvert;
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.common.utils.Result;
|
||||||
|
import net.srt.framework.common.utils.TreeNodeVo;
|
||||||
|
import net.srt.query.ApiConfigQuery;
|
||||||
|
import net.srt.service.ApiGroupService;
|
||||||
|
import net.srt.vo.ApiConfigVo;
|
||||||
|
import net.srt.vo.ApiGroupVo;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据服务-api分组
|
||||||
|
*
|
||||||
|
* @author zrx 985134801@qq.com
|
||||||
|
* @since 1.0.0 2023-01-28
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api-group")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiGroupController {
|
||||||
|
private final ApiGroupService apiGroupService;
|
||||||
|
@GetMapping("api-group")
|
||||||
|
@Operation(summary = "查询文件分组树")
|
||||||
|
public Result<List<TreeNodeVo>> listTree() {
|
||||||
|
return Result.ok(apiGroupService.listTree());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{id}")
|
||||||
|
@Operation(summary = "信息")
|
||||||
|
@PreAuthorize("hasAuthority('data-service:api-group:info')")
|
||||||
|
public Result<ApiGroupVo> get(@PathVariable("id") Long id){
|
||||||
|
ApiGroupEntity entity = apiGroupService.getById(id);
|
||||||
|
|
||||||
|
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "保存")
|
||||||
|
@PreAuthorize("hasAuthority('data-service:api-group:save')")
|
||||||
|
public Result<String> save(@RequestBody ApiGroupVo vo) {
|
||||||
|
apiGroupService.save(vo);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
@PreAuthorize("hasAuthority('data-service:api-group:update')")
|
||||||
|
public Result<String> update(@RequestBody @Valid ApiGroupVo vo) {
|
||||||
|
apiGroupService.update(vo);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
@PreAuthorize("hasAuthority('data-service:api-group:delete')")
|
||||||
|
public Result<String> delete(@PathVariable Long id) {
|
||||||
|
apiGroupService.delete(id);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.srt.controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthController
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:22
|
||||||
|
*/
|
||||||
|
public class DataServiceApiAuthController {
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package net.srt.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.common.utils.Result;
|
||||||
|
import net.srt.query.DataServiceApiLogQuery;
|
||||||
|
import net.srt.query.DataServiceAppQuery;
|
||||||
|
import net.srt.service.DataServiceApiLogService;
|
||||||
|
import net.srt.vo.DataServiceApiLogVo;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogController
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:29
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("log")
|
||||||
|
@Tag(name = "api请求日志")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DataServiceApiLogController {
|
||||||
|
private final DataServiceApiLogService dataServiceApiLogService;
|
||||||
|
|
||||||
|
@GetMapping("page")
|
||||||
|
@Operation(summary = "分页")
|
||||||
|
public Result<PageResult<DataServiceApiLogVo>> page(@Valid DataServiceApiLogQuery query){
|
||||||
|
//查询数据
|
||||||
|
PageResult<DataServiceApiLogVo> page=dataServiceApiLogService.dataPageList(query);
|
||||||
|
return Result.ok(page);
|
||||||
|
}
|
||||||
|
@DeleteMapping
|
||||||
|
@Operation(summary ="删除")
|
||||||
|
public Result<String> delete(@RequestBody List<Long> idList){
|
||||||
|
dataServiceApiLogService.removeId(idList);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.dto.ApiConfigDto;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.vo.ApiConfigVo;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据服务-api配置
|
||||||
|
*
|
||||||
|
* @author zrx 985134801@qq.com
|
||||||
|
* @since 1.0.0 2023-01-28
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ApiConfigConvert {
|
||||||
|
ApiConfigConvert INSTANCE = Mappers.getMapper(ApiConfigConvert.class);
|
||||||
|
|
||||||
|
ApiConfigEntity convert(ApiConfigVo vo);
|
||||||
|
|
||||||
|
ApiConfigVo convert(ApiConfigEntity entity);
|
||||||
|
|
||||||
|
ApiConfigDto convertDto(ApiConfigEntity entity);
|
||||||
|
|
||||||
|
List<ApiConfigVo> convertList(List<ApiConfigEntity> list);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.vo.ApiGroupVo;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据服务-api分组
|
||||||
|
*
|
||||||
|
* @author zrx 985134801@qq.com
|
||||||
|
* @since 1.0.0 2023-01-28
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ApiGroupConvert {
|
||||||
|
ApiGroupConvert INSTANCE = Mappers.getMapper(ApiGroupConvert.class);
|
||||||
|
|
||||||
|
ApiGroupEntity convert(ApiGroupVo vo);
|
||||||
|
|
||||||
|
ApiGroupVo convert(ApiGroupEntity entity);
|
||||||
|
|
||||||
|
List<ApiGroupVo> convertList(List<ApiGroupEntity> list);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.srt.convert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthConvert
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:23
|
||||||
|
*/
|
||||||
|
public interface DataServiceApiAuthConvert {
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.entity.DataServiceApiLogEntity;
|
||||||
|
import net.srt.vo.DataServiceApiLogVo;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogConvert
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:30
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface DataServiceApiLogConvert {
|
||||||
|
DataServiceApiLogConvert INSTANCE = Mappers.getMapper(DataServiceApiLogConvert.class);
|
||||||
|
DataServiceApiLogEntity convert(DataServiceApiLogVo vo);
|
||||||
|
|
||||||
|
DataServiceApiLogVo convert(DataServiceApiLogEntity entity);
|
||||||
|
|
||||||
|
List<DataServiceApiLogVo> convertList(List<DataServiceApiLogEntity> list);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package net.srt.dao;
|
||||||
|
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.framework.mybatis.dao.BaseDao;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ApiConfigDao extends BaseDao<ApiConfigEntity> {
|
||||||
|
List<ApiConfigEntity> getResourceList(Map<String, Object> params);
|
||||||
|
|
||||||
|
ApiConfigEntity getById(Long id);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package net.srt.dao;
|
||||||
|
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.framework.mybatis.dao.BaseDao;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ApiGroupDao extends BaseDao<ApiGroupEntity> {
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.srt.dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthDao
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:23
|
||||||
|
*/
|
||||||
|
public interface DataServiceApiAuthDao {
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package net.srt.dao;
|
||||||
|
|
||||||
|
import net.srt.entity.DataServiceApiLogEntity;
|
||||||
|
import net.srt.framework.mybatis.dao.BaseDao;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogDao
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:30
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface DataServiceApiLogDao extends BaseDao<DataServiceApiLogEntity> {
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package net.srt.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiConfigDto implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long id;
|
||||||
|
private Long groupId;
|
||||||
|
private String path;
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String note;
|
||||||
|
private String sqlText;
|
||||||
|
private String sqlSeparator;
|
||||||
|
private Integer sqlMaxRow;
|
||||||
|
private String sqlParam;
|
||||||
|
private String jsonParam;
|
||||||
|
private String responseResult;
|
||||||
|
private String contentType;
|
||||||
|
private Integer status;
|
||||||
|
private Date releaseTime;
|
||||||
|
private Long releaseUserId;
|
||||||
|
private Integer sqlDbType;
|
||||||
|
private Long databaseId;
|
||||||
|
private Integer privates;
|
||||||
|
private Integer openTrans;
|
||||||
|
private Long projectId;
|
||||||
|
private Integer version;
|
||||||
|
private Integer deleted;
|
||||||
|
private Long creator;
|
||||||
|
private Date createTime;
|
||||||
|
private Long updater;
|
||||||
|
private Date updateTime;
|
||||||
|
private Integer requestedTimes;
|
||||||
|
private Integer requestedSuccessTimes;
|
||||||
|
private Integer requestedFailedTimes;
|
||||||
|
private Long authId;
|
||||||
|
private String group;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package net.srt.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AppToken implements Serializable {
|
||||||
|
private Long appId;
|
||||||
|
private String appKey;
|
||||||
|
private String token;
|
||||||
|
private Long expireAt;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package net.srt.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SqlDto {
|
||||||
|
private Integer sqlDbType;
|
||||||
|
private Long projectId;
|
||||||
|
private String statement;
|
||||||
|
private String sqlSeparator;
|
||||||
|
private Long databaseId;
|
||||||
|
private Integer openTrans;
|
||||||
|
private String jsonParams;
|
||||||
|
private Integer sqlMaxRow;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package net.srt.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("data_service_api_config")
|
||||||
|
public class ApiConfigEntity extends BaseEntity {
|
||||||
|
private Long groupId;
|
||||||
|
private String path;
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String note;
|
||||||
|
private String sqlText;
|
||||||
|
private String sqlSeparator;
|
||||||
|
private Integer sqlMaxRow;
|
||||||
|
private String sqlParam;
|
||||||
|
private String jsonParam;
|
||||||
|
private String responseResult;
|
||||||
|
private String contentType;
|
||||||
|
private Integer status;
|
||||||
|
private Date releaseTime;
|
||||||
|
private Long releaseUserId;
|
||||||
|
private Integer sqlDbType;
|
||||||
|
private Long databaseId;
|
||||||
|
private Integer privates;
|
||||||
|
private Integer openTrans;
|
||||||
|
private Long projectId;
|
||||||
|
private Integer requestedTimes;
|
||||||
|
private Integer requestedSuccessTimes;
|
||||||
|
private Integer requestedFailedTimes;
|
||||||
|
private Long authId;
|
||||||
|
private String groupPath;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package net.srt.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("data_service_api_group")
|
||||||
|
public class ApiGroupEntity extends BaseEntity {
|
||||||
|
private Long parentId;
|
||||||
|
private Integer type;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private Integer orderNo;
|
||||||
|
private String path;
|
||||||
|
private Long projectId;
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package net.srt.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthEntity
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:20
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Data
|
||||||
|
@TableName("data_service_api_auth1")
|
||||||
|
public class DataServiceApiAuthEntity extends BaseEntity {
|
||||||
|
/**
|
||||||
|
* app的id
|
||||||
|
*/
|
||||||
|
private Long appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组id
|
||||||
|
*/
|
||||||
|
private Long groupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api的id
|
||||||
|
*/
|
||||||
|
private Long apiId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用次数 不限次数为-1
|
||||||
|
*/
|
||||||
|
private Integer requestTimes;
|
||||||
|
|
||||||
|
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||||
|
private Date startTime;
|
||||||
|
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||||
|
private Date endTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已调用次数
|
||||||
|
*/
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||||
|
private Integer requestedTimes;
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||||
|
private Integer requestedSuccessTimes;
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||||
|
private Integer requestedFailedTimes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属项目id
|
||||||
|
*/
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 真删
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package net.srt.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogEntity
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:11
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Data
|
||||||
|
@TableName("data_service_api_log1")
|
||||||
|
public class DataServiceApiLogEntity extends BaseEntity {
|
||||||
|
/**
|
||||||
|
* url
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应状态码
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时长
|
||||||
|
*/
|
||||||
|
private Long duration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP地址
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app的id
|
||||||
|
*/
|
||||||
|
private Long appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api的id
|
||||||
|
*/
|
||||||
|
private Long apiId;
|
||||||
|
|
||||||
|
private String appName;
|
||||||
|
private String apiName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目id
|
||||||
|
*/
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package net.srt.handler;
|
||||||
|
|
||||||
|
// 导入必要的类
|
||||||
|
|
||||||
|
import net.srt.constants.ApiConstants;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
// 假设这是你的接口处理类
|
||||||
|
public class ApiHandler {
|
||||||
|
private Map<RequestMappingInfo, ApiConfigEntity> mappings = new HashMap<>();
|
||||||
|
|
||||||
|
public void registerApi(ApiConfigEntity api) {
|
||||||
|
RequestMappingInfo mappingInfo = RequestMappingInfo
|
||||||
|
.paths(ApiConstants.API_PREFIX + api.getPath()) // 使用API_PREFIX常量
|
||||||
|
.methods(RequestMethod.valueOf(api.getType()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
mappings.put(mappingInfo, api);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package net.srt.handler;
|
||||||
|
|
||||||
|
import net.srt.constants.ApiConstants;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
|
|
||||||
|
public class ApiRegistration {
|
||||||
|
private RequestMappingHandlerMapping handlerMapping; // 注入或实例化 RequestMappingHandlerMapping 对象
|
||||||
|
|
||||||
|
public void registerApi(String path, String method, Object handler, String handlerMethod) throws NoSuchMethodException {
|
||||||
|
RequestMappingInfo mappingInfo = RequestMappingInfo
|
||||||
|
.paths(ApiConstants.API_PREFIX + path)
|
||||||
|
.methods(RequestMethod.valueOf(method))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HandlerMethod handlerMethodObject = new HandlerMethod(handler, handlerMethod);
|
||||||
|
handlerMapping.registerMapping(mappingInfo, handlerMethodObject.getBean(), handlerMethodObject.getMethod());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package net.srt.handler;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface MappingRequestHandler {
|
||||||
|
Object invoke(HttpServletRequest request, String apiToken, Map<String, Object> pathVariables,
|
||||||
|
Map<String, Object> requestParams, Map<String, Object> requestBodys);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package net.srt.handler;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MappingRequestHandlerExample {
|
||||||
|
private final MappingRequestHandler handler;
|
||||||
|
private Method method;
|
||||||
|
|
||||||
|
public MappingRequestHandlerExample(MappingRequestHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
try {
|
||||||
|
method = MappingRequestHandler.class.getDeclaredMethod(
|
||||||
|
"invoke", HttpServletRequest.class, String.class, Map.class, Map.class, Map.class);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getHandlerAndMethod() {
|
||||||
|
System.out.println("Handler: " + handler);
|
||||||
|
System.out.println("Method: " + method);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package net.srt.query;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.query.Query;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiConfigQuery extends Query {
|
||||||
|
private Long groupId;
|
||||||
|
private Long resourceId;
|
||||||
|
private Long appId;
|
||||||
|
private String name;
|
||||||
|
private String path;
|
||||||
|
private String contentType;
|
||||||
|
private Integer status;
|
||||||
|
private Integer sqlDbType;
|
||||||
|
private Long databaseId;
|
||||||
|
private Integer privates;
|
||||||
|
private Integer openTrans;
|
||||||
|
private Integer queryApply;
|
||||||
|
private Integer ifMarket;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.srt.query;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import net.srt.framework.common.query.Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogQuery
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Schema(description = "api日志")
|
||||||
|
public class DataServiceApiLogQuery extends Query {
|
||||||
|
private String ip;
|
||||||
|
private String apiName;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package net.srt.service;
|
||||||
|
|
||||||
|
import cn.hutool.http.server.HttpServerResponse;
|
||||||
|
import net.srt.dto.SqlDto;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.mybatis.service.BaseService;
|
||||||
|
import net.srt.query.ApiConfigQuery;
|
||||||
|
import net.srt.vo.ApiConfigVo;
|
||||||
|
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ApiConfigService extends BaseService<ApiConfigEntity> {
|
||||||
|
String getIpPort();
|
||||||
|
|
||||||
|
PageResult<ApiConfigVo> page(ApiConfigQuery query);
|
||||||
|
|
||||||
|
void save(ApiConfigVo vo);
|
||||||
|
|
||||||
|
void update(ApiConfigVo vo);
|
||||||
|
|
||||||
|
void delete(List<Long> idList);
|
||||||
|
|
||||||
|
PageResult<ApiConfigVo> pageResource(ApiConfigQuery query);
|
||||||
|
|
||||||
|
List<ApiConfigEntity> listActiveByGroupId(Long id);
|
||||||
|
|
||||||
|
void online(Long id);
|
||||||
|
|
||||||
|
void offline(Long id);
|
||||||
|
|
||||||
|
String ipPort();
|
||||||
|
|
||||||
|
JdbcSelectResult sqlExecute(SqlDto dto);
|
||||||
|
|
||||||
|
void exportDocs(List<Long> ids, HttpServletResponse response);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package net.srt.service;
|
||||||
|
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.framework.common.utils.TreeNodeVo;
|
||||||
|
import net.srt.framework.mybatis.service.BaseService;
|
||||||
|
import net.srt.vo.ApiGroupVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ApiGroupService extends BaseService<ApiGroupEntity> {
|
||||||
|
List<TreeNodeVo> listTree();
|
||||||
|
|
||||||
|
void save(ApiGroupVo vo);
|
||||||
|
|
||||||
|
void update(ApiGroupVo vo);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.srt.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthService
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:23
|
||||||
|
*/
|
||||||
|
public interface DataServiceApiAuthService {
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package net.srt.service;
|
||||||
|
|
||||||
|
import net.srt.entity.DataServiceApiLogEntity;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.mybatis.service.BaseService;
|
||||||
|
import net.srt.query.DataServiceApiLogQuery;
|
||||||
|
import net.srt.vo.DataServiceApiLogVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogService
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:31
|
||||||
|
*/
|
||||||
|
public interface DataServiceApiLogService extends BaseService<DataServiceApiLogEntity> {
|
||||||
|
PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query);
|
||||||
|
|
||||||
|
void removeId(List<Long> idList);
|
||||||
|
}
|
|
@ -0,0 +1,260 @@
|
||||||
|
package net.srt.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.api.ServerNames;
|
||||||
|
import net.srt.convert.ApiConfigConvert;
|
||||||
|
import net.srt.dao.ApiConfigDao;
|
||||||
|
import net.srt.dao.ApiGroupDao;
|
||||||
|
import net.srt.dto.SqlDto;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.framework.common.constant.Constant;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
|
import net.srt.framework.security.user.SecurityUser;
|
||||||
|
import net.srt.query.ApiConfigQuery;
|
||||||
|
import net.srt.service.ApiConfigService;
|
||||||
|
import net.srt.vo.ApiConfigVo;
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfigEntity> implements ApiConfigService {
|
||||||
|
private final ApiGroupDao apiGroupDao;
|
||||||
|
private final DiscoveryClient discoveryClient;
|
||||||
|
private final ApiConfigDao apiConfigDao;
|
||||||
|
private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>();
|
||||||
|
@Override
|
||||||
|
public String getIpPort() {
|
||||||
|
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||||
|
return instances.get(0).getHost() + ":" + instances.get(0).getPort()+"/data-service/api/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void online(Long id) {
|
||||||
|
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||||
|
if (apiConfigEntity != null) {
|
||||||
|
apiConfigEntity.setStatus(1);
|
||||||
|
apiConfigEntity.setReleaseTime(new Date());
|
||||||
|
apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
|
||||||
|
String routeKey = getRouteKeyByRequestTypeAndUrl(apiConfigEntity.getType(), apiConfigEntity.getPath());
|
||||||
|
boolean isExists = checkIfExists(routeKey);
|
||||||
|
|
||||||
|
if (isExists) {
|
||||||
|
ApiConfigEntity configEntity = mappings.get(routeKey);
|
||||||
|
if (configEntity != null) { // 添加 null 判断
|
||||||
|
offline(configEntity.getId()); // 修正方法调用为传入id
|
||||||
|
// 从 mappings 中移除该 routeKey
|
||||||
|
mappings.remove(routeKey);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mappings.put(routeKey, apiConfigEntity);
|
||||||
|
}
|
||||||
|
apiConfigDao.updateById(apiConfigEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfExists(String routeKey) {
|
||||||
|
// 这里是全局的 mappings
|
||||||
|
Map<String, ApiConfigEntity> globalMappings = getGlobalMappings();
|
||||||
|
|
||||||
|
return globalMappings.containsKey(routeKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, ApiConfigEntity> getGlobalMappings() {
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRouteKeyByRequestTypeAndUrl(String type, String path) {
|
||||||
|
return getRouteKey(type, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRouteKey(String type, String path) {
|
||||||
|
return type.toUpperCase() + "_" + path.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void offline(Long id) { // 修正参数类型为 Long id
|
||||||
|
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||||
|
if (apiConfigEntity != null) {
|
||||||
|
apiConfigEntity.setStatus(0);
|
||||||
|
apiConfigEntity.setReleaseTime(null);
|
||||||
|
apiConfigEntity.setReleaseUserId(null);
|
||||||
|
apiConfigDao.updateById(apiConfigEntity);
|
||||||
|
}else{
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// @Override
|
||||||
|
// public void online(Long id) {
|
||||||
|
// ApiConfigEntity apiConfigEntity = new ApiConfigEntity();
|
||||||
|
// apiConfigEntity.setId(id);
|
||||||
|
// apiConfigEntity.setStatus(1);
|
||||||
|
// apiConfigEntity.setReleaseTime(new Date());
|
||||||
|
// apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
|
||||||
|
//
|
||||||
|
// apiConfigDao.updateById(apiConfigEntity);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String ipPort() {
|
||||||
|
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||||
|
return instances.get(0).getHost() + ":" + instances.get(0).getPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JdbcSelectResult sqlExecute(SqlDto dto) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportDocs(List<Long> ids, HttpServletResponse response) {
|
||||||
|
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||||
|
ServiceInstance instance = instances.get(0);
|
||||||
|
StringBuilder docs = new StringBuilder("## 接口文档\n---\n");
|
||||||
|
List<ApiConfigEntity> apiConfigEntities = baseMapper.selectBatchIds(ids);
|
||||||
|
for (ApiConfigEntity api : apiConfigEntities) {
|
||||||
|
docs.append("### ").append(api.getName())
|
||||||
|
.append("\n- IP地址:").append(instance.getHost())
|
||||||
|
.append("\n- 端口:").append(instance.getPort())
|
||||||
|
.append("\n- 接口地址:/data-service/api/").append(api.getPath())
|
||||||
|
.append("\n- 请求方式:").append(api.getType())
|
||||||
|
.append("\n- Content-Type:").append(api.getContentType())
|
||||||
|
.append("\n- 是否需要鉴权:").append(api.getPrivates() == 1 ? "是" : "否");
|
||||||
|
if (api.getPrivates() == 1) {
|
||||||
|
docs.append("\n- 获取鉴权token:").append("/data-service/api/token/generate?appKey=您的appKey&appSecret=您的appToken");
|
||||||
|
}
|
||||||
|
docs.append("\n- 接口备注:").append(api.getNote())
|
||||||
|
.append("\n- 请求参数示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getJsonParam()) ? api.getJsonParam() : "{}").append("\n```\n")
|
||||||
|
.append("\n- 响应结果示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getResponseResult()) ? api.getResponseResult() : "{\"code\":0,\"msg\":\"success\",\"data\":[]}").append("\n```\n")
|
||||||
|
.append("\n---\n");
|
||||||
|
}
|
||||||
|
response.setContentType("application/x-msdownload;charset=utf-8");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=API DOCS.md");
|
||||||
|
OutputStream os = null;
|
||||||
|
try {
|
||||||
|
os = response.getOutputStream();
|
||||||
|
os.write(docs.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (os != null)
|
||||||
|
os.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ApiConfigVo> page(ApiConfigQuery query) {
|
||||||
|
IPage<ApiConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
|
|
||||||
|
return new PageResult<>(ApiConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||||
|
}
|
||||||
|
private LambdaQueryWrapper getWrapper(ApiConfigQuery query) {
|
||||||
|
LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
|
wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName());
|
||||||
|
wrapper.like(StringUtil.isNotBlank(query.getPath()), ApiConfigEntity::getPath, query.getPath());
|
||||||
|
wrapper.eq(StringUtil.isNotBlank(query.getContentType()), ApiConfigEntity::getContentType, query.getContentType());
|
||||||
|
wrapper.eq(query.getStatus()!= null, ApiConfigEntity::getStatus, query.getStatus());
|
||||||
|
wrapper.eq(query.getSqlDbType() != null, ApiConfigEntity::getSqlDbType, query.getSqlDbType());
|
||||||
|
wrapper.eq(query.getDatabaseId()!= null, ApiConfigEntity::getDatabaseId, query.getDatabaseId());
|
||||||
|
wrapper.eq(query.getPrivates()!= null, ApiConfigEntity::getPrivates, query.getPrivates());
|
||||||
|
wrapper.eq(query.getOpenTrans()!= null, ApiConfigEntity::getOpenTrans, query.getOpenTrans());
|
||||||
|
dataScopeWithoutOrgId(wrapper);
|
||||||
|
wrapper.orderByDesc(ApiConfigEntity::getCreateTime);
|
||||||
|
wrapper.orderByDesc(ApiConfigEntity::getId);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(ApiConfigVo vo) {
|
||||||
|
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||||
|
entity.setProjectId(getProjectId());
|
||||||
|
baseMapper.insert(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(ApiConfigVo vo) {
|
||||||
|
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||||
|
entity.setProjectId(getProjectId());
|
||||||
|
updateById(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(List<Long> idList) {
|
||||||
|
removeByIds(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ApiConfigVo> pageResource(ApiConfigQuery query) {
|
||||||
|
// 查询参数
|
||||||
|
Map<String, Object> params = getParams(query);
|
||||||
|
IPage<ApiConfigEntity> page = getPage(query);
|
||||||
|
params.put(Constant.PAGE, page);
|
||||||
|
// 数据列表
|
||||||
|
List<ApiConfigEntity> list = baseMapper.getResourceList(params);
|
||||||
|
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list);
|
||||||
|
for (ApiConfigVo apiConfigVo : apiConfigVos) {
|
||||||
|
ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId());
|
||||||
|
apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null);
|
||||||
|
}
|
||||||
|
return new PageResult<>(apiConfigVos, page.getTotal());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ApiConfigEntity> listActiveByGroupId(Long id) {
|
||||||
|
LambdaQueryWrapper<ApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(ApiConfigEntity::getStatus, 1).eq(ApiConfigEntity::getGroupId, id).orderByDesc(ApiConfigEntity::getId);
|
||||||
|
dataScopeWithoutOrgId(wrapper);
|
||||||
|
return baseMapper.selectList(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getParams(ApiConfigQuery query) {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("ifMarket", query.getIfMarket());
|
||||||
|
params.put("queryApply", query.getQueryApply());
|
||||||
|
if (query.getQueryApply() != null && query.getQueryApply() == 1) {
|
||||||
|
params.put("userId", SecurityUser.getUserId());
|
||||||
|
}
|
||||||
|
params.put("resourceId", query.getResourceId());
|
||||||
|
params.put("groupId", query.getGroupId());
|
||||||
|
params.put("appId", query.getAppId());
|
||||||
|
params.put("name", query.getName());
|
||||||
|
params.put("path", query.getPath());
|
||||||
|
params.put("contentType", query.getContentType());
|
||||||
|
params.put("status", query.getStatus());
|
||||||
|
params.put("sqlDbType", query.getSqlDbType());
|
||||||
|
params.put("databaseId", query.getDatabaseId());
|
||||||
|
params.put("privates", query.getPrivates());
|
||||||
|
params.put("openTrans", query.getOpenTrans());
|
||||||
|
// 数据权限
|
||||||
|
params.put(Constant.DATA_SCOPE, getDataScope("dsac", null, null, "project_id", false, true));
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
package net.srt.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.constants.ApiGroupType;
|
||||||
|
import net.srt.convert.ApiGroupConvert;
|
||||||
|
import net.srt.dao.ApiGroupDao;
|
||||||
|
import net.srt.entity.ApiConfigEntity;
|
||||||
|
import net.srt.entity.ApiGroupEntity;
|
||||||
|
import net.srt.framework.common.exception.ServerException;
|
||||||
|
import net.srt.framework.common.utils.BeanUtil;
|
||||||
|
import net.srt.framework.common.utils.BuildTreeUtils;
|
||||||
|
import net.srt.framework.common.utils.TreeNodeVo;
|
||||||
|
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
|
import net.srt.service.ApiConfigService;
|
||||||
|
import net.srt.service.ApiGroupService;
|
||||||
|
import net.srt.vo.ApiGroupVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{
|
||||||
|
private final ApiConfigService apiConfigService;
|
||||||
|
@Override
|
||||||
|
public List<TreeNodeVo> listTree() {
|
||||||
|
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
|
||||||
|
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TreeNodeVo> getTreeNodeVos() {
|
||||||
|
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
dataScopeWithoutOrgId(wrapper);
|
||||||
|
wrapper.orderByAsc(ApiGroupEntity::getOrderNo);
|
||||||
|
List<ApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper);
|
||||||
|
return BeanUtil.copyListProperties(apiGroupEntities, TreeNodeVo::new, (oldItem, newItem) -> {
|
||||||
|
newItem.setLabel(oldItem.getName());
|
||||||
|
newItem.setValue(oldItem.getId());
|
||||||
|
newItem.setDisabled(oldItem.getType() == 1);
|
||||||
|
if (newItem.getPath().contains("/")) {
|
||||||
|
newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(ApiGroupVo vo) {
|
||||||
|
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||||
|
entity.setPath(recursionPath(entity, null));
|
||||||
|
entity.setProjectId(getProjectId());
|
||||||
|
baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(ApiGroupVo vo) {
|
||||||
|
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||||
|
entity.setPath(recursionPath(entity, null));
|
||||||
|
entity.setProjectId(getProjectId());
|
||||||
|
updateById(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String recursionPath(ApiGroupEntity groupEntity, String path) {
|
||||||
|
if (StringUtil.isBlank(path)) {
|
||||||
|
path = groupEntity.getName();
|
||||||
|
}
|
||||||
|
if (groupEntity.getParentId() != 0) {
|
||||||
|
ApiGroupEntity parent = getById(groupEntity.getParentId());
|
||||||
|
path = parent.getName() + "/" + path;
|
||||||
|
return recursionPath(parent, path);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Long id) {
|
||||||
|
//查询有没有子节点
|
||||||
|
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(ApiGroupEntity::getParentId, id).last(" limit 1");
|
||||||
|
ApiGroupEntity one = baseMapper.selectOne(wrapper);
|
||||||
|
if (one != null) {
|
||||||
|
throw new ServerException("存在子节点,不允许删除!");
|
||||||
|
}
|
||||||
|
//查询有没有api与之关联
|
||||||
|
LambdaQueryWrapper<ApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>();
|
||||||
|
serviceApiConfigWrapper.eq(ApiConfigEntity::getGroupId, id).last(" limit 1");
|
||||||
|
ApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper);
|
||||||
|
if (apiConfigEntity != null) {
|
||||||
|
throw new ServerException("节点下有 api 与之关联,不允许删除!");
|
||||||
|
}
|
||||||
|
removeById(id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.srt.service.impl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiAuthServiceImpl
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-26 15:23
|
||||||
|
*/
|
||||||
|
public class DataServiceApiAuthServiceImpl {
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package net.srt.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.convert.DataServiceApiLogConvert;
|
||||||
|
import net.srt.dao.DataServiceApiLogDao;
|
||||||
|
import net.srt.entity.DataServiceApiLogEntity;
|
||||||
|
import net.srt.framework.common.page.PageResult;
|
||||||
|
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
|
import net.srt.query.DataServiceApiLogQuery;
|
||||||
|
import net.srt.service.DataServiceApiLogService;
|
||||||
|
import net.srt.vo.DataServiceApiLogVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLogServiceImpl
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:31
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DataServiceApiLogServiceImpl extends BaseServiceImpl<DataServiceApiLogDao, DataServiceApiLogEntity> implements DataServiceApiLogService {
|
||||||
|
@Override
|
||||||
|
public PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query) {
|
||||||
|
IPage<DataServiceApiLogEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
|
|
||||||
|
return new PageResult<>(DataServiceApiLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeId(List<Long> idList) {
|
||||||
|
removeByIds(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<DataServiceApiLogEntity> getWrapper(DataServiceApiLogQuery query) {
|
||||||
|
LambdaQueryWrapper<DataServiceApiLogEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
|
wrapper.like(StringUtil.isNotBlank(query.getIp()), DataServiceApiLogEntity::getIp, query.getIp())
|
||||||
|
.like(StringUtil.isNotBlank(query.getApiName()), DataServiceApiLogEntity::getApiName, query.getApiName())
|
||||||
|
.orderByDesc(DataServiceApiLogEntity::getCreateTime).orderByDesc(DataServiceApiLogEntity::getId);
|
||||||
|
dataScopeWithoutOrgId(wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package net.srt.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据服务-api配置
|
||||||
|
*
|
||||||
|
* @author zrx 985134801@qq.com
|
||||||
|
* @since 1.0.0 2023-01-28
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ApiConfigVo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long id;
|
||||||
|
private Long groupId;
|
||||||
|
private String path;
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String note;
|
||||||
|
private String sqlText;
|
||||||
|
private String sqlSeparator;
|
||||||
|
private Integer sqlMaxRow;
|
||||||
|
private String sqlParam;
|
||||||
|
private String jsonParam;
|
||||||
|
private String responseResult;
|
||||||
|
private String contentType;
|
||||||
|
private Integer status;
|
||||||
|
private Date releaseTime;
|
||||||
|
private Long releaseUserId;
|
||||||
|
private Integer sqlDbType;
|
||||||
|
private Long databaseId;
|
||||||
|
private Integer privates;
|
||||||
|
private Integer openTrans;
|
||||||
|
private Long projectId;
|
||||||
|
private Integer version;
|
||||||
|
private Integer deleted;
|
||||||
|
private Long creator;
|
||||||
|
private Date createTime;
|
||||||
|
private Long updater;
|
||||||
|
private Date updateTime;
|
||||||
|
private Integer requestedTimes;
|
||||||
|
private Integer requestedSuccessTimes;
|
||||||
|
private Integer requestedFailedTimes;
|
||||||
|
private Long authId;
|
||||||
|
private String group;
|
||||||
|
private String groupPath;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package net.srt.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiGroupVo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long id;
|
||||||
|
private Long parentId;
|
||||||
|
private Integer type;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private Integer orderNo;
|
||||||
|
private String path;
|
||||||
|
private Long projectId;
|
||||||
|
private Integer version;
|
||||||
|
private Integer deleted;
|
||||||
|
private Long creator;
|
||||||
|
private Date createTime;
|
||||||
|
private Long updater;
|
||||||
|
private Date updateTime;
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package net.srt.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : DataServiceApiLog
|
||||||
|
* @Description :
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2023-12-25 11:05
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "api请求日志")
|
||||||
|
public class DataServiceApiLogVo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
@Schema(description = "主键id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "url")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Schema(description = "响应状态码")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "时长")
|
||||||
|
private Long duration;
|
||||||
|
|
||||||
|
@Schema(description = "IP地址")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Schema(description = "app的id")
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
@Schema(description = "api的id")
|
||||||
|
private String apiId;
|
||||||
|
|
||||||
|
private String appName;
|
||||||
|
private String apiName;
|
||||||
|
|
||||||
|
@Schema(description = "错误信息")
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
@Schema(description = "项目id")
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
@Schema(description = "版本号")
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
@Schema(description = "删除标识 0:正常 1:已删除")
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
@Schema(description = "创建者")
|
||||||
|
private Long creator;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Schema(description = "更新者")
|
||||||
|
private Long updater;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date updateTime;
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package net.srt.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: data-center
|
||||||
|
* @BelongsPackage: net.srt.vo
|
||||||
|
* @Author: yanqiang
|
||||||
|
* @CreateTime: 2023-12-24 15:21
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "api日志")
|
||||||
|
public class ServiceApiLogVo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "主键id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "url")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Schema(description = "响应状态码")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "时长")
|
||||||
|
private Long duration;
|
||||||
|
|
||||||
|
@Schema(description = "IP地址")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Schema(description = "app的id")
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
@Schema(description = "api的id")
|
||||||
|
private String apiId;
|
||||||
|
|
||||||
|
private String appName;
|
||||||
|
private String apiName;
|
||||||
|
|
||||||
|
@Schema(description = "错误信息")
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
@Schema(description = "项目id")
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
@Schema(description = "版本号")
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
@Schema(description = "删除标识 0:正常 1:已删除")
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
@Schema(description = "创建者")
|
||||||
|
private Long creator;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Schema(description = "更新者")
|
||||||
|
private Long updater;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package net.srt.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: data-center
|
||||||
|
* @BelongsPackage: net.srt.vo
|
||||||
|
* @Author: yanqiang
|
||||||
|
* @CreateTime: 2023-12-21 20:50
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "数据app")
|
||||||
|
public class ServiceAppVo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "主键id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String note;
|
||||||
|
|
||||||
|
@Schema(description = "appKey")
|
||||||
|
private String appKey;
|
||||||
|
|
||||||
|
@Schema(description = "appSecret")
|
||||||
|
private String appSecret;
|
||||||
|
|
||||||
|
@Schema(description = "过期时间")
|
||||||
|
private String expireDesc;
|
||||||
|
/**
|
||||||
|
* 过期时间 -1永久;0 单次失效;> 0 失效时间
|
||||||
|
*/
|
||||||
|
private Long expireDuration;
|
||||||
|
private Integer ifMarket;
|
||||||
|
|
||||||
|
@Schema(description = "项目id")
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
@Schema(description = "版本号")
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
@Schema(description = "0:正常 1:已删除")
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
@Schema(description = "创建人")
|
||||||
|
private Long creator;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Schema(description = "更新人")
|
||||||
|
private Long updater;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间")
|
||||||
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?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="net.srt.dao.ApiConfigDao">
|
||||||
|
<select id="getResourceList" resultType="net.srt.entity.ApiConfigEntity">
|
||||||
|
<choose>
|
||||||
|
<when test="queryApply!=null and queryApply==1">
|
||||||
|
SELECT * FROM data_service_api_config
|
||||||
|
WHERE id IN (SELECT mount_id FROM data_assets_resource_mount WHERE mount_type=2 AND resource_id=#{resourceId})
|
||||||
|
AND deleted=0
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
SELECT
|
||||||
|
dsac.*
|
||||||
|
FROM
|
||||||
|
data_service_api_config dsac
|
||||||
|
INNER JOIN data_assets_resource_mount darm ON dsac.id = darm.mount_id
|
||||||
|
WHERE
|
||||||
|
darm.mount_type=2
|
||||||
|
AND darm.resource_id=#{resourceId}
|
||||||
|
AND dsac.deleted=0
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</select>
|
||||||
|
<select id="getById" resultType="net.srt.entity.ApiConfigEntity">
|
||||||
|
SELECT * FROM data_service_api_config WHERE id = #{id}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue