<?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="dimensionSqlMapper">
	
	<!-- 报表维度 -->
	<!-- 维度字段 -->
	<sql id="base_column">
		id,name,account_id as accountId,content,is_default as isDefault	
	</sql>
	
	<!-- 根据account_id查询维度不带分页 -->
	<select id="queryDimensionByAccountId" parameterType="java.lang.Long" resultType="com.cloudcross.ssp.model.Dimension">
		select id,name,content,is_default as isDefault from t_rpt_adv_schema where account_id = #{accountId} 
	</select>
	
	<!-- 根据account_id查询维度带分页 -->
	<select id="queryDimensionByAccountIdWithPage" parameterType="java.lang.Long" resultType="com.cloudcross.ssp.model.Dimension">
		select id,name,content,is_default as isDefault from t_rpt_adv_schema where account_id = #{accountId} limit #{pager.offset}, #{pager.limit}
	</select>
	
	<!--查询满足条件的记录数  -->
	<select id="queryDimensionCountByAccountId" parameterType="java.util.Map" resultType="java.lang.Integer">
		select count(id) from t_rpt_adv_schema where account_id = #{accountId}
	</select>
	
	<!-- 插入一条维度信息 -->
	<insert id="insertDimension" parameterType="com.cloudcross.ssp.model.Dimension">
		insert into t_rpt_adv_schema(account_id,name,content,is_default) values (#{accountId},#{name},#{content},#{isDefault})
	</insert>
	
	<!-- 根据ID查询维度信息 -->
	<select id="selectDimensionById" parameterType="int" resultType="com.cloudcross.ssp.model.Dimension">
		select <include refid="base_column"/> from t_rpt_adv_schema where id = #{id} 
	</select>
	
	<!-- 根据ID删除维度 -->
	<delete id="deleteDimensionById" parameterType="java.util.Map">
		delete from t_rpt_adv_schema where id in
		<foreach item="id" collection="idList" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>
	
	<!-- 根据ID修改维度 -->
	<update id="editDimension" parameterType="com.cloudcross.ssp.model.Dimension">
		update t_rpt_adv_schema set name=#{name},content=#{content} where id = #{id}
	</update>
	 
	<insert id="addDimension" parameterType="com.cloudcross.ssp.model.Dimension">
		insert into t_rpt_adv_schema(account_id,name,content,is_default)
		values(#{accountId},#{name},#{content},#{isDefault})
	</insert>
	
	<!-- 将否改为是 -->
	<update id="updateDimensionDefaulToTrue" parameterType="com.cloudcross.ssp.model.Dimension">
		update t_rpt_adv_schema set is_default=1 where id = #{id} and account_id = #{accountId};
	</update>
	
	<!-- 将是改为否 -->
	<update id="updateDimensionDefaultToFalse" parameterType="com.cloudcross.ssp.model.Dimension">
		update t_rpt_adv_schema set is_default=0 where is_default = 1 and account_id = #{accountId};
	</update>
	
	<select id="queryDimensionByNameAndAccountId" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.Dimension">
		select <include refid="base_column"/> from t_rpt_adv_schema where name = #{name} and account_id = #{accountId}
	</select>
	
	<select id="queryDimensionByContentAndAccountId" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.Dimension">
		select <include refid="base_column"/> from t_rpt_adv_schema where content = #{content} and account_id = #{accountId}
	</select>
	
	<select id="selectDimensionIdBydefault" parameterType="java.lang.Integer" resultType="java.util.Map">
		select count(id) as num,id,name from t_rpt_adv_schema where is_default=1 and account_id = #{accountId}
	</select>
	
	
	<select id="selectByName"  parameterType="string" resultType="com.cloudcross.ssp.model.Dimension">
		select <include refid="base_column" /> from t_rpt_adv_schema where name = #{name} order by id  desc
	</select>
		
</mapper>