<?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.BizYakCollarLocationMapper">

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizYakCollarLocation" id="BizYakCollarLocationResult">
        <id property="id" column="id"/>
        <result property="yakAssetId" column="yak_asset_id"/>
        <result property="yakNo" column="yak_no"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <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="selectByYakNoAndReportTime" resultMap="BizYakCollarLocationResult">
        select id, yak_asset_id, yak_no, longitude, latitude, report_time,
               data_source, last_sync_time, del_flag, create_by, create_time, update_by, update_time, remark
        from biz_yak_collar_location
        where yak_no = #{yakNo} and report_time = #{reportTime}
        limit 1
    </select>

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

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

    <insert id="insertBizYakCollarLocation" parameterType="com.ruoyi.web.modules.industryservice.domain.BizYakCollarLocation" useGeneratedKeys="true" keyProperty="id">
        insert into biz_yak_collar_location (
            yak_asset_id, yak_no, longitude, latitude, report_time,
            data_source, last_sync_time, del_flag, create_by, create_time, remark
        ) values (
            #{yakAssetId}, #{yakNo}, #{longitude}, #{latitude}, #{reportTime, jdbcType=TIMESTAMP},
            #{dataSource}, #{lastSyncTime}, #{delFlag}, #{createBy}, #{createTime, jdbcType=TIMESTAMP}, #{remark}
        )
    </insert>

    <update id="updateBizYakCollarLocationFromSync" parameterType="com.ruoyi.web.modules.industryservice.domain.BizYakCollarLocation">
        update biz_yak_collar_location set
            yak_asset_id = #{yakAssetId}, longitude = #{longitude}, latitude = #{latitude},
            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>
