<?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="cn.com.xingxi.store.data.mapper.WxaStoreUserProdMapper">

    <resultMap id="selectUserProdListByUpIdResult" type="UserProdDTO">
        <result property="id" column="id"/>
        <result property="userId" column="userId"/>
        <result property="upId" column="upId"/>
        <result property="mercId" column="mercId"/>
        <result property="prodId" column="prodId"/>
        <result property="pprId" column="pprId"/>
        <result property="surfaceSeq" column="surfaceSeq"/>
        <result property="mateContent" column="mateContent"/>
        <result property="resultImgId" column="resultImgId"/>
        <result property="printImgId" column="printImgId"/>
        <result property="delFlag" column="delFlag"/>
        <result property="createUser" column="createUser"/>
        <result property="createTime" column="createTime"/>
        <result property="updateUser" column="updateUser"/>
        <result property="updateTime" column="updateTime"/>
        <collection property="userProdDetails" select="selectUserProdDetailListByUpId" column="upId=upId,surfaceSeq=surfaceSeq"/>
    </resultMap>

    <resultMap id="selectUserProdDetailListByUserIdResult" type="UserProdDTO">
        <result property="id" column="id"/>
        <result property="userId" column="userId"/>
        <result property="upId" column="upId"/>
        <result property="mercId" column="mercId"/>
        <result property="prodId" column="prodId"/>
        <result property="prodName" column="prodName"/>
        <result property="pprId" column="pprId"/>
        <result property="surfaceSeq" column="surfaceSeq"/>
        <result property="mateContent" column="mateContent"/>
        <result property="resultImgId" column="resultImgId"/>
        <result property="printImgId" column="printImgId"/>
        <result property="delFlag" column="delFlag"/>
        <result property="createUser" column="createUser"/>
        <result property="createTime" column="createTime"/>
        <result property="updateUser" column="updateUser"/>
        <result property="updateTime" column="updateTime"/>
        <collection property="userProdDTOS" select="selectUserProdImageListByUpId" column="upId=upId"/>
    </resultMap>


    <resultMap id="selectUserProdImageListByUpIdResult" type="UserProdDTO">
        <id property="id" column="id"/>
        <result property="userId" column="userId"/>
        <result property="upId" column="upId"/>
        <result property="mercId" column="mercId"/>
        <result property="prodId" column="prodId"/>
        <result property="prodName" column="prodName"/>
        <result property="pprId" column="pprId"/>
        <result property="surfaceSeq" column="surfaceSeq"/>
        <result property="resultImgId" column="resultImgId"/>
        <result property="surfaceSeq" column="surfaceSeq"/>
        <association property="imageDTO" javaType="ImageDTO">
            <id property="imageId" column="fileId"/>
            <result property="imageUrl" column="fileUrl"/>
        </association>
    </resultMap>



    <select id="selectUserProdListByUpId" parameterType="String" resultMap="selectUserProdListByUpIdResult">
        SELECT t_user_prod.*
        FROM t_user_prod
        WHERE t_user_prod.delFlag = '0'
          AND t_user_prod.upId = #{resourceId}
    </select>

    <select id="selectUserProdDetailListByUpId" resultMap="cn.com.wingxi.xingxi.system.customer.mapper.UserProdDetailMapper.UserProdDetailResult">
        SELECT t_user_prod_detail.*
        FROM t_user_prod_detail
        WHERE t_user_prod_detail.upId = #{upId}
          AND t_user_prod_detail.surfaceSeq = #{surfaceSeq}
    </select>


    <select id="selectUserProdImageListByUpId"  resultMap="selectUserProdImageListByUpIdResult">
        SELECT t_user_prod.*,t_attch_file.fileId, t_attch_file.fileUrl
        FROM t_user_prod
        INNER JOIN t_attch_file ON t_user_prod.resultImgId = t_attch_file.fileId
        WHERE t_user_prod.upId = #{upId}
    </select>

    <select id="selectUserProdDetailListByUserId" resultMap="selectUserProdDetailListByUserIdResult">
        SELECT  t_user_prod.upId,t_user_prod.userId,t_user_prod.mercId,
                t_user_prod.prodId,t_user_prod.prodName,t_user_prod.pprid,
                t_user_prod.createTime,t_user_prod.mateContent
        FROM t_user_prod
        WHERE t_user_prod.delFlag = '0'
          AND t_user_prod.mercId = #{mercId}
          AND t_user_prod.userId = #{userId}
        GROUP BY t_user_prod.upId
        ORDER BY t_user_prod.createTime desc
    </select>




</mapper>
