<?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.ruoyi.web.modules.freight.mapper.BizShopFreightTemplateRegionMapper">

    <resultMap id="BizShopFreightTemplateRegionResult" type="com.ruoyi.web.modules.freight.domain.BizShopFreightTemplateRegion">
        <id property="regionRuleId" column="region_rule_id"/>
        <result property="templateId" column="template_id"/>
        <result property="provinceIds" column="province_ids"/>
        <result property="provinceNames" column="province_names"/>
        <result property="firstUnit" column="first_unit"/>
        <result property="firstFee" column="first_fee"/>
        <result property="addUnit" column="add_unit"/>
        <result property="addFee" column="add_fee"/>
        <result property="freeThreshold" column="free_threshold"/>
        <result property="sortNo" column="sort_no"/>
    </resultMap>

    <select id="selectByTemplateId" resultMap="BizShopFreightTemplateRegionResult">
        select region_rule_id, template_id, province_ids, province_names,
               first_unit, first_fee, add_unit, add_fee, free_threshold, sort_no
        from biz_shop_freight_template_region
        where template_id = #{templateId}
        order by sort_no asc, region_rule_id asc
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="regionRuleId">
        insert into biz_shop_freight_template_region (
            template_id, province_ids, province_names,
            first_unit, first_fee, add_unit, add_fee, free_threshold, sort_no
        ) values (
            #{templateId}, #{provinceIds}, #{provinceNames},
            #{firstUnit}, #{firstFee}, #{addUnit}, #{addFee}, #{freeThreshold}, #{sortNo}
        )
    </insert>

    <delete id="deleteByTemplateId">
        delete from biz_shop_freight_template_region where template_id = #{templateId}
    </delete>

</mapper>
