<?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.bootdo.data.dao.DataPartDao">

	<select id="get" resultType="com.bootdo.data.domain.DataPartDO">
		select `PART_ID`,`parent_id`,`PART_NAME`,`PART_DESC`,`PART_IS_MAJOR`,`order_num`,`del_flag` from tf_data_part where PART_ID = #{value}
	</select>

	<select id="list" resultType="com.bootdo.data.domain.DataPartDO">
		select `PART_ID`,`parent_id`,`PART_NAME`,`PART_DESC`,`PART_IS_MAJOR`,`order_num`,`del_flag` from tf_data_part
        <where>  
		  		  <if test="partId != null and partId != ''"> and PART_ID = #{partId} </if>
		  		  <if test="parentId != null and parentId != ''"> and parent_id = #{parentId} </if>
		  		  <if test="partName != null and partName != ''"> and PART_NAME = #{partName} </if>
		  		  <if test="partDesc != null and partDesc != ''"> and PART_DESC = #{partDesc} </if>
		  		  <if test="partIsMajor != null and partIsMajor != ''"> and PART_IS_MAJOR = #{partIsMajor} </if>
		  		  <if test="orderNum != null and orderNum != ''"> and order_num = #{orderNum} </if>
		  		  <if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag} </if>
		  		</where>
        <choose>
			<otherwise>
                order by order_num desc
			</otherwise>
        </choose>
	</select>
	
 	<select id="count" resultType="int">
		select count(*) from tf_data_part
		 <where>  
		  		  <if test="partId != null and partId != ''"> and PART_ID = #{partId} </if>
		  		  <if test="parentId != null and parentId != ''"> and parent_id = #{parentId} </if>
		  		  <if test="partName != null and partName != ''"> and PART_NAME = #{partName} </if>
		  		  <if test="partDesc != null and partDesc != ''"> and PART_DESC = #{partDesc} </if>
		  		  <if test="partIsMajor != null and partIsMajor != ''"> and PART_IS_MAJOR = #{partIsMajor} </if>
		  		  <if test="orderNum != null and orderNum != ''"> and order_num = #{orderNum} </if>
		  		  <if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag} </if>
		  		</where>
	</select>
	 
	<insert id="save" parameterType="com.bootdo.data.domain.DataPartDO" useGeneratedKeys="true" keyProperty="partId">
		insert into tf_data_part
		(
			`parent_id`, 
			`PART_NAME`, 
			`PART_DESC`, 
			`PART_IS_MAJOR`, 
			`order_num`, 
			`del_flag`
		)
		values
		(
			#{parentId}, 
			#{partName}, 
			#{partDesc}, 
			#{partIsMajor}, 
			#{orderNum}, 
			#{delFlag}
		)
	</insert>
	 
	<update id="update" parameterType="com.bootdo.data.domain.DataPartDO">
		update tf_data_part 
		<set>
			<if test="parentId != null">`parent_id` = #{parentId}, </if>
			<if test="partName != null">`PART_NAME` = #{partName}, </if>
			<if test="partDesc != null">`PART_DESC` = #{partDesc}, </if>
			<if test="partIsMajor != null">`PART_IS_MAJOR` = #{partIsMajor}, </if>
			<if test="orderNum != null">`order_num` = #{orderNum}, </if>
			<if test="delFlag != null">`del_flag` = #{delFlag}</if>
		</set>
		where PART_ID = #{partId}
	</update>
	
	<delete id="remove">
		delete from tf_data_part where PART_ID = #{value}
	</delete>
	
	<delete id="batchRemove">
		delete from tf_data_part where PART_ID in 
		<foreach item="partId" collection="array" open="(" separator="," close=")">
			#{partId}
		</foreach>
	</delete>

</mapper>