Commit a78ae097 by yuwei

2.0.0项目初始化

parent f0dbb0e5
......@@ -14,14 +14,19 @@ import cn.datax.service.data.factory.api.feign.DataSourceServiceFeign;
import cn.datax.service.data.market.api.call.service.ApiCallService;
import cn.datax.service.data.market.api.call.utils.SqlBuilderUtil;
import cn.datax.service.data.market.api.call.utils.ThreadUtil;
import cn.datax.service.data.market.api.dto.FieldRule;
import cn.datax.service.data.market.api.entity.ApiMaskEntity;
import cn.datax.service.data.market.api.entity.DataApiEntity;
import cn.datax.service.data.market.api.feign.ApiMaskServiceFeign;
import cn.datax.service.data.market.api.feign.DataApiServiceFeign;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Optional;
......@@ -38,6 +43,9 @@ public class ApiCallServiceImpl implements ApiCallService {
@Autowired
private DataApiServiceFeign dataApiServiceFeign;
@Autowired
private ApiMaskServiceFeign apiMaskServiceFeign;
@Override
public PageResult<Map<String, Object>> v1() {
R apiResult = dataApiServiceFeign.getDataApiById(ThreadUtil.getInstance().get().getApiId());
......@@ -75,8 +83,19 @@ public class ApiCallServiceImpl implements ApiCallService {
throw new DataException("API调用动态构造SQL语句出错");
}
Map<String, Object> acceptedFilters = sqlFilterResult.getAcceptedFilters();
// 数据脱敏
List<FieldRule> rules = null;
R maskResult = apiMaskServiceFeign.getApiMaskById(ThreadUtil.getInstance().get().getApiId());
if(maskResult != null && maskResult.isSuccess() && ObjectUtil.isNotEmpty(maskResult.getData())){
ApiMaskEntity apiMask = JSON.parseObject(JSON.toJSONString(maskResult.getData()), ApiMaskEntity.class);
rules = apiMask.getRules();
}
try {
PageResult<Map<String, Object>> pageResult = dbQuery.queryByPage(sqlFilterResult.getSql(), acceptedFilters, offset, pageSize);
if (CollUtil.isNotEmpty(rules)){
// 并行流处理脱敏
// pageResult.getData().parallelStream()
}
pageResult.setPageNum(pageNum).setPageSize(pageSize);
ThreadUtil.getInstance().get().setCallerSize(pageResult.getData().size());
return pageResult;
......
package cn.datax.service.data.market.api.entity;
import cn.datax.common.base.DataScopeBaseEntity;
import cn.datax.service.data.market.api.dto.FieldRule;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
......@@ -24,8 +25,8 @@ import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("data_api_mask")
public class ApiMaskEntity extends BaseEntity {
@TableName(value = "data_api_mask", autoResultMap = true)
public class ApiMaskEntity extends DataScopeBaseEntity {
private static final long serialVersionUID=1L;
......
package cn.datax.service.data.market.api.feign;
import cn.datax.common.core.R;
import cn.datax.service.data.market.api.feign.factory.ApiMaskServiceFeignFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(contextId = "apiMaskServiceFeign", value = "datax-service-data-masking", fallbackFactory = ApiMaskServiceFeignFallbackFactory.class)
public interface ApiMaskServiceFeign {
@GetMapping("/inner/apiMask/{id}")
R getApiMaskById(@PathVariable("id") String id);
}
package cn.datax.service.data.market.api.feign.factory;
import cn.datax.service.data.market.api.feign.ApiMaskServiceFeign;
import cn.datax.service.data.market.api.feign.fallback.ApiMaskServiceFeignFallbackImpl;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
@Component
public class ApiMaskServiceFeignFallbackFactory implements FallbackFactory<ApiMaskServiceFeign> {
@Override
public ApiMaskServiceFeign create(Throwable throwable) {
ApiMaskServiceFeignFallbackImpl apiMaskServiceFeignFallbackImpl = new ApiMaskServiceFeignFallbackImpl();
apiMaskServiceFeignFallbackImpl.setCause(throwable);
return apiMaskServiceFeignFallbackImpl;
}
}
package cn.datax.service.data.market.api.feign.fallback;
import cn.datax.common.core.R;
import cn.datax.service.data.market.api.feign.ApiMaskServiceFeign;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ApiMaskServiceFeignFallbackImpl implements ApiMaskServiceFeign {
@Setter
private Throwable cause;
@Override
public R getApiMaskById(String id) {
log.error("feign 调用{}出错", id, cause);
return null;
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.service.data.market.api.feign.factory.DataApiServiceFeignFallbackFactory,\
cn.datax.service.data.market.api.feign.fallback.DataApiServiceFeignFallbackImpl
cn.datax.service.data.market.api.feign.fallback.DataApiServiceFeignFallbackImpl,\
cn.datax.service.data.market.api.feign.factory.ApiMaskServiceFeignFallbackFactory,\
cn.datax.service.data.market.api.feign.fallback.ApiMaskServiceFeignFallbackImpl
......@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
*/
@Api(tags = {"数据API脱敏信息表"})
@RestController
@RequestMapping("/masking/dataApiMask")
@RequestMapping("/apiMask")
public class ApiMaskController extends BaseController {
@Autowired
......
package cn.datax.service.data.market.data.masking.controller;
import cn.datax.common.base.BaseController;
import cn.datax.common.core.R;
import cn.datax.service.data.market.api.entity.ApiMaskEntity;
import cn.datax.service.data.market.data.masking.mapstruct.ApiMaskMapper;
import cn.datax.service.data.market.data.masking.service.ApiMaskService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/inner")
public class InnerController 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("/apiMask/{id}")
public R getApiMaskById(@PathVariable String id) {
ApiMaskEntity apiMaskEntity = apiMaskService.getById(id);
return R.ok().setData(apiMaskMapper.toVO(apiMaskEntity));
}
}
......@@ -51,7 +51,7 @@ public class ApiMaskServiceImpl extends BaseServiceImpl<ApiMaskDao, ApiMaskEntit
apiMaskDao.updateById(apiMask);
}
@Cacheable(key = "#id", unless = "#result == null")
@Cacheable(key = "#id")
@Override
public ApiMaskEntity getById(Serializable id) {
return super.getById(id);
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.datax.service.data.market.data.masking.dao.ApiMaskDao">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.datax.service.data.market.api.entity.ApiMaskEntity">
<result column="id" property="id" />
<result column="status" property="status" />
<result column="create_by" property="createBy" />
<result column="create_time" property="createTime" />
<result column="create_dept" property="createDept" />
<result column="update_by" property="updateBy" />
<result column="update_time" property="updateTime" />
<result column="api_id" property="apiId" />
<result column="mask_name" property="maskName" />
<result column="remark" property="remark" />
<result column="config_json" property="rules" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id,
status,
create_by,
create_time,
create_dept,
update_by,
update_time,
api_id, mask_name, remark, config_json
</sql>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment