新增:机台获取数据源,新增数据源接口

This commit is contained in:
liuzhaotian
2024-07-24 09:10:56 +08:00
parent 86bf4f8cb8
commit 540e840a8d
13 changed files with 589 additions and 27 deletions
@@ -1,6 +1,6 @@
package com.cf.imes.module.system.controller.admin.datasource;
import io.swagger.v3.oas.annotations.media.Schema;
import com.cf.imes.framework.es.core.valid.CreateGroup;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -12,7 +12,6 @@ import java.util.*;
import java.io.IOException;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
@@ -90,6 +89,28 @@ public class DataSourceController {
return success(BeanUtils.toBean(list, DataSourceRespVO.class));*/
}
@PostMapping("/create")
@Operation(summary = "新增数据源字段")
@PreAuthorize("@ss.hasPermission('system:data-source:create')")
public CommonResult<Boolean> createDataSource(@Validated @RequestBody List<DataSourceSaveReqVO> createReqVO) {
dataSourceService.createDataSource(createReqVO);
return success(true);
}
@GetMapping("/getList")
@Operation(summary = "获取数据源参数")
@Parameter(name = "type", description = "标签类型", required = true, example = "9")
//@PreAuthorize("@ss.hasPermission('system:data-source:query')")
public CommonResult<List<DataSourceFiledReqVO>> getList(@RequestParam("type") Integer type ) {
return success(dataSourceService.getList( type));
}
@GetMapping("/export-excel")
@Operation(summary = "导出系统数据源 Excel")
@PreAuthorize("@ss.hasPermission('system:data-source:export')")
@@ -0,0 +1,32 @@
package com.cf.imes.module.system.controller.admin.datasource.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
@Schema(description = "")
@Data
@ToString(callSuper = true)
public class DataSourceFiledReqVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "数据源id")
private String sourceId;
@Schema(description = "字段名称")
private String name;
@Schema(description = "字段key")
private String key;
@Schema(description = "下一层级结构")
private List<DataSourceFiledReqVO> children;
}
@@ -4,26 +4,45 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 系统数据源新增/修改 Request VO")
@Schema(description = "数据源字段新增/修改")
@Data
public class DataSourceSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "30829")
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED)
private Long id;
@Schema(description = "数据源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@NotEmpty(message = "数据源名称不能为空")
// @Schema(description = "字段数据", requiredMode = Schema.RequiredMode.REQUIRED)
// private List<SourceField> sourceFields;
@Schema(description = "字段名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
private String name;
@Schema(description = "sql", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "sql不能为空")
private String sql;
@Schema(description = "数据源的字段key", requiredMode = Schema.RequiredMode.REQUIRED)
private String key;
@Schema(description = "数据源的父ID", requiredMode = Schema.RequiredMode.REQUIRED)
private Long parentId;
// @Valid
// @Data
// public static class SourceField {
//
// @Schema(description = "字段名称", requiredMode = Schema.RequiredMode.REQUIRED)
// private String name;
//
// @Schema(description = "数据源的字段key", requiredMode = Schema.RequiredMode.REQUIRED)
// private String key;
//
// @Schema(description = "数据源的父ID", requiredMode = Schema.RequiredMode.REQUIRED)
// private Long parentId;
// }
@Schema(description = "数据源类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "数据源类型不能为空")
private Integer type;
}
@@ -31,10 +31,6 @@ public class DataSourceDO extends BaseDO {
* 数据源名称
*/
private String name;
/**
* sql
*/
private String sqlStr;
/**
* 数据源类型
*/
@@ -1,21 +1,42 @@
package com.cf.imes.module.system.dal.dataobject.datasource;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder;
import lombok.Data;
/**
* @author Beal
*/
@Data
@Builder
@TableName("system_data_source_field")
public class DataSourceFiledDO {
/**
* 主键
*/
@TableId
private Long id;
private Long sourceId;
/**
* 数据源id
*/
private String sourceId;
/**
* 字段名称
*/
private String name;
/**
* 字段key
*/
@TableField("`key`")
private String key;
}
@@ -0,0 +1,27 @@
package com.cf.imes.module.system.dal.mysql.datasource;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.system.controller.admin.datasource.vo.DataSourceFiledReqVO;
import com.cf.imes.module.system.controller.admin.datasource.vo.DataSourceSaveReqVO;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface DataSourceFiledMapper extends BaseMapperX<DataSourceFiledDO> {
List<DataSourceFiledReqVO> selectFiledList(@Param("ids")List<Long> ids);
List<DataSourceFiledDO> selectFiled(@Param("sourceFields") List<DataSourceSaveReqVO> sourceFields);
List<DataSourceFiledDO> selectFiledListByKey(@Param("keyList") List<String> keyList);
}
@@ -20,11 +20,19 @@ public interface DataSourceMapper extends BaseMapperX<DataSourceDO> {
default PageResult<DataSourceDO> selectPage(DataSourcePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DataSourceDO>()
.likeIfPresent(DataSourceDO::getName, reqVO.getName())
.eqIfPresent(DataSourceDO::getSqlStr, reqVO.getSqlStr())
.eqIfPresent(DataSourceDO::getType, reqVO.getType())
.betweenIfPresent(DataSourceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DataSourceDO::getId));
}
List<DataSourceRespVO> selectListVO();
default List<DataSourceDO> selectByType() {
return selectList( new LambdaQueryWrapperX<DataSourceDO>()
.eqIfPresent(DataSourceDO::getType,9)
/* .eqIfPresent(DataSourceDO::getId,1004)*/);
}
}
@@ -5,6 +5,7 @@ import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO;
import javax.validation.Valid;
@@ -21,7 +22,7 @@ public interface DataSourceService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createDataSource(@Valid DataSourceSaveReqVO createReqVO);
void createDataSource(@Valid List<DataSourceSaveReqVO> createReqVO);
/**
* 更新系统数据源
@@ -56,4 +57,6 @@ public interface DataSourceService {
List<DataSourceDO> list(Integer type);
List<DataSourceRespVO> list();
List<DataSourceFiledReqVO> getList(Integer type);
}
@@ -1,19 +1,27 @@
package com.cf.imes.module.system.service.datasource;
import com.alibaba.fastjson.JSON;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceFiledMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceMapper;
import javax.annotation.Resource;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.PLAN_NOT_ALLOW_DELETE;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
/**
@@ -28,15 +36,217 @@ public class DataSourceServiceImpl implements DataSourceService {
@Resource
private DataSourceMapper dataSourceMapper;
@Resource
private DataSourceFiledMapper dataSourceFiledMapper;
@Override
public Long createDataSource(DataSourceSaveReqVO createReqVO) {
// 插入
DataSourceDO dataSource = BeanUtils.toBean(createReqVO, DataSourceDO.class);
dataSourceMapper.insert(dataSource);
// 返回
return dataSource.getId();
public void createDataSource(List<DataSourceSaveReqVO> createReqVO) {
// 提取 SourceField 中的 key 列表
List<String> keyList = createReqVO.stream()
.map(DataSourceSaveReqVO::getKey)
.collect(Collectors.toList());
// 根据 key 列表查询对应的 DataSourceFiledDO 列表并转换为 Map
Map<String, List<DataSourceFiledDO>> dataSourceFiledDoMap = dataSourceFiledMapper
.selectFiledListByKey(keyList)
.stream()
.collect(Collectors.groupingBy(DataSourceFiledDO::getKey));
List<DataSourceFiledDO> insertFiledDoS = new ArrayList<>();
List<DataSourceFiledDO> updateFiledDoS = new ArrayList<>();
// 遍历 SourceFields 进行插入或更新操作
for (DataSourceSaveReqVO sourceField : createReqVO) {
List<DataSourceFiledDO> existingFiledDoS = dataSourceFiledDoMap.get(sourceField.getKey());
if (existingFiledDoS != null) {
DataSourceFiledDO dataSourceFiledDO = existingFiledDoS.get(0);
if (shouldUpdate(dataSourceFiledDO, sourceField)) {
dataSourceFiledDO.setSourceId(dataSourceFiledDO.getSourceId() + "," + sourceField.getParentId());
updateFiledDoS.add(dataSourceFiledDO);
}
} else {
insertFiledDoS.add(DataSourceFiledDO.builder()
.key(sourceField.getKey())
.sourceId(String.valueOf(sourceField.getParentId()))
.name(sourceField.getName())
.build());
}
}
// 批量插入和更新 DataSourceFiledDO 列表
if (!insertFiledDoS.isEmpty()) {
dataSourceFiledMapper.insertBatch(insertFiledDoS);
}
if (!updateFiledDoS.isEmpty()) {
dataSourceFiledMapper.updateBatch(updateFiledDoS);
}
}
private boolean shouldUpdate(DataSourceFiledDO existingFiledDO, DataSourceSaveReqVO sourceField) {
return existingFiledDO.getId() > 1000 &&
Objects.equals(existingFiledDO.getName(), sourceField.getName()) &&
!conversion(existingFiledDO.getSourceId()).contains(sourceField.getParentId());
}
//
// @Override
// public void createDataSource(List<DataSourceSaveReqVO> createReqVO) {
// // 获取请求中的 SourceFields 列表
// List<DataSourceSaveReqVO.SourceField> sourceFields = createReqVO.getSourceFields();
//
// // 提取 SourceField 中的 key 列表
// List<String> keyList = sourceFields.stream()
// .map(DataSourceSaveReqVO.SourceField::getKey)
// .collect(Collectors.toList());
//
// // 根据 key 列表查询对应的 DataSourceFiledDO 列表并转换为 Map
// Map<String, List<DataSourceFiledDO>> dataSourceFiledDOMap = dataSourceFiledMapper
// .selectFiledListByKey(keyList)
// .stream()
// .collect(Collectors.groupingBy(DataSourceFiledDO::getKey));
//
// List<DataSourceFiledDO> insertFiledDOS = new ArrayList<>();
// List<DataSourceFiledDO> updateFiledDOS = new ArrayList<>();
//
// // 遍历 SourceFields 进行插入或更新操作
// for (DataSourceSaveReqVO.SourceField sourceField : sourceFields) {
// List<DataSourceFiledDO> existingFiledDOS = dataSourceFiledDOMap.get(sourceField.getKey());
//
// if (existingFiledDOS != null) {
// DataSourceFiledDO dataSourceFiledDO = existingFiledDOS.get(0);
// if (shouldUpdate(dataSourceFiledDO, sourceField)) {
// dataSourceFiledDO.setSourceId(dataSourceFiledDO.getSourceId() + "," + sourceField.getParentId());
// updateFiledDOS.add(dataSourceFiledDO);
// }
//
// } else {
// insertFiledDOS.add(DataSourceFiledDO.builder()
// .key(sourceField.getKey())
// .sourceId(String.valueOf(sourceField.getParentId()))
// .name(sourceField.getName())
// .build());
// }
// }
//
// // 批量插入和更新 DataSourceFiledDO 列表
// if (!insertFiledDOS.isEmpty()) {
// dataSourceFiledMapper.insertBatch(insertFiledDOS);
// }
// if (!updateFiledDOS.isEmpty()) {
// dataSourceFiledMapper.updateBatch(updateFiledDOS);
// }
// }
//
// private boolean shouldUpdate(DataSourceFiledDO existingFiledDO, DataSourceSaveReqVO.SourceField sourceField) {
// return existingFiledDO.getId() > 1000 &&
// Objects.equals(existingFiledDO.getName(), sourceField.getName()) &&
// !conversion(existingFiledDO.getSourceId()).contains(sourceField.getParentId());
// }
//
// @Override
// public void createDataSource(DataSourceSaveReqVO createReqVO) {
// // 获取请求中的 SourceFields 列表
// List<DataSourceSaveReqVO.SourceField> sourceFields = createReqVO.getSourceFields();
//
// List<DataSourceFiledDO> insertFiledDOS = new ArrayList<>();
//
// List<DataSourceFiledDO> updateFiledDOS = new ArrayList<>();
//
// // 提取 SourceField 中的 key 列表
// List<String> keyList = sourceFields.stream().map(DataSourceSaveReqVO.SourceField::getKey).toList();
//
// // 根据 key 列表查询对应的 DataSourceFiledDO 列表
// List<DataSourceFiledDO> dataSourceFiledDOS = dataSourceFiledMapper.selectFiledListByKey(keyList);
//
// if (!dataSourceFiledDOS.isEmpty()) {
//
// // 提取已存在的 DataSourceFiledDO 的 key 列表
// List<String> keys = dataSourceFiledDOS.stream().map(DataSourceFiledDO::getKey).toList();
//
// StringBuilder data = new StringBuilder();
//
// for (DataSourceSaveReqVO.SourceField sourceField : sourceFields) {
// // 过滤出符合条件的 DataSourceFiledDO
// List<DataSourceFiledDO> sourceFiledDOS = dataSourceFiledDOS.stream()
// .filter(f -> Objects.equals(f.getKey(), sourceField.getKey()))
// .filter(f->Objects.equals(f.getName(),sourceField.getName()))
// .filter(f -> !conversion(f.getSourceId()).contains(sourceField.getParentId()))
// .filter(f -> f.getId() > 1000)
// .toList();
//
// if (!sourceFiledDOS.isEmpty()) {
//
// data.append(",").append(sourceField.getParentId());
//
// DataSourceFiledDO dataSourceFiledDO = BeanUtils.toBean(sourceFiledDOS.get(0), DataSourceFiledDO.class);
// dataSourceFiledDO.setSourceId(dataSourceFiledDO.getSourceId() + data);
// updateFiledDOS.add(dataSourceFiledDO);
//
// }
//
// // 如果 key 不存在于已查询的列表中,新增一个 DataSourceFiledDO
// if (!keys.contains(sourceField.getKey())) {
// insertFiledDOS.add(DataSourceFiledDO.builder()
// .key(sourceField.getKey())
// .sourceId(String.valueOf(sourceField.getParentId()))
// .name(sourceField.getName())
// .build());
// }
// }
//
// dataSourceFiledMapper.updateBatch(updateFiledDOS);
//
// } else {
// // 如果查询结果为空,直接将所有 sourceFields 转换为 DataSourceFiledDO 并添加到列表中
// insertFiledDOS.addAll(sourceFields.stream()
// .map(m -> DataSourceFiledDO.builder()
// .key(m.getKey())
// .sourceId(String.valueOf(m.getParentId()))
// .name(m.getName())
// .build())
// .toList());
// }
//
// // 批量插入 DataSourceFiledDO 列表
// dataSourceFiledMapper.insertBatch(insertFiledDOS);
//
//
// }
// 目前不对重复添加的数据进行删选处理,后续有需求再处理
// List<DataSourceFiledDO> dataSourceFiledDO = dataSourceFiledMapper.selectFiled(sourceFields);
//
// List<DataSourceSaveReqVO.SourceField> fieldList = new ArrayList<>();
//
// if(! dataSourceFiledDO.isEmpty()){
//
// List<String> sourceIds = dataSourceFiledDO.stream().map(m -> m.getSourceId()).toList();
//
// for (String sourceId : sourceIds) {
// fieldList.addAll(sourceFields.stream()
// .filter(f -> !conversion(sourceId).contains(f.getParentId()))
// .toList());
// }
//
// }
@Override
public void updateDataSource(DataSourceSaveReqVO updateReqVO) {
// 校验存在
@@ -80,4 +290,171 @@ public class DataSourceServiceImpl implements DataSourceService {
return dataSourceMapper.selectListVO();
}
//
// @Override
// public List<DataSourceFiledReqVO> getList(Integer type) {
//
//
// List<DataSourceDO> dataSourceDOS = dataSourceMapper.selectByType();
//
//
// List<DataSourceFiledReqVO> bean = BeanUtils.toBean(dataSourceDOS, DataSourceFiledReqVO.class);
//
//
// List<Long> ids = dataSourceDOS.stream().map(DataSourceDO::getId).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS = dataSourceFiledMapper.selectFiledList(ids);
//
//
// List<Long> list = dataSourceFiledDOS.stream().filter(f -> f.getKey() == null).map(m -> m.getId()).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS1 = dataSourceFiledMapper.selectFiledList(list);
//
//
// List<Long> list1 = dataSourceFiledDOS1.stream().filter(f -> f.getKey() == null).map(m -> m.getId()).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS2 = dataSourceFiledMapper.selectFiledList(list1);
//
//
// List<Long> list2 = dataSourceFiledDOS2.stream().filter(f -> f.getKey() == null).map(m -> m.getId()).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS3 = dataSourceFiledMapper.selectFiledList(list2);
//
//
// List<Long> list3 = dataSourceFiledDOS3.stream().filter(f -> f.getKey() == null).map(m -> m.getId()).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS4 = dataSourceFiledMapper.selectFiledList(list3);
//
//
// List<Long> list4 = dataSourceFiledDOS4.stream().filter(f -> f.getKey() == null).map(m -> m.getId()).toList();
//
//
// List<DataSourceFiledReqVO> dataSourceFiledDOS5 = dataSourceFiledMapper.selectFiledList(list4);
//
//
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledDOS4) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS5.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledDOS3) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS4.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledDOS2) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS3.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledDOS1) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS2.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledDOS) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS1.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
//
//
// for (DataSourceFiledReqVO dataSourceFiledDO : bean) {
// dataSourceFiledDO.setChildren(dataSourceFiledDOS.stream().filter(f->conversion(f.getSourceId()).contains(dataSourceFiledDO.getId())).toList());
//
// }
//
// return bean;
//
// }
@Override
public List<DataSourceFiledReqVO> getList(Integer type) {
List<DataSourceDO> dataSourceDOS = dataSourceMapper.selectByType();
List<DataSourceFiledReqVO> dataSourceFiledReqVOS = BeanUtils.toBean(dataSourceDOS, DataSourceFiledReqVO.class);
List<Long> ids = dataSourceDOS.stream().map(DataSourceDO::getId).toList();
// 获取字段列表
List<DataSourceFiledReqVO> dataSourceFiledDOS = dataSourceFiledMapper.selectFiledList(ids);
// 递归填充子节点
populateChildren(dataSourceFiledDOS);
// 为根节点填充子节点
for (DataSourceFiledReqVO dataSourceFiledDO : dataSourceFiledReqVOS) {
dataSourceFiledDO.setChildren(dataSourceFiledDOS.stream()
.filter(f -> conversion(f.getSourceId()).contains(dataSourceFiledDO.getId()))
.toList());
}
return dataSourceFiledReqVOS;
}
/**
* 递归填充子节点
*
* @param parentList 父节点列表
*/
private void populateChildren(List<DataSourceFiledReqVO> parentList) {
if (parentList == null || parentList.isEmpty()) {
return;
}
// 获取没有key的节点ID
List<Long> ids = parentList.stream()
.filter(f -> f.getKey() == null)
.map(DataSourceFiledReqVO::getId)
.distinct()
.toList();
if (ids.isEmpty()) {
return;
}
// 获取子节点列表
List<DataSourceFiledReqVO> childList = dataSourceFiledMapper.selectFiledList(ids);
if (childList.isEmpty()) {
return;
}
// 为每个父节点填充子节点并递归处理子节点
for (DataSourceFiledReqVO parent : parentList) {
List<DataSourceFiledReqVO> children = childList.stream()
.filter(f -> conversion(f.getSourceId()).contains(parent.getId()))
.toList();
parent.setChildren(children);
// 递归处理子节点
populateChildren(children);
}
}
private List<Long> conversion(String sourceId) {
return Arrays.stream(sourceId.split(","))
.map(Long::parseLong)
.toList();
}
}
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cf.imes.module.system.dal.mysql.datasource.DataSourceFiledMapper">
<select id="selectFiledList" resultType="com.cf.imes.module.system.controller.admin.datasource.vo.DataSourceFiledReqVO"
parameterType="java.lang.Long">
select distinct
* from system_data_source_field
where
<foreach item="ids" collection="ids" open="(" separator="OR" close=")">
source_id LIKE CONCAT('%', #{ids}, '%')
</foreach>
</select>
<select id="selectFiled" resultType="com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO">
select distinct
*
from system_data_source_field
where
<foreach item="sourceFields" collection="sourceFields" open="(" separator="OR" close=")">
source_id LIKE CONCAT('%', #{sourceFields.parentId}, '%')
</foreach>
and
`key` in
<foreach collection="sourceFields" item="sourceFields" open="(" close=")" separator=",">
#{sourceFields.key}
</foreach>
</select>
<select id="selectFiledListByKey" resultType="com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO">
select distinct
*
from system_data_source_field
where
`key` in
<foreach collection="keyList" item="keyList" open="(" close=")" separator=",">
#{keyList}
</foreach>
</select>
</mapper>
@@ -19,5 +19,6 @@
select a.*, b.id field_id, b.name field_name, b.source_id field_source_id, b.key field_key
from system_data_source a
left join system_data_source_field b on a.id = b.source_id
where a.type in (1,2)
</select>
</mapper>