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

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizFarmEnclosure" id="BizFarmEnclosureResult">
        <id property="id" column="id"/>
        <result property="externalId" column="external_id"/>
        <result property="pastureId" column="pasture_id"/>
        <result property="farmExternalId" column="farm_external_id"/>
        <result property="farmName" column="farm_name"/>
        <result property="enclosureName" column="enclosure_name"/>
        <result property="enclosureNo" column="enclosure_no"/>
        <result property="qrCode" column="qr_code"/>
        <result property="supervisor" column="supervisor"/>
        <result property="introduction" column="introduction"/>
        <result property="enclosureStatus" column="enclosure_status"/>
        <result property="areaType" column="area_type"/>
        <result property="cattleQuantity" column="cattle_quantity"/>
        <result property="externalCreateTime" column="external_create_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="selectBizFarmEnclosureByExternalId" resultMap="BizFarmEnclosureResult">
        select id, external_id, pasture_id, farm_external_id, farm_name, enclosure_name, enclosure_no, qr_code,
               supervisor, introduction, enclosure_status, area_type, cattle_quantity, external_create_time,
               data_source, last_sync_time, del_flag, create_by, create_time, update_by, update_time, remark
        from biz_farm_enclosure
        where external_id = #{externalId}
        limit 1
    </select>

    <insert id="insertBizFarmEnclosure" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmEnclosure" useGeneratedKeys="true" keyProperty="id">
        insert into biz_farm_enclosure (
            external_id, pasture_id, farm_external_id, farm_name, enclosure_name, enclosure_no, qr_code,
            supervisor, introduction, enclosure_status, area_type, cattle_quantity, external_create_time,
            data_source, last_sync_time, del_flag, create_by, create_time, remark
        ) values (
            #{externalId}, #{pastureId}, #{farmExternalId}, #{farmName}, #{enclosureName}, #{enclosureNo}, #{qrCode},
            #{supervisor}, #{introduction}, #{enclosureStatus}, #{areaType}, #{cattleQuantity}, #{externalCreateTime, jdbcType=TIMESTAMP},
            #{dataSource}, #{lastSyncTime}, #{delFlag}, #{createBy}, #{createTime, jdbcType=TIMESTAMP}, #{remark}
        )
    </insert>

    <update id="updateBizFarmEnclosureFromSync" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmEnclosure">
        update biz_farm_enclosure set
            pasture_id = #{pastureId},
            farm_external_id = #{farmExternalId},
            farm_name = #{farmName},
            enclosure_name = #{enclosureName},
            enclosure_no = #{enclosureNo},
            qr_code = #{qrCode},
            supervisor = #{supervisor},
            introduction = #{introduction},
            enclosure_status = #{enclosureStatus},
            area_type = #{areaType},
            cattle_quantity = #{cattleQuantity},
            external_create_time = #{externalCreateTime, 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>
