<?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="org.springblade.modules.guosen.userGoods.mapper.UserGoodsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userGoodsResultMap" type="org.springblade.modules.guosen.userGoods.entity.UserGoods">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="user_id" property="userId"/>
        <result column="present_id" property="presentId"/>
        <result column="goods_status" property="goodsStatus"/>
    </resultMap>


    <select id="selectUserGoodsPage" resultMap="userGoodsResultMap">
        select * from cyzh_user_goods where is_deleted = 0
    </select>

    <select id="getMyGoods"  resultType="org.springblade.modules.guosen.userGoods.vo.UserGoodsVO">
         SELECT COUNT(1) as count,a.*,GROUP_CONCAT(a.id) as userGoodsIds,b.goods_name,b.goods_pic,
         b.goods_post_amount as goodsPostAmount,b.donate_medal_id
         FROM cyzh_user_goods as a
         LEFT JOIN cyzh_present as b on a.present_id=b.id
         WHERE a.is_deleted=0 and a.user_id=#{userGoods.userId}
        <if test="userGoods.goodsStatus != null and userGoods.goodsStatus != ''">
            AND a.goods_status=#{userGoods.goodsStatus}
        </if>
        <if test="userGoods.presentId != null and userGoods.presentId != ''">
            AND a.present_id=#{userGoods.presentId}
        </if>
         GROUP BY a.present_id,a.goods_status
    </select>

</mapper>
