【feat】整合数据资产相关
This commit is contained in:
parent
42faa66134
commit
18445195d6
@ -3,7 +3,7 @@ package com.czsj.web.controller.flink.api;
|
||||
|
||||
import com.czsj.bigdata.entity.BaseResource;
|
||||
import com.czsj.bigdata.mapper.BaseResourceMapper;
|
||||
import com.czsj.common.config.czsjConfig;
|
||||
import com.czsj.common.config.CzsjConfig;
|
||||
import com.czsj.common.utils.ReadYmlUtil;
|
||||
import com.czsj.common.utils.file.FileUploadUtils;
|
||||
import com.czsj.common.utils.file.FileUtils;
|
||||
@ -58,7 +58,7 @@ public class UploadApiController extends BaseController {
|
||||
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
|
||||
public RestResult<?> upload(HttpServletRequest request, @RequestParam(value="resourceId") String resourceId,@RequestParam(value="remarks") String remarks,@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
String uploadPath = czsjConfig.getUploadPath();
|
||||
String uploadPath = CzsjConfig.getUploadPath();
|
||||
//通过ID查资源服务器信息
|
||||
BaseResource baseResource = baseResourceMapper.getById(Integer.parseInt(resourceId));
|
||||
log.info("uploadPath={}", uploadPath);
|
||||
@ -92,7 +92,7 @@ public class UploadApiController extends BaseController {
|
||||
public RestResult<?> deleteFile(Long id) {
|
||||
try {
|
||||
UploadFileDTO uploadFileById = uploadFileService.getUploadFileById(id);
|
||||
String uploadPath = czsjConfig.getUploadPath();
|
||||
String uploadPath = CzsjConfig.getUploadPath();
|
||||
// String[] split = uploadFileById.getDownloadJarHttp().split("/");
|
||||
// String filePath = uploadPath + "/" + split[split.length-4] + "/" + split[split.length-3] + "/" + split[split.length-2] + "/" + uploadFileById.getFilePath();
|
||||
String filePath = uploadPath + "/" + uploadFileById.getFilePath();
|
||||
|
@ -0,0 +1,135 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
import com.czsj.market.mapstruct.ApiLogMapper;
|
||||
import com.czsj.market.query.ApiLogQuery;
|
||||
import com.czsj.market.service.ApiLogService;
|
||||
import com.czsj.market.vo.ApiLogVo;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* api调用日志信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-21
|
||||
*/
|
||||
@Api(tags = {"api调用日志信息表"})
|
||||
@RestController
|
||||
@RequestMapping("market/apiLogs")
|
||||
public class ApiLogController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ApiLogService apiLogService;
|
||||
|
||||
@Autowired
|
||||
private ApiLogMapper apiLogMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getApiLogById(@PathVariable String id) {
|
||||
ApiLogEntity apiLogEntity = apiLogService.getApiLogById(id);
|
||||
return AjaxResult.success(apiLogMapper.toVO(apiLogEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param apiLogQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "apiLogQuery", value = "查询实体apiLogQuery", required = true, dataTypeClass = ApiLogQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getApiLogPage(ApiLogQuery apiLogQuery) {
|
||||
QueryWrapper<ApiLogEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(apiLogQuery.getApiName()), "api.api_name", apiLogQuery.getApiName());
|
||||
IPage<ApiLogEntity> page = apiLogService.page(new Page<>(apiLogQuery.getPageNum(), apiLogQuery.getPageSize()), queryWrapper);
|
||||
List<ApiLogVo> collect = page.getRecords().stream().map(apiLogMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<ApiLogVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param apiLog
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据apiLog对象添加信息")
|
||||
@ApiImplicitParam(name = "apiLog", value = "详细实体apiLog", required = true, dataType = "ApiLogDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveApiLog(@RequestBody @Validated({ValidationGroups.Insert.class}) ApiLogDto apiLog) {
|
||||
ApiLogEntity apiLogEntity = apiLogService.saveApiLog(apiLog);
|
||||
return AjaxResult.success(apiLogMapper.toVO(apiLogEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param apiLog
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "apiLog", value = "详细实体apiLog", required = true, dataType = "ApiLogDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateApiLog(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) ApiLogDto apiLog) {
|
||||
ApiLogEntity apiLogEntity = apiLogService.updateApiLog(apiLog);
|
||||
return AjaxResult.success(apiLogMapper.toVO(apiLogEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteApiLogById(@PathVariable String id) {
|
||||
apiLogService.deleteApiLogById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteApiLogBatch(@PathVariable List<String> ids) {
|
||||
apiLogService.deleteApiLogBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.market.dto.ApiMaskDto;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.mapstruct.ApiMaskMapper;
|
||||
import com.czsj.market.query.ApiMaskQuery;
|
||||
import com.czsj.market.service.ApiMaskService;
|
||||
import com.czsj.market.vo.ApiMaskVo;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@Api(tags = {"数据API脱敏信息表"})
|
||||
@RestController
|
||||
@RequestMapping("market/apiMasks")
|
||||
public class ApiMaskController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ApiMaskService apiMaskService;
|
||||
|
||||
@Autowired
|
||||
private ApiMaskMapper apiMaskMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getApiMaskById(@PathVariable String id) {
|
||||
ApiMaskEntity apiMaskEntity = apiMaskService.getApiMaskById(id);
|
||||
return AjaxResult.success(apiMaskMapper.toVO(apiMaskEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/api/{id}")
|
||||
public AjaxResult getApiMaskByApiId(@PathVariable String id) {
|
||||
ApiMaskEntity apiMaskEntity = apiMaskService.getApiMaskByApiId(id);
|
||||
return AjaxResult.success(apiMaskMapper.toVO(apiMaskEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param apiMaskQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "apiMaskQuery", value = "查询实体apiMaskQuery", required = true, dataTypeClass = ApiMaskQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getApiMaskPage(ApiMaskQuery apiMaskQuery) {
|
||||
QueryWrapper<ApiMaskEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(apiMaskQuery.getMaskName()), "mask_name", apiMaskQuery.getMaskName());
|
||||
IPage<ApiMaskEntity> page = apiMaskService.page(new Page<>(apiMaskQuery.getPageNum(), apiMaskQuery.getPageSize()), queryWrapper);
|
||||
List<ApiMaskVo> collect = page.getRecords().stream().map(apiMaskMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<ApiMaskVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param apiMask
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据apiMask对象添加信息")
|
||||
@ApiImplicitParam(name = "apiMask", value = "详细实体apiMask", required = true, dataType = "ApiMaskDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveApiMask(@RequestBody @Validated({ValidationGroups.Insert.class}) ApiMaskDto apiMask) {
|
||||
apiMaskService.saveApiMask(apiMask);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param apiMask
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "apiMask", value = "详细实体apiMask", required = true, dataType = "ApiMaskDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateApiMask(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) ApiMaskDto apiMask) {
|
||||
apiMaskService.updateApiMask(apiMask);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteApiMaskById(@PathVariable String id) {
|
||||
apiMaskService.deleteApiMaskById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteApiMaskBatch(@PathVariable List<String> ids) {
|
||||
apiMaskService.deleteApiMaskBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import com.aspose.words.SaveOptions;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.market.dto.DataApiDto;
|
||||
import com.czsj.market.dto.SqlParseDto;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.mapstruct.DataApiMapper;
|
||||
import com.czsj.market.query.DataApiQuery;
|
||||
import com.czsj.market.service.DataApiService;
|
||||
import com.czsj.market.vo.DataApiVo;
|
||||
import com.czsj.market.vo.SqlParseVo;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Api(tags = {"数据API信息表"})
|
||||
@RestController
|
||||
@RequestMapping("market/dataApis")
|
||||
public class DataApiController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DataApiService dataApiService;
|
||||
|
||||
@Autowired
|
||||
private DataApiMapper dataApiMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getDataApiById(@PathVariable String id) {
|
||||
DataApiEntity dataApiEntity = dataApiService.getDataApiById(id);
|
||||
return AjaxResult.success(dataApiMapper.toVO(dataApiEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult getDataApiList() {
|
||||
QueryWrapper<DataApiEntity> queryWrapper = new QueryWrapper<>();
|
||||
List<DataApiEntity> list = dataApiService.list(queryWrapper);
|
||||
List<DataApiVo> collect = list.stream().map(dataApiMapper::toVO).collect(Collectors.toList());
|
||||
return AjaxResult.success(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param dataApiQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dataApiQuery", value = "查询实体dataApiQuery", required = true, dataTypeClass = DataApiQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getDataApiPage(DataApiQuery dataApiQuery) {
|
||||
QueryWrapper<DataApiEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(dataApiQuery.getApiName()), "api_name", dataApiQuery.getApiName());
|
||||
IPage<DataApiEntity> page = dataApiService.page(new Page<>(dataApiQuery.getPageNum(), dataApiQuery.getPageSize()), queryWrapper);
|
||||
List<DataApiVo> collect = page.getRecords().stream().map(dataApiMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<DataApiVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param dataApi
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据dataApi对象添加信息")
|
||||
@ApiImplicitParam(name = "dataApi", value = "详细实体dataApi", required = true, dataType = "DataApiDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveDataApi(@RequestBody @Validated({ValidationGroups.Insert.class}) DataApiDto dataApi) {
|
||||
dataApiService.saveDataApi(dataApi);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param dataApi
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "dataApi", value = "详细实体dataApi", required = true, dataType = "DataApiDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateDataApi(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) DataApiDto dataApi) {
|
||||
dataApiService.updateDataApi(dataApi);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteDataApiById(@PathVariable String id) {
|
||||
dataApiService.deleteDataApiById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteDataApiBatch(@PathVariable List<String> ids) {
|
||||
dataApiService.deleteDataApiBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL解析
|
||||
* @param sqlParseDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "SQL解析")
|
||||
@ApiImplicitParam(name = "sqlParseDto", value = "SQL解析实体sqlParseDto", required = true, dataType = "SqlParseDto")
|
||||
@PostMapping("/sql/parse")
|
||||
public AjaxResult sqlParse(@RequestBody @Validated SqlParseDto sqlParseDto) throws SQLException, JSQLParserException {
|
||||
SqlParseVo sqlParseVo = dataApiService.sqlParse(sqlParseDto);
|
||||
return AjaxResult.success(sqlParseVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/{id}/copy")
|
||||
public AjaxResult copyDataApi(@PathVariable String id) {
|
||||
dataApiService.copyDataApi(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/{id}/release")
|
||||
public AjaxResult releaseDataApi(@PathVariable String id){
|
||||
dataApiService.releaseDataApi(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/{id}/cancel")
|
||||
public AjaxResult cancelDataApi(@PathVariable String id){
|
||||
dataApiService.cancelDataApi(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "接口文档", notes = "根据url的id来指定生成接口文档对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@PostMapping("/word/{id}")
|
||||
public void wordDataApi(@PathVariable String id, HttpServletResponse response) throws Exception {
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setContentType("application/octet-stream;charset=utf-8");
|
||||
// 设置content-disposition响应头控制浏览器以下载的形式打开文件
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + new String("接口文档.docx".getBytes()));
|
||||
Document doc = dataApiService.wordDataApi(id);
|
||||
OutputStream out = response.getOutputStream();
|
||||
doc.save(out, SaveOptions.createSaveOptions(SaveFormat.DOCX));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
public AjaxResult getDataApiDetailById(@PathVariable String id) {
|
||||
Map<String, Object> map = dataApiService.getDataApiDetailById(id);
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.czsj.async.AsyncTask;
|
||||
import com.czsj.common.core.data.R;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.core.database.core.PageResult;
|
||||
import com.czsj.core.util.IPUtil;
|
||||
import com.czsj.core.util.RequestHolder;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.utils.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class GetApiLogAspect {
|
||||
|
||||
@Autowired
|
||||
private AsyncTask asyncTask;
|
||||
|
||||
@Pointcut("execution(* com.czsj.web.controller.market.marketInnerController.getApiMaskByApiId(..))")
|
||||
public void logPointCut() {
|
||||
System.out.println(1111);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知方法会将目标方法封装起来
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
*/
|
||||
@Around(value = "logPointCut()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object result = joinPoint.proceed();
|
||||
long endTime = System.currentTimeMillis();
|
||||
ApiLogDto log = getLog();
|
||||
log.setTime(endTime - startTime);
|
||||
R r = JSON.parseObject(JSON.toJSONString(result), R.class);
|
||||
if (r != null) {
|
||||
log.setCallerSize(JSON.parseObject(JSON.toJSONString(r.getData()), PageResult.class).getData().size());
|
||||
}
|
||||
handleLog(joinPoint,log);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知方法会在目标方法抛出异常后执行
|
||||
*
|
||||
* @param joinPoint
|
||||
* @param e
|
||||
*/
|
||||
@AfterThrowing(value = "logPointCut()", throwing = "e")
|
||||
public void doAfterThrowing(JoinPoint joinPoint, Exception e) {
|
||||
log.error("出错{}", e.getMessage());
|
||||
ApiLogDto log = getLog();
|
||||
log.setStatus(DataConstant.EnableState.DISABLE.getKey());
|
||||
log.setMsg(e.getMessage());
|
||||
handleLog(joinPoint, log);
|
||||
}
|
||||
|
||||
private ApiLogDto getLog() {
|
||||
ApiLogDto log = new ApiLogDto();
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
String apiKey = request.getHeader("api_key");
|
||||
String secretKey = request.getHeader("secret_key");
|
||||
try {
|
||||
MD5Util mt = MD5Util.getInstance();
|
||||
String apiId = mt.decode(apiKey);
|
||||
String userId = mt.decode(secretKey);
|
||||
log.setCallerId(userId);
|
||||
log.setApiId(apiId);
|
||||
} catch (Exception e) {}
|
||||
String uri = request.getRequestURI();
|
||||
log.setCallerUrl(uri);
|
||||
String ipAddr = IPUtil.getIpAddr(request);
|
||||
log.setCallerIp(ipAddr);
|
||||
log.setCallerDate(LocalDateTime.now());
|
||||
log.setStatus(DataConstant.EnableState.ENABLE.getKey());
|
||||
return log;
|
||||
}
|
||||
|
||||
protected void handleLog(final JoinPoint joinPoint, ApiLogDto log) {
|
||||
Map<String, Object> pathVariables = (Map<String, Object>) joinPoint.getArgs()[2];
|
||||
Map<String, Object> requestParams = (Map<String, Object>) joinPoint.getArgs()[3];
|
||||
Map<String, Object> requestBodys = (Map<String, Object>) joinPoint.getArgs()[4];
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (MapUtil.isNotEmpty(pathVariables)) {
|
||||
params.putAll(pathVariables);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestParams)) {
|
||||
params.putAll(requestParams);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestBodys)) {
|
||||
params.putAll(requestBodys);
|
||||
}
|
||||
try {
|
||||
log.setCallerParams(new ObjectMapper().writeValueAsString(params));
|
||||
} catch (JsonProcessingException e) {}
|
||||
asyncTask.doTask(log);
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.czsj.async.AsyncTask;
|
||||
import com.czsj.common.core.data.R;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.core.database.core.PageResult;
|
||||
import com.czsj.core.util.IPUtil;
|
||||
import com.czsj.core.util.RequestHolder;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.utils.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class PostApiLogAspect {
|
||||
|
||||
@Autowired
|
||||
private AsyncTask asyncTask;
|
||||
|
||||
@Pointcut("execution(* com.czsj.web.controller.market.marketInnerController.postApiMaskByApiId(..))")
|
||||
public void logPointCut() {
|
||||
System.out.println(1111);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知方法会将目标方法封装起来
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
*/
|
||||
@Around(value = "logPointCut()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object result = joinPoint.proceed();
|
||||
long endTime = System.currentTimeMillis();
|
||||
ApiLogDto log = getLog();
|
||||
log.setTime(endTime - startTime);
|
||||
R r = JSON.parseObject(JSON.toJSONString(result), R.class);
|
||||
if (r != null) {
|
||||
log.setCallerSize(JSON.parseObject(JSON.toJSONString(r.getData()), PageResult.class).getData().size());
|
||||
}
|
||||
handleLog(joinPoint,log);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知方法会在目标方法抛出异常后执行
|
||||
*
|
||||
* @param joinPoint
|
||||
* @param e
|
||||
*/
|
||||
@AfterThrowing(value = "logPointCut()", throwing = "e")
|
||||
public void doAfterThrowing(JoinPoint joinPoint, Exception e) {
|
||||
log.error("出错{}", e.getMessage());
|
||||
ApiLogDto log = getLog();
|
||||
log.setStatus(DataConstant.EnableState.DISABLE.getKey());
|
||||
log.setMsg(e.getMessage());
|
||||
handleLog(joinPoint, log);
|
||||
}
|
||||
|
||||
private ApiLogDto getLog() {
|
||||
ApiLogDto log = new ApiLogDto();
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
String apiKey = request.getHeader("api_key");
|
||||
String secretKey = request.getHeader("secret_key");
|
||||
try {
|
||||
MD5Util mt = MD5Util.getInstance();
|
||||
String apiId = mt.decode(apiKey);
|
||||
String userId = mt.decode(secretKey);
|
||||
log.setCallerId(userId);
|
||||
log.setApiId(apiId);
|
||||
} catch (Exception e) {}
|
||||
String uri = request.getRequestURI();
|
||||
log.setCallerUrl(uri);
|
||||
String ipAddr = IPUtil.getIpAddr(request);
|
||||
log.setCallerIp(ipAddr);
|
||||
log.setCallerDate(LocalDateTime.now());
|
||||
log.setStatus(DataConstant.EnableState.ENABLE.getKey());
|
||||
return log;
|
||||
}
|
||||
|
||||
protected void handleLog(final JoinPoint joinPoint, ApiLogDto log) {
|
||||
Map<String, Object> pathVariables = (Map<String, Object>) joinPoint.getArgs()[2];
|
||||
Map<String, Object> requestParams = (Map<String, Object>) joinPoint.getArgs()[3];
|
||||
Map<String, Object> requestBodys = (Map<String, Object>) joinPoint.getArgs()[4];
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (MapUtil.isNotEmpty(pathVariables)) {
|
||||
params.putAll(pathVariables);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestParams)) {
|
||||
params.putAll(requestParams);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestBodys)) {
|
||||
params.putAll(requestBodys);
|
||||
}
|
||||
try {
|
||||
log.setCallerParams(new ObjectMapper().writeValueAsString(params));
|
||||
} catch (JsonProcessingException e) {}
|
||||
asyncTask.doTask(log);
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.czsj.web.controller.market;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.core.database.core.PageResult;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.handler.MappingHandlerMapping;
|
||||
import com.czsj.market.handler.RequestHandler;
|
||||
import com.czsj.market.service.ApiMaskService;
|
||||
import com.czsj.market.service.DataApiService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/inner")
|
||||
public class marketInnerController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DataApiService dataApiService;
|
||||
|
||||
@Autowired
|
||||
private ApiMaskService apiMaskService;
|
||||
|
||||
@Autowired
|
||||
private RequestHandler requestHandler;
|
||||
|
||||
|
||||
@GetMapping("/apis/{id}")
|
||||
public DataApiEntity getDataApiById(@PathVariable("id") String id) {
|
||||
DataApiEntity dataApiEntity = dataApiService.getDataApiById(id);
|
||||
return dataApiEntity;
|
||||
}
|
||||
|
||||
@GetMapping("/apis/release/list")
|
||||
public List<DataApiEntity> getReleaseDataApiList() {
|
||||
QueryWrapper<DataApiEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("status", DataConstant.ApiState.RELEASE.getKey());
|
||||
List<DataApiEntity> dataApiEntityList = dataApiService.list(queryWrapper);
|
||||
return dataApiEntityList;
|
||||
}
|
||||
|
||||
@GetMapping("/apiMasks/api/{id}")
|
||||
public ApiMaskEntity getApiMaskByApiId(@PathVariable("id") String id) {
|
||||
ApiMaskEntity apiMaskEntity = apiMaskService.getApiMaskByApiId(id);
|
||||
return apiMaskEntity;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ResponseBody
|
||||
@GetMapping("/data/api")
|
||||
public Object getApiMaskByApiId(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable(required = false) Map<String, Object> pathVariables,
|
||||
@RequestParam(required = false) Map<String, Object> requestParams,
|
||||
@RequestBody(required = false) Map<String, Object> requestBodys) {
|
||||
|
||||
DataApiEntity api;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (MapUtil.isNotEmpty(pathVariables)) {
|
||||
params.putAll(pathVariables);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestParams)) {
|
||||
params.putAll(requestParams);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestBodys)) {
|
||||
params.putAll(requestBodys);
|
||||
}
|
||||
api = MappingHandlerMapping.getMappingApiInfoA(params.get("apiCode").toString());
|
||||
params.remove("apiCode");
|
||||
if(null == api){
|
||||
throw new DataException("api接口未发布或不存在!");
|
||||
}
|
||||
// 序列化
|
||||
api = requestHandler.getObjectMapper().readValue(requestHandler.getObjectMapper().writeValueAsString(api), DataApiEntity.class);
|
||||
// 执行前置拦截器
|
||||
requestHandler.getRequestInterceptor().preHandle(request, response, api, params);
|
||||
PageResult<Map<String, Object>> value = requestHandler.getApiMappingEngine().execute(api, params);
|
||||
// 执行后置拦截器
|
||||
requestHandler.getRequestInterceptor().postHandle(request, response, api, params, value);
|
||||
return AjaxResult.success(value);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ResponseBody
|
||||
@PostMapping("/data/api")
|
||||
public Object postApiMaskByApiId(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable(required = false) Map<String, Object> pathVariables,
|
||||
@RequestParam(required = false) Map<String, Object> requestParams,
|
||||
@RequestBody(required = false) Map<String, Object> requestBodys) {
|
||||
|
||||
DataApiEntity api;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (MapUtil.isNotEmpty(pathVariables)) {
|
||||
params.putAll(pathVariables);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestParams)) {
|
||||
params.putAll(requestParams);
|
||||
}
|
||||
if (MapUtil.isNotEmpty(requestBodys)) {
|
||||
params.putAll(requestBodys);
|
||||
}
|
||||
api = MappingHandlerMapping.getMappingApiInfoA(params.get("apiCode").toString());
|
||||
params.remove("apiCode");
|
||||
if(null == api){
|
||||
throw new DataException("api接口未发布或不存在!");
|
||||
}
|
||||
// 序列化
|
||||
api = requestHandler.getObjectMapper().readValue(requestHandler.getObjectMapper().writeValueAsString(api), DataApiEntity.class);
|
||||
// 执行前置拦截器
|
||||
requestHandler.getRequestInterceptor().preHandle(request, response, api, params);
|
||||
PageResult<Map<String, Object>> value = requestHandler.getApiMappingEngine().execute(api, params);
|
||||
// 执行后置拦截器
|
||||
requestHandler.getRequestInterceptor().postHandle(request, response, api, params, value);
|
||||
return AjaxResult.success(value);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
package com.czsj.web.controller.metadata;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.metadata.dto.MetadataChangeRecordDto;
|
||||
import com.czsj.metadata.entity.MetadataChangeRecordEntity;
|
||||
import com.czsj.metadata.mapstruct.MetadataChangeRecordMapper;
|
||||
import com.czsj.metadata.query.MetadataChangeRecordQuery;
|
||||
import com.czsj.metadata.service.MetadataChangeRecordService;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import com.czsj.metadata.vo.MetadataChangeRecordVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-07-30
|
||||
*/
|
||||
@Api(tags = {"元数据变更记录表"})
|
||||
@RestController
|
||||
@RequestMapping("/changeRecords")
|
||||
public class MetadataChangeRecordController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordService metadataChangeRecordService;
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordMapper metadataChangeRecordMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getMetadataChangeRecordById(@PathVariable String id) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.getMetadataChangeRecordById(id);
|
||||
return AjaxResult.success(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataChangeRecordQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "metadataChangeRecordQuery", value = "查询实体metadataChangeRecordQuery", required = true, dataTypeClass = MetadataChangeRecordQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getMetadataChangeRecordPage(MetadataChangeRecordQuery metadataChangeRecordQuery) {
|
||||
QueryWrapper<MetadataChangeRecordEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataChangeRecordQuery.getObjectId()), "r.object_id", metadataChangeRecordQuery.getObjectId());
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataChangeRecordQuery.getFieldName()), "r.field_name", metadataChangeRecordQuery.getFieldName());
|
||||
IPage<MetadataChangeRecordEntity> page = metadataChangeRecordService.page(new Page<>(metadataChangeRecordQuery.getPageNum(), metadataChangeRecordQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataChangeRecordVo> collect = page.getRecords().stream().map(metadataChangeRecordMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataChangeRecordVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param metadataChangeRecord
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据metadataChangeRecord对象添加信息")
|
||||
@ApiImplicitParam(name = "metadataChangeRecord", value = "详细实体metadataChangeRecord", required = true, dataType = "MetadataChangeRecordDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveMetadataChangeRecord(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataChangeRecordDto metadataChangeRecord) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.saveMetadataChangeRecord(metadataChangeRecord);
|
||||
return AjaxResult.success(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param metadataChangeRecord
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataChangeRecord", value = "详细实体metadataChangeRecord", required = true, dataType = "MetadataChangeRecordDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateMetadataChangeRecord(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataChangeRecordDto metadataChangeRecord) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.updateMetadataChangeRecord(metadataChangeRecord);
|
||||
return AjaxResult.success(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteMetadataChangeRecordById(@PathVariable String id) {
|
||||
metadataChangeRecordService.deleteMetadataChangeRecordById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteMetadataChangeRecordBatch(@PathVariable List<String> ids) {
|
||||
metadataChangeRecordService.deleteMetadataChangeRecordBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package com.czsj.web.controller.metadata;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.metadata.dto.MetadataColumnDto;
|
||||
import com.czsj.metadata.entity.MetadataColumnEntity;
|
||||
import com.czsj.metadata.query.MetadataColumnQuery;
|
||||
import com.czsj.metadata.service.MetadataColumnMapper;
|
||||
import com.czsj.metadata.service.MetadataColumnService;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import com.czsj.metadata.vo.MetadataColumnVo;
|
||||
import com.czsj.metadata.vo.MetadataTreeVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-07-29
|
||||
*/
|
||||
@Api(tags = {"元数据信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/columns")
|
||||
public class MetadataColumnController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnService metadataColumnService;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnMapper metadataColumnMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getDataMetadataColumnById(@PathVariable String id) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.getMetadataColumnById(id);
|
||||
return AjaxResult.success(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult getDataMetadataColumnList(MetadataColumnQuery metadataColumnQuery) {
|
||||
List<MetadataColumnEntity> list = metadataColumnService.getDataMetadataColumnList(metadataColumnQuery);
|
||||
List<MetadataColumnVo> collect = list.stream().map(metadataColumnMapper::toVO).collect(Collectors.toList());
|
||||
return AjaxResult.success(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataColumnQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dataMetadataColumnQuery", value = "查询实体dataMetadataColumnQuery", required = true, dataTypeClass = MetadataColumnQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getDataMetadataColumnPage(MetadataColumnQuery metadataColumnQuery) {
|
||||
QueryWrapper<MetadataColumnEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataColumnQuery.getColumnName()), "c.column_name", metadataColumnQuery.getColumnName());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getSourceId()), "c.source_id", metadataColumnQuery.getSourceId());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getTableId()), "c.table_id", metadataColumnQuery.getTableId());
|
||||
IPage<MetadataColumnEntity> page = metadataColumnService.pageWithAuth(new Page<>(metadataColumnQuery.getPageNum(), metadataColumnQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataColumnVo> collect = page.getRecords().stream().map(metadataColumnMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataColumnVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param dataMetadataColumn
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据dataMetadataColumn对象添加信息")
|
||||
@ApiImplicitParam(name = "dataMetadataColumn", value = "详细实体dataMetadataColumn", required = true, dataType = "DataMetadataColumnDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveDataMetadataColumn(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataColumnDto dataMetadataColumn) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.saveMetadataColumn(dataMetadataColumn);
|
||||
return AjaxResult.success(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param dataMetadataColumn
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "dataMetadataColumn", value = "详细实体dataMetadataColumn", required = true, dataType = "DataMetadataColumnDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateDataMetadataColumn(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataColumnDto dataMetadataColumn) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.updateMetadataColumn(dataMetadataColumn);
|
||||
return AjaxResult.success(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteDataMetadataColumnById(@PathVariable String id) {
|
||||
metadataColumnService.deleteMetadataColumnById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteDataMetadataColumnBatch(@PathVariable List<String> ids) {
|
||||
metadataColumnService.deleteMetadataColumnBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取层级树
|
||||
* @param level 层级database、table、column
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取层级树", notes = "根据url的层级来获取树对象")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "level", value = "层级", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataColumnQuery", value = "查询实体metadataColumnQuery", required = false, dataType = "MetadataColumnQuery")
|
||||
})
|
||||
@GetMapping("/tree/{level}")
|
||||
public AjaxResult getDataMetadataTree(@PathVariable String level, MetadataColumnQuery metadataColumnQuery) {
|
||||
List<MetadataTreeVo> list = metadataColumnService.getDataMetadataTree(level, metadataColumnQuery);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
package com.czsj.web.controller.metadata;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import com.aspose.words.SaveOptions;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.common.database.service.DbQuery;
|
||||
import com.czsj.core.database.core.DbColumn;
|
||||
import com.czsj.core.database.core.DbTable;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.core.database.core.PageResult;
|
||||
import com.czsj.metadata.dto.MetadataSourceDto;
|
||||
import com.czsj.metadata.entity.MetadataSourceEntity;
|
||||
import com.czsj.metadata.query.DbDataQuery;
|
||||
import com.czsj.metadata.query.MetadataSourceQuery;
|
||||
import com.czsj.metadata.service.MetadataSourceMapper;
|
||||
import com.czsj.metadata.service.MetadataSourceService;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import com.czsj.metadata.vo.MetadataSourceVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-14
|
||||
*/
|
||||
@Api(tags = {"数据源信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/sources")
|
||||
public class MetadataSourceController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceService metadataSourceService;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceMapper metadataSourceMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getMetadataSourceById(@PathVariable String id) {
|
||||
MetadataSourceEntity metadataSourceEntity = metadataSourceService.getMetadataSourceById(id);
|
||||
return AjaxResult.success(metadataSourceMapper.toVO(metadataSourceEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult getMetadataSourceList() {
|
||||
List<MetadataSourceEntity> list = metadataSourceService.getMetadataSourceList();
|
||||
List<MetadataSourceVo> collect = list.stream().map(metadataSourceMapper::toVO).collect(Collectors.toList());
|
||||
return AjaxResult.success(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataSourceQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "metadataSourceQuery", value = "查询实体metadataSourceQuery", required = true, dataTypeClass = MetadataSourceQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getMetadataSourcePage(MetadataSourceQuery metadataSourceQuery) {
|
||||
QueryWrapper<MetadataSourceEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataSourceQuery.getSourceName()), "s.source_name", metadataSourceQuery.getSourceName());
|
||||
IPage<MetadataSourceEntity> page = metadataSourceService.pageWithAuth(new Page<>(metadataSourceQuery.getPageNum(), metadataSourceQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataSourceVo> collect = page.getRecords().stream().map(metadataSourceMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataSourceVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据metadataSourceDto对象添加信息")
|
||||
@ApiImplicitParam(name = "metadataSourceDto", value = "详细实体metadataSourceDto", required = true, dataType = "MetadataSourceDto")
|
||||
@PostMapping()
|
||||
public AjaxResult saveMetadataSource(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataSourceDto metadataSourceDto) {
|
||||
metadataSourceDto.setUser(getUsername());
|
||||
metadataSourceService.saveMetadataSource(metadataSourceDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataSourceDto", value = "详细实体metadataSourceDto", required = true, dataType = "MetadataSourceDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult updateMetadataSource(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataSourceDto metadataSourceDto) {
|
||||
metadataSourceDto.setUser(getUsername());
|
||||
metadataSourceService.updateMetadataSource(metadataSourceDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteMetadataSourceById(@PathVariable String id) {
|
||||
metadataSourceService.deleteMetadataSourceById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public AjaxResult deleteMetadataSourceBatch(@PathVariable List<String> ids) {
|
||||
metadataSourceService.deleteMetadataSourceBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测数据库连通性
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库连通性", notes = "根据数据库配置信息检测数据库连通性")
|
||||
@ApiImplicitParam(name = "dataSource", value = "详细实体dataSource", required = true, dataType = "DataSourceDto")
|
||||
@PostMapping("/checkConnection")
|
||||
public AjaxResult checkConnection(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataSourceDto metadataSourceDto) {
|
||||
DbQuery dbQuery = metadataSourceService.checkConnection(metadataSourceDto);
|
||||
Boolean valid = dbQuery.valid();
|
||||
return valid ? AjaxResult.success("数据库连接成功") : AjaxResult.error("数据库连接有误,请检查数据库配置是否正确");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库表", notes = "根据数据源的id来获取指定数据库表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
})
|
||||
@GetMapping("/{id}/tables")
|
||||
public AjaxResult getDbTables(@PathVariable String id) {
|
||||
List<DbTable> tables = metadataSourceService.getDbTables(id);
|
||||
return AjaxResult.success(tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表结构
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库表结构", notes = "根据数据源的id来获取指定数据库表的表结构")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "tableName", value = "数据库表", required = true, dataType = "String", paramType = "path")
|
||||
})
|
||||
@GetMapping("/{id}/{tableName}/columns")
|
||||
public AjaxResult getDbTableColumns(@PathVariable String id, @PathVariable String tableName) {
|
||||
List<DbColumn> columns = metadataSourceService.getDbTableColumns(id, tableName);
|
||||
return AjaxResult.success(columns);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取SQL结果", notes = "根据数据源的id来获取SQL结果")
|
||||
@ApiImplicitParam(name = "dbDataQuery", value = "详细实体dbDataQuery", required = true, dataType = "DbDataQuery")
|
||||
@PostMapping("/queryList")
|
||||
public AjaxResult queryList(@RequestBody @Validated DbDataQuery dbDataQuery) {
|
||||
DbQuery dbQuery = metadataSourceService.getDbQuery(dbDataQuery.getDataSourceId());
|
||||
List<Map<String, Object>> list = dbQuery.queryList(dbDataQuery.getSql());
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页获取SQL结果", notes = "根据数据源的id来分页获取SQL结果")
|
||||
@ApiImplicitParam(name = "dbDataQuery", value = "详细实体dbDataQuery", required = true, dataType = "DbDataQuery")
|
||||
@PostMapping("/queryByPage")
|
||||
public AjaxResult queryByPage(@RequestBody @Validated DbDataQuery dbDataQuery) {
|
||||
DbQuery dbQuery = metadataSourceService.getDbQuery(dbDataQuery.getDataSourceId());
|
||||
PageResult<Map<String, Object>> page = dbQuery.queryByPage(dbDataQuery.getSql(), dbDataQuery.getOffset(), dbDataQuery.getPageSize());
|
||||
page.setPageNum(dbDataQuery.getPageNum()).setPageSize(dbDataQuery.getPageSize());
|
||||
return AjaxResult.success(page);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步", notes = "根据url的id来指定同步对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@PostMapping("/sync/{id}")
|
||||
public AjaxResult syncMetadata(@PathVariable String id) {
|
||||
metadataSourceService.syncMetadata(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "数据库设计文档", notes = "根据url的id来指定生成数据库设计文档对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@PostMapping("/word/{id}")
|
||||
public void wordMetadata(@PathVariable String id, HttpServletResponse response) throws Exception {
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setContentType("application/octet-stream;charset=utf-8");
|
||||
// 设置content-disposition响应头控制浏览器以下载的形式打开文件
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + new String("数据库设计文档.doc".getBytes()));
|
||||
Document doc = metadataSourceService.wordMetadata(id);
|
||||
OutputStream out = response.getOutputStream();
|
||||
doc.save(out, SaveOptions.createSaveOptions(SaveFormat.DOC));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新参数缓存
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/refresh")
|
||||
public AjaxResult refreshMetadata() {
|
||||
metadataSourceService.refreshMetadata();
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.czsj.web.controller.metadata;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.core.database.core.JsonPage;
|
||||
import com.czsj.metadata.dto.MetadataTableDto;
|
||||
import com.czsj.metadata.entity.MetadataTableEntity;
|
||||
import com.czsj.metadata.mapstruct.MetadataTableMapper;
|
||||
import com.czsj.metadata.query.MetadataTableQuery;
|
||||
import com.czsj.metadata.service.MetadataTableService;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import com.czsj.metadata.vo.MetadataTableVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-07-29
|
||||
*/
|
||||
@Api(tags = {"数据库表信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/tables")
|
||||
public class MetadataTableController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataTableService metadataTableService;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableMapper metadataTableMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getDataMetadataTableById(@PathVariable String id) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.getMetadataTableById(id);
|
||||
return AjaxResult.success(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
@PreAuthorize("@ss.hasPermi('metadata:tables:list')")
|
||||
public AjaxResult getDataMetadataTableList(MetadataTableQuery metadataTableQuery) {
|
||||
List<MetadataTableEntity> list = metadataTableService.getDataMetadataTableList(metadataTableQuery);
|
||||
List<MetadataTableVo> collect = list.stream().map(metadataTableMapper::toVO).collect(Collectors.toList());
|
||||
return AjaxResult.success(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataTableQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dataMetadataTableQuery", value = "查询实体dataMetadataTableQuery", required = true, dataTypeClass = MetadataTableQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getDataMetadataTablePage(MetadataTableQuery metadataTableQuery) {
|
||||
QueryWrapper<MetadataTableEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataTableQuery.getTableName()), "t.table_name", metadataTableQuery.getTableName());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataTableQuery.getSourceId()), "t.source_id", metadataTableQuery.getSourceId());
|
||||
IPage<MetadataTableEntity> page = metadataTableService.pageWithAuth(new Page<>(metadataTableQuery.getPageNum(), metadataTableQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataTableVo> collect = page.getRecords().stream().map(metadataTableMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataTableVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return AjaxResult.success(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param dataMetadataTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据dataMetadataTable对象添加信息")
|
||||
@ApiImplicitParam(name = "dataMetadataTable", value = "详细实体dataMetadataTable", required = true, dataType = "DataMetadataTableDto")
|
||||
@PostMapping()
|
||||
@PreAuthorize("@ss.hasPermi('metadata:tables:add')")
|
||||
public AjaxResult saveDataMetadataTable(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataTableDto dataMetadataTable) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.saveMetadataTable(dataMetadataTable);
|
||||
return AjaxResult.success(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param dataMetadataTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "dataMetadataTable", value = "详细实体dataMetadataTable", required = true, dataType = "DataMetadataTableDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermi('metadata:tables:edit')")
|
||||
public AjaxResult updateDataMetadataTable(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataTableDto dataMetadataTable) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.updateMetadataTable(dataMetadataTable);
|
||||
return AjaxResult.success(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermi('metadata:tables:remove')")
|
||||
public AjaxResult deleteDataMetadataTableById(@PathVariable String id) {
|
||||
metadataTableService.deleteMetadataTableById(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
@PreAuthorize("@ss.hasPermi('metadata:tables:remove')")
|
||||
public AjaxResult deleteDataMetadataTableBatch(@PathVariable List<String> ids) {
|
||||
metadataTableService.deleteMetadataTableBatch(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.czsj.web.controller.metadata;
|
||||
|
||||
|
||||
import com.czsj.common.core.controller.BaseController;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.metadata.dto.SqlConsoleDto;
|
||||
import com.czsj.metadata.service.SqlConsoleService;
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import com.czsj.metadata.vo.SqlConsoleVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sql")
|
||||
public class SqlConsoleController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private SqlConsoleService sqlConsoleService;
|
||||
|
||||
@PostMapping("/run")
|
||||
public AjaxResult sqlRun(@RequestBody @Validated SqlConsoleDto sqlConsoleDto) throws SQLException {
|
||||
List<SqlConsoleVo> list = sqlConsoleService.sqlRun(sqlConsoleDto);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/stop")
|
||||
public AjaxResult sqlStop(@RequestBody @Validated({ValidationGroups.Other.class}) SqlConsoleDto sqlConsoleDto){
|
||||
sqlConsoleService.sqlStop(sqlConsoleDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -119,4 +119,12 @@ public class CzsjConfig
|
||||
{
|
||||
return getProfile() + "/upload";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取临时上传路径
|
||||
*/
|
||||
public static String getTemporaryUploadPath()
|
||||
{
|
||||
return getProfile() + "/temporary";
|
||||
}
|
||||
}
|
||||
|
88
czsj-common/src/main/java/com/czsj/common/core/data/R.java
Normal file
88
czsj-common/src/main/java/com/czsj/common/core/data/R.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.czsj.common.core.data;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
public class R implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean success;
|
||||
private int code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
private long timestamp;
|
||||
|
||||
private R() {}
|
||||
|
||||
public static R error() {
|
||||
return error(null);
|
||||
}
|
||||
|
||||
public static R error(String message) {
|
||||
return error(null, message);
|
||||
}
|
||||
|
||||
public static R error(Integer code, String message) {
|
||||
if(code == null) {
|
||||
code = 500;
|
||||
}
|
||||
if(message == null) {
|
||||
message = "服务器内部错误";
|
||||
}
|
||||
return build(code, false, message);
|
||||
}
|
||||
|
||||
public static R ok() {
|
||||
return ok(null);
|
||||
}
|
||||
|
||||
public static R ok(String message) {
|
||||
return ok(null, message);
|
||||
}
|
||||
|
||||
public static R ok(Integer code, String message) {
|
||||
if(code == null) {
|
||||
code = 200;
|
||||
}
|
||||
if(message == null) {
|
||||
message = "操作成功";
|
||||
}
|
||||
return build(code, true, message);
|
||||
}
|
||||
|
||||
public static R build(int code, boolean success, String message) {
|
||||
return new R()
|
||||
.setCode(code)
|
||||
.setSuccess(success)
|
||||
.setMessage(message)
|
||||
.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public R setCode(int code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public R setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
return this;
|
||||
}
|
||||
public R setMessage(String msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public R setData(Object data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public R setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,5 @@
|
||||
package com.czsj.common.core.redis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
@ -13,6 +7,10 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* spring redis 工具类
|
||||
*
|
||||
@ -265,4 +263,55 @@ public class RedisCache
|
||||
{
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 普通缓存获取
|
||||
*
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public Object get(String key) {
|
||||
return key == null ? null : redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HashGet
|
||||
*
|
||||
* @param key 键 不能为 null
|
||||
* @param map 项 不能为 null
|
||||
* @return 值
|
||||
*/
|
||||
public void putAll(String key, Map map) {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HashGet
|
||||
*
|
||||
* @param key 键 不能为 null
|
||||
* @param item 项 不能为 null
|
||||
* @return 值
|
||||
*/
|
||||
public Object hget(String key, String item) {
|
||||
return redisTemplate.opsForHash().get(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param key 可以传一个值 或多个
|
||||
*/
|
||||
public void del(String... key) {
|
||||
if (key != null && key.length > 0) {
|
||||
if (key.length == 1) {
|
||||
redisTemplate.delete(key[0]);
|
||||
} else {
|
||||
redisTemplate.delete(Arrays.asList(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
100
czsj-common/src/main/java/com/czsj/common/utils/ListUtils.java
Normal file
100
czsj-common/src/main/java/com/czsj/common/utils/ListUtils.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.czsj.common.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ListUtils {
|
||||
private static void stupidMethod2(List<String> listA, List<String> listB) {
|
||||
System.out.println("数量级为 " + listA.size() + "集合的不同元素为");
|
||||
List<String> differList = new ArrayList<>();
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (String str : listB) {
|
||||
if (!listA.contains(str)) {
|
||||
differList.add(str);
|
||||
}
|
||||
}
|
||||
traverse(differList);
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("使用双层遍历方法 对比耗时: " + (endTime - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历集合,打印出每个元素
|
||||
*
|
||||
* @param list List集合
|
||||
*/
|
||||
private static void traverse(List<String> list) {
|
||||
for (String str : list) {
|
||||
System.out.print(str + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private static void stupidMethod(List<String> listA, List<String> listB) {
|
||||
System.out.println("数量级为 " + listA.size() + "集合的不同元素为");
|
||||
List<String> listABak = new ArrayList<>(listA); // 复制A集合作为备份
|
||||
long startTime = System.currentTimeMillis();
|
||||
listB.removeAll(listA); // B集合与A集合的不同元素
|
||||
traverse(listB);
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("直接调用java api 方法 对比耗时: " + (endTime - startTime));
|
||||
// listABak.removeAll(listB); // A集合与B集合的相同元素
|
||||
// listA.removeAll(listABak); // A集合与B集合的不同元素
|
||||
}
|
||||
|
||||
/**
|
||||
* 制造任意个元素的的List集合
|
||||
*
|
||||
* @param size List集合的size
|
||||
* @return List<String>
|
||||
*/
|
||||
private static List<String> dataList(int size) {
|
||||
List<String> dataList = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
dataList.add("" + i);
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 借助Map来获取listA、listB的不同元素集合
|
||||
*
|
||||
* @param listA 集合A
|
||||
* @param listB 集合B
|
||||
* @return list<String>
|
||||
*/
|
||||
public static List<String> getDifferListByMap(List<String> listA, List<String> listB) {
|
||||
System.out.println("数量级为 " + listA.size() + "集合的不同元素为");
|
||||
List<String> differList = new ArrayList<>();
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
long beginTime = System.currentTimeMillis();
|
||||
for (String strA : listA) {
|
||||
map.put(strA, 1);
|
||||
}
|
||||
for (String strB : listB) {
|
||||
Integer value = map.get(strB);
|
||||
if (value != null) {
|
||||
map.put(strB, ++value);
|
||||
continue;
|
||||
}
|
||||
map.put(strB, 1);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 1) { //获取不同元素集合
|
||||
differList.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
traverse(differList);
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("使用map方式遍历, 对比耗时: " + (endTime - beginTime));
|
||||
return differList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
157
czsj-common/src/main/java/com/czsj/common/utils/ReadYmlUtil.java
Normal file
157
czsj-common/src/main/java/com/czsj/common/utils/ReadYmlUtil.java
Normal file
@ -0,0 +1,157 @@
|
||||
package com.czsj.common.utils;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @Deacription 支持读取${}占位符中的内容
|
||||
* @Author levi
|
||||
* @Date 2022/06/16 9:43
|
||||
* @Version 1.0
|
||||
**/
|
||||
public class ReadYmlUtil {
|
||||
private static String DATAX_HOME;
|
||||
|
||||
|
||||
// ${} 占位符 正则表达式
|
||||
private static Pattern p1 = Pattern.compile("\\$\\{.*?\\}");
|
||||
|
||||
private ReadYmlUtil(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* key:文件索引名
|
||||
* value:配置文件内容
|
||||
*/
|
||||
private static Map<String , LinkedHashMap> ymls = new HashMap<>();
|
||||
/**
|
||||
* String:当前线程需要查询的文件名
|
||||
*/
|
||||
private static ThreadLocal<String> nowFileName = new InheritableThreadLocal<>();
|
||||
|
||||
private static ThreadLocal<String> profileLocal = new InheritableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 主动设置,初始化当前线程的环境
|
||||
* @param profile
|
||||
*/
|
||||
public static void setProfile(String profile) {
|
||||
profileLocal.set(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载配置文件
|
||||
* @param fileName
|
||||
*/
|
||||
private static void loadYml(String fileName){
|
||||
nowFileName.set(fileName);
|
||||
if (!ymls.containsKey(fileName)){
|
||||
ymls.put(fileName , new Yaml().loadAs(ReadYmlUtil.class.getResourceAsStream("/" + fileName),LinkedHashMap.class));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取yml文件中的某个value。
|
||||
* 支持解析 yml文件中的 ${} 占位符
|
||||
* @param key
|
||||
* @return Object
|
||||
*/
|
||||
private static Object getValue(String key){
|
||||
String[] keys = key.split("[.]");
|
||||
Map ymlInfo = (Map) ymls.get(nowFileName.get()).clone();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object value = ymlInfo.get(keys[i]);
|
||||
if (i < keys.length - 1){
|
||||
ymlInfo = (Map) value;
|
||||
}else if (value == null){
|
||||
throw new RuntimeException("key不存在");
|
||||
}else {
|
||||
String g;
|
||||
String keyChild;
|
||||
String v1 = value+"";
|
||||
for(Matcher m = p1.matcher(v1); m.find(); value = v1.replace(g, (String)getValue(keyChild))) {
|
||||
g = m.group();
|
||||
keyChild = g.replaceAll("\\$\\{", "").replaceAll("\\}", "");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取yml文件中的某个value
|
||||
* @param fileName yml名称
|
||||
* @param key
|
||||
* @return Object
|
||||
*/
|
||||
public static Object getValue(String fileName , String key){
|
||||
loadYml(fileName);
|
||||
return getValue(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 框架私有方法,非通用。
|
||||
* 获取 spring.profiles.active的值: test/prod 测试环境/生成环境
|
||||
* @return
|
||||
*/
|
||||
public static String getProfiles(){
|
||||
if (profileLocal.get() == null) {
|
||||
String value = (String) getValue("application.yml", "spring.profiles.active");
|
||||
setProfile(value);
|
||||
}
|
||||
return profileLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取yml文件中的某个value,返回String
|
||||
* @param fileName
|
||||
* @param key
|
||||
* @return String
|
||||
*/
|
||||
public static String getValueToString(String fileName , String key){
|
||||
return (String)getValue(fileName , key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 application.yml 的配置
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getValueToString(String key){
|
||||
return String.valueOf(getValue("application.yml" , key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 application-test/prod.yml 的配置
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getProfileValueToString(String key){
|
||||
String fileName = "application-" + getProfiles() + ".yml";
|
||||
return (String)getValue(fileName , key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// System.out.println(getProfiles());
|
||||
//System.out.println(ReadYmlUtil.getValueToString("server.port"));//get application.yml
|
||||
|
||||
// System.out.println(ReadYmlUtil.getValueToString("application.yml", "server.port"));//get other yml
|
||||
// System.out.println(ReadYmlUtil.getProfileValueToString("Ignite-addr"));// get application-${profile}.yml
|
||||
//
|
||||
// ReadYmlUtil.setProfile("test"); //主动修改环境配置
|
||||
// System.out.println(ReadYmlUtil.getProfileValueToString("Ignite-addr"));// get application-${profile}.yml
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.czsj.common.utils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* 异常工具
|
||||
*/
|
||||
public class ThrowableUtil {
|
||||
|
||||
/**
|
||||
* 获取堆栈信息
|
||||
* @param throwable
|
||||
* @return
|
||||
*/
|
||||
public static String getStackTrace(Throwable throwable){
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
try {
|
||||
throwable.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
} finally {
|
||||
pw.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,5 @@
|
||||
package com.czsj.common.utils.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.czsj.common.config.CzsjConfig;
|
||||
import com.czsj.common.constant.Constants;
|
||||
import com.czsj.common.exception.file.FileNameLengthLimitExceededException;
|
||||
@ -14,6 +8,13 @@ import com.czsj.common.exception.file.InvalidExtensionException;
|
||||
import com.czsj.common.utils.DateUtils;
|
||||
import com.czsj.common.utils.StringUtils;
|
||||
import com.czsj.common.utils.uuid.Seq;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 文件上传工具类
|
||||
@ -23,9 +24,9 @@ import com.czsj.common.utils.uuid.Seq;
|
||||
public class FileUploadUtils
|
||||
{
|
||||
/**
|
||||
* 默认大小 50M
|
||||
* 默认大小 500M
|
||||
*/
|
||||
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024L;
|
||||
public static final long DEFAULT_MAX_SIZE = 500 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* 默认的文件名最大长度 100
|
||||
@ -66,6 +67,8 @@ public class FileUploadUtils
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据文件路径上传
|
||||
*
|
||||
@ -86,6 +89,26 @@ public class FileUploadUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件路径上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @return 文件名称
|
||||
* @throws IOException
|
||||
*/
|
||||
public static final String flnkJarupload(String baseDir, MultipartFile file) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return flinkJarupload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IOException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
@ -117,6 +140,37 @@ public class FileUploadUtils
|
||||
return getPathFileName(baseDir, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* flink文件上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param allowedExtension 上传文件类型
|
||||
* @return 返回上传成功的文件名
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||
* @throws IOException 比如读写文件出错时
|
||||
* @throws InvalidExtensionException 文件校验异常
|
||||
*/
|
||||
public static final String flinkJarupload(String baseDir, MultipartFile file, String[] allowedExtension)
|
||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||
InvalidExtensionException
|
||||
{
|
||||
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
||||
{
|
||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||
}
|
||||
|
||||
assertAllowed(file, allowedExtension);
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
||||
file.transferTo(Paths.get(absPath));
|
||||
return getPathFileName(baseDir, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码文件名
|
||||
*/
|
||||
@ -144,6 +198,9 @@ public class FileUploadUtils
|
||||
{
|
||||
int dirLastIndex = CzsjConfig.getProfile().length() + 1;
|
||||
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
||||
if("".equals(currentDir)||null==currentDir){
|
||||
return Constants.RESOURCE_PREFIX + "/" + fileName;
|
||||
}
|
||||
return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
||||
}
|
||||
|
||||
@ -193,6 +250,7 @@ public class FileUploadUtils
|
||||
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.czsj.common.utils.uuid;
|
||||
|
||||
import com.czsj.common.exception.UtilException;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import com.czsj.common.exception.UtilException;
|
||||
|
||||
/**
|
||||
* 提供通用唯一识别码(universally unique identifier)(UUID)实现
|
||||
@ -66,7 +67,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型 4(伪随机生成的)UUID 的静态工厂。
|
||||
* 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
|
||||
*
|
||||
* @return 随机生成的 {@code UUID}
|
||||
*/
|
||||
@ -150,15 +151,15 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
components[i] = "0x" + components[i];
|
||||
}
|
||||
|
||||
long mostSigBits = Long.decode(components[0]).longValue();
|
||||
long mostSigBits = Long.decode(components[0]);
|
||||
mostSigBits <<= 16;
|
||||
mostSigBits |= Long.decode(components[1]).longValue();
|
||||
mostSigBits |= Long.decode(components[1]);
|
||||
mostSigBits <<= 16;
|
||||
mostSigBits |= Long.decode(components[2]).longValue();
|
||||
mostSigBits |= Long.decode(components[2]);
|
||||
|
||||
long leastSigBits = Long.decode(components[3]).longValue();
|
||||
long leastSigBits = Long.decode(components[3]);
|
||||
leastSigBits <<= 48;
|
||||
leastSigBits |= Long.decode(components[4]).longValue();
|
||||
leastSigBits |= Long.decode(components[4]);
|
||||
|
||||
return new UUID(mostSigBits, leastSigBits);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.czsj.flink.streaming.web.common.util;
|
||||
|
||||
import ch.ethz.ssh2.Connection;
|
||||
import com.czsj.common.config.czsjConfig;
|
||||
import com.czsj.common.config.CzsjConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.czsj.common.utils.file.FileUtils;
|
||||
|
||||
@ -68,7 +68,7 @@ public class UrlUtil {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
//获取自己数组
|
||||
byte[] getData = readInputStream(inputStream);
|
||||
String uploadPath = czsjConfig.getTemporaryUploadPath();
|
||||
String uploadPath = CzsjConfig.getTemporaryUploadPath();
|
||||
//文件保存位置
|
||||
File saveDir = new File(uploadPath);
|
||||
if (!saveDir.exists()) {
|
||||
|
@ -1,8 +1,16 @@
|
||||
package com.czsj.framework.config;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.czsj.common.utils.ServletUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.regex.Pattern.compile;
|
||||
|
||||
/**
|
||||
* 服务相关配置
|
||||
@ -29,4 +37,37 @@ public class ServerConfig
|
||||
String contextPath = request.getServletContext().getContextPath();
|
||||
return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();
|
||||
}
|
||||
|
||||
public Map<String,String> getIpAndPort(String url) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
Pattern p = compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\:(\\d+)?");
|
||||
Matcher m = p.matcher(url);
|
||||
String ip = "";
|
||||
String port = "";
|
||||
while (m.find()) {
|
||||
ip = m.group(1);
|
||||
port = m.group(2);
|
||||
}
|
||||
map.put("ip",ip);
|
||||
map.put("port",port);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String,String> getIpAndPort1(String url) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
URI uri = URI.create(url);
|
||||
String host = uri.getHost();
|
||||
int port = uri.getPort();
|
||||
map.put("ip",host);
|
||||
map.put("port", String.valueOf(port));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] arg){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
158
czsj-system/src/main/java/com/czsj/async/AsyncTask.java
Normal file
158
czsj-system/src/main/java/com/czsj/async/AsyncTask.java
Normal file
@ -0,0 +1,158 @@
|
||||
package com.czsj.async;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czsj.common.database.constants.DbQueryProperty;
|
||||
import com.czsj.common.database.service.DataSourceFactory;
|
||||
import com.czsj.common.database.service.DbQuery;
|
||||
import com.czsj.common.utils.ListUtils;
|
||||
import com.czsj.core.database.core.DbColumn;
|
||||
import com.czsj.core.database.core.DbTable;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.service.ApiLogService;
|
||||
import com.czsj.metadata.dto.DbSchema;
|
||||
import com.czsj.metadata.entity.MetadataColumnEntity;
|
||||
import com.czsj.metadata.entity.MetadataSourceEntity;
|
||||
import com.czsj.metadata.entity.MetadataTableEntity;
|
||||
import com.czsj.metadata.enums.SyncStatus;
|
||||
import com.czsj.metadata.mapper.MetadataColumnDao;
|
||||
import com.czsj.metadata.mapper.MetadataSourceDao;
|
||||
import com.czsj.metadata.mapper.MetadataTableDao;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 异步处理
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AsyncTask {
|
||||
|
||||
@Autowired
|
||||
private ApiLogService apiLogService;
|
||||
|
||||
@Autowired
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceDao metadataSourceDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableDao metadataTableDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnDao metadataColumnDao;
|
||||
|
||||
@Async("taskExecutor")
|
||||
public void doTask(ApiLogDto apiLogDto) {
|
||||
|
||||
apiLogService.saveApiLog(apiLogDto);
|
||||
}
|
||||
|
||||
@Async("taskExecutor")
|
||||
public void doTask(MetadataSourceEntity dataSource) {
|
||||
Boolean completed = false;
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
List<DbTable> tables = dbQuery.getTables(dbSchema.getDbName());
|
||||
List<String> SourcetablesList = new ArrayList<>();
|
||||
List<String> SourcecolumnsList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(tables)) {
|
||||
List<MetadataTableEntity> metadataTableEntityList = tables.stream().map(table -> {
|
||||
MetadataTableEntity metadataTable = new MetadataTableEntity();
|
||||
metadataTable.setSourceId(dataSource.getId());
|
||||
metadataTable.setTableName(table.getTableName());
|
||||
metadataTable.setTableComment(table.getTableComment());
|
||||
SourcetablesList.add(table.getTableName());
|
||||
return metadataTable;
|
||||
}).collect(Collectors.toList());
|
||||
List<String> tableList = metadataTableDao.selectTableBySourceId(dataSource.getId());
|
||||
|
||||
if(null != tableList && null != SourcetablesList && tableList.size() > SourcetablesList.size()){
|
||||
List<String> differListByMap = ListUtils.getDifferListByMap(tableList, SourcetablesList);
|
||||
System.out.println("集合A和集合B不同的元素:"+differListByMap);
|
||||
for(String tablename : differListByMap) {
|
||||
metadataTableDao.deleteBysourceId(dataSource.getId(), tablename);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(metadataTableEntityList)) {
|
||||
metadataTableEntityList.stream().forEach(table -> {
|
||||
Integer tablenumber = metadataTableDao.countByTableName(table.getTableName(),table.getSourceId());
|
||||
if(tablenumber == 0){
|
||||
metadataTableDao.insert(table);
|
||||
}else{
|
||||
String id = metadataTableDao.selectIdByTableName(table.getTableName(),table.getSourceId());
|
||||
table.setId(id);
|
||||
metadataTableDao.updateById(table);
|
||||
}
|
||||
List<DbColumn> columns = dbQuery.getTableColumns(dbSchema.getDbName(), table.getTableName());
|
||||
if (CollUtil.isNotEmpty(columns)) {
|
||||
List<MetadataColumnEntity> metadataColumnEntityList = columns.stream().map(column -> {
|
||||
MetadataColumnEntity metadataColumn = new MetadataColumnEntity();
|
||||
metadataColumn.setSourceId(dataSource.getId());
|
||||
metadataColumn.setTableId(table.getId());
|
||||
metadataColumn.setColumnName(column.getColName());
|
||||
metadataColumn.setColumnComment(column.getColComment());
|
||||
metadataColumn.setColumnKey(column.getColKey() ? "1" : "0");
|
||||
metadataColumn.setColumnNullable(column.getNullable() ? "1" : "0");
|
||||
metadataColumn.setColumnPosition(column.getColPosition());
|
||||
metadataColumn.setDataType(column.getDataType());
|
||||
metadataColumn.setDataLength(column.getDataLength());
|
||||
metadataColumn.setDataPrecision(column.getDataPrecision());
|
||||
metadataColumn.setDataScale(column.getDataScale());
|
||||
metadataColumn.setDataDefault(column.getDataDefault());
|
||||
SourcecolumnsList.add(column.getColName());
|
||||
return metadataColumn;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
List<String> columnsList = metadataColumnDao.selectColumnNameByTableId(table.getId(),table.getSourceId());
|
||||
if(null != tableList && null != SourcecolumnsList && columnsList.size() > SourcecolumnsList.size()){
|
||||
List<String> differListByMap = ListUtils.getDifferListByMap(columnsList, SourcecolumnsList);
|
||||
for(String columnName : differListByMap) {
|
||||
metadataColumnDao.deleteBysourceIdAndTidAndColName(table.getId(),table.getSourceId(),columnName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (CollUtil.isNotEmpty(metadataColumnEntityList)) {
|
||||
metadataColumnEntityList.stream().forEach(column ->
|
||||
{
|
||||
Integer Columnnumber = metadataColumnDao.countByColumnName(column.getColumnName(),column.getTableId(),column.getSourceId());
|
||||
if(Columnnumber == 0){
|
||||
metadataColumnDao.insert(column);
|
||||
}else{
|
||||
String id = metadataColumnDao.selectIdByColumnName(column.getColumnName(),column.getTableId(),column.getSourceId());
|
||||
column.setId(id);
|
||||
metadataColumnDao.updateById(column);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
dataSource.setIsSync(SyncStatus.IsSync.getKey());
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
completed = true;
|
||||
log.info("异步任务执行完成!耗时{}秒", (System.currentTimeMillis() - start / 1000));
|
||||
}finally {
|
||||
if(!completed){
|
||||
dataSource.setIsSync(SyncStatus.ErrSync.getKey());
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
log.info("异步任务执行失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.czsj.market.config;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.czsj.market.handler.MappingHandlerMapping;
|
||||
import com.czsj.market.handler.RequestHandler;
|
||||
import com.czsj.market.handler.RequestInterceptor;
|
||||
import com.czsj.market.service.impl.ApiMappingEngine;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
@Configuration
|
||||
public class ApiMappingConfig {
|
||||
|
||||
@Bean
|
||||
public MappingHandlerMapping mappingHandlerMapping(RequestMappingHandlerMapping requestMappingHandlerMapping,
|
||||
ApiMappingEngine apiMappingEngine,
|
||||
RedisTemplate redisTemplate,
|
||||
ObjectMapper objectMapper) {
|
||||
MappingHandlerMapping mappingHandlerMapping = new MappingHandlerMapping();
|
||||
mappingHandlerMapping.setHandler(requestHandler(apiMappingEngine, redisTemplate, objectMapper));
|
||||
mappingHandlerMapping.setRequestMappingHandlerMapping(requestMappingHandlerMapping);
|
||||
return mappingHandlerMapping;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RequestHandler requestHandler(ApiMappingEngine apiMappingEngine, RedisTemplate redisTemplate, ObjectMapper objectMapper) {
|
||||
RequestHandler handler = new RequestHandler();
|
||||
handler.setApiMappingEngine(apiMappingEngine);
|
||||
handler.setObjectMapper(objectMapper);
|
||||
handler.setRequestInterceptor(new RequestInterceptor(redisTemplate));
|
||||
return handler;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.czsj.market.config;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.handler.MappingHandlerMapping;
|
||||
import com.czsj.market.service.DataApiService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class StartedUpRunner implements ApplicationRunner {
|
||||
|
||||
private final ConfigurableApplicationContext context;
|
||||
private final Environment environment;
|
||||
|
||||
|
||||
@Autowired
|
||||
private MappingHandlerMapping mappingHandlerMapping;
|
||||
|
||||
@Autowired
|
||||
private DataApiService dataApiService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (context.isActive()) {
|
||||
String banner = "-----------------------------------------\n" +
|
||||
"服务启动成功,时间:" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()) + "\n" +
|
||||
"服务名称:" + environment.getProperty("czsj.name") + "\n" +
|
||||
"端口号:" + environment.getProperty("server.port") + "\n" +
|
||||
"-----------------------------------------";
|
||||
System.out.println(banner);
|
||||
|
||||
// 项目启动时,初始化已发布的接口
|
||||
List<DataApiEntity> releaseDataApiList = dataApiService.getDataApiEntityList(DataConstant.ApiState.RELEASE.getKey());
|
||||
if (CollUtil.isNotEmpty(releaseDataApiList)) {
|
||||
releaseDataApiList.stream().forEach(api -> mappingHandlerMapping.registerMapping(api));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
czsj-system/src/main/java/com/czsj/market/dto/ApiLogDto.java
Normal file
24
czsj-system/src/main/java/com/czsj/market/dto/ApiLogDto.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ApiLogDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String apiId;
|
||||
private String callerId;
|
||||
private String callerIp;
|
||||
private String callerUrl;
|
||||
private String callerParams;
|
||||
private Integer callerSize;
|
||||
private LocalDateTime callerDate;
|
||||
private Long time;
|
||||
private String msg;
|
||||
private String status;
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@ApiModel(value = "数据API脱敏信息表Model")
|
||||
@Data
|
||||
public class ApiMaskDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "数据API")
|
||||
@NotBlank(message = "数据API不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String apiId;
|
||||
@ApiModelProperty(value = "脱敏名称")
|
||||
@NotBlank(message = "脱敏名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String maskName;
|
||||
@ApiModelProperty(value = "脱敏字段规则配置")
|
||||
@Valid
|
||||
@NotEmpty(message = "脱敏字段规则配置不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
@Size(min = 1, message="脱敏字段规则配置长度不能少于{min}位")
|
||||
private List<FieldRule> rules;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@ApiModel(value = "数据API信息表Model")
|
||||
@Data
|
||||
public class DataApiDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "API名称")
|
||||
@NotBlank(message = "API名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String apiName;
|
||||
@ApiModelProperty(value = "API版本")
|
||||
@NotBlank(message = "API版本不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String apiVersion;
|
||||
@ApiModelProperty(value = "API路径")
|
||||
@NotBlank(message = "API路径不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String apiUrl;
|
||||
@ApiModelProperty(value = "请求方式")
|
||||
@NotBlank(message = "请求方式不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String reqMethod;
|
||||
@ApiModelProperty(value = "返回格式")
|
||||
@NotBlank(message = "返回格式不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String resType;
|
||||
@ApiModelProperty(value = "IP黑名单多个用英文,隔开")
|
||||
private String deny;
|
||||
@ApiModelProperty(value = "限流配置")
|
||||
@Valid
|
||||
private RateLimit rateLimit;
|
||||
@ApiModelProperty(value = "执行配置")
|
||||
@Valid
|
||||
private ExecuteConfig executeConfig;
|
||||
@ApiModelProperty(value = "请求参数")
|
||||
@Valid
|
||||
@NotEmpty(message = "请求参数不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
@Size(min = 1, message="请求参数长度不能少于{min}位")
|
||||
private List<ReqParam> reqParams;
|
||||
@ApiModelProperty(value = "返回参数")
|
||||
@Valid
|
||||
@NotEmpty(message = "返回字段不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
@Size(min = 1, message="返回字段长度不能少于{min}位")
|
||||
private List<ResParam> resParams;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
@ApiModelProperty(value = "接口编码")
|
||||
private String apiCode;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "执行配置信息Model")
|
||||
@Data
|
||||
public class ExecuteConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "数据源")
|
||||
@NotBlank(message = "数据源不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String sourceId;
|
||||
|
||||
@ApiModelProperty(value = "配置方式")
|
||||
@NotNull(message = "配置方式不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String configType;
|
||||
|
||||
@ApiModelProperty(value = "数据库表主键")
|
||||
private String tableId;
|
||||
|
||||
@ApiModelProperty(value = "数据库表")
|
||||
private String tableName;
|
||||
|
||||
@ApiModelProperty(value = "表字段列表")
|
||||
@Valid
|
||||
private List<FieldParam> fieldParams;
|
||||
|
||||
@ApiModelProperty(value = "解析SQL")
|
||||
private String sqlText;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "字段信息Model")
|
||||
@Data
|
||||
public class FieldParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 列名
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 数据长度
|
||||
*/
|
||||
private Integer dataLength;
|
||||
|
||||
/**
|
||||
* 数据精度
|
||||
*/
|
||||
private Integer dataPrecision;
|
||||
|
||||
/**
|
||||
* 数据小数位
|
||||
*/
|
||||
private Integer dataScale;
|
||||
|
||||
/**
|
||||
* 是否主键
|
||||
*/
|
||||
private String columnKey;
|
||||
|
||||
/**
|
||||
* 是否允许为空
|
||||
*/
|
||||
private String columnNullable;
|
||||
|
||||
/**
|
||||
* 列的序号
|
||||
*/
|
||||
private Integer columnPosition;
|
||||
|
||||
/**
|
||||
* 列默认值
|
||||
*/
|
||||
private String dataDefault;
|
||||
|
||||
/**
|
||||
* 列注释
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/**
|
||||
* 作为请求参数
|
||||
*/
|
||||
private String reqable;
|
||||
|
||||
/**
|
||||
* 作为返回参数
|
||||
*/
|
||||
private String resable;
|
||||
}
|
27
czsj-system/src/main/java/com/czsj/market/dto/FieldRule.java
Normal file
27
czsj-system/src/main/java/com/czsj/market/dto/FieldRule.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "字段信息Model")
|
||||
@Data
|
||||
public class FieldRule implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "字段名称")
|
||||
@NotBlank(message = "字段名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String fieldName;
|
||||
@ApiModelProperty(value = "脱敏类型")
|
||||
@NotNull(message = "脱敏类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String cipherType;
|
||||
@ApiModelProperty(value = "规则类型")
|
||||
@NotNull(message = "规则类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String cryptType;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "http接口Model")
|
||||
@Data
|
||||
public class HttpService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "请求地址")
|
||||
private String url;
|
||||
@ApiModelProperty(value = "请求头")
|
||||
private String header;
|
||||
@ApiModelProperty(value = "请求参数")
|
||||
private String param;
|
||||
@ApiModelProperty(value = "请求方式")
|
||||
private String httpMethod;
|
||||
}
|
24
czsj-system/src/main/java/com/czsj/market/dto/RateLimit.java
Normal file
24
czsj-system/src/main/java/com/czsj/market/dto/RateLimit.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "限流信息Model")
|
||||
@Data
|
||||
public class RateLimit implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "是否限流:0:否,1:是")
|
||||
@NotNull(message = "是否限流不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String enable;
|
||||
@ApiModelProperty(value = "请求次数默认5次")
|
||||
private Integer times = 5;
|
||||
@ApiModelProperty(value = "请求时间范围默认60秒")
|
||||
private Integer seconds = 60;
|
||||
}
|
54
czsj-system/src/main/java/com/czsj/market/dto/ReqParam.java
Normal file
54
czsj-system/src/main/java/com/czsj/market/dto/ReqParam.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "请求参数信息Model")
|
||||
@Data
|
||||
public class ReqParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "参数名称")
|
||||
@NotBlank(message = "参数名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String paramName;
|
||||
|
||||
@ApiModelProperty(value = "是否为空")
|
||||
@NotNull(message = "是否为空不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String nullable;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
@NotBlank(message = "描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String paramComment;
|
||||
|
||||
@ApiModelProperty(value = "操作符")
|
||||
@NotNull(message = "操作符不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String whereType;
|
||||
|
||||
@ApiModelProperty(value = "参数类型")
|
||||
@NotNull(message = "参数类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String paramType;
|
||||
|
||||
@ApiModelProperty(value = "开始时间")
|
||||
private String startValue;
|
||||
|
||||
@ApiModelProperty(value = "结束时间")
|
||||
private String endValue;
|
||||
|
||||
@ApiModelProperty(value = "示例值")
|
||||
@NotBlank(message = "示例值不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String exampleValue;
|
||||
|
||||
@ApiModelProperty(value = "默认值")
|
||||
@NotBlank(message = "默认值不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String defaultValue;
|
||||
|
||||
|
||||
|
||||
}
|
36
czsj-system/src/main/java/com/czsj/market/dto/ResParam.java
Normal file
36
czsj-system/src/main/java/com/czsj/market/dto/ResParam.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "返回参数信息Model")
|
||||
@Data
|
||||
public class ResParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "字段名称")
|
||||
@NotBlank(message = "字段名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String fieldName;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
@NotBlank(message = "描述不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String fieldComment;
|
||||
|
||||
@ApiModelProperty(value = "数据类型")
|
||||
@NotNull(message = "数据类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String dataType;
|
||||
|
||||
@ApiModelProperty(value = "示例值")
|
||||
@NotBlank(message = "示例值不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String exampleValue;
|
||||
|
||||
@ApiModelProperty(value = "字段别名")
|
||||
private String fieldAliasName;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "服务调用Model")
|
||||
@Data
|
||||
public class ServiceExecuteDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "服务编号")
|
||||
private String serviceNo;
|
||||
|
||||
@ApiModelProperty(value = "http服务请求头")
|
||||
private String header;
|
||||
@ApiModelProperty(value = "http服务请求参数")
|
||||
private String param;
|
||||
|
||||
@ApiModelProperty(value = "webservice服务请求报文")
|
||||
private String soap;
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@ApiModel(value = "服务集成表Model")
|
||||
@Data
|
||||
public class ServiceIntegrationDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "服务名称")
|
||||
@NotBlank(message = "服务名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String serviceName;
|
||||
@ApiModelProperty(value = "服务类型(1http接口,2webservice接口)")
|
||||
private String serviceType;
|
||||
@ApiModelProperty(value = "http接口")
|
||||
@Valid
|
||||
private HttpService httpService;
|
||||
@ApiModelProperty(value = "webservice接口")
|
||||
@Valid
|
||||
private WebService webService;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import com.czsj.metadata.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成调用日志表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@ApiModel(value = "服务集成调用日志表Model")
|
||||
@Data
|
||||
public class ServiceLogDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "服务id")
|
||||
private String serviceId;
|
||||
@ApiModelProperty(value = "调用者id")
|
||||
private String callerId;
|
||||
@ApiModelProperty(value = "调用者ip")
|
||||
private String callerIp;
|
||||
@ApiModelProperty(value = "调用时间")
|
||||
private LocalDateTime callerDate;
|
||||
@ApiModelProperty(value = "调用请求头")
|
||||
private String callerHeader;
|
||||
@ApiModelProperty(value = "调用请求参数")
|
||||
private String callerParam;
|
||||
@ApiModelProperty(value = "调用报文")
|
||||
private String callerSoap;
|
||||
@ApiModelProperty(value = "调用耗时")
|
||||
private Long time;
|
||||
@ApiModelProperty(value = "信息记录")
|
||||
private String msg;
|
||||
@ApiModelProperty(value = "状态:0:失败,1:成功")
|
||||
private String status;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SqlParseDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "数据源")
|
||||
@NotBlank(message = "数据源不能为空")
|
||||
private String sourceId;
|
||||
|
||||
@ApiModelProperty(value = "SQL文本")
|
||||
@NotBlank(message = "SQL不能为空")
|
||||
private String sqlText;
|
||||
}
|
22
czsj-system/src/main/java/com/czsj/market/dto/TryParam.java
Normal file
22
czsj-system/src/main/java/com/czsj/market/dto/TryParam.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "API调用参数信息Model")
|
||||
@Data
|
||||
public class TryParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "参数名称")
|
||||
@NotBlank(message = "参数名称不能为空")
|
||||
private String paramName;
|
||||
|
||||
@ApiModelProperty(value = "参数值")
|
||||
private Object paramValue;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.czsj.market.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "webservice接口Model")
|
||||
@Data
|
||||
public class WebService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "wsdl地址")
|
||||
private String wsdl;
|
||||
@ApiModelProperty(value = "命名空间")
|
||||
private String targetNamespace;
|
||||
@ApiModelProperty(value = "请求报文")
|
||||
private String soap;
|
||||
@ApiModelProperty(value = "调用方法")
|
||||
private String method;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.czsj.market.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("market_api_log")
|
||||
public class ApiLogEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
/**
|
||||
* 调用api
|
||||
*/
|
||||
private String apiId;
|
||||
/**
|
||||
* api名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String apiName;
|
||||
/**
|
||||
* 调用者id
|
||||
*/
|
||||
private String callerId;
|
||||
/**
|
||||
* 调用者ip
|
||||
*/
|
||||
private String callerIp;
|
||||
/**
|
||||
* 调用url
|
||||
*/
|
||||
private String callerUrl;
|
||||
/**
|
||||
* 调用参数
|
||||
*/
|
||||
private String callerParams;
|
||||
/**
|
||||
* 调用数据量
|
||||
*/
|
||||
private Integer callerSize;
|
||||
/**
|
||||
* 调用耗时
|
||||
*/
|
||||
private Long time;
|
||||
/**
|
||||
* 信息记录
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 状态:0:失败,1:成功
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 调用时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime callerDate;
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.czsj.market.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.czsj.core.database.base.DataScopeBaseEntity;
|
||||
import com.czsj.market.dto.FieldRule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
|
||||
@TableName(value = "market_api_mask", autoResultMap = true)
|
||||
public class ApiMaskEntity extends DataScopeBaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 数据API
|
||||
*/
|
||||
private String apiId;
|
||||
|
||||
/**
|
||||
* 脱敏名称
|
||||
*/
|
||||
private String maskName;
|
||||
|
||||
/**
|
||||
* 脱敏字段规则配置
|
||||
*/
|
||||
@TableField(value = "config_json", typeHandler = JacksonTypeHandler.class)
|
||||
private List<FieldRule> rules;
|
||||
|
||||
public String getApiId() {
|
||||
return apiId;
|
||||
}
|
||||
|
||||
public void setApiId(String apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
|
||||
public String getMaskName() {
|
||||
return maskName;
|
||||
}
|
||||
|
||||
public void setMaskName(String maskName) {
|
||||
this.maskName = maskName;
|
||||
}
|
||||
|
||||
public List<FieldRule> getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(List<FieldRule> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.czsj.market.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.czsj.core.database.base.DataScopeBaseEntity;
|
||||
import com.czsj.market.dto.ExecuteConfig;
|
||||
import com.czsj.market.dto.RateLimit;
|
||||
import com.czsj.market.dto.ReqParam;
|
||||
import com.czsj.market.dto.ResParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "market_api", autoResultMap = true)
|
||||
public class DataApiEntity extends DataScopeBaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* API名称
|
||||
*/
|
||||
private String apiName;
|
||||
|
||||
/**
|
||||
* API版本
|
||||
*/
|
||||
private String apiVersion;
|
||||
|
||||
/**
|
||||
* API路径
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String reqMethod;
|
||||
|
||||
/**
|
||||
* 返回格式
|
||||
*/
|
||||
private String resType;
|
||||
|
||||
/**
|
||||
* IP黑名单多个,隔开
|
||||
*/
|
||||
private String deny;
|
||||
|
||||
/**
|
||||
* 限流配置
|
||||
*/
|
||||
@TableField(value = "limit_json", typeHandler = JacksonTypeHandler.class)
|
||||
private RateLimit rateLimit;
|
||||
|
||||
/**
|
||||
* 执行配置
|
||||
*/
|
||||
@TableField(value = "config_json", typeHandler = JacksonTypeHandler.class)
|
||||
private ExecuteConfig executeConfig;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@TableField(value = "req_json", typeHandler = JacksonTypeHandler.class)
|
||||
private List<ReqParam> reqParams;
|
||||
|
||||
/**
|
||||
* 返回字段
|
||||
*/
|
||||
@TableField(value = "res_json", typeHandler = JacksonTypeHandler.class)
|
||||
private List<ResParam> resParams;
|
||||
|
||||
|
||||
/**
|
||||
* 返回字段
|
||||
*/
|
||||
private String apiCode;
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.czsj.market.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.czsj.core.database.base.DataScopeBaseEntity;
|
||||
import com.czsj.market.dto.HttpService;
|
||||
import com.czsj.market.dto.WebService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成表
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "market_service_integration", autoResultMap = true)
|
||||
public class ServiceIntegrationEntity extends DataScopeBaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 服务编号
|
||||
*/
|
||||
private String serviceNo;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 服务类型(1http接口,2webservice接口)
|
||||
*/
|
||||
private String serviceType;
|
||||
|
||||
/**
|
||||
* http接口
|
||||
*/
|
||||
@TableField(value = "httpservice_json", typeHandler = JacksonTypeHandler.class)
|
||||
private HttpService httpService;
|
||||
|
||||
/**
|
||||
* webservice接口
|
||||
*/
|
||||
@TableField(value = "webservice_json", typeHandler = JacksonTypeHandler.class)
|
||||
private WebService webService;
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.czsj.market.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成调用日志表
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("market_service_log")
|
||||
public class ServiceLogEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 服务id
|
||||
*/
|
||||
private String serviceId;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 调用者id
|
||||
*/
|
||||
private String callerId;
|
||||
|
||||
/**
|
||||
* 调用者ip
|
||||
*/
|
||||
private String callerIp;
|
||||
|
||||
/**
|
||||
* 调用时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime callerDate;
|
||||
|
||||
/**
|
||||
* 调用请求头
|
||||
*/
|
||||
private String callerHeader;
|
||||
|
||||
/**
|
||||
* 调用请求参数
|
||||
*/
|
||||
private String callerParam;
|
||||
|
||||
/**
|
||||
* 调用报文
|
||||
*/
|
||||
private String callerSoap;
|
||||
|
||||
/**
|
||||
* 调用耗时
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
/**
|
||||
* 信息记录
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 状态:0:失败,1:成功
|
||||
*/
|
||||
private String status;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum AlgorithmCrypto {
|
||||
|
||||
BASE64("1", "BASE64加密"),
|
||||
MD5("2", "MD5加密"),
|
||||
SHA_1("3", "SHA_1加密"),
|
||||
SHA_256("4", "SHA_256加密"),
|
||||
AES("5", "AES加密"),
|
||||
DES("6", "DES加密");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
AlgorithmCrypto(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static AlgorithmCrypto getAlgorithmCrypto(String algorithmCrypt) {
|
||||
for (AlgorithmCrypto type : AlgorithmCrypto.values()) {
|
||||
if (type.key.equals(algorithmCrypt)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return BASE64;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum CipherType {
|
||||
|
||||
REGEX("1", "正则替换"),
|
||||
ALGORITHM("2", "加密算法");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
CipherType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static CipherType getCipherType(String cipherType) {
|
||||
for (CipherType type : CipherType.values()) {
|
||||
if (type.key.equals(cipherType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return REGEX;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum ConfigType {
|
||||
|
||||
FORM("1", "表引导模式"),
|
||||
SCRIPT("2", "脚本模式");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
ConfigType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public enum ParamType {
|
||||
|
||||
String("1", "字符串"),
|
||||
Integer("2", "整型"),
|
||||
Float("3", "浮点型"),
|
||||
Date("4", "时间"),
|
||||
List("5", "集合");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
ParamType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static Object parse(ParamType paramType, Object obj) {
|
||||
if (ObjectUtil.isEmpty(obj)) {
|
||||
return null;
|
||||
}
|
||||
switch (paramType) {
|
||||
case String:
|
||||
try {
|
||||
return (java.lang.String)obj;
|
||||
} catch (Exception e) {
|
||||
throw new DataException("参数值[" + obj + "]不是" + String.getVal() + "数据类型]");
|
||||
}
|
||||
case Float:
|
||||
try {
|
||||
return new BigDecimal(obj.toString()).doubleValue();
|
||||
} catch (Exception e) {
|
||||
throw new DataException("参数值[" + obj + "]不是" + Float.getVal() + "数据类型]");
|
||||
}
|
||||
case Integer:
|
||||
try {
|
||||
return (java.lang.Integer)obj;
|
||||
} catch (Exception e) {
|
||||
throw new DataException("参数值[" + obj + "]不是" + Integer.getVal() + "数据类型]");
|
||||
}
|
||||
case List:
|
||||
try {
|
||||
return (java.util.List<?>)obj;
|
||||
} catch (Exception e) {
|
||||
throw new DataException("参数值[" + obj + "]不是" + List.getVal() + "数据类型]");
|
||||
}
|
||||
case Date:
|
||||
try {
|
||||
return DateUtil.parse(obj.toString(), "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return DateUtil.parse(obj.toString(), "yyyy-MM-dd");
|
||||
} catch (Exception ex) {
|
||||
throw new DataException("参数值[" + obj + "]不是" + Date.getVal() + "数据类型]");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ParamType getParamType(String paramType) {
|
||||
for (ParamType type : ParamType.values()) {
|
||||
if (type.key.equals(paramType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return String;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum RegexCrypto {
|
||||
|
||||
CHINESE_NAME("1", "中文姓名"),
|
||||
ID_CARD("2", "身份证号"),
|
||||
FIXED_PHONE("3", "固定电话"),
|
||||
MOBILE_PHONE("4", "手机号码"),
|
||||
ADDRESS("5", "地址"),
|
||||
EMAIL("6", "电子邮箱"),
|
||||
BANK_CARD("7", "银行卡号"),
|
||||
CNAPS_CODE("8", "公司开户银行联号");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
RegexCrypto(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static RegexCrypto getRegexCrypto(String regexCrypt) {
|
||||
for (RegexCrypto type : RegexCrypto.values()) {
|
||||
if (type.key.equals(regexCrypt)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return CHINESE_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum ReqMethod {
|
||||
|
||||
GET("GET"),
|
||||
POST("POST");
|
||||
|
||||
private String desc;
|
||||
|
||||
ReqMethod(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
17
czsj-system/src/main/java/com/czsj/market/enums/ResType.java
Normal file
17
czsj-system/src/main/java/com/czsj/market/enums/ResType.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum ResType {
|
||||
|
||||
JSON("JSON"),
|
||||
XML("XML");
|
||||
|
||||
private String desc;
|
||||
|
||||
ResType(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum ServiceType {
|
||||
|
||||
HTTP("1", "http接口"),
|
||||
WEBSERVICE("2", "webservice接口");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
ServiceType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.czsj.market.enums;
|
||||
|
||||
public enum WhereType {
|
||||
|
||||
EQUALS("1", "=", "等于"),
|
||||
NOT_EQUALS("2", "!=", "不等于"),
|
||||
LIKE("3", "LIKE", "全模糊查询"),
|
||||
LIKE_LEFT("4", "LIKE", "左模糊查询"),
|
||||
LIKE_RIGHT("5", "LIKE", "右模糊查询"),
|
||||
GREATER_THAN("6", ">", "大于"),
|
||||
GREATER_THAN_EQUALS("7", ">=", "大于等于"),
|
||||
LESS_THAN("8", "<", "小于"),
|
||||
LESS_THAN_EQUALS("9", "<=", "小于等于"),
|
||||
NULL("10", "IS NULL", "是否为空"),
|
||||
NOT_NULL("11", "IS NOT NULL", "是否不为空"),
|
||||
IN("12", "IN", "IN"),
|
||||
BETWEEN("13", "BETWEEN", "BETWEEN");
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String desc;
|
||||
|
||||
WhereType(String type, String key, String desc) {
|
||||
this.type = type;
|
||||
this.key = key;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static WhereType getWhereType(String whereType) {
|
||||
for (WhereType type : WhereType.values()) {
|
||||
if (type.type.equals(whereType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return EQUALS;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.czsj.market.factory;
|
||||
|
||||
import com.czsj.market.factory.crypto.Crypto;
|
||||
|
||||
public abstract class AbstractFactory {
|
||||
|
||||
public abstract Crypto getCrypto(String type);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.czsj.market.factory;
|
||||
|
||||
|
||||
import com.czsj.market.enums.AlgorithmCrypto;
|
||||
import com.czsj.market.factory.crypto.AlgorithmRegistry;
|
||||
import com.czsj.market.factory.crypto.Crypto;
|
||||
|
||||
public class AlgorithmFactory extends AbstractFactory {
|
||||
|
||||
private static final AlgorithmRegistry ALGORITHM_REGISTRY = new AlgorithmRegistry();
|
||||
|
||||
@Override
|
||||
public Crypto getCrypto(String type) {
|
||||
AlgorithmCrypto crypto = AlgorithmCrypto.getAlgorithmCrypto(type);
|
||||
return ALGORITHM_REGISTRY.getAlgorithm(crypto);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.czsj.market.factory;
|
||||
|
||||
|
||||
import com.czsj.market.enums.CipherType;
|
||||
|
||||
public class FactoryProducer {
|
||||
|
||||
public static AbstractFactory getFactory(String type){
|
||||
CipherType cipherType = CipherType.getCipherType(type);
|
||||
switch (cipherType) {
|
||||
case REGEX:
|
||||
return new RegexFactory();
|
||||
case ALGORITHM:
|
||||
return new AlgorithmFactory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.czsj.market.factory;
|
||||
|
||||
|
||||
import com.czsj.market.enums.RegexCrypto;
|
||||
import com.czsj.market.factory.crypto.Crypto;
|
||||
import com.czsj.market.factory.crypto.RegexRegistry;
|
||||
|
||||
|
||||
public class RegexFactory extends AbstractFactory {
|
||||
|
||||
private static final RegexRegistry REGEX_REGISTRY = new RegexRegistry();
|
||||
|
||||
@Override
|
||||
public Crypto getCrypto(String type) {
|
||||
RegexCrypto crypto = RegexCrypto.getRegexCrypto(type);
|
||||
return REGEX_REGISTRY.getRegex(crypto);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [地址] 只显示前六位,不显示详细地址;我们要对个人信息增强保护<例子:北京市海淀区****>
|
||||
*/
|
||||
public class ADDRESSCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.rightPad(StringUtils.left(content, 6), StringUtils.length(content), "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
public class AESCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StrUtil.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
//1.构造密钥生成器,指定为AES算法,不区分大小写
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("AES");
|
||||
//2.根据 RULES 规则初始化密钥生成器,根据传入的字节数组生成一个128位的随机源
|
||||
kGen.init(128, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
//3.产生原始对称密钥
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
//4.获得原始对称密钥的字节数组
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
//5.根据字节数组生成AES密钥
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
|
||||
//6.根据指定算法AES生成密码器
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
//8.根据密码器的初始化方式--加密:将数据加密
|
||||
byte[] AES_encrypt = cipher.doFinal(content.getBytes(CHARSET_UTF8));
|
||||
//9.将字符串返回
|
||||
return Base64.getEncoder().encodeToString(AES_encrypt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
//1.构造密钥生成器,指定为AES算法,不区分大小写
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("AES");
|
||||
//2.根据 RULES 规则初始化密钥生成器,根据传入的字节数组生成一个128位的随机源
|
||||
kGen.init(128, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
//3.产生原始对称密钥
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
//4.获得原始对称密钥的字节数组
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
//5.根据字节数组生成AES密钥
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
|
||||
//6.根据指定算法AES生成密码器
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
|
||||
//8.根据密码器的初始化方式--加密:将数据加密
|
||||
byte[] AES_decode = cipher.doFinal(Base64.getDecoder().decode(content));
|
||||
return new String(AES_decode, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import com.czsj.market.enums.AlgorithmCrypto;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AlgorithmRegistry {
|
||||
|
||||
private final Map<AlgorithmCrypto, Crypto> algorithm_enum_map = new EnumMap<>(AlgorithmCrypto.class);
|
||||
|
||||
public AlgorithmRegistry() {
|
||||
algorithm_enum_map.put(AlgorithmCrypto.BASE64, new BASE64Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.AES, new AESCrypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.DES, new DESCrypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.MD5, new MD5Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.SHA_1, new SHA1Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.SHA_256, new SHA256Crypto());
|
||||
}
|
||||
|
||||
public Crypto getAlgorithm(AlgorithmCrypto crypto) {
|
||||
return algorithm_enum_map.get(crypto);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号<例子:6222600**********1234>
|
||||
*/
|
||||
public class BANKCARDCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.left(content, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(content, 4), StringUtils.length(content), "*"), "******"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class BASE64Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] encode = Base64.getEncoder().encode(content.getBytes(CHARSET_UTF8));
|
||||
return new String(encode, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] decode = Base64.getDecoder().decode(content.getBytes(CHARSET_UTF8));
|
||||
return new String(decode, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [中文姓名] 只显示第一个汉字,其他隐藏为星号<例子:李**>
|
||||
*/
|
||||
public class CHINESENAMECrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.rightPad(StringUtils.left(content, 1), StringUtils.length(content), "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [公司开户银行联号] 公司开户银行联行号,显示前四位,其他用星号隐藏,每位1个星号<例子:1234********>
|
||||
*/
|
||||
public class CNAPSCODECrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.rightPad(StringUtils.left(content, 4), StringUtils.length(content), "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
public interface Crypto {
|
||||
|
||||
/**
|
||||
* 字符编码
|
||||
*/
|
||||
String CHARSET_UTF8 = "UTF-8";
|
||||
/**
|
||||
* 密码盐
|
||||
*/
|
||||
String SLAT = "DATAX:20200101";
|
||||
|
||||
String encrypt(String content);
|
||||
|
||||
String decrypt(String content);
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
public class DESCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("DES");
|
||||
kGen.init(56, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
|
||||
Cipher cipher = Cipher.getInstance("DES");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
byte[] DES_encrypt = cipher.doFinal(content.getBytes(CHARSET_UTF8));
|
||||
return Base64.getEncoder().encodeToString(DES_encrypt);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("DES");
|
||||
kGen.init(56, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
|
||||
Cipher cipher = Cipher.getInstance("DES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||
byte[] DES_decrypt = cipher.doFinal(Base64.getDecoder().decode(content));
|
||||
return new String(DES_decrypt, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [电子邮箱] 只显示前三后显示邮箱后缀,其他隐藏为星号<例子:312****@qq.com>
|
||||
*/
|
||||
public class EMAILCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return content.replaceAll("(\\w{3}).*@(\\w+)", "$1****@$2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [固定电话] 后四位,其他隐藏<例子:****1234>
|
||||
*/
|
||||
public class FIXEDPHONECrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.leftPad(StringUtils.right(content, 4), StringUtils.length(content), "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [身份证号] 显示最后四位,其他隐藏。共计18位或者15位。<例子:*************5762>
|
||||
*/
|
||||
public class IDCARDCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.leftPad(StringUtils.right(content, 4), StringUtils.length(content), "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
public class MD5Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(content.getBytes(CHARSET_UTF8));
|
||||
md5.update(SLAT.getBytes(CHARSET_UTF8));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(md5.digest());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [手机号码] 前三位,后四位,其他隐藏<例子:138******1234>
|
||||
*/
|
||||
public class MOBILEPHONECrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.left(content, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(content, 4), StringUtils.length(content), "*"), "***"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import com.czsj.market.enums.RegexCrypto;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RegexRegistry {
|
||||
|
||||
private final Map<RegexCrypto, Crypto> regex_enum_map = new EnumMap<>(RegexCrypto.class);
|
||||
|
||||
public RegexRegistry() {
|
||||
regex_enum_map.put(RegexCrypto.CHINESE_NAME, new CHINESENAMECrypto());
|
||||
regex_enum_map.put(RegexCrypto.ID_CARD, new IDCARDCrypto());
|
||||
regex_enum_map.put(RegexCrypto.FIXED_PHONE, new FIXEDPHONECrypto());
|
||||
regex_enum_map.put(RegexCrypto.MOBILE_PHONE, new MOBILEPHONECrypto());
|
||||
regex_enum_map.put(RegexCrypto.ADDRESS, new ADDRESSCrypto());
|
||||
regex_enum_map.put(RegexCrypto.EMAIL, new EMAILCrypto());
|
||||
regex_enum_map.put(RegexCrypto.BANK_CARD, new BANKCARDCrypto());
|
||||
regex_enum_map.put(RegexCrypto.CNAPS_CODE, new CNAPSCODECrypto());
|
||||
}
|
||||
|
||||
public Crypto getRegex(RegexCrypto crypto) {
|
||||
return regex_enum_map.get(crypto);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
public class SHA1Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("SHA-1");
|
||||
md5.update(content.getBytes(CHARSET_UTF8));
|
||||
md5.update(SLAT.getBytes(CHARSET_UTF8));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(md5.digest());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.czsj.market.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
public class SHA256Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("SHA-256");
|
||||
md5.update(content.getBytes(CHARSET_UTF8));
|
||||
md5.update(SLAT.getBytes(CHARSET_UTF8));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(md5.digest());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.czsj.market.handler;
|
||||
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class MappingHandlerMapping {
|
||||
|
||||
private static Map<String, DataApiEntity> mappings = new ConcurrentHashMap<>();
|
||||
private RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
private RequestHandler handler;
|
||||
private Method method;
|
||||
|
||||
{
|
||||
try {
|
||||
method = RequestHandler.class.getDeclaredMethod("invoke", HttpServletRequest.class, HttpServletResponse.class, Map.class, Map.class, Map.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private String ignore = "services";
|
||||
private String prefix = "v1.0.0";
|
||||
private String separator = "/";
|
||||
|
||||
public MappingHandlerMapping() {}
|
||||
|
||||
public void setRequestMappingHandlerMapping(RequestMappingHandlerMapping requestMappingHandlerMapping) {
|
||||
this.requestMappingHandlerMapping = requestMappingHandlerMapping;
|
||||
}
|
||||
|
||||
public void setHandler(RequestHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public static DataApiEntity getMappingApiInfo(HttpServletRequest request,String url) {
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
String requestMapping = (String) webRequest.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return getMappingApiInfo(buildMappingKey(request.getMethod(), url));
|
||||
}
|
||||
|
||||
public static DataApiEntity getMappingApiInfoA(String apicode) {
|
||||
return getMappingApiInfo(apicode);
|
||||
}
|
||||
|
||||
public static DataApiEntity getMappingApiInfo(String key) {
|
||||
return mappings.get(key);
|
||||
}
|
||||
|
||||
public static String buildMappingKey(String requestMethod, String requestMapping) {
|
||||
return requestMethod.toUpperCase() + ":" + requestMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册请求映射
|
||||
*
|
||||
* @param api
|
||||
*/
|
||||
public static void registerMapping(DataApiEntity api) {
|
||||
String mappingKey = api.getApiCode();
|
||||
//String mappingKey = getMappingKey(api);
|
||||
if (mappings.containsKey(mappingKey)) {
|
||||
// 取消注册
|
||||
mappings.remove(mappingKey);
|
||||
//requestMappingHandlerMapping.unregisterMapping(getRequestMapping(api));
|
||||
}
|
||||
log.info("注册接口:{}", api.getApiName());
|
||||
//RequestMappingInfo requestMapping = getRequestMapping(api);
|
||||
mappings.put(mappingKey, api);
|
||||
//requestMappingHandlerMapping.registerMapping(requestMapping, handler, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消注册请求映射
|
||||
*
|
||||
* @param api
|
||||
*/
|
||||
public static void unregisterMapping(DataApiEntity api) {
|
||||
log.info("取消注册接口:{}", api.getApiName());
|
||||
String mappingKey = api.getApiCode();
|
||||
//String mappingKey = getMappingKey(api);
|
||||
if (mappings.containsKey(mappingKey)) {
|
||||
// 取消注册
|
||||
mappings.remove(mappingKey);
|
||||
//requestMappingHandlerMapping.unregisterMapping(getRequestMapping(api));
|
||||
}
|
||||
}
|
||||
|
||||
private String getMappingKey(DataApiEntity api) {
|
||||
return buildMappingKey(api.getReqMethod().toUpperCase(), getRequestPath(api.getApiVersion(), api.getApiUrl()));
|
||||
}
|
||||
|
||||
private RequestMappingInfo getRequestMapping(DataApiEntity api) {
|
||||
return RequestMappingInfo.paths(getRequestPath(api.getApiVersion(), api.getApiUrl())).methods(RequestMethod.valueOf(api.getReqMethod().toUpperCase())).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用接口 /services/v1.0.0/user/1
|
||||
* @param version
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private String getRequestPath(String version, String path) {
|
||||
if (version != null) {
|
||||
prefix = version;
|
||||
}
|
||||
return separator + ignore + separator + prefix + (path.startsWith(separator) ? path : (separator + path));
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.czsj.market.handler;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.czsj.market.service.impl.ApiMappingEngine;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class RequestHandler {
|
||||
|
||||
private RequestInterceptor requestInterceptor;
|
||||
|
||||
private ApiMappingEngine apiMappingEngine;
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public void setRequestInterceptor(RequestInterceptor requestInterceptor) {
|
||||
this.requestInterceptor = requestInterceptor;
|
||||
}
|
||||
|
||||
public void setApiMappingEngine(ApiMappingEngine apiMappingEngine) {
|
||||
this.apiMappingEngine = apiMappingEngine;
|
||||
}
|
||||
|
||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public RequestInterceptor getRequestInterceptor() {
|
||||
return requestInterceptor;
|
||||
}
|
||||
|
||||
public ApiMappingEngine getApiMappingEngine() {
|
||||
return apiMappingEngine;
|
||||
}
|
||||
|
||||
public ObjectMapper getObjectMapper() {
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.czsj.market.handler;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.core.util.IPUtil;
|
||||
import com.czsj.market.dto.RateLimit;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.enums.ParamType;
|
||||
import com.czsj.market.utils.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
public class RequestInterceptor {
|
||||
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public RequestInterceptor(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求之前执行
|
||||
*
|
||||
* @return 当返回对象时,直接将此对象返回到页面,返回null时,继续执行后续操作
|
||||
* @throws Exception
|
||||
*/
|
||||
public void preHandle(HttpServletRequest request, HttpServletResponse response, DataApiEntity api, Map<String, Object> params) throws Exception {
|
||||
System.out.println("************ApiInterceptor preHandle executed**********");
|
||||
String uri = request.getRequestURI();
|
||||
log.info("getRequestURI的值:" + uri);
|
||||
String ipAddr = IPUtil.getIpAddr(request);
|
||||
log.info("ipAddr的值:" + ipAddr);
|
||||
|
||||
// 密钥校验
|
||||
String apiKey = request.getHeader("api_key");
|
||||
String secretKey = request.getHeader("secret_key");
|
||||
if (StrUtil.isBlank(apiKey) || StrUtil.isBlank(secretKey)) {
|
||||
throw new DataException("api_key或secret_key空");
|
||||
}
|
||||
MD5Util mt = MD5Util.getInstance();
|
||||
String apiId = mt.decode(apiKey);
|
||||
String userId = mt.decode(secretKey);
|
||||
|
||||
// 黑名单校验
|
||||
String deny = api.getDeny();
|
||||
if (StrUtil.isNotBlank(deny)) {
|
||||
List<String> denyList = Arrays.asList(deny.split(","));
|
||||
if (CollUtil.isNotEmpty(denyList)) {
|
||||
for (String ip : denyList) {
|
||||
if(ip.equals(ipAddr)){
|
||||
throw new DataException(ip + "已被加入IP黑名单");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 参数校验
|
||||
if (MapUtil.isNotEmpty(params)) {
|
||||
if(null == api.getReqParams()||api.getReqParams().size() == 0){
|
||||
throw new DataException("API请求参数与系统参数不匹配!");
|
||||
}
|
||||
api.getReqParams().stream().forEach(param -> {
|
||||
if (params.containsKey(param.getParamName())) {
|
||||
// 参数类型是否正确
|
||||
ParamType.parse(ParamType.getParamType(param.getParamType()), params.get(param.getParamName()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 限流校验
|
||||
RateLimit rateLimit = api.getRateLimit();
|
||||
if (DataConstant.TrueOrFalse.TRUE.getKey().equals(rateLimit.getEnable())) {
|
||||
Integer times = rateLimit.getTimes();
|
||||
Integer seconds = rateLimit.getSeconds();
|
||||
// 请求次数
|
||||
times = Optional.ofNullable(times).orElse(5);
|
||||
// 请求时间范围60秒
|
||||
seconds = Optional.ofNullable(seconds).orElse(60);
|
||||
// 根据 USER + API 限流
|
||||
String key = "user:" + userId + ":api:" + apiId;
|
||||
// 根据key获取已请求次数
|
||||
Integer maxTimes = (Integer) redisTemplate.opsForValue().get(key);
|
||||
if (maxTimes == null) {
|
||||
// set时一定要加过期时间
|
||||
redisTemplate.opsForValue().set(key, 1, seconds, TimeUnit.SECONDS);
|
||||
} else if (maxTimes < times) {
|
||||
redisTemplate.opsForValue().set(key, maxTimes + 1, seconds, TimeUnit.SECONDS);
|
||||
} else {
|
||||
throw new DataException("API调用过于频繁");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行完毕之后执行
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, DataApiEntity api, Map<String, Object> params, Object value) throws Exception {
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.czsj.core.database.base.BaseDao;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Mapper
|
||||
public interface ApiLogDao extends BaseDao<ApiLogEntity> {
|
||||
|
||||
@Override
|
||||
ApiLogEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
<E extends IPage<ApiLogEntity>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<ApiLogEntity> queryWrapper);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.czsj.market.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.czsj.core.database.base.BaseDao;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface ApiMaskDao extends BaseDao<ApiMaskEntity> {
|
||||
|
||||
@Override
|
||||
ApiMaskEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
<E extends IPage<ApiMaskEntity>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<ApiMaskEntity> queryWrapper);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.czsj.market.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.czsj.core.database.base.BaseDao;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataApiDao extends BaseDao<DataApiEntity> {
|
||||
|
||||
@Override
|
||||
DataApiEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
List<DataApiEntity> selectList(@Param(Constants.WRAPPER) Wrapper<DataApiEntity> queryWrapper);
|
||||
|
||||
@Override
|
||||
<E extends IPage<DataApiEntity>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<DataApiEntity> queryWrapper);
|
||||
|
||||
List<DataApiEntity> getDataApiEntityList(String status);
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.czsj.market.mapstruct;
|
||||
|
||||
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
import com.czsj.market.vo.ApiLogVo;
|
||||
import com.czsj.metadata.mapstruct.EntityMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ApiLogMapper extends EntityMapper<ApiLogDto, ApiLogEntity, ApiLogVo> {
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.czsj.market.mapstruct;
|
||||
|
||||
|
||||
import com.czsj.market.dto.ApiMaskDto;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.vo.ApiMaskVo;
|
||||
import com.czsj.metadata.mapstruct.EntityMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ApiMaskMapper extends EntityMapper<ApiMaskDto, ApiMaskEntity, ApiMaskVo> {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.mapstruct;
|
||||
|
||||
|
||||
import com.czsj.market.dto.DataApiDto;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.vo.DataApiVo;
|
||||
import com.czsj.metadata.mapstruct.EntityMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface DataApiMapper extends EntityMapper<DataApiDto, DataApiEntity, DataApiVo> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package com.czsj.market.mapstruct.impl;
|
||||
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
import com.czsj.market.mapstruct.ApiLogMapper;
|
||||
import com.czsj.market.vo.ApiLogVo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ApiLogMapperImpl implements ApiLogMapper {
|
||||
|
||||
@Override
|
||||
public ApiLogDto toDTO(ApiLogEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiLogDto apiLogDto = new ApiLogDto();
|
||||
|
||||
apiLogDto.setId( e.getId() );
|
||||
apiLogDto.setApiId( e.getApiId() );
|
||||
apiLogDto.setCallerId( e.getCallerId() );
|
||||
apiLogDto.setCallerIp( e.getCallerIp() );
|
||||
apiLogDto.setCallerUrl( e.getCallerUrl() );
|
||||
apiLogDto.setCallerParams( e.getCallerParams() );
|
||||
apiLogDto.setCallerSize( e.getCallerSize() );
|
||||
apiLogDto.setCallerDate( e.getCallerDate() );
|
||||
apiLogDto.setTime( e.getTime() );
|
||||
apiLogDto.setMsg( e.getMsg() );
|
||||
apiLogDto.setStatus( e.getStatus() );
|
||||
|
||||
return apiLogDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiLogDto> toDTO(List<ApiLogEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiLogDto> list = new ArrayList<ApiLogDto>( es.size() );
|
||||
for ( ApiLogEntity apiLogEntity : es ) {
|
||||
list.add( toDTO( apiLogEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiLogVo toVO(ApiLogEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiLogVo apiLogVo = new ApiLogVo();
|
||||
|
||||
apiLogVo.setId( e.getId() );
|
||||
apiLogVo.setApiId( e.getApiId() );
|
||||
apiLogVo.setApiName( e.getApiName() );
|
||||
apiLogVo.setCallerId( e.getCallerId() );
|
||||
apiLogVo.setCallerIp( e.getCallerIp() );
|
||||
apiLogVo.setCallerUrl( e.getCallerUrl() );
|
||||
apiLogVo.setCallerSize( e.getCallerSize() );
|
||||
apiLogVo.setCallerParams( e.getCallerParams() );
|
||||
apiLogVo.setCallerDate( e.getCallerDate() );
|
||||
apiLogVo.setTime( e.getTime() );
|
||||
apiLogVo.setMsg( e.getMsg() );
|
||||
apiLogVo.setStatus( e.getStatus() );
|
||||
|
||||
return apiLogVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiLogVo> toVO(List<ApiLogEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiLogVo> list = new ArrayList<ApiLogVo>( es.size() );
|
||||
for ( ApiLogEntity apiLogEntity : es ) {
|
||||
list.add( toVO( apiLogEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiLogEntity toEntity(ApiLogDto d) {
|
||||
if ( d == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiLogEntity apiLogEntity = new ApiLogEntity();
|
||||
|
||||
apiLogEntity.setId( d.getId() );
|
||||
apiLogEntity.setApiId( d.getApiId() );
|
||||
apiLogEntity.setCallerId( d.getCallerId() );
|
||||
apiLogEntity.setCallerIp( d.getCallerIp() );
|
||||
apiLogEntity.setCallerUrl( d.getCallerUrl() );
|
||||
apiLogEntity.setCallerParams( d.getCallerParams() );
|
||||
apiLogEntity.setCallerSize( d.getCallerSize() );
|
||||
apiLogEntity.setTime( d.getTime() );
|
||||
apiLogEntity.setMsg( d.getMsg() );
|
||||
apiLogEntity.setStatus( d.getStatus() );
|
||||
apiLogEntity.setCallerDate( d.getCallerDate() );
|
||||
|
||||
return apiLogEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiLogEntity> toEntity(List<ApiLogDto> ds) {
|
||||
if ( ds == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiLogEntity> list = new ArrayList<ApiLogEntity>( ds.size() );
|
||||
for ( ApiLogDto apiLogDto : ds ) {
|
||||
list.add( toEntity( apiLogDto ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.czsj.market.mapstruct.impl;
|
||||
|
||||
|
||||
import com.czsj.market.dto.ApiMaskDto;
|
||||
import com.czsj.market.dto.FieldRule;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.mapstruct.ApiMaskMapper;
|
||||
import com.czsj.market.vo.ApiMaskVo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class ApiMaskMapperImpl implements ApiMaskMapper {
|
||||
|
||||
@Override
|
||||
public ApiMaskDto toDTO(ApiMaskEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiMaskDto apiMaskDto = new ApiMaskDto();
|
||||
|
||||
apiMaskDto.setId( e.getId() );
|
||||
apiMaskDto.setApiId( e.getApiId() );
|
||||
apiMaskDto.setMaskName( e.getMaskName() );
|
||||
List<FieldRule> list = e.getRules();
|
||||
if ( list != null ) {
|
||||
apiMaskDto.setRules( new ArrayList<FieldRule>( list ) );
|
||||
}
|
||||
apiMaskDto.setStatus( e.getStatus() );
|
||||
apiMaskDto.setRemark( e.getRemark() );
|
||||
|
||||
return apiMaskDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiMaskDto> toDTO(List<ApiMaskEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiMaskDto> list = new ArrayList<ApiMaskDto>( es.size() );
|
||||
for ( ApiMaskEntity apiMaskEntity : es ) {
|
||||
list.add( toDTO( apiMaskEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiMaskVo toVO(ApiMaskEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiMaskVo apiMaskVo = new ApiMaskVo();
|
||||
|
||||
apiMaskVo.setId( e.getId() );
|
||||
apiMaskVo.setStatus( e.getStatus() );
|
||||
apiMaskVo.setCreateTime( e.getCreateTime() );
|
||||
apiMaskVo.setRemark( e.getRemark() );
|
||||
apiMaskVo.setApiId( e.getApiId() );
|
||||
apiMaskVo.setMaskName( e.getMaskName() );
|
||||
List<FieldRule> list = e.getRules();
|
||||
if ( list != null ) {
|
||||
apiMaskVo.setRules( new ArrayList<FieldRule>( list ) );
|
||||
}
|
||||
|
||||
return apiMaskVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiMaskVo> toVO(List<ApiMaskEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiMaskVo> list = new ArrayList<ApiMaskVo>( es.size() );
|
||||
for ( ApiMaskEntity apiMaskEntity : es ) {
|
||||
list.add( toVO( apiMaskEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiMaskEntity toEntity(ApiMaskDto d) {
|
||||
if ( d == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApiMaskEntity apiMaskEntity = new ApiMaskEntity();
|
||||
|
||||
apiMaskEntity.setId( d.getId() );
|
||||
apiMaskEntity.setStatus( d.getStatus() );
|
||||
apiMaskEntity.setRemark( d.getRemark() );
|
||||
apiMaskEntity.setApiId( d.getApiId() );
|
||||
apiMaskEntity.setMaskName( d.getMaskName() );
|
||||
List<FieldRule> list = d.getRules();
|
||||
if ( list != null ) {
|
||||
apiMaskEntity.setRules( new ArrayList<FieldRule>( list ) );
|
||||
}
|
||||
|
||||
return apiMaskEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiMaskEntity> toEntity(List<ApiMaskDto> ds) {
|
||||
if ( ds == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ApiMaskEntity> list = new ArrayList<ApiMaskEntity>( ds.size() );
|
||||
for ( ApiMaskDto apiMaskDto : ds ) {
|
||||
list.add( toEntity( apiMaskDto ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
package com.czsj.market.mapstruct.impl;
|
||||
|
||||
import com.czsj.market.dto.DataApiDto;
|
||||
import com.czsj.market.dto.ReqParam;
|
||||
import com.czsj.market.dto.ResParam;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.mapstruct.DataApiMapper;
|
||||
import com.czsj.market.vo.DataApiVo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DataApiMapperImpl implements DataApiMapper {
|
||||
|
||||
@Override
|
||||
public DataApiDto toDTO(DataApiEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DataApiDto dataApiDto = new DataApiDto();
|
||||
|
||||
dataApiDto.setId( e.getId() );
|
||||
dataApiDto.setApiName( e.getApiName() );
|
||||
dataApiDto.setApiVersion( e.getApiVersion() );
|
||||
dataApiDto.setApiUrl( e.getApiUrl() );
|
||||
dataApiDto.setReqMethod( e.getReqMethod() );
|
||||
dataApiDto.setResType( e.getResType() );
|
||||
dataApiDto.setDeny( e.getDeny() );
|
||||
dataApiDto.setRateLimit( e.getRateLimit() );
|
||||
dataApiDto.setExecuteConfig( e.getExecuteConfig() );
|
||||
dataApiDto.setApiCode(e.getApiCode());
|
||||
|
||||
List<ReqParam> list = e.getReqParams();
|
||||
if ( list != null ) {
|
||||
dataApiDto.setReqParams( new ArrayList<ReqParam>( list ) );
|
||||
}
|
||||
List<ResParam> list1 = e.getResParams();
|
||||
if ( list1 != null ) {
|
||||
dataApiDto.setResParams( new ArrayList<ResParam>( list1 ) );
|
||||
}
|
||||
dataApiDto.setStatus( e.getStatus() );
|
||||
dataApiDto.setRemark( e.getRemark() );
|
||||
|
||||
return dataApiDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataApiDto> toDTO(List<DataApiEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DataApiDto> list = new ArrayList<DataApiDto>( es.size() );
|
||||
for ( DataApiEntity dataApiEntity : es ) {
|
||||
list.add( toDTO( dataApiEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataApiVo toVO(DataApiEntity e) {
|
||||
if ( e == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DataApiVo dataApiVo = new DataApiVo();
|
||||
|
||||
dataApiVo.setId( e.getId() );
|
||||
dataApiVo.setStatus( e.getStatus() );
|
||||
dataApiVo.setCreateTime( e.getCreateTime() );
|
||||
dataApiVo.setRemark( e.getRemark() );
|
||||
dataApiVo.setApiName( e.getApiName() );
|
||||
dataApiVo.setApiVersion( e.getApiVersion() );
|
||||
dataApiVo.setApiUrl( e.getApiUrl() );
|
||||
dataApiVo.setReqMethod( e.getReqMethod() );
|
||||
dataApiVo.setDeny( e.getDeny() );
|
||||
dataApiVo.setResType( e.getResType() );
|
||||
dataApiVo.setRateLimit( e.getRateLimit() );
|
||||
dataApiVo.setExecuteConfig( e.getExecuteConfig() );
|
||||
dataApiVo.setApiCode(e.getApiCode());
|
||||
List<ReqParam> list = e.getReqParams();
|
||||
if ( list != null ) {
|
||||
dataApiVo.setReqParams( new ArrayList<ReqParam>( list ) );
|
||||
}
|
||||
List<ResParam> list1 = e.getResParams();
|
||||
if ( list1 != null ) {
|
||||
dataApiVo.setResParams( new ArrayList<ResParam>( list1 ) );
|
||||
}
|
||||
|
||||
return dataApiVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataApiVo> toVO(List<DataApiEntity> es) {
|
||||
if ( es == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DataApiVo> list = new ArrayList<DataApiVo>( es.size() );
|
||||
for ( DataApiEntity dataApiEntity : es ) {
|
||||
list.add( toVO( dataApiEntity ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataApiEntity toEntity(DataApiDto d) {
|
||||
if ( d == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DataApiEntity dataApiEntity = new DataApiEntity();
|
||||
dataApiEntity.setApiCode(d.getApiCode());
|
||||
dataApiEntity.setId( d.getId() );
|
||||
dataApiEntity.setStatus( d.getStatus() );
|
||||
dataApiEntity.setRemark( d.getRemark() );
|
||||
dataApiEntity.setApiName( d.getApiName() );
|
||||
dataApiEntity.setApiVersion( d.getApiVersion() );
|
||||
dataApiEntity.setApiUrl( d.getApiUrl() );
|
||||
dataApiEntity.setReqMethod( d.getReqMethod() );
|
||||
dataApiEntity.setResType( d.getResType() );
|
||||
dataApiEntity.setDeny( d.getDeny() );
|
||||
dataApiEntity.setRateLimit( d.getRateLimit() );
|
||||
dataApiEntity.setExecuteConfig( d.getExecuteConfig() );
|
||||
List<ReqParam> list = d.getReqParams();
|
||||
if ( list != null ) {
|
||||
dataApiEntity.setReqParams( new ArrayList<ReqParam>( list ) );
|
||||
}
|
||||
List<ResParam> list1 = d.getResParams();
|
||||
if ( list1 != null ) {
|
||||
dataApiEntity.setResParams( new ArrayList<ResParam>( list1 ) );
|
||||
}
|
||||
|
||||
return dataApiEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataApiEntity> toEntity(List<DataApiDto> ds) {
|
||||
if ( ds == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DataApiEntity> list = new ArrayList<DataApiEntity>( ds.size() );
|
||||
for ( DataApiDto dataApiDto : ds ) {
|
||||
list.add( toEntity( dataApiDto ) );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.query;
|
||||
|
||||
import com.czsj.core.database.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* api调用日志信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-21
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiLogQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String apiName;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.query;
|
||||
|
||||
import com.czsj.core.database.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiMaskQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String maskName;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.query;
|
||||
|
||||
import com.czsj.core.database.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DataApiQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String apiName;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.czsj.market.query;
|
||||
|
||||
import com.czsj.core.database.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ServiceIntegrationQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String serviceName;
|
||||
private String serviceType;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.query;
|
||||
|
||||
import com.czsj.core.database.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务集成调用日志表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-08-20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ServiceLogQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String serviceName;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.czsj.market.service;
|
||||
|
||||
|
||||
|
||||
import com.czsj.core.database.base.BaseService;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApiLogService extends BaseService<ApiLogEntity> {
|
||||
|
||||
ApiLogEntity saveApiLog(ApiLogDto apiLog);
|
||||
|
||||
ApiLogEntity updateApiLog(ApiLogDto apiLog);
|
||||
|
||||
ApiLogEntity getApiLogById(String id);
|
||||
|
||||
void deleteApiLogById(String id);
|
||||
|
||||
void deleteApiLogBatch(List<String> ids);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.czsj.market.service;
|
||||
|
||||
|
||||
import com.czsj.core.database.base.BaseService;
|
||||
import com.czsj.market.dto.ApiMaskDto;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
public interface ApiMaskService extends BaseService<ApiMaskEntity> {
|
||||
|
||||
void saveApiMask(ApiMaskDto dataApiMask);
|
||||
|
||||
void updateApiMask(ApiMaskDto dataApiMask);
|
||||
|
||||
ApiMaskEntity getApiMaskById(String id);
|
||||
|
||||
ApiMaskEntity getApiMaskByApiId(String apiId);
|
||||
|
||||
void deleteApiMaskById(String id);
|
||||
|
||||
void deleteApiMaskBatch(List<String> ids);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.czsj.market.service;
|
||||
|
||||
|
||||
import com.aspose.words.Document;
|
||||
import com.czsj.core.database.base.BaseService;
|
||||
import com.czsj.market.dto.DataApiDto;
|
||||
import com.czsj.market.dto.SqlParseDto;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.vo.SqlParseVo;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
public interface DataApiService extends BaseService<DataApiEntity> {
|
||||
|
||||
void saveDataApi(DataApiDto dataApi);
|
||||
|
||||
void updateDataApi(DataApiDto dataApi);
|
||||
|
||||
DataApiEntity getDataApiById(String id);
|
||||
|
||||
void deleteDataApiById(String id);
|
||||
|
||||
void deleteDataApiBatch(List<String> ids);
|
||||
|
||||
SqlParseVo sqlParse(SqlParseDto sqlParseDto) throws SQLException, JSQLParserException;
|
||||
|
||||
void copyDataApi(String id);
|
||||
|
||||
void releaseDataApi(String id);
|
||||
|
||||
void cancelDataApi(String id);
|
||||
|
||||
Document wordDataApi(String id) throws Exception;
|
||||
|
||||
Map<String, Object> getDataApiDetailById(String id);
|
||||
|
||||
List<DataApiEntity> getDataApiEntityList(String status);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.czsj.market.service.impl;
|
||||
|
||||
|
||||
import com.czsj.core.database.base.BaseServiceImpl;
|
||||
import com.czsj.market.dto.ApiLogDto;
|
||||
import com.czsj.market.entity.ApiLogEntity;
|
||||
import com.czsj.market.mapper.ApiLogDao;
|
||||
import com.czsj.market.mapstruct.ApiLogMapper;
|
||||
import com.czsj.market.service.ApiLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class ApiLogServiceImpl extends BaseServiceImpl<ApiLogDao, ApiLogEntity> implements ApiLogService {
|
||||
|
||||
@Autowired
|
||||
private ApiLogDao apiLogDao;
|
||||
|
||||
@Autowired
|
||||
private ApiLogMapper apiLogMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiLogEntity saveApiLog(ApiLogDto apiLogDto) {
|
||||
ApiLogEntity apiLog = apiLogMapper.toEntity(apiLogDto);
|
||||
apiLogDao.insert(apiLog);
|
||||
return apiLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiLogEntity updateApiLog(ApiLogDto apiLogDto) {
|
||||
ApiLogEntity apiLog = apiLogMapper.toEntity(apiLogDto);
|
||||
apiLogDao.updateById(apiLog);
|
||||
return apiLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiLogEntity getApiLogById(String id) {
|
||||
ApiLogEntity apiLogEntity = super.getById(id);
|
||||
return apiLogEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApiLogById(String id) {
|
||||
apiLogDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApiLogBatch(List<String> ids) {
|
||||
apiLogDao.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.czsj.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
import com.czsj.common.database.constants.DbQueryProperty;
|
||||
import com.czsj.common.database.service.DataSourceFactory;
|
||||
import com.czsj.common.database.service.DbQuery;
|
||||
import com.czsj.common.utils.ThrowableUtil;
|
||||
import com.czsj.core.database.core.PageResult;
|
||||
import com.czsj.core.util.PageUtil;
|
||||
import com.czsj.market.dto.FieldRule;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.factory.AbstractFactory;
|
||||
import com.czsj.market.factory.FactoryProducer;
|
||||
import com.czsj.market.factory.crypto.Crypto;
|
||||
import com.czsj.market.service.ApiMaskService;
|
||||
import com.czsj.market.utils.SqlBuilderUtil;
|
||||
import com.czsj.metadata.dto.DbSchema;
|
||||
import com.czsj.metadata.entity.MetadataSourceEntity;
|
||||
import com.czsj.metadata.service.MetadataSourceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ApiMappingEngine {
|
||||
|
||||
@Autowired
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceService metadataSourceService;
|
||||
|
||||
@Autowired
|
||||
private ApiMaskService apiMaskService;
|
||||
|
||||
public PageResult<Map<String, Object>> execute(DataApiEntity dataApi, Map<String, Object> params) {
|
||||
MetadataSourceEntity dataSource = Optional.ofNullable(metadataSourceService.getMetadataSourceById(dataApi.getExecuteConfig().getSourceId())).orElseThrow(() -> new DataException("API调用查询数据源出错"));
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = Optional.ofNullable(dataSourceFactory.createDbQuery(dbQueryProperty)).orElseThrow(() -> new DataException("创建数据查询接口出错"));
|
||||
// 参数
|
||||
Integer pageNum = Integer.parseInt(String.valueOf( params.getOrDefault("pageNum", 1)));
|
||||
Integer pageSize = Integer.parseInt(String.valueOf(params.getOrDefault("pageSize", 20)));
|
||||
PageUtil pageUtil = new PageUtil(pageNum, pageSize);
|
||||
Integer offset = pageUtil.getOffset();
|
||||
SqlBuilderUtil.SqlFilterResult sqlFilterResult;
|
||||
try {
|
||||
sqlFilterResult = SqlBuilderUtil.getInstance().applyFilters(dataApi.getExecuteConfig().getSqlText(), params);
|
||||
} catch (Exception e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("API调用动态构造SQL语句出错");
|
||||
}
|
||||
Map<String, Object> acceptedFilters = sqlFilterResult.getAcceptedFilters();
|
||||
// 数据脱敏
|
||||
List<FieldRule> rules = null;
|
||||
|
||||
ApiMaskEntity apiMaskEntity = apiMaskService.getApiMaskByApiId(dataApi.getId());
|
||||
if (apiMaskEntity != null) {
|
||||
rules = apiMaskEntity.getRules();
|
||||
}
|
||||
PageResult<Map<String, Object>> pageResult;
|
||||
try {
|
||||
pageResult = dbQuery.queryByPage(sqlFilterResult.getSql(), acceptedFilters, offset, pageSize);
|
||||
} catch (Exception e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("API调用查询结果集出错");
|
||||
} finally {
|
||||
dbQuery.close();
|
||||
}
|
||||
try {
|
||||
if (CollUtil.isNotEmpty(rules)){
|
||||
System.out.println(rules.toString());
|
||||
// 并行流处理脱敏
|
||||
List<FieldRule> finalRules = new ArrayList<>();
|
||||
for(int i=0;i<rules.size();i++){
|
||||
Map<String,Object> ruless = (Map<String,Object>)rules.get(i);
|
||||
FieldRule fieldRule = BeanUtil.fillBeanWithMap(ruless, new FieldRule(), false);
|
||||
finalRules.add(fieldRule);
|
||||
}
|
||||
|
||||
pageResult.getData().parallelStream().forEach(m -> {
|
||||
finalRules.stream().forEach(r -> {
|
||||
if (m.containsKey(r.getFieldName())) {
|
||||
Object obj = m.get(r.getFieldName());
|
||||
if (null != obj){
|
||||
AbstractFactory factory = FactoryProducer.getFactory(r.getCipherType());
|
||||
Crypto crypto = factory.getCrypto(r.getCryptType());
|
||||
String encrypt = crypto.encrypt(String.valueOf(obj));
|
||||
m.put(r.getFieldName(), encrypt);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("API调用数据脱敏出错");
|
||||
}
|
||||
pageResult.setPageNum(pageNum).setPageSize(pageSize);
|
||||
return pageResult;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.czsj.market.service.impl;
|
||||
|
||||
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.czsj.core.database.base.BaseServiceImpl;
|
||||
import com.czsj.market.dto.ApiMaskDto;
|
||||
import com.czsj.market.entity.ApiMaskEntity;
|
||||
import com.czsj.market.mapper.ApiMaskDao;
|
||||
import com.czsj.market.mapstruct.ApiMaskMapper;
|
||||
import com.czsj.market.service.ApiMaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-04-14
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class ApiMaskServiceImpl extends BaseServiceImpl<ApiMaskDao, ApiMaskEntity> implements ApiMaskService {
|
||||
|
||||
@Autowired
|
||||
private ApiMaskDao apiMaskDao;
|
||||
|
||||
@Autowired
|
||||
private ApiMaskMapper apiMaskMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveApiMask(ApiMaskDto apiMaskDto) {
|
||||
ApiMaskEntity apiMask = apiMaskMapper.toEntity(apiMaskDto);
|
||||
// 校验api唯一
|
||||
int n = apiMaskDao.selectCount(Wrappers.<ApiMaskEntity>lambdaQuery().eq(ApiMaskEntity::getApiId, apiMask.getApiId()));
|
||||
if(n > 0){
|
||||
throw new DataException("该api已进行过脱敏配置");
|
||||
}
|
||||
apiMaskDao.insert(apiMask);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateApiMask(ApiMaskDto apiMaskDto) {
|
||||
ApiMaskEntity apiMask = apiMaskMapper.toEntity(apiMaskDto);
|
||||
apiMaskDao.updateById(apiMask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiMaskEntity getApiMaskById(String id) {
|
||||
ApiMaskEntity apiMaskEntity = super.getById(id);
|
||||
return apiMaskEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiMaskEntity getApiMaskByApiId(String apiId) {
|
||||
ApiMaskEntity apiMaskEntity = apiMaskDao.selectOne(new QueryWrapper<ApiMaskEntity>().eq("api_id", apiId));
|
||||
return apiMaskEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApiMaskById(String id) {
|
||||
apiMaskDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApiMaskBatch(List<String> ids) {
|
||||
apiMaskDao.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
@ -0,0 +1,527 @@
|
||||
package com.czsj.market.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.MailMerge;
|
||||
import com.aspose.words.net.System.Data.DataException;
|
||||
import com.aspose.words.net.System.Data.DataRow;
|
||||
import com.aspose.words.net.System.Data.DataTable;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.czsj.common.core.domain.AjaxResult;
|
||||
import com.czsj.common.core.redis.RedisCache;
|
||||
import com.czsj.common.database.utils.SecurityUtil;
|
||||
import com.czsj.common.database.utils.WordUtil;
|
||||
import com.czsj.common.utils.ThrowableUtil;
|
||||
import com.czsj.core.database.base.BaseServiceImpl;
|
||||
import com.czsj.core.database.core.DataConstant;
|
||||
import com.czsj.market.dto.DataApiDto;
|
||||
import com.czsj.market.dto.ReqParam;
|
||||
import com.czsj.market.dto.ResParam;
|
||||
import com.czsj.market.dto.SqlParseDto;
|
||||
import com.czsj.market.entity.DataApiEntity;
|
||||
import com.czsj.market.enums.ConfigType;
|
||||
import com.czsj.market.handler.MappingHandlerMapping;
|
||||
import com.czsj.market.mapper.DataApiDao;
|
||||
import com.czsj.market.mapstruct.DataApiMapper;
|
||||
import com.czsj.market.service.DataApiService;
|
||||
import com.czsj.market.utils.MD5Util;
|
||||
import com.czsj.market.utils.SqlBuilderUtil;
|
||||
import com.czsj.market.vo.ApiHeader;
|
||||
import com.czsj.market.vo.SqlParseVo;
|
||||
import com.czsj.metadata.service.SqlConsoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import net.sf.jsqlparser.expression.ExpressionVisitorAdapter;
|
||||
import net.sf.jsqlparser.expression.Function;
|
||||
import net.sf.jsqlparser.expression.JdbcNamedParameter;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.Statement;
|
||||
import net.sf.jsqlparser.statement.StatementVisitorAdapter;
|
||||
import net.sf.jsqlparser.statement.select.*;
|
||||
import net.sf.jsqlparser.util.SelectUtils;
|
||||
import net.sf.jsqlparser.util.TablesNamesFinder;
|
||||
import net.sf.jsqlparser.util.deparser.ExpressionDeParser;
|
||||
import net.sf.jsqlparser.util.deparser.SelectDeParser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.czsj.common.utils.uuid.UUID;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yuwei
|
||||
* @since 2020-03-31
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntity> implements DataApiService {
|
||||
|
||||
@Autowired
|
||||
private DataApiDao dataApiDao;
|
||||
|
||||
@Autowired
|
||||
private DataApiMapper dataApiMapper;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisService;
|
||||
|
||||
@Autowired
|
||||
private SqlConsoleService sqlConsoleService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDataApi(DataApiDto dataApiDto) {
|
||||
String uuid = UUID.randomUUID(true).toString();
|
||||
dataApiDto.setApiCode(uuid);
|
||||
DataApiEntity dataApi = shareCode(dataApiDto);
|
||||
dataApiDao.insert(dataApi);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDataApi(DataApiDto dataApiDto) {
|
||||
DataApiEntity dataApi = shareCode(dataApiDto);
|
||||
dataApiDao.updateById(dataApi);
|
||||
}
|
||||
|
||||
private DataApiEntity shareCode(DataApiDto dataApiDto) {
|
||||
DataApiEntity dataApi = dataApiMapper.toEntity(dataApiDto);
|
||||
String configType = dataApi.getExecuteConfig().getConfigType();
|
||||
if (ConfigType.FORM.getKey().equals(configType)) {
|
||||
try {
|
||||
dataApi.getExecuteConfig().setSqlText(sqlJdbcNamedParameterBuild(dataApi));
|
||||
} catch (JSQLParserException e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("SQL语法有问题,解析出错");
|
||||
}
|
||||
} else if (ConfigType.SCRIPT.getKey().equals(configType)) {}
|
||||
return dataApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataApiEntity getDataApiById(String id) {
|
||||
DataApiEntity dataApiEntity = super.getById(id);
|
||||
return dataApiEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDataApiById(String id) {
|
||||
dataApiDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDataApiBatch(List<String> ids) {
|
||||
dataApiDao.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlParseVo sqlParse(SqlParseDto sqlParseDto) throws SQLException, JSQLParserException {
|
||||
String sourceId = sqlParseDto.getSourceId();
|
||||
String sql = sqlParseDto.getSqlText();
|
||||
sql = sql.replace(SqlBuilderUtil.getInstance().MARK_KEY_START, "");
|
||||
sql = sql.replace(SqlBuilderUtil.getInstance().MARK_KEY_END, "");
|
||||
Statement stmt;
|
||||
try {
|
||||
stmt = CCJSqlParserUtil.parse(sql);
|
||||
} catch (JSQLParserException e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("SQL语法有问题,解析出错");
|
||||
}
|
||||
// 维护元数据缓存数据
|
||||
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
|
||||
List<String> tables = tablesNamesFinder.getTableList(stmt);
|
||||
// 查询字段
|
||||
final List<Map<String,String>> cols = new ArrayList<>();
|
||||
// 查询参数
|
||||
final List<String> vars = new ArrayList<>();
|
||||
if (tables.size() == 1) {
|
||||
// 单表解析
|
||||
singleSqlParse(stmt, cols, vars, tables.get(0));
|
||||
} else if (tables.size() > 1) {
|
||||
// 多表解析
|
||||
multipleSqlParse(stmt, cols, vars);
|
||||
}
|
||||
SqlParseVo sqlParseVo = new SqlParseVo();
|
||||
List<ReqParam> reqParams = vars.stream().map(s -> {
|
||||
ReqParam reqParam = new ReqParam();
|
||||
reqParam.setParamName(s);
|
||||
reqParam.setNullable(DataConstant.TrueOrFalse.FALSE.getKey());
|
||||
return reqParam;
|
||||
}).collect(Collectors.toList());
|
||||
sqlParseVo.setReqParams(reqParams);
|
||||
|
||||
|
||||
final List<ResParam> resParams = new ArrayList<>();
|
||||
parseFields(sqlParseDto.getSqlText()).forEach((column, alias) -> {
|
||||
ResParam resParam = new ResParam();
|
||||
if(alias.isEmpty()){
|
||||
resParam.setFieldName(column);
|
||||
}else {
|
||||
resParam.setFieldName(alias);
|
||||
}
|
||||
resParams.add(resParam);
|
||||
});
|
||||
|
||||
// List<MetadataSourceEntity> sourceEntityList = (List<MetadataSourceEntity>) redisService.get(RedisConstant.METADATA_SOURCE_KEY);
|
||||
// MetadataSourceEntity sourceEntity = sourceEntityList.stream().filter(s -> sourceId.equals(s.getId())).findFirst().orElse(null);
|
||||
// if (sourceEntity != null) {
|
||||
// List<MetadataTableEntity> tableEntityList = (List<MetadataTableEntity>) redisService.hget(RedisConstant.METADATA_TABLE_KEY, sourceEntity.getId());
|
||||
// Map<String, List<Map<String, String>>> map = cols.stream().collect(Collectors.groupingBy(e -> e.get("tableName").toString()));
|
||||
// for (Map.Entry<String, List<Map<String, String>>> entry : map.entrySet()) {
|
||||
// String entryKey = entry.getKey().toLowerCase();
|
||||
// List<Map<String, String>> entryValue = entry.getValue();
|
||||
// MetadataTableEntity tableEntity = tableEntityList.stream().filter(t -> entryKey.equals(t.getTableName().toLowerCase())).findFirst().orElse(null);
|
||||
// if (tableEntity != null) {
|
||||
// List<MetadataColumnEntity> columnEntityList = (List<MetadataColumnEntity>) redisService.hget(RedisConstant.METADATA_COLUMN_KEY, tableEntity.getId());
|
||||
// entryValue.stream().forEach(m -> {
|
||||
// String columnName = m.get("columnName").toLowerCase();
|
||||
// String columnAliasName = m.get("columnAliasName");
|
||||
// Stream<MetadataColumnEntity> stream = columnEntityList.stream().filter(c -> columnName.equals(c.getColumnName().toLowerCase()));
|
||||
// MetadataColumnEntity columnEntity = stream.findFirst().orElse(null);
|
||||
// ResParam resParam = new ResParam();
|
||||
// if (columnEntity != null) {
|
||||
// resParam.setFieldName(columnEntity.getColumnName());
|
||||
// resParam.setFieldComment(StrUtil.isNotBlank(columnEntity.getColumnComment()) ? columnEntity.getColumnComment() : "");
|
||||
// resParam.setDataType(StrUtil.isNotBlank(columnEntity.getDataType()) ? columnEntity.getDataType() : "");
|
||||
// resParam.setFieldAliasName(StrUtil.isNotBlank(columnAliasName) ? columnAliasName : "");
|
||||
// }else{
|
||||
// resParam.setFieldName(columnName);
|
||||
// }
|
||||
// resParams.add(resParam);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
sqlParseVo.setResParams(resParams);
|
||||
return sqlParseVo;
|
||||
}
|
||||
|
||||
private void singleSqlParse(Statement stmt, List<Map<String, String>> cols, List<String> vars, String tableName) {
|
||||
stmt.accept(new StatementVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(Select select) {
|
||||
select.getSelectBody().accept(new SelectVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(PlainSelect plainSelect) {
|
||||
plainSelect.getSelectItems().forEach(selectItem -> {
|
||||
selectItem.accept(new SelectItemVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(SelectExpressionItem item) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String columnName;
|
||||
Object expression = item.getExpression();
|
||||
|
||||
if (expression instanceof Column) {
|
||||
Column column = (Column) expression;
|
||||
columnName = column.getColumnName();
|
||||
if (item.getAlias() != null) {
|
||||
map.put("columnAliasName", item.getAlias().getName());
|
||||
}
|
||||
} else if (expression instanceof Function) {
|
||||
columnName = expression.toString();
|
||||
} else {
|
||||
// 增加对select 'aaa' from table; 的支持
|
||||
columnName = String.valueOf(expression);
|
||||
columnName = columnName.replace("'", "").replace("\"", "").replace("`", "");
|
||||
}
|
||||
columnName = columnName.replace("'", "").replace("\"", "").replace("`", "");
|
||||
map.put("tableName", tableName);
|
||||
map.put("columnName", columnName);
|
||||
cols.add(map);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (plainSelect.getWhere() != null) {
|
||||
plainSelect.getWhere().accept(new ExpressionVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(JdbcNamedParameter jdbcNamedParameter) {
|
||||
vars.add(jdbcNamedParameter.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void multipleSqlParse(Statement stmt, List<Map<String, String>> cols, List<String> vars) {
|
||||
stmt.accept(new StatementVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(Select select) {
|
||||
select.getSelectBody().accept(new SelectVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(PlainSelect plainSelect) {
|
||||
// 存储表名
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Table table = (Table) plainSelect.getFromItem();
|
||||
if (table.getAlias() != null) {
|
||||
map.put(table.getName(), table.getAlias().getName());
|
||||
}
|
||||
for (Join join : plainSelect.getJoins()) {
|
||||
Table table1 = (Table) join.getRightItem();
|
||||
if (table1.getAlias() != null) {
|
||||
map.put(table1.getName(), table1.getAlias().getName());
|
||||
}
|
||||
}
|
||||
plainSelect.getSelectItems().forEach(selectItem -> {
|
||||
selectItem.accept(new SelectItemVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(SelectExpressionItem item) {
|
||||
Map<String, String> m = new HashMap<>();
|
||||
String tableName = "", columnName;
|
||||
Object expression = item.getExpression();
|
||||
if (expression instanceof Column) {
|
||||
Column column = (Column) expression;
|
||||
Table table = column.getTable();
|
||||
if (table != null) {
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
if (table.getName().equals(entry.getValue())) {
|
||||
tableName = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
columnName = column.getColumnName();
|
||||
if (item.getAlias() != null) {
|
||||
m.put("columnAliasName", item.getAlias().getName());
|
||||
}
|
||||
} else if (expression instanceof Function) {
|
||||
columnName = expression.toString();
|
||||
} else {
|
||||
// 增加对select 'aaa' from table; 的支持
|
||||
columnName = String.valueOf(expression);
|
||||
columnName = columnName.replace("'", "").replace("\"", "").replace("`", "");
|
||||
}
|
||||
columnName = columnName.replace("'", "").replace("\"", "").replace("`", "");
|
||||
m.put("tableName", tableName);
|
||||
m.put("columnName", columnName);
|
||||
cols.add(m);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (plainSelect.getWhere() != null) {
|
||||
plainSelect.getWhere().accept(new ExpressionVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(JdbcNamedParameter jdbcNamedParameter) {
|
||||
vars.add(jdbcNamedParameter.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String sqlJdbcNamedParameterBuild(DataApiEntity dataApi) throws JSQLParserException {
|
||||
Table table = new Table(dataApi.getExecuteConfig().getTableName());
|
||||
String[] resParams = dataApi.getResParams().stream().map(s -> s.getFieldName()).toArray(String[]::new);
|
||||
Select select = SelectUtils.buildSelectFromTableAndExpressions(table, resParams);
|
||||
return SqlBuilderUtil.getInstance().buildHql(select.toString(), dataApi.getReqParams());
|
||||
}
|
||||
|
||||
private String sqlJdbcNamedParameterParse(String sqlText) throws JSQLParserException {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
ExpressionDeParser expressionDeParser = new ExpressionDeParser() {
|
||||
@Override
|
||||
public void visit(JdbcNamedParameter jdbcNamedParameter) {
|
||||
this.getBuffer().append("?");
|
||||
}
|
||||
};
|
||||
SelectDeParser deparser = new SelectDeParser(expressionDeParser, buffer);
|
||||
expressionDeParser.setSelectVisitor(deparser);
|
||||
expressionDeParser.setBuffer(buffer);
|
||||
Statement stmt = CCJSqlParserUtil.parse(sqlText);
|
||||
stmt.accept(new StatementVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(Select select) {
|
||||
select.getSelectBody().accept(deparser);
|
||||
}
|
||||
});
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyDataApi(String id) {
|
||||
DataApiEntity dataApiEntity = Optional.ofNullable(super.getById(id)).orElseThrow(() -> new DataException("获取失败"));
|
||||
DataApiEntity copy = new DataApiEntity();
|
||||
copy.setApiName(dataApiEntity.getApiName() + "_副本" + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
copy.setApiVersion(dataApiEntity.getApiVersion());
|
||||
copy.setApiUrl(dataApiEntity.getApiUrl() + "/copy" + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
copy.setReqMethod(dataApiEntity.getReqMethod());
|
||||
copy.setResType(dataApiEntity.getResType());
|
||||
copy.setDeny(dataApiEntity.getDeny());
|
||||
copy.setRateLimit(dataApiEntity.getRateLimit());
|
||||
copy.setExecuteConfig(dataApiEntity.getExecuteConfig());
|
||||
copy.setReqParams(dataApiEntity.getReqParams());
|
||||
copy.setResParams(dataApiEntity.getResParams());
|
||||
copy.setStatus(DataConstant.ApiState.WAIT.getKey());
|
||||
dataApiDao.insert(copy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseDataApi(String id) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("id", id);
|
||||
map.put("type", "1");
|
||||
LambdaUpdateWrapper<DataApiEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(DataApiEntity::getStatus, DataConstant.ApiState.RELEASE.getKey());
|
||||
updateWrapper.eq(DataApiEntity::getId, id);
|
||||
dataApiDao.update(null, updateWrapper);
|
||||
DataApiEntity dataApiEntity = dataApiDao.selectById(id);
|
||||
MappingHandlerMapping.registerMapping(dataApiEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelDataApi(String id) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("id", id);
|
||||
map.put("type", "2");
|
||||
LambdaUpdateWrapper<DataApiEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(DataApiEntity::getStatus, DataConstant.ApiState.CANCEL.getKey());
|
||||
updateWrapper.eq(DataApiEntity::getId, id);
|
||||
dataApiDao.update(null, updateWrapper);
|
||||
DataApiEntity dataApiEntity = dataApiDao.selectById(id);
|
||||
MappingHandlerMapping.unregisterMapping(dataApiEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document wordDataApi(String id) throws Exception {
|
||||
//注册编码提供程序
|
||||
DataApiEntity dataApiEntity = super.getById(id);
|
||||
// 合并模版
|
||||
ClassPathResource classPathResource = new ClassPathResource("templates/api_1.0.0.docx");
|
||||
InputStream inputStream = classPathResource.getInputStream();
|
||||
Document doc = WordUtil.getInstance().getDocument(inputStream);
|
||||
// 提供字段
|
||||
MD5Util mt = MD5Util.getInstance();
|
||||
String apiKey = mt.encode(id);
|
||||
String secretkey = mt.encode(SecurityUtil.getUserId());
|
||||
String[] fieldNames = new String[] {"apiName", "apiVersion", "reqMethod", "resType", "apiUrl", "remark", "apiKey", "secretkey","apiCode"};
|
||||
Object[] fieldValues = new Object[] {dataApiEntity.getApiName(), dataApiEntity.getApiVersion(), dataApiEntity.getReqMethod(), dataApiEntity.getResType(), dataApiEntity.getApiUrl(), dataApiEntity.getRemark(), apiKey, secretkey,dataApiEntity.getApiCode()};
|
||||
MailMerge mailMerge = doc.getMailMerge();
|
||||
mailMerge.execute(fieldNames, fieldValues);
|
||||
// 请求参数 TableStart:ReqParamList TableEnd:ReqParamList
|
||||
DataTable reqParamTable = new DataTable("ReqParamList");
|
||||
reqParamTable.getColumns().add("paramName");
|
||||
reqParamTable.getColumns().add("paramComment");
|
||||
reqParamTable.getColumns().add("paramType");
|
||||
reqParamTable.getColumns().add("nullable");
|
||||
reqParamTable.getColumns().add("exampleValue");
|
||||
List<ReqParam> reqParamList = objectMapper.convertValue(dataApiEntity.getReqParams(), new TypeReference<List<ReqParam>>() {});
|
||||
ReqParam reqparam = new ReqParam();
|
||||
reqparam.setParamName("apiCode");
|
||||
reqparam.setParamComment("接口key");
|
||||
reqparam.setParamType("String");
|
||||
reqparam.setNullable("N");
|
||||
reqparam.setExampleValue(dataApiEntity.getApiCode());
|
||||
reqParamList.add(reqparam);
|
||||
for (int i = 0; i < reqParamList.size(); i++) {
|
||||
DataRow row = reqParamTable.newRow();
|
||||
ReqParam param = reqParamList.get(i);
|
||||
row.set(0, param.getParamName());
|
||||
row.set(1, param.getParamComment());
|
||||
row.set(2, param.getParamType());
|
||||
row.set(3, "1".equals(param.getNullable()) ? "Y" : "N");
|
||||
row.set(4, param.getExampleValue());
|
||||
reqParamTable.getRows().add(row);
|
||||
}
|
||||
mailMerge.executeWithRegions(reqParamTable);
|
||||
// 返回字段 TableStart:ResParamList TableEnd:ResParamList
|
||||
DataTable resParamTable = new DataTable("ResParamList");
|
||||
resParamTable.getColumns().add("fieldName");
|
||||
resParamTable.getColumns().add("dataType");
|
||||
resParamTable.getColumns().add("fieldComment");
|
||||
resParamTable.getColumns().add("exampleValue");
|
||||
List<ResParam> resParamList = objectMapper.convertValue(dataApiEntity.getResParams(), new TypeReference<List<ResParam>>() {});
|
||||
for (int i = 0; i < resParamList.size(); i++) {
|
||||
DataRow row = resParamTable.newRow();
|
||||
ResParam param = resParamList.get(i);
|
||||
row.set(0, param.getFieldName());
|
||||
row.set(1, param.getDataType());
|
||||
row.set(2, param.getFieldComment());
|
||||
row.set(3, param.getExampleValue());
|
||||
resParamTable.getRows().add(row);
|
||||
}
|
||||
mailMerge.executeWithRegions(resParamTable);
|
||||
// 返回示例 reqExample resExample
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
for (int i = 0; i < resParamList.size(); i++) {
|
||||
ResParam param = resParamList.get(i);
|
||||
objectNode.put(param.getFieldName(), param.getExampleValue());
|
||||
}
|
||||
mailMerge.execute(new String[] {"reqExample", "resExample"}, new Object[] {objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(AjaxResult.success(new LinkedList<ObjectNode>(){{add(objectNode);}})), objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(AjaxResult.error("返回失败"))});
|
||||
WordUtil.getInstance().insertWatermarkText(doc, SecurityUtil.getUserName());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDataApiDetailById(String id) {
|
||||
DataApiEntity dataApiEntity = super.getById(id);
|
||||
ApiHeader apiHeader = new ApiHeader();
|
||||
MD5Util mt = null;
|
||||
try {
|
||||
mt = MD5Util.getInstance();
|
||||
apiHeader.setApiKey(mt.encode(id));
|
||||
apiHeader.setSecretKey(mt.encode(SecurityUtil.getUserId()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("data", dataApiMapper.toVO(dataApiEntity));
|
||||
map.put("header", apiHeader);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataApiEntity> getDataApiEntityList(String status) {
|
||||
return dataApiDao.getDataApiEntityList(status);
|
||||
}
|
||||
|
||||
public static Map<String, String> parseFields(String sql) throws JSQLParserException {
|
||||
// Remove placeholders
|
||||
sql = sql.replaceAll("\\$\\{.*?\\}", "");
|
||||
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
Select select = (Select) CCJSqlParserUtil.parse(sql);
|
||||
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
|
||||
List<SelectItem> selectItems = plainSelect.getSelectItems();
|
||||
|
||||
for (SelectItem selectItem : selectItems) {
|
||||
selectItem.accept(new SelectItemVisitorAdapter() {
|
||||
@Override
|
||||
public void visit(SelectExpressionItem item) {
|
||||
String columnName = item.getExpression().toString().replaceAll("^[a-zA-Z]+\\.", "");
|
||||
String alias = item.getAlias() != null ? item.getAlias().getName().replaceAll("^[a-zA-Z]+\\.", "") : columnName;
|
||||
fields.put(columnName, alias);
|
||||
}
|
||||
});
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user