<?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.crm.custom.dao.mapper.GoldenGoodsMapper">

    <select id="customOrderCount" resultType="integer"
            parameterType="com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsSearchEntity">
        select count(*) from golden_goods goods
        left join golden_order_details der on goods.id = der.goods_id
        left join golden_order gor on der.serial = gor.serial
        where gor.status = 2 and der.custom_id = #{customId}
        <if test="goodsType!=null">
            and goods.`goods_type` = #{goodsType}
        </if>
    </select>

    <select id="customOrderList" resultType="com.crm.rely.backend.model.pojo.table.GoldenGoodsTable"
            parameterType="com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsSearchEntity">
        select goods.*
        from golden_goods goods
        left join golden_order_details der on goods.id = der.goods_id
        left join golden_order gor on der.serial = gor.serial
        where gor.status = 2 and der.custom_id = #{customId}
        <if test="goodsType!=null">
            and goods.`goods_type` = #{goodsType}
        </if>
        <if test="goodsIds!=null and goodsIds.size()>0">
            and goods.id in
            <foreach collection="goodsIds" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        order by der.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>


    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsSearchEntity">
        select count(*) from golden_goods
        <where>
            <if test="goodsName!=null and goodsName!=''">
                and goods_name like concat('%',#{goodsName},'%')
            </if>
            <if test="goodsType!=null">
                and `goods_type` = #{goodsType}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.model.pojo.table.GoldenGoodsTable"
            parameterType="com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsSearchEntity">
        select * from golden_goods
        <where>
            <if test="goodsName!=null and goodsName!=''">
                and goods_name like concat('%',#{goodsName},'%')
            </if>
            <if test="goodsType!=null">
                and `goods_type` = #{goodsType}
            </if>
        </where>
        order by id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper>