<?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.th.demo.mapping.ware.DistributionDetailMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.ware.DistributionDetail" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="distribution_id" property="distributionId" jdbcType="VARCHAR" />
    <result column="add_id" property="addId" jdbcType="VARCHAR" />
    <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
    <result column="modify_id" property="modifyId" jdbcType="VARCHAR" />
    <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="cancel_id" property="cancelId" jdbcType="VARCHAR" />
    <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="belong_id" property="belongId" jdbcType="VARCHAR" />

    <association  column="store_id" property="store" select="com.th.demo.mapping.ware.StoreMapper.selectByPrimaryKey" />

  </resultMap>
  <sql id="Base_Column_List" >
    id, distribution_id, store_id,
      add_id, add_time, modify_id, modify_time, cancel_id, cancel_time, cancel_flag, belong_id
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_ware_distribution_detail
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_ware_distribution_detail
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.ware.DistributionDetail" >

    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
      SELECT  REPLACE(UUID(),'-','') as id from dual
    </selectKey>


    insert into t_ware_distribution_detail (id, distribution_id, store_id,
    add_id, add_time, modify_id, modify_time, cancel_id, cancel_time, cancel_flag, belong_id
    )
    values (#{id,jdbcType=VARCHAR}, #{distributionId,jdbcType=VARCHAR}, #{store.id,jdbcType=VARCHAR}
    , #{addId,jdbcType=VARCHAR},
    #{addTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
    #{cancelId,jdbcType=VARCHAR}, #{cancelTime,jdbcType=TIMESTAMP}, #{cancelFlag,jdbcType=VARCHAR},
    #{belongId,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.ware.DistributionDetail" >
    insert into t_ware_distribution_detail
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="distributionId != null" >
        distribution_id,
      </if>
      <if test="storeId != null" >
        store_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="distributionId != null" >
        #{distributionId,jdbcType=VARCHAR},
      </if>
      <if test="storeId != null" >
        #{storeId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.ware.DistributionDetail" >
    update t_ware_distribution_detail
    <set >
      <if test="distributionId != null" >
        distribution_id = #{distributionId,jdbcType=VARCHAR},
      </if>
      <if test="storeId != null" >
        store_id = #{storeId,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.DistributionDetail" >
    update t_ware_distribution_detail
    set distribution_id = #{distributionId,jdbcType=VARCHAR},
      store_id = #{store.id,jdbcType=VARCHAR},
         add_id = #{addId,jdbcType=VARCHAR},
      add_time = #{addTime,jdbcType=TIMESTAMP},
      modify_id = #{modifyId,jdbcType=VARCHAR},
      modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      cancel_id = #{cancelId,jdbcType=VARCHAR},
      cancel_time = #{cancelTime,jdbcType=TIMESTAMP},
      cancel_flag = #{cancelFlag,jdbcType=VARCHAR},
      belong_id = #{belongId,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>


  <select id="selectByFid" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_ware_distribution_detail
    where distribution_id = #{param1,jdbcType=VARCHAR}
    and ifnull(cancel_flag,'0') = '0'
  </select>

  <select id="selectByFidDist" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_ware_distribution_detail
    where distribution_id = #{param1,jdbcType=VARCHAR}
    and ifnull(cancel_flag,'0') = '0'
  </select>

  <select id="selectByStoreId" resultMap="BaseResultMap">
    select *
    from t_ware_distribution_detail
    where store_id = #{param1,jdbcType=VARCHAR}
    and ifnull(cancel_flag,'0') = '0'
  </select>

</mapper>