<?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.appshow.mapper.ChartInfoMapper">
	<select id="listChartType" resultType="com.datau.appshow.dto.ChartTypeDTO">
		select id,value
		from
		apps_dim_chart_type
	</select>
	<select id="listChartInfo" resultType="com.datau.appshow.dto.ChartInfoDTO">
		SELECT
		aic.id,
		chart_name,
		chart_type,
		chart_class_code,
		database_id,
		table_id,
		aic.update_user_id,
		aic.update_time,
		adct.value
		chart_type_value,
		aicc.class_name chart_class_name
		FROM
		apps_info_chart
		aic
		LEFT JOIN apps_dim_chart_type adct ON aic.chart_type
		= adct.id
		LEFT
		JOIN apps_info_chart_class aicc ON aic.chart_class_code =
		aicc.class_code
		where 1=1
		<if test="chartName != null &amp;&amp; chartName != ''">
			and chart_name like concat('%',#{chartName},'%')
		</if>
		<if test="chartType != null &amp;&amp; chartType != ''">
			and chart_type = #{chartType}
		</if>
	</select>
	<select id="getChartInfo" resultType="com.datau.appshow.dto.ChartInfoDTO">
		SELECT
		aic.id,
		chart_name,
		DML,
		chart_type,
		chart_class_code,
		database_id,
		table_id,
		chart_json,
		rich_text,
		file_path,
		aic.update_user_id,
		aic.update_time,
		adct.
		VALUE
		chart_type_value,
		aicc.class_name chart_class_name
		FROM
		apps_info_chart
		aic
		LEFT JOIN apps_dim_chart_type adct ON aic.chart_type
		= adct.id
		LEFT
		JOIN apps_info_chart_class aicc ON aic.chart_class_code =
		aicc.class_code
		where 1=1
		and aic.id = #{chartId}
	</select>
	<select id="getChartInfoByName" resultType="com.datau.appshow.dto.ChartInfoDTO">
		SELECT
		aic.id,
		chart_name,
		DML,
		chart_type,
		chart_class_code,
		database_id,
		table_id,
		chart_json,
		rich_text,
		file_path,
		aic.update_user_id,
		aic.update_time,
		adct.
		VALUE
		chart_type_value,
		aicc.class_name chart_class_name
		FROM
		apps_info_chart
		aic
		LEFT JOIN apps_dim_chart_type adct ON aic.chart_type
		= adct.id
		LEFT
		JOIN apps_info_chart_class aicc ON aic.chart_class_code =
		aicc.class_code
		where 1=1
		and chart_name = #{chartName}
	</select>
	<insert id="saveChartInfo" parameterType="com.datau.appshow.dto.ChartInfoDTO">
		insert into
		apps_info_chart(
		id,chart_name,DML,chart_type,chart_class_code,database_id,table_id,chart_json,rich_text,file_path,update_user_id,update_time)
		value(uuid(),#{chartName},#{DML},#{chartType},#{chartClassCode},#{databaseId},#{tableId},#{chartJson},#{richText},#{filePath},#{updateUserId},now())
	</insert>
	<update id="updateChartInfo" parameterType="com.datau.appshow.dto.ChartInfoDTO">
		update
		apps_info_chart set
		update_user_id=#{updateUserId}
		,update_time
		=now()
		, chart_name = #{chartName}
		, chart_class_code =
		#{chartClassCode},chart_type = #{chartType}
		<if test="DML != null &amp;&amp; DML != ''">
			, DML = #{DML}
		</if>
		<if test="databaseId != null &amp;&amp; databaseId != ''">
			, database_id = #{databaseId}
		</if>
		<if test="tableId != null &amp;&amp; tableId != ''">
			, table_id = #{tableId}
		</if>
		<if test="chartJson != null &amp;&amp; chartJson != ''">
			, chart_json = #{chartJson}
		</if>
		<if test="richText != null &amp;&amp; richText != ''">
			, rich_text = #{richText}
		</if>
		<if test="filePath != null &amp;&amp; filePath != ''">
			, file_path = #{filePath}
		</if>
		where id = #{id}
	</update>
	<update id="updateChartJson" parameterType="com.datau.appshow.dto.ChartInfoDTO">
		update
		apps_info_chart set
		update_user_id=#{updateUserId}
		,update_time
		=now()
		,
		chart_json = #{chartJson}
		where id = #{id}
	</update>
	<delete id="removeChart" parameterType="java.lang.String">
		delete from
		apps_info_chart where id =
		#{id}
	</delete>
	<select id="countRelSubjectChart" resultType="java.lang.Integer">
		select count(0)
		from
		apps_rel_subject_chart where chart_id = #{chartId}
	</select>
	<select id="listChartInfoByClass" resultType="com.datau.appshow.dto.ChartInfoDTO">
		SELECT
		aic.id,
		chart_name,
		chart_type,
		chart_class_code,
		database_id,
		table_id,
		aic.update_user_id,
		aic.update_time,
		adct.value
		chart_type_value,
		aicc.class_name chart_class_name
		FROM
		apps_info_chart
		aic
		LEFT JOIN
		apps_dim_chart_type adct ON aic.chart_type
		= adct.id
		LEFT
		JOIN
		apps_info_chart_class aicc ON aic.chart_class_code =
		aicc.class_code
		where 1=1
		and chart_class_code = #{classCode}
	</select>
</mapper>