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

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizFarmingPlan" id="BizFarmingPlanResult">
        <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="regionExternalId" column="region_external_id"/>
        <result property="regionName" column="region_name"/>
        <result property="enclosureExternalId" column="enclosure_external_id"/>
        <result property="enclosureId" column="enclosure_id"/>
        <result property="planBatch" column="plan_batch"/>
        <result property="planName" column="plan_name"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="planStatus" column="plan_status"/>
        <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="selectBizFarmingPlanByExternalId" resultMap="BizFarmingPlanResult">
        select id, external_id, pasture_id, farm_external_id, region_external_id, region_name,
               enclosure_external_id, enclosure_id, plan_batch, plan_name, start_time, end_time, plan_status,
               data_source, last_sync_time, del_flag, create_by, create_time, update_by, update_time, remark
        from biz_farming_plan
        where external_id = #{externalId}
        limit 1
    </select>

    <insert id="insertBizFarmingPlan" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmingPlan" useGeneratedKeys="true" keyProperty="id">
        insert into biz_farming_plan (
            external_id, pasture_id, farm_external_id, region_external_id, region_name,
            enclosure_external_id, enclosure_id, plan_batch, plan_name, start_time, end_time, plan_status,
            data_source, last_sync_time, del_flag, create_by, create_time, remark
        ) values (
            #{externalId}, #{pastureId}, #{farmExternalId}, #{regionExternalId}, #{regionName},
            #{enclosureExternalId}, #{enclosureId}, #{planBatch}, #{planName}, #{startTime, jdbcType=TIMESTAMP}, #{endTime, jdbcType=TIMESTAMP}, #{planStatus},
            #{dataSource}, #{lastSyncTime}, #{delFlag}, #{createBy}, #{createTime, jdbcType=TIMESTAMP}, #{remark}
        )
    </insert>

    <update id="updateBizFarmingPlanFromSync" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmingPlan">
        update biz_farming_plan set
            pasture_id = #{pastureId},
            farm_external_id = #{farmExternalId},
            region_external_id = #{regionExternalId},
            region_name = #{regionName},
            enclosure_external_id = #{enclosureExternalId},
            enclosure_id = #{enclosureId},
            plan_batch = #{planBatch},
            plan_name = #{planName},
            start_time = #{startTime, jdbcType=TIMESTAMP},
            end_time = #{endTime, jdbcType=TIMESTAMP},
            plan_status = #{planStatus},
            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>
