<?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.ghy.goods.mapper.GoodsAreaMapper">

    <resultMap id="GoodsAreaResult" type="com.ghy.goods.domain.GoodsArea">
        <result property="goodsAreaId"         column="goods_area_id" />
        <result property="goodsId"             column="goods_id"      />
        <result property="countryAreaId"       column="country_area_id"/>
        <result property="areaName"            column="area_name"/>
    </resultMap>

    <sql id="selectGoodsArea">
        SELECT ga.goods_area_id, ga.goods_id, ga.country_area_id, sa.area_name
        FROM goods_area ga
        LEFT JOIN sys_area sa on ga.country_area_id = sa.area_id
    </sql>

    <select id="selectByGoodsId" resultMap="GoodsAreaResult">
        <include refid="selectGoodsArea"/>
        <where>
            <if test="goodsId != null and goodsId != 0">
                AND goods_id = #{goodsId}
            </if>
        </where>
    </select>

    <insert id="batchInsert" parameterType="list" >
        INSERT INTO goods_area ( goods_id,country_area_id)
        VALUES
        <foreach collection="areas" separator=","  item="area">
            (#{area.goodsId},#{area.countryAreaId})
        </foreach>
    </insert>


</mapper>