<?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.cku.oa.clubdog.dao.TcbDogChipDao">
    
	<sql id="tcbDogChipColumns">
		a.id AS "id",
		a.birth_code AS "birthCode",
		a.chip_code AS "chipCode",
		a.org_id AS "orgId",
		a.org_code AS "orgCode",
		a.operator AS "operator",
		a.price AS "price",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag"
	</sql>
	
	<sql id="tcbDogChipJoins">
	</sql>
    
	<select id="get" resultType="TcbDogChip">
		SELECT 
			<include refid="tcbDogChipColumns"/>
		FROM tcb_dog_chip a
		<include refid="tcbDogChipJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="TcbDogChip">
		SELECT 
			<include refid="tcbDogChipColumns"/>
		FROM tcb_dog_chip a
		<include refid="tcbDogChipJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="TcbDogChip">
		SELECT 
			<include refid="tcbDogChipColumns"/>
		FROM tcb_dog_chip a
		<include refid="tcbDogChipJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO tcb_dog_chip(
			id,
			birth_code,
			chip_code,
			org_id,
			org_code,
			operator,
			price,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{birthCode},
			#{chipCode},
			#{orgId},
			#{orgCode},
			#{operator},
			#{price},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE tcb_dog_chip SET 	
			birth_code = #{birthCode},
			chip_code = #{chipCode},
			org_id = #{orgId},
			org_code = #{orgCode},
			operator = #{operator},
			price = #{price},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	<update id="delete">
		UPDATE tcb_dog_chip SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
</mapper>