<?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.ejweb.modules.report.dao.CtBbtcRegionDao">
    
	<sql id="ctBbtcRegionColumns">
		a.id AS "id",
		a.fnumber AS "number",
		a.name AS "name",
		a.supplement_group AS "group",
		b.label AS "groupName"
	</sql>
	
	<sql id="ctBbtcRegionJoins">
		LEFT JOIN ct_bbtc_sys_dict b on b.id = a.supplement_group
	</sql>
    
	<select id="get" resultType="CtBbtcRegion">
		SELECT 
			<include refid="ctBbtcRegionColumns"/>
		FROM ct_bbtc_region a
		<include refid="ctBbtcRegionJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByGroupId" resultType="CtBbtcRegion">
		SELECT
		<include refid="ctBbtcRegionColumns"/>
		FROM ct_bbtc_region a
		<include refid="ctBbtcRegionJoins"/>
		WHERE a.supplement_group = #{groupId}

	</select>

	<select id="findList" resultType="CtBbtcRegion">
		SELECT 
			<include refid="ctBbtcRegionColumns"/>
		FROM ct_bbtc_region a
		<include refid="ctBbtcRegionJoins"/>
		<where>
			
			<if test="name != null and name != ''">
				AND a.name LIKE 
					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="group != null and group != ''">
				AND a.supplement_group = #{group}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
			</otherwise>
		</choose>
	</select>


	
	<select id="findAllList" resultType="CtBbtcRegion">
		SELECT 
			<include refid="ctBbtcRegionColumns"/>
		FROM ct_bbtc_region a
		<include refid="ctBbtcRegionJoins"/>
		<where>
			
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO ct_bbtc_region(
			id,
			fnumber,
			name,
			supplement_group
		) VALUES (
			#{id},
			#{number},
			#{name},
			#{group}
		)
	</insert>
	
	<update id="update">
		UPDATE ct_bbtc_region SET 	
			fnumber = #{number},
			name = #{name},
			supplement_group = #{group}
		WHERE id = #{id}
	</update>
	
	<update id="delete">
		DELETE FROM ct_bbtc_region
		WHERE id = #{id}
	</update>
	
</mapper>