<?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.slodon.b2b2c.dao.write.goods.GoodsFreightTemplateWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.goods.pojo.GoodsFreightTemplate">
    <id column="freight_template_id" property="freightTemplateId" />
    <result column="template_name" property="templateName" />
    <result column="store_id" property="storeId" />
    <result column="update_time" property="updateTime" />
    <result column="deliver_time" property="deliverTime" />
    <result column="is_free" property="isFree" />
    <result column="charge_type" property="chargeType" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="templateName != null">
        `template_name`,
      </if>
      <if test="storeId != null">
        `store_id`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
      <if test="deliverTime != null">
        `deliver_time`,
      </if>
      <if test="isFree != null">
        `is_free`,
      </if>
      <if test="chargeType != null">
        `charge_type`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `freight_template_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.freightTemplateIdNotEquals != null">
          AND `freight_template_id` != #{example.freightTemplateIdNotEquals}
        </if>
        <if test="example.freightTemplateIdIn != null">
          AND `freight_template_id` in (${example.freightTemplateIdIn})
        </if>
        <if test="example.templateName != null">
          AND `template_name` = #{example.templateName}
        </if>
        <if test="example.templateNameLike != null">
          AND `template_name` like concat('%',#{example.templateNameLike},'%')
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </if>
        <if test="example.updateTimeAfter != null">
          AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
        </if>
        <if test="example.updateTimeBefore != null">
          AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
        </if>
        <if test="example.isFree != null">
          AND `is_free` = #{example.isFree}
        </if>
        <if test="example.chargeType != null">
          AND `charge_type` = #{example.chargeType}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `freight_template_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.goods.example.GoodsFreightTemplateExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `goods_freight_template`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `goods_freight_template`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `goods_freight_template`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `goods_freight_template`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `goods_freight_template`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `goods_freight_template`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `goods_freight_template`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `goods_freight_template`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="freight_template_id" keyProperty="freightTemplateId" parameterType="com.slodon.b2b2c.goods.pojo.GoodsFreightTemplate" useGeneratedKeys="true">
    INSERT INTO `goods_freight_template`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="templateName != null">
        #{templateName},
      </if>
      <if test="storeId != null">
        #{storeId},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="deliverTime != null">
        #{deliverTime},
      </if>
      <if test="isFree != null">
        #{isFree},
      </if>
      <if test="chargeType != null">
        #{chargeType},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `goods_freight_template`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.templateName != null">
        `template_name` = #{record.templateName},
      </if>
      <if test="record.storeId != null">
        `store_id` = #{record.storeId},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
      <if test="record.deliverTime != null">
        `deliver_time` = #{record.deliverTime},
      </if>
      <if test="record.isFree != null">
        `is_free` = #{record.isFree},
      </if>
      <if test="record.chargeType != null">
        `charge_type` = #{record.chargeType},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `goods_freight_template`
    <trim prefix="SET" suffixOverrides=",">
      <if test="templateName != null">
        `template_name` = #{templateName},
      </if>
      <if test="storeId != null">
        `store_id` = #{storeId},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
      <if test="deliverTime != null">
        `deliver_time` = #{deliverTime},
      </if>
      <if test="isFree != null">
        `is_free` = #{isFree},
      </if>
      <if test="chargeType != null">
        `charge_type` = #{chargeType},
      </if>
    </trim>
    WHERE `freight_template_id` = #{freightTemplateId}
  </update>
</mapper>