<?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.business.mapper.ImageClassificationFileMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="imageClassificationFileResultMap" type="org.springblade.business.entity.ImageClassificationFile">
        <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="classify_id" property="classifyId"/>
        <result column="project_id" property="projectId"/>
        <result column="contract_id" property="contractId"/>
        <result column="wbs_id" property="wbsId"/>
        <result column="title" property="title"/>
        <result column="type" property="type"/>
        <result column="image_url" property="imageUrl"/>
        <result column="file_size" property="fileSize"/>
        <result column="file_name" property="fileName"/>
        <result column="shooting_user" property="shootingUser"/>
        <result column="shooting_time" property="shootingTime"/>
        <result column="upload_time" property="uploadTime"/>
        <result column="photo_code" property="photoCode"/>
        <result column="film_code" property="filmCode"/>
        <result column="see_also_code" property="seeAlsoCode"/>
        <result column="text_content" property="textContent"/>
    </resultMap>

    <select id="queryCurrentClassifyAllFileCount" resultType="java.lang.Integer">
        select count(id) from u_image_classification_file where is_deleted = 0 and classify_id = #{classifyId} and contract_id = #{contractId}
        <if test="projectId != null and projectId != ''">
            and project_id = #{projectId}
        </if>
    </select>

    <select id="selectShootingTimeByClassifyAndProjectId" resultType="java.util.Date">
        select shooting_time from u_image_classification_file where is_deleted = 0 and classify_id = #{classifyId} and project_id = #{projectId}
        <if test="contractId != null and contractId != ''">
            and contract_id = #{contractId}
        </if>
        group by shooting_time
    </select>

    <select id="selectImageClassificationFilePage" resultMap="imageClassificationFileResultMap">
        select
            files.id,
            files.title,
            files.text_content,
            files.shooting_user,
            files.shooting_time,
            files.file_size,
            files.image_url,
            files.type
        from
        (
            select
                id,
                title,
                text_content,
                shooting_user,
                shooting_time,
                file_size,
                image_url,
                type,
                date_format(shooting_time,'%Y-%m-%d') as shootingTimeStr
            from u_image_classification_file where is_deleted = 0
            and project_id = #{param.projectId} and classify_id = #{param.classifyId}
            <if test="param.contractId != null and param.contractId != ''">
                and contract_id = #{param.contractId}
            </if>
            <if test="param.queryStr != null and param.queryStr != ''">
                and (title like concat('%',#{param.queryStr},'%') OR shooting_user like concat('%',#{param.queryStr},'%'))
            </if>
            <if test="param.wbsIds != null and param.wbsIds.size != 0">
                and wbs_id in
                <foreach collection="param.wbsIds" item="webId" open="(" separator="," close=")">#{webId}</foreach>
            </if>
            order by shooting_time desc
        ) as files
        where
            1 = 1
        <if test="param.queryDate != null and param.queryDate != ''">
            and files.shootingTimeStr like concat('%',#{param.queryDate},'%')
        </if>
    </select>

</mapper>
