<?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.kmall.admin.dao.FreightItemDao">

    <resultMap type="com.kmall.admin.entity.FreightItemEntity" id="freightItemMap">
        <result property="id" column="id"/>
        <result property="freId" column="fre_id"/>
        <result property="deliveryArea" column="delivery_area"/>
        <result property="firstPiece" column="first_piece"/>
        <result property="freight" column="freight"/>
        <result property="continuePiece" column="continue_piece"/>
        <result property="renew" column="renew"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.FreightItemEntity">
		select
			`id`,
			`fre_id`,
			`delivery_area`,
			`first_piece`,
			`freight`,
			`continue_piece`,
			`renew`
		from mall_freight_item
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.FreightItemEntity">
		select
    		`id`,
    		`fre_id`,
    		`delivery_area`,
    		`first_piece`,
    		`freight`,
    		`continue_piece`,
    		`renew`
		from mall_freight_item
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<if test="freId != null and freId != ''">
			AND fre_id = #{freId}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from mall_freight_item
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
		<if test="freId != null and freId != ''">
			AND fre_id = #{freId}
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.FreightItemEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_freight_item(
			`fre_id`,
			`delivery_area`,
			`first_piece`,
			`freight`,
			`continue_piece`,
			`renew`)
		values(
			#{freId},
			#{deliveryArea},
			#{firstPiece},
			#{freight},
			#{continuePiece},
			#{renew})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.FreightItemEntity">
		update mall_freight_item 
		<set>
			<if test="freId != null">`fre_id` = #{freId}, </if>
			<if test="deliveryArea != null">`delivery_area` = #{deliveryArea}, </if>
			<if test="firstPiece != null">`first_piece` = #{firstPiece}, </if>
			<if test="freight != null">`freight` = #{freight}, </if>
			<if test="continuePiece != null">`continue_piece` = #{continuePiece}, </if>
			<if test="renew != null">`renew` = #{renew}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from mall_freight_item where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mall_freight_item where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

	<delete id="deleteByFreId">
		delete from mall_freight_item where fre_id = #{freId}
	</delete>
</mapper>