<?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="cn.iocoder.yudao.module.inspection.mapper.InspectionEquInfoMapper">




    <select id="selectInspectionEquInfoList" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionEquInfo" resultType="cn.iocoder.yudao.module.inspection.entity.InspectionEquInfo">
        select * from inspection_equ_info
        <where>
            deleted = 0
            <if test="inspectionEquInfo.equName != null  and inspectionEquInfo.equName != ''">and equ_name like
                concat('%', #{inspectionEquInfo.equName}, '%')
            </if>
            <if test="inspectionEquInfo.equModel != null  and inspectionEquInfo.equModel != ''">and equ_model like
                concat('%', #{inspectionEquInfo.equModel}, '%')
            </if>
            <if test="inspectionEquInfo.equNumber != null  and inspectionEquInfo.equNumber != ''">and equ_number like
                concat('%', #{inspectionEquInfo.equNumber}, '%')
            </if>
            <if test="inspectionEquInfo.params.beginNextCheckTime != null and inspectionEquInfo.params.beginNextCheckTime != '' and params.endNextCheckTime != null and params.endNextCheckTime != ''">
                and next_check_time between #{inspectionEquInfo.params.beginNextCheckTime} and
                #{inspectionEquInfo.params.endNextCheckTime}
            </if>
            <if test="inspectionEquInfo.type != null and inspectionEquInfo.type != ''">
                and `type` = #{inspectionEquInfo.type}
            </if>
        </where>
    </select>

    <select id="selectInspectionEquInfoById"  resultType="cn.iocoder.yudao.module.inspection.entity.InspectionEquInfo">
      select  * from inspection_equ_info
        where id = #{id}
    </select>
    <select id="queryEquipmentCountByCategory"
            resultType="cn.iocoder.yudao.module.inspection.vo.EquipmentCountVo">
        SELECT
            sd.value AS categoryId,
            COUNT(iei.id) AS count,
            sd.label AS categoryName
        FROM system_dict_data sd
                 LEFT JOIN inspection_equ_info iei
                           ON iei.type = sd.value AND iei.deleted = 0
        WHERE sd.dict_type = 'ins_equ_type'
          AND sd.deleted = 0
        GROUP BY sd.value, sd.label;
    </select>

</mapper>
