<?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.web.modules.industryservice.mapper.BizYakEarTagRecordMapper">

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizYakEarTagRecord" id="BizYakEarTagRecordResult">
        <id property="id" column="id"/>
        <result property="externalId" column="external_id"/>
        <result property="yakAssetId" column="yak_asset_id"/>
        <result property="earTagNumber" column="ear_tag_number"/>
        <result property="yakNo" column="yak_no"/>
        <result property="actualTemperature" column="actual_temperature"/>
        <result property="temperature" column="temperature"/>
        <result property="steps" column="steps"/>
        <result property="reportTime" column="report_time"/>
        <result property="dataSource" column="data_source"/>
        <result property="lastSyncTime" column="last_sync_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <select id="selectByExternalId" resultMap="BizYakEarTagRecordResult">
        select id, external_id, yak_asset_id, ear_tag_number, yak_no, actual_temperature, temperature, steps, report_time,
               data_source, last_sync_time, del_flag, create_by, create_time, update_by, update_time, remark
        from biz_yak_ear_tag_record where external_id = #{externalId} limit 1
    </select>

    <select id="selectMaxReportTime" resultType="java.util.Date">
        select max(report_time) from biz_yak_ear_tag_record
    </select>

    <select id="countRecords" resultType="long">
        select count(*) from biz_yak_ear_tag_record
    </select>

    <insert id="insertBizYakEarTagRecord" parameterType="com.ruoyi.web.modules.industryservice.domain.BizYakEarTagRecord"
            useGeneratedKeys="true" keyProperty="id">
        insert into biz_yak_ear_tag_record (
            external_id, yak_asset_id, ear_tag_number, yak_no, actual_temperature, temperature, steps, report_time,
            data_source, last_sync_time, del_flag, create_by, create_time, remark
        ) values (
            #{externalId}, #{yakAssetId}, #{earTagNumber}, #{yakNo}, #{actualTemperature}, #{temperature}, #{steps},
            #{reportTime, jdbcType=TIMESTAMP}, #{dataSource}, #{lastSyncTime}, #{delFlag},
            #{createBy}, #{createTime, jdbcType=TIMESTAMP}, #{remark}
        )
    </insert>

    <update id="updateBizYakEarTagRecordFromSync" parameterType="com.ruoyi.web.modules.industryservice.domain.BizYakEarTagRecord">
        update biz_yak_ear_tag_record set
            yak_asset_id = #{yakAssetId}, ear_tag_number = #{earTagNumber}, yak_no = #{yakNo},
            actual_temperature = #{actualTemperature}, temperature = #{temperature}, steps = #{steps},
            report_time = #{reportTime, jdbcType=TIMESTAMP},
            data_source = #{dataSource}, last_sync_time = #{lastSyncTime}, del_flag = #{delFlag},
            update_by = #{updateBy}, update_time = #{updateTime, jdbcType=TIMESTAMP}, remark = #{remark}
        where id = #{id}
    </update>
</mapper>
