<?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.fzm.mall.server.admin.distribution.mapper.TemplateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.distribution.model.Template">
        <id column="id" property="id" />
        <result column="template_name" property="templateName" />
        <result column="template_id" property="templateId" />
        <result column="delivery_address_id" property="deliveryAddressId" />
        <result column="billing_type" property="billingType" />
        <result column="freight_amount" property="freightAmount" />
        <result column="pricing_type" property="pricingType" />
        <result column="base_number" property="baseNumber" />
        <result column="base_amount" property="baseAmount" />
        <result column="add_number" property="addNumber" />
        <result column="add_cost" property="addCost" />
        <result column="merchant_id" property="merchantId" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <select id="read" resultMap="BaseResultMap">
        select t.id, t.template_id, t.template_name, t.delivery_address_id, t.billing_type, t.freight_amount, t.pricing_type,
               t.base_number, t.base_amount, t.add_number, t.add_cost, t.merchant_id, t.create_time, t.update_time,
               a.address_name as deliveryAddressName
        from distribution_template t
        left join distribution_address a on t.delivery_address_id = a.address_id and t.merchant_id = a.merchant_id
        where t.template_id = #{templateId} and t.merchant_id = #{merchantId}
        order by t.create_time desc
    </select>

    <select id="list" resultMap="BaseResultMap">
        select t.id, t.template_id, t.template_name, t.delivery_address_id, t.billing_type, t.freight_amount, t.pricing_type,
               t.base_number, t.base_amount, t.add_number, t.add_cost, t.merchant_id, t.create_time, t.update_time,
               a.address_name as deliveryAddressName
        from distribution_template t
        left join distribution_address a on t.delivery_address_id = a.address_id and t.merchant_id = a.merchant_id
        where t.merchant_id = #{merchantId}
        order by t.create_time desc
    </select>
</mapper>
