<?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.goafanti.common.dao.NatureOwnershipMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.NatureOwnership" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="id_number" property="idNumber" jdbcType="VARCHAR" />
    <result column="investment" property="investment" jdbcType="DECIMAL" />
    <result column="deleted_sign" property="deletedSign" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, type, name, id_number, investment, deleted_sign
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from nature_ownership
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from nature_ownership
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.NatureOwnership" >
    insert into nature_ownership (id, uid, type, 
      name, id_number, investment, 
      deleted_sign)
    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, 
      #{name,jdbcType=VARCHAR}, #{idNumber,jdbcType=VARCHAR}, #{investment,jdbcType=DECIMAL}, 
      #{deletedSign,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.NatureOwnership" >
    insert into nature_ownership
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="type != null" >
        type,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="idNumber != null" >
        id_number,
      </if>
      <if test="investment != null" >
        investment,
      </if>
      <if test="deletedSign != null" >
        deleted_sign,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="idNumber != null" >
        #{idNumber,jdbcType=VARCHAR},
      </if>
      <if test="investment != null" >
        #{investment,jdbcType=DECIMAL},
      </if>
      <if test="deletedSign != null" >
        #{deletedSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.NatureOwnership" >
    update nature_ownership
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="idNumber != null" >
        id_number = #{idNumber,jdbcType=VARCHAR},
      </if>
      <if test="investment != null" >
        investment = #{investment,jdbcType=DECIMAL},
      </if>
      <if test="deletedSign != null" >
        deleted_sign = #{deletedSign,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.NatureOwnership" >
    update nature_ownership
    set uid = #{uid,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      id_number = #{idNumber,jdbcType=VARCHAR},
      investment = #{investment,jdbcType=DECIMAL},
      deleted_sign = #{deletedSign,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="selectByUid" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from nature_ownership
    where uid = #{uid,jdbcType=VARCHAR} and deleted_sign = 0 order by investment desc
  </select>
  
  <update id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	update nature_ownership set deleted_sign = 1
  	where  id in 
	<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
		#{item}
	</foreach>
  </update>
  
  <insert id="batchInsert" parameterType="com.goafanti.common.model.NatureOwnership">
    insert into nature_ownership (id, uid, type, name, id_number, investment, deleted_sign)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (#{item.id,jdbcType=VARCHAR}, #{item.uid,jdbcType=VARCHAR}, #{item.type,jdbcType=INTEGER},
      #{item.name,jdbcType=VARCHAR}, #{item.idNumber,jdbcType=VARCHAR}, #{item.investment,jdbcType=DECIMAL},
      #{item.deletedSign,jdbcType=INTEGER})
    </foreach>
    ON DUPLICATE KEY UPDATE
	    type = values(type),
	    name = values(name),
	    id_number = values(id_number),
	    investment = values(investment),
	    deleted_sign = values(deleted_sign)
  </insert>
</mapper>