<?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.datau.mdm.mapper.KpiManageMapper">
	<select id="listDatabase" resultType="com.datau.mdm.dto.MdmInfoDatabase">
		select
		id,resource_name,database_name from mdm_info_database where 1=1
		and database_type != 1
		<if test="resourceName !=null &amp;&amp; resourceName !=''">
			and resource_name like concat('',#{resourceName},'')
		</if>
	</select>
	<select id="listTableByDatabaseId" resultType="com.datau.mdm.dto.MdmInfoTable">
		select id
		,table_name,table_comment from mdm_info_table where 1=1
		<if test="databaseId !=null &amp;&amp; databaseId !=''">
			and database_id =
			#{databaseId}
		</if>
	</select>
	<select id="listColumnByTableId" resultType="com.datau.mdm.dto.MdmInfoColumn">
		SELECT
		mic.id,
		column_code,
		column_name,
		column_comment,
		column_type,
		mdct.type_name column_type_name,
		mdct.is_float_point is_float_point,
		mdct.is_time is_time,mdct.if_char,
		mic.if_primary,
		mic.if_null,
		mic.length,
		mic.numeric_scale
		FROM
		mdm_info_column mic
		LEFT JOIN mdm_dim_column_type
		mdct ON mic.column_type = mdct.id
		WHERE
		1 = 1
		<if test="tableId !=null &amp;&amp; tableId !=''">
			and mic.table_id = #{tableId}
		</if>

	</select>

	<select id="listColumn" resultType="com.datau.mdm.dto.KpiListColumnDTO">
		SELECT
		mic.id,
		mic.column_code,
		concat('C',mic.column_code)
		column_code_value,
		mic.column_name,
		mic.column_comment,
		mic.column_type,
		mic.length,
		mic.numeric_scale,
		mic.if_primary,
		mic.if_null,
		mic.table_id,
		mic.update_time,
		mic.update_user_id,
		mit.table_comment tableComment,
		mit.table_name
		tableName,
		mid.database_name databaseName,
		mid.resource_name
		resourceName,
		mdct.type_name columnTypeName
		FROM
		mdm_info_column
		mic
		LEFT
		JOIN mdm_info_table mit ON mic.table_id =
		mit.id
		LEFT JOIN
		mdm_info_database mid ON mit.database_id = mid.id
		left
		join
		mdm_dim_column_type mdct on mic.column_type = mdct.id
		where 1=1
		<if test="tableId !=null &amp;&amp; tableId !=''">
			and mic.table_id = #{tableId}
		</if>
		<if test="databaseId !=null &amp;&amp; databaseId !=''">
			and mit.database_id = #{databaseId}
		</if>

	</select>

	<select id="listColumnByIds" resultType="com.datau.mdm.dto.MdmInfoColumn">
		SELECT
		mic.id,
		column_code,
		column_name,
		column_comment,
		mit.id table_id,
		mit.table_name,
		mit.table_comment
		FROM
		mdm_info_column mic
		LEFT JOIN
		mdm_info_table mit
		ON mic.table_id = mit.id where mic.id in(
		<foreach collection="list" item="id" separator=",">
			#{id}
		</foreach>
		)
	</select>


	<select id="getColumnInfoByIds" resultType="com.datau.mdm.dto.ColumnInfoDTO">
		SELECT
		mic.id,
		mic.column_comment,
		mic.column_name,
		mic.update_time,
		mic.column_code,
		concat('C', mic.column_code) column_code_value,
		mic.table_id,
		mit.table_comment,
		mit.table_name,
		mit.database_id,
		mid.resource_name,
		mid.database_name
		FROM
		mdm_info_column mic
		LEFT JOIN mdm_info_table mit
		ON mic.table_id = mit.id
		LEFT JOIN mdm_info_database mid ON
		mit.database_id = mid.id
		where
		mic.id = #{id}
	</select>
	<select id="listOriginal" resultType="com.datau.mdm.dto.MdmInfoDatabase">
		select
		id,resource_name,database_name from mdm_info_database where 1=1
		and database_type = 1
		<if test="resourceName !=null &amp;&amp; resourceName !=''">
			and resource_name like concat('',#{resourceName},'')
		</if>
	</select>
	<select id="getDatabase" resultType="com.datau.mdm.dto.MdmInfoDatabase">
		select mid.id,
		mid.resource_name,
		mid.ip,
		mid.username,
		mid.password,
		mid.resource_port,
		mid.database_name,
		mdrt.type_name resource_type_name,
		mdrt.driver_name,
		mdrt.url,
		mid.charset ,
		mddc.charset_name
		from
		mdm_info_database mid left join
		mdm_dim_resource_type mdrt on
		mid.resource_type = mdrt.id left join mdm_dim_database_charset mddc on
		mid.charset = mddc.id
		where 1=1
		<if test="id !=null &amp;&amp; id !=''">
			and mid.id = #{id}
		</if>
	</select>
</mapper>