<?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.youlai.boot.system.mapper.OMRecordMapper">

    <!-- 获取运维管理分页列表 -->
    <select id="getOMRecordPage" resultType="com.youlai.boot.system.model.vo.OMRecordVO">
        SELECT
                id,
                project_name,
                operation_staff,
                update_date,
                frontend_version,
                backend_version,
                update_description,
                create_time,
                update_time,
        (
        (project_name IS NULL OR project_name = '') +
        (operation_staff IS NULL OR operation_staff = '') +
        (update_date IS NULL) +
        (frontend_version IS NULL OR frontend_version = '') +
        (backend_version IS NULL OR backend_version = '') +
        (update_description IS NULL OR update_description = '')
        ) AS empty_field_count
        FROM
            om_record
        <where>
            <if test="queryParams.subIds != null and queryParams.subIds.size() > 0">
                AND folder_id IN
                <foreach collection="queryParams.subIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="queryParams.projectName != null and queryParams.projectName != ''">
                AND project_name LIKE CONCAT('%', #{queryParams.projectName}, '%')
            </if>
            <if test="queryParams.operationStaff != null and queryParams.operationStaff != ''">
                AND operation_staff LIKE CONCAT('%', #{queryParams.operationStaff}, '%')
            </if>
            <if test="queryParams.updateDateRange != null and queryParams.updateDateRange.length == 2">
                and update_date &gt;= #{queryParams.updateDateRange[0]}
                and update_date &lt;= #{queryParams.updateDateRange[1]}
            </if>
        </where>
        ORDER BY
        -- 未填写项越多越靠前
        empty_field_count DESC,
        -- 全部填写完成的按更新日期由近到远排列
        update_date DESC,
        create_time DESC;
    </select>

</mapper>
