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

    <select id="selectVisibleByGoodsId" resultType="com.ruoyi.web.modules.goods.vo.GoodsServiceSnapshotVO">
        select s.service_id as serviceId, s.service_name as serviceName, s.service_intro as serviceIntro,
               s.service_icon as serviceIcon, s.sort_no as sortNo
        from biz_goods_service_snapshot s
        left join biz_goods_service gs on s.service_id = gs.service_id
        where s.goods_id = #{goodsId}
          and (gs.service_id is null or gs.del_flag = '0')
        order by s.sort_no asc, s.snapshot_id asc
    </select>

    <delete id="deleteByGoodsId">
        delete from biz_goods_service_snapshot where goods_id = #{goodsId}
    </delete>

    <insert id="batchInsert">
        insert into biz_goods_service_snapshot (
            goods_id, service_id, service_name, service_intro, service_icon, sort_no
        ) values
        <foreach collection="list" item="item" separator=",">
            (#{item.goodsId}, #{item.serviceId}, #{item.serviceName}, #{item.serviceIntro},
             #{item.serviceIcon}, #{item.sortNo})
        </foreach>
    </insert>

    <select id="existsGoodsRef" resultType="int">
        select count(1)
        from biz_goods_service_snapshot s
        inner join biz_goods g on g.goods_id = s.goods_id and g.del_flag = '0'
        where s.service_id = #{serviceId}
        limit 1
    </select>
</mapper>
