<?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="cn.com.countrygarden.bi.main.dao.advise.AfAdviseTypeMapper">
	<!-- 通用查询映射结果 -->
	<resultMap id="BaseResultMap"
		type="cn.com.countrygarden.bi.main.model.advise.AfAdviseType">
		<id column="id" property="id" />
		<result column="code" property="code" />
		<result column="name" property="name" />
		<result column="descs" property="descs" />
		<result column="soft" property="soft" />
		<result column="enable" property="enable" />
		<result column="create_time" property="createTime" />
		<result column="create_by" property="createBy" />
		<result column="update_time" property="updateTime" />
		<result column="update_by" property="updateBy" />
		<result column="branch_type_code" property="branchTypeCode" />
	</resultMap>

	<select id="queryList"
		resultType="cn.com.countrygarden.bi.main.dto.advise.AfAdviseTypeVO">
		SELECT DISTINCT
		id id,
		CODE CODE,
		NAME NAME,
		descs descs,
		soft soft,
		ENABLE ENABLE,
		branch_type_code branchTypeCode
		FROM
		af_advise_type WHERE ENABLE = 1 AND  branch_type_code=#{adviseTypeParam.branchTypeCode}
		<if test="adviseTypeParam!=null">
			<if test="adviseTypeParam.name!=null and adviseTypeParam.name!=''">
				AND name LIKE
				concat('%',#{adviseTypeParam.name},'%')
			</if>
		</if>
	</select>
	<select id="queryAllList"
			resultType="cn.com.countrygarden.bi.main.dto.advise.AfAdviseTypeVO">

	SELECT
	AT .id id,
	AT . CODE CODE,
	AT . NAME NAME,
	AT .descs descs,
	AT .soft soft,
	AT . ENABLE ENABLE,
	AT.branch_type_code branchTypeCode,
	(
		SELECT
			COUNT(aaf.advise_type_id)
		FROM
			af_advise_feedback aaf,
			af_advise_responsibler aar
		WHERE
			aaf.advise_type_id = `AT`.id
		AND aaf.advise_type_id = aar.advise_type_id
	) adviseTypeCount
FROM
	af_advise_type AT   where  AT.branch_type_code=#{adviseTypeParam.branchTypeCode}

	</select>
</mapper>