<?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.casic.missiles.mapper.equipment.EquipmentAcceptanceCheckMapper">

    <sql id="acceptanceCheck">
        SELECT
            ea.id,
            ea.apply_no,
            ea.apply_type,
            ea.approval_status,
            ea.apply_name,
            cea.apply_no AS checkApplyNo,
            cea.apply_name AS checkApplyName,
            DATE_FORMAT( ea.time, '%Y-%m-%d %H:%i' ) AS checkDate,
            ea.overhaul_person,
            ea.apply_desc,
            ea.process_id,
            ea.process_result,
            ea.remark,
            ea.acceptance_check_id AS acceptanceCheckId
        FROM
            equipment_apply ea
                LEFT JOIN equipment_apply cea ON ea.acceptance_check_id = cea.id
        WHERE
        ea.is_del = 0
    </sql>
    <select id="acceptanceCheckList" resultType="com.casic.missiles.dto.equipment.AcceptanceCheck">
        <include refid="acceptanceCheck"/>
        <if test="request.applyNo != null and request.applyNo !=''">
            and ea.apply_no like concat('%', #{request.applyNo}, '%')
        </if>
        <if test="request.applyName != null and request.applyName !=''">
            and ea.apply_name like concat('%', #{request.applyName}, '%')
        </if>
        <if test="request.checkApplyNo != null and request.checkApplyNo !=''">
            and cea.apply_no like concat('%', #{request.checkApplyNo}, '%')
        </if>
        <if test="request.overhaulPerson != null and request.overhaulPerson !=''">
            and ea.overhaul_person = #{request.overhaulPerson}
        </if>
        <if test="request.approvalStatus != null and request.approvalStatus !='' and request.approvalStatus != 0">
            and ea.approval_status = #{request.approvalStatus}
        </if>
        <if test="request.checkStartDate != null and request.checkStartDate !=''">
            and DATE_FORMAT( ea.time, '%Y-%m-%d' ) &gt;= #{request.checkStartDate}
        </if>
        <if test="request.checkEndDate != null and request.checkEndDate !=''">
            and DATE_FORMAT( ea.time, '%Y-%m-%d' ) &lt;= #{request.checkEndDate}
        </if>
        <if test="request.applyType != null and request.applyType !=''">
            and ea.apply_type = #{request.applyType}
        </if>
        <if test="request.businessKeys != null and request.businessKeys.size() > 0">
            and ea.id in
            <foreach collection='request.businessKeys' item='id' open='(' separator=',' close=')'>
                #{id}
            </foreach>
        </if>
        <if test="request.ids != null and request.ids.size() > 0">
            and ea.id in
            <foreach collection='request.ids' item='id' open='(' separator=',' close=')'>
                #{id}
            </foreach>
        </if>
        ORDER BY ea.create_time DESC
    </select>

    <select id="acceptanceCheckInfo" resultType="com.casic.missiles.dto.equipment.AcceptanceCheck">
        <include refid="acceptanceCheck"/>
        and ea.id = #{id}
    </select>

    <select id="selectMaxNo" resultType="java.lang.Long">
        SELECT IFNULL(max(RIGHT(check_no, 12)), 0) from equipment_check_info
    </select>

</mapper>
