<?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.caimei.www.mapper.DocumentAuthDao">
    <select id="findOssAuthorizationByMobile" resultType="com.caimei.www.pojo.document.OssAuthorization">
        SELECT * FROM cm_oss_authorization WHERE mobile = #{mobile}
    </select>

    <select id="findOssArchive" resultType="com.caimei.www.pojo.document.OssArchive">
        SELECT
          coa.*,
          p.name AS productName,
          p.mainImage AS mainImage,
          s.name AS shopName
        FROM
          cm_oss_archive coa
          LEFT JOIN product p ON coa.productId = p.productID
          LEFT JOIN shop s ON p.shopID = s.shopID
          <if test="name != null and name != ''">
              WHERE (coa.name LIKE CONCAT('%',#{name},'%')
               OR p.name LIKE CONCAT('%',#{name},'%')
               OR s.name LIKE CONCAT('%',#{name},'%'))
          </if>
        ORDER BY
          coa.updateDate DESC
    </select>

    <select id="findOssArchivePdf" resultType="com.caimei.www.pojo.document.OssArchivePdf">
        SELECT * FROM cm_oss_archive_pdf WHERE archiveId = #{archiveId} ORDER BY uploadTime DESC
    </select>

    <select id="findOssArchivePdfById" resultType="com.caimei.www.pojo.document.OssArchivePdf">
        SELECT * FROM cm_oss_archive_pdf WHERE id = #{pdfId}
    </select>

    <select id="getOssArchive" resultType="com.caimei.www.pojo.document.OssArchive">
        SELECT
          coa.*,
          p.name AS productName,
          p.mainImage AS mainImage,
          s.name AS shopName
        FROM
          cm_oss_archive coa
          LEFT JOIN product p ON coa.productId = p.productID
          LEFT JOIN shop s ON p.shopID = s.shopID
        WHERE
          coa.id = #{archiveId}
    </select>

</mapper>