<?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.system.mapper.AkmDataMapper">
    
    <resultMap type="AkmData" id="AkmDataResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="idCard"    column="id_card"    />
        <result property="phoneNum"    column="phone_num"    />
        <result property="collectTime"    column="collect_time"    />
        <result property="collectSite"    column="collect_site"    />

        <result property="equipId"    column="equip_id"    />
        <result property="equipName"    column="equip_name"    />
        <result property="unitName"    column="unit_name"    />
        <result property="community"    column="community"    />
        <result property="type"    column="type"    />
        <result property="state"    column="state"    />
        <result property="temperature"    column="temperature"    />
        <result property="belongsUser"    column="belongs_user"    />
    </resultMap>

    <sql id="selectAkmDataVo">
        select id, name, id_card, phone_num, collect_time, collect_site, equip_id, equip_name, unit_name, community, equip_id, type, state, temperature, belongs_user from akm_data
    </sql>

    <select id="selectAkmDataList" parameterType="AkmData" resultMap="AkmDataResult">
        <include refid="selectAkmDataVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''"> and phone_num = #{phoneNum}</if>
            <if test="collectTime != null "> and collect_time = #{collectTime}</if>
            <if test="collectSite != null  and collectSite != ''"> and collect_site = #{collectSite}</if>

            <if test="equipId != null  and equipId != ''"> and equip_id = #{equipId}</if>
            <if test="equipName != null  and equipName != ''"> and equip_name = #{equipName}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name = #{unitName}</if>
            <if test="community != null  and community != ''"> and community = #{community}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="temperature != null  and temperature != ''"> and temperature = #{temperature}</if>
            <if test="belongsUser != null  and belongsUser != ''"> and belongs_user = #{belongsUser}</if>
            <if test="startTime != null  and startTime != '' and startTime != 'null'">and
                DATE_FORMAT(collect_time,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="endTime != null  and endTime != ''  and endTime != 'null'">and
                DATE_FORMAT(collect_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="equipIdList != null">
            and equip_id in
            <foreach item="equipId" collection="equipIdList" open="(" separator="," close=")">
                #{equipId}
            </foreach>
            </if>

        </where>
    </select>
    
    <select id="selectAkmDataById" parameterType="Long" resultMap="AkmDataResult">
        <include refid="selectAkmDataVo"/>
        where id = #{id}
    </select>

    <select id="selectAkmDataListByIdList" resultMap="AkmDataResult">
        <include refid="selectAkmDataVo"/>
        where collect_time > #{startTime}  and #{endTime}>=collect_time
        and id_card in
        <foreach item="idCard" collection="idCardList" open="(" separator="," close=")">
            #{idCard}
        </foreach>
    </select>
    <select id="selectAkmData65ListByIdList" resultType="com.ruoyi.system.domain.AkmData">
        <include refid="selectAkmDataVo"/>
        where collect_time > #{startTime}  and #{endTime}>=collect_time
        and SUBSTRING(id_card, 1,2) = '65'
    </select>

    <select id="selectAkmDataName" resultMap ="AkmDataResult">
        select name,id_card from akm_data where id_card = #{idCard} and name is not null and name !='' limit 1
    </select>

    <insert id="insertAkmData" parameterType="AkmData" useGeneratedKeys="true" keyProperty="id">
        insert into akm_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="collectTime != null">collect_time,</if>
            <if test="collectSite != null">collect_site,</if>

            <if test="equipId != null ">equip_id,</if>
            <if test="equipName != null"> equip_name, </if>
            <if test="unitName != null ">  unit_name,</if>
            <if test="community != null ">  community,</if>
            <if test="type != null ">  type,</if>
            <if test="state != null ">  state,</if>
            <if test="temperature != null ">  temperature, </if>
            <if test="belongsUser != null ">  belongs_user,</if>

            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            create_time,
            update_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="collectTime != null">#{collectTime},</if>
            <if test="collectSite != null">#{collectSite},</if>


            <if test="equipId != null "> #{equipId},</if>
            <if test="equipName != null"> #{equipName},</if>
            <if test="unitName != null ">#{unitName},</if>
            <if test="community != null ">#{community},</if>
            <if test="type != null">#{type},</if>
            <if test="state != null ">#{state},</if>
            <if test="temperature != null ">#{temperature},</if>
            <if test="belongsUser != null ">  #{belongsUser},</if>

            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            sysdate(),sysdate()
         </trim>
    </insert>

    <update id="updateAkmData" parameterType="AkmData">
        update akm_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="collectTime != null">collect_time = #{collectTime},</if>
            <if test="collectSite != null">collect_site = #{collectSite},</if>

            <if test="equipId != null  and equipId != ''">  equip_id = #{equipId},</if>
            <if test="equipName != null  and equipName != ''">  equip_name = #{equipName},</if>
            <if test="unitName != null  and unitName != ''">  unit_name = #{unitName},</if>
            <if test="community != null  and community != ''">  community = #{community},</if>
            <if test="type != null  and type != ''">type = #{type},</if>
            <if test="state != null  and state != ''">state = #{state},</if>
            <if test="temperature != null  and temperature != ''">  temperature = #{temperature},</if>
            <if test="belongsUser != null  and belongsUser != ''">  belongs_user = #{belongsUser},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAkmDataById" parameterType="Long">
        delete from akm_data where id = #{id}
    </delete>

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