<?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.system.mapper.ServiceGoodsMapper">
    
    <resultMap type="ServiceGoods" id="ServiceGoodsResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="icon"    column="icon"    />
        <result property="imgs"    column="imgs"    />
        <result property="subTitle"    column="sub_title"    />
        <result property="info"    column="info"    />
        <result property="price"    column="price"    />
        <result property="priceZn"    column="price_zn"    />
        <result property="sales"    column="sales"    />
        <result property="stock"    column="stock"    />
        <result property="status"    column="status"    />
        <result property="description"    column="description"    />
        <result property="skuType"    column="sku_type"    />
        <result property="sku"    column="sku"    />
        <result property="latitude"    column="latitude"    />
        <result property="longitude"    column="longitude"    />
        <result property="type"    column="type"    />
        <result property="cateId"    column="cate_id"    />
        <result property="project"    column="project"    />
        <result property="sort"    column="sort"    />
        <result property="material"    column="material"    />
        <result property="postage"    column="postage"    />
        <result property="basic"    column="basic"    />
        <result property="margin"    column="margin"    />
        <result property="skillIds"    column="skill_ids"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="deletedAt"    column="deleted_at"    />
    </resultMap>

    <sql id="selectServiceGoodsVo">
        select id, title, icon, imgs, sub_title, info, price, price_zn, sales, stock, status, description, sku_type, sku, latitude, longitude, type, cate_id, project, sort, material, postage, basic, margin, skill_ids, created_at, updated_at, deleted_at from service_goods
    </sql>

    <select id="selectServiceGoodsList" parameterType="ServiceGoods" resultMap="ServiceGoodsResult">
        <include refid="selectServiceGoodsVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like '%${title}%'</if>
            <if test="subTitle != null  and subTitle != ''"> and sub_title like  '%${subTitle}%'</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="minPrice != null and maxPrice != null">
                and price BETWEEN #{maxPrice} AND #{maxPrice}
            </if>
            <if test="createdStart != null and createdEnd != null">
                and created_at BETWEEN #{createdStart} AND #{createdEnd}
            </if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="type != null "> and type = #{type}</if>

        </where>
    </select>

    <select id="selectTitlesByIds" parameterType="list" resultType="string">
        SELECT GROUP_CONCAT(title SEPARATOR '|') FROM service_goods
        WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="selectServiceGoodsById" parameterType="Long" resultMap="ServiceGoodsResult">
        <include refid="selectServiceGoodsVo"/>
        where id = #{id}
    </select>

    <insert id="insertServiceGoods" parameterType="ServiceGoods" useGeneratedKeys="true" keyProperty="id">
        insert into service_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="title != null and title != ''">title,</if>
            <if test="icon != null">icon,</if>
            <if test="imgs != null">imgs,</if>
            <if test="subTitle != null and subTitle != ''">sub_title,</if>
            <if test="info != null">info,</if>
            <if test="price != null">price,</if>
            <if test="priceZn != null">price_zn,</if>
            <if test="sales != null">sales,</if>
            <if test="stock != null">stock,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="description != null">description,</if>
            <if test="skuType != null">sku_type,</if>
            <if test="sku != null">sku,</if>
            <if test="latitude != null and latitude != ''">latitude,</if>
            <if test="longitude != null and longitude != ''">longitude,</if>
            <if test="type != null">type,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="project != null">project,</if>
            <if test="sort != null">sort,</if>
            <if test="material != null">material,</if>
            <if test="postage != null">postage,</if>
            <if test="basic != null">basic,</if>
            <if test="margin != null">margin,</if>
            <if test="skillIds != null">skill_ids,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="deletedAt != null">deleted_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="icon != null">#{icon},</if>
            <if test="imgs != null">#{imgs},</if>
            <if test="subTitle != null and subTitle != ''">#{subTitle},</if>
            <if test="info != null">#{info},</if>
            <if test="price != null">#{price},</if>
            <if test="priceZn != null">#{priceZn},</if>
            <if test="sales != null">#{sales},</if>
            <if test="stock != null">#{stock},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="description != null">#{description},</if>
            <if test="skuType != null">#{skuType},</if>
            <if test="sku != null">#{sku},</if>
            <if test="latitude != null and latitude != ''">#{latitude},</if>
            <if test="longitude != null and longitude != ''">#{longitude},</if>
            <if test="type != null">#{type},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="project != null">#{project},</if>
            <if test="sort != null">#{sort},</if>
            <if test="material != null">#{material},</if>
            <if test="postage != null">#{postage},</if>
            <if test="basic != null">#{basic},</if>
            <if test="margin != null">#{margin},</if>
            <if test="skillIds != null">#{skillIds},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="deletedAt != null">#{deletedAt},</if>
         </trim>
    </insert>

    <update id="updateServiceGoods" parameterType="ServiceGoods">
        update service_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="icon != null">icon = #{icon},</if>
            <if test="imgs != null">imgs = #{imgs},</if>
            <if test="subTitle != null and subTitle != ''">sub_title = #{subTitle},</if>
            <if test="info != null">info = #{info},</if>
            <if test="price != null">price = #{price},</if>
            <if test="priceZn != null">price_zn = #{priceZn},</if>
            <if test="sales != null">sales = #{sales},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="description != null">description = #{description},</if>
            <if test="skuType != null">sku_type = #{skuType},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="latitude != null and latitude != ''">latitude = #{latitude},</if>
            <if test="longitude != null and longitude != ''">longitude = #{longitude},</if>
            <if test="type != null">type = #{type},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="project != null">project = #{project},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="material != null">material = #{material},</if>
            <if test="postage != null">postage = #{postage},</if>
            <if test="basic != null">basic = #{basic},</if>
            <if test="margin != null">margin = #{margin},</if>
            <if test="skillIds != null">skill_ids = #{skillIds},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="deletedAt != null">deleted_at = #{deletedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteServiceGoodsById" parameterType="Long">
        delete from service_goods where id = #{id}
    </delete>

    <delete id="deleteServiceGoodsByIds" parameterType="String">
        delete from service_goods where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>