<?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.ozs.kpim.mapper.kpiconfig.KpiRelationMapper">

	<!--批量插入数据到kpim_rel_kpi_topic表 -->
	<insert id="insertKpiRelTopicBatch" parameterType="java.util.List">
		INSERT INTO kpim_rel_kpi_topic(kpi_id,topic_id)
		VALUES
		<foreach collection="list" item="item" index="index"
			separator=",">
			(#{item.kpiId,jdbcType=VARCHAR},
			#{item.relId,jdbcType=VARCHAR})
		</foreach>
	</insert>

	<!--批量插入数据到kpim_rel_kpi_user表 -->
	<insert id="insertKpiRelUserBatch" parameterType="java.util.List">
		INSERT INTO kpim_rel_kpi_user(kpi_id,user_id)
		VALUES
		<foreach collection="list" item="item" index="index"
			separator=",">
			(#{item.kpiId,jdbcType=VARCHAR},
			#{item.relId,jdbcType=VARCHAR})
		</foreach>
	</insert>

	<!--批量插入数据到kpim_rel_kpi_column表 -->
	<insert id="insertKpiRelColumnBatch" parameterType="java.util.List">
		INSERT INTO kpim_rel_kpi_column(kpi_id,column_id,sort)
		VALUES
		<foreach collection="list" item="item" index="index"
			separator=",">
			(#{item.kpiId,jdbcType=VARCHAR},
			#{item.relId,jdbcType=VARCHAR},
			#{item.sort})
		</foreach>
	</insert>

	<!--删除kpim_rel_kpi_topic表kpiId相关的数据 -->
	<delete id="deleteKpiRelTopicByKpiId">
		DELETE FROM kpim_rel_kpi_topic WHERE kpi_id =
		#{kpiId}
	</delete>

	<!--删除kpim_rel_kpi_user表kpiId相关的数据 -->
	<delete id="deleteKpiRelUserByKpiId">
		DELETE FROM kpim_rel_kpi_user WHERE kpi_id = #{kpiId}
	</delete>

	<!--删除kpim_rel_kpi_column表kpiId相关的数据 -->
	<delete id="deleteKpiRelColumnByKpiId">
		DELETE FROM kpim_rel_kpi_column WHERE kpi_id =
		#{kpiId}
	</delete>

	<!--查询kpi_id关联的columnId -->
	<select id="listColumnIdsByKpiId" resultType="java.lang.String">
		SELECT column_id
		FROM kpim_rel_kpi_column WHERE kpi_id = #{kpiId} order by sort
	</select>

	<!--查询columnId是否在使用中 -->
	<select id="getCountByColumnId" resultType="java.lang.Integer">
		SELECT
		COUNT(column_id) FROM kpim_rel_kpi_column WHERE column_id =
		#{columnId}
	</select>

	<insert id="insertKpiRelFunctionBatch" parameterType="java.lang.String">
		INSERT INTO
		kpim_rel_kpi_function(kpi_id,function_id)
		VALUES
		(#{kpiId,jdbcType=VARCHAR},
		#{functionId,jdbcType=VARCHAR})
	</insert>
	<delete id="deleteKpiRelFunctionByKpiId" parameterType="java.lang.String">
		DELETE FROM
		kpim_rel_kpi_function WHERE kpi_id =
		#{kpiId}
	</delete>
</mapper>