<?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.pine.admin.modules.business.dao.LogisticsTemplateDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.pine.admin.modules.business.entity.LogisticsTemplate" id="entityMap">
        <result property="id" column="id"/>
        <result property="companyId" column="company_id"/>
        <result property="name" column="name"/>
        <result property="isDefault" column="is_default"/>
        <result property="freightBear" column="freight_bear"/>
        <result property="pricintMethod" column="pricint_method"/>
        <result property="storeId" column="store_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="modifyTime" column="modify_time"/>
        <result property="delTime" column="del_time"/>
    </resultMap>

    <sql id="Base_Column_List">
                 id,
                     company_id,
                     name,
                     is_default,
                     freight_bear,
                     pricint_method,
                     store_id,
                     del_flag,
                     create_time,
                     modify_time,
                    del_time         </sql>
    <!-- 根据Id查询-->
    <select id="selectByPrimaryKey" resultMap="entityMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from ls_logistics_template
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="byId" resultMap="entityMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from ls_logistics_template
        where id = #{id,jdbcType=INTEGER}
    </select>

    <!-- 根据Id删除-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		delete from ls_logistics_template
		where id = #{id,jdbcType=INTEGER}
	</delete>

    <!-- 插入数据-->
    <insert id="insertSelective" parameterType="com.pine.admin.modules.business.entity.LogisticsTemplate"
            useGeneratedKeys="true" keyProperty="id">
        insert into ls_logistics_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="name != null">name,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="freightBear != null">freight_bear,</if>
            <if test="pricintMethod != null">pricint_method,</if>
            <if test="storeId != null">store_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="modifyTime != null">modify_time,</if>
            <if test="delTime != null">del_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="name != null">#{name},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="freightBear != null">#{freightBear},</if>
            <if test="pricintMethod != null">#{pricintMethod},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="modifyTime != null">#{modifyTime},</if>
            <if test="delTime != null">#{delTime},</if>
        </trim>
    </insert>

    <!-- 更新数据-->
    <update id="updateByPrimaryKeySelective"
            parameterType="com.pine.admin.modules.business.entity.LogisticsTemplate">
        update ls_logistics_template
        <set>
            <if test="id != null">id = #{id},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="freightBear != null">freight_bear = #{freightBear},</if>
            <if test="pricintMethod != null">pricint_method = #{pricintMethod},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
            <if test="delTime != null">del_time = #{delTime},</if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 分页查询-->
    <select id="queryByPage" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_logistics_template
        <where>
            and del_flag = 'N'
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.companyId != null and !&quot;&quot;.equals(record.companyId)">
                and company_id = #{record.companyId}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and name = #{record.name}
            </if>
            <if test="record.isDefault != null and !&quot;&quot;.equals(record.isDefault)">
                and is_default = #{record.isDefault}
            </if>
            <if test="record.freightBear != null and !&quot;&quot;.equals(record.freightBear)">
                and freight_bear = #{record.freightBear}
            </if>
            <if test="record.pricintMethod != null and !&quot;&quot;.equals(record.pricintMethod)">
                and pricint_method = #{record.pricintMethod}
            </if>
            <if test="record.storeId != null and !&quot;&quot;.equals(record.storeId)">
                and store_id = #{record.storeId}
            </if>
            <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                and del_flag = #{record.delFlag}
            </if>
            <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
                and create_time = #{record.createTime}
            </if>
            <if test="record.modifyTime != null and !&quot;&quot;.equals(record.modifyTime)">
                and modify_time = #{record.modifyTime}
            </if>
            <if test="record.delTime != null and !&quot;&quot;.equals(record.delTime)">
                and del_time = #{record.delTime}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 全部查询 -->
    <select id="queryAll" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_logistics_template
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="companyId != null and !&quot;&quot;.equals(companyId)">
                and company_id = #{companyId}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="isDefault != null and !&quot;&quot;.equals(isDefault)">
                and is_default = #{isDefault}
            </if>
            <if test="freightBear != null and !&quot;&quot;.equals(freightBear)">
                and freight_bear = #{freightBear}
            </if>
            <if test="pricintMethod != null and !&quot;&quot;.equals(pricintMethod)">
                and pricint_method = #{pricintMethod}
            </if>
            <if test="storeId != null and !&quot;&quot;.equals(storeId)">
                and store_id = #{storeId}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="modifyTime != null and !&quot;&quot;.equals(modifyTime)">
                and modify_time = #{modifyTime}
            </if>
            <if test="delTime != null and !&quot;&quot;.equals(delTime)">
                and del_time = #{delTime}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 根据条件查询一个 -->
    <select id="queryOne" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_logistics_template
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="companyId != null and !&quot;&quot;.equals(companyId)">
                and company_id = #{companyId}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="isDefault != null and !&quot;&quot;.equals(isDefault)">
                and is_default = #{isDefault}
            </if>
            <if test="freightBear != null and !&quot;&quot;.equals(freightBear)">
                and freight_bear = #{freightBear}
            </if>
            <if test="pricintMethod != null and !&quot;&quot;.equals(pricintMethod)">
                and pricint_method = #{pricintMethod}
            </if>
            <if test="storeId != null and !&quot;&quot;.equals(storeId)">
                and store_id = #{storeId}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="modifyTime != null and !&quot;&quot;.equals(modifyTime)">
                and modify_time = #{modifyTime}
            </if>
            <if test="delTime != null and !&quot;&quot;.equals(delTime)">
                and del_time = #{delTime}
            </if>
        </where>
        LIMIT 1
    </select>

    <update id="delete">
        UPDATE ls_logistics_template SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>

    <update id="deleteIds" parameterType="java.util.ArrayList">
        UPDATE ls_logistics_template SET del_flag = 'Y'
        WHERE id IN
        <foreach item='ids' collection="array" index="index" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </update>

</mapper>
