<?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.ruoyi.file.mapper.FilesAchievementMapper">
    
    <resultMap type="FilesAchievement" id="FilesAchievementResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
        <result property="achiName"    column="achi_name"    />
        <result property="dataYear"    column="data_year"    />
        <result property="scaleGrade"    column="scale_grade"    />
        <result property="resultType"    column="result_type"    />
        <result property="fileType"    column="file_type"    />
        <result property="kmlUrl"    column="kml_url"    />
        <result property="kmlLng"    column="kml_lng"    />
        <result property="kmlLat"    column="kml_lat"    />
        <result property="workLoad"    column="work_load"    />
        <result property="unit"    column="unit"    />
        <result property="dataSource"    column="data_source"    />
        <result property="dataType"    column="data_type"    />
        <result property="storageId"    column="storage_id"    />
        <result property="storageAddress"    column="storage_address"    />
        <result property="remark"    column="remark"    />
        <result property="submitDate"    column="submit_date"    />
        <result property="productionTime"    column="production_time"    />
        <result property="resolution"    column="resolution"    />
        <result property="geodeticDatum"    column="geodetic_datum"    />
    </resultMap>

    <sql id="selectFilesAchievementVo">
        select id, project_id, achi_name, data_year, scale_grade, result_type, file_type, kml_url, kml_lng, kml_lat, work_load, unit, data_source, data_type, storage_id, remark, submit_date, production_time, resolution, geodetic_datum from files_achievement
    </sql>

    <sql id="Base_Column_List" >
        a.id, a.project_id, p.project_number, p.project_name, a.achi_name, a.data_year, a.scale_grade, a.result_type, a.file_type, a.kml_url, a.kml_lng, a.kml_lat, a.work_load, a.unit, a.data_source, a.data_type, a.storage_id, s.storage_address, a.remark, a.submit_date, a.production_time, a.resolution, a.geodetic_datum
    </sql>

    <sql id="selectFilesAchievementAllVo">
        select <include refid="Base_Column_List"/> from files_achievement a
        left join files_storage s on a.storage_id = s.id
        left join cmc_project p on a.project_id = p.project_id
    </sql>

    <select id="selectFilesAchievementList" parameterType="FilesAchievement" resultMap="FilesAchievementResult">
        <include refid="selectFilesAchievementAllVo"/>
        <where>  
            <if test="projectId != null  and projectId != ''"> and a.project_id = #{projectId}</if>
            <if test="projectNumber != null  and projectNumber != ''"> and p.project_number like concat('%', #{projectNumber}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and p.project_name like concat('%', #{projectName}, '%')</if>
            <if test="achiName != null  and achiName != ''"> and a.achi_name like concat('%', #{achiName}, '%')</if>
            <if test="dataYear != null  and dataYear != ''"> and a.data_year like concat('%', #{dataYear}, '%')</if>
            <if test="scaleGrade != null  and scaleGrade != ''"> and a.scale_grade like concat('%', #{scaleGrade}, '%')</if>
            <if test="resultType != null  and resultType != ''"> and a.result_type like concat('%', #{resultType}, '%')</if>
            <if test="fileType != null  and fileType != ''"> and a.file_type like concat('%', #{fileType}, '%')</if>
            <if test="kmlUrl != null  and kmlUrl != ''"> and a.kml_url like concat('%', #{kmlUrl}, '%')</if>
            <if test="kmlLng != null  and kmlLng != ''"> and a.kml_lng like concat('%', #{kmlLng}, '%')</if>
            <if test="kmlLat != null  and kmlLat != ''"> and a.kml_lat like concat('%', #{kmlLat}, '%')</if>
            <if test="workLoad != null  and workLoad != ''"> and a.work_load = #{workLoad}</if>
            <if test="unit != null  and unit != ''"> and a.unit = #{unit}</if>
            <if test="dataSource != null  and dataSource != ''"> and a.data_source like concat('%', #{dataSource}, '%')</if>
            <if test="dataType != null  and dataType != ''"> and a.data_type like concat('%', #{dataType}, '%')</if>
            <if test="storageId != null  and storageId != ''"> and a.storage_id like concat('%', #{storageId}, '%')</if>
            <if test="submitDate != null  and submitDate != ''"> and a.submit_date like concat('%', #{submitDate}, '%')</if>
            <if test="productionTime != null"> and a.production_time like concat('%', #{productionTime}, '%')</if>
            <if test="resolution != null  and resolution != ''"> and a.resolution like concat('%', #{resolution}, '%')</if>
            <if test="geodeticDatum != null  and geodeticDatum != ''"> and a.geodetic_datum like concat('%', #{geodeticDatum}, '%')</if>
        </where>
        order by p.project_number desc
    </select>
    
    <select id="selectFilesAchievementById" parameterType="String" resultMap="FilesAchievementResult">
        <include refid="selectFilesAchievementAllVo"/>
        where a.id = #{id}
    </select>
    <insert id="insertFilesAchievement" parameterType="FilesAchievement">
        insert into files_achievement
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="achiName != null">achi_name,</if>
            <if test="dataYear != null">data_year,</if>
            <if test="scaleGrade != null">scale_grade,</if>
            <if test="resultType != null">result_type,</if>
            <if test="fileType != null">file_type,</if>
            <if test="kmlUrl != null">kml_url,</if>
            <if test="kmlLng != null">kml_lng,</if>
            <if test="kmlLat != null">kml_lat,</if>
            <if test="workLoad != null">work_load,</if>
            <if test="unit != null">unit,</if>
            <if test="dataSource != null">data_source,</if>
            <if test="dataType != null">data_type,</if>
            <if test="storageId != null">storage_id,</if>
            <if test="remark != null">remark,</if>
            <if test="submitDate != null">submit_date,</if>
            <if test="productionTime != null">production_time,</if>
            <if test="resolution != null">resolution,</if>
            <if test="geodeticDatum != null">geodetic_datum,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="achiName != null">#{achiName},</if>
            <if test="dataYear != null">#{dataYear},</if>
            <if test="scaleGrade != null">#{scaleGrade},</if>
            <if test="resultType != null">#{resultType},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="kmlUrl != null">#{kmlUrl},</if>
            <if test="kmlLng != null">#{kmlLng},</if>
            <if test="kmlLat != null">#{kmlLat},</if>
            <if test="workLoad != null">#{workLoad},</if>
            <if test="unit != null">#{unit},</if>
            <if test="dataSource != null">#{dataSource},</if>
            <if test="dataType != null">#{dataType},</if>
            <if test="storageId != null">#{storageId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="submitDate != null">#{submitDate},</if>
            <if test="productionTime != null">#{productionTime},</if>
            <if test="resolution != null">#{resolution},</if>
            <if test="geodeticDatum != null">#{geodeticDatum},</if>
         </trim>
    </insert>

    <update id="updateFilesAchievement" parameterType="FilesAchievement">
        update files_achievement
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="achiName != null">achi_name = #{achiName},</if>
            <if test="dataYear != null">data_year = #{dataYear},</if>
            <if test="scaleGrade != null">scale_grade = #{scaleGrade},</if>
            <if test="resultType != null">result_type = #{resultType},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="kmlUrl != null">kml_url = #{kmlUrl},</if>
            <if test="kmlLng != null">kml_lng = #{kmlLng},</if>
            <if test="kmlLat != null">kml_lat = #{kmlLat},</if>
            <if test="workLoad != null">work_load = #{workLoad},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="dataSource != null">data_source = #{dataSource},</if>
            <if test="dataType != null">data_type = #{dataType},</if>
            <if test="storageId != null">storage_id = #{storageId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="submitDate != null">submit_date = #{submitDate},</if>
            <if test="productionTime != null">production_time = #{productionTime},</if>
            <if test="resolution != null">resolution = #{resolution},</if>
            <if test="resolution != null">resolution = #{resolution},</if>
            <if test="geodeticDatum != null">geodetic_datum = #{geodeticDatum},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFilesAchievementById" parameterType="String">
        delete from files_achievement where id = #{id}
    </delete>

    <delete id="deleteFilesAchievementByProjectIds" parameterType="String">
        delete from files_achievement where project_id  in
        <foreach item="projectId" collection="array" open="(" separator="," close=")">
            #{projectId}
        </foreach>
    </delete>

    <delete id="deleteFilesAchievementByIds" parameterType="String">
        delete from files_achievement where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>