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

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizFarmingBatch" id="BizFarmingBatchResult">
        <id property="id" column="id"/>
        <result property="externalId" column="external_id"/>
        <result property="batchNo" column="batch_no"/>
        <result property="batchName" column="batch_name"/>
        <result property="pastureId" column="pasture_id"/>
        <result property="farmExternalId" column="farm_external_id"/>
        <result property="enclosureExternalId" column="enclosure_external_id"/>
        <result property="enclosureId" column="enclosure_id"/>
        <result property="planExternalId" column="plan_external_id"/>
        <result property="cattleVariety" column="cattle_variety"/>
        <result property="plannedQuantity" column="planned_quantity"/>
        <result property="entryQuantity" column="entry_quantity"/>
        <result property="currentQuantity" column="current_quantity"/>
        <result property="leaveQuantity" column="leave_quantity"/>
        <result property="deathQuantity" column="death_quantity"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="managerUserId" column="manager_user_id"/>
        <result property="batchStatus" column="batch_status"/>
        <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="selectBizFarmingBatchByExternalId" resultMap="BizFarmingBatchResult">
        select id, external_id, batch_no, batch_name, pasture_id, farm_external_id, enclosure_external_id, enclosure_id,
               plan_external_id, cattle_variety, planned_quantity, entry_quantity, current_quantity, leave_quantity, death_quantity,
               start_time, end_time, manager_user_id, batch_status, external_create_time,
               data_source, last_sync_time, del_flag, create_by, create_time, update_by, update_time, remark
        from biz_farming_batch
        where external_id = #{externalId}
        limit 1
    </select>

    <insert id="insertBizFarmingBatch" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmingBatch" useGeneratedKeys="true" keyProperty="id">
        insert into biz_farming_batch (
            external_id, batch_no, batch_name, pasture_id, farm_external_id, enclosure_external_id, enclosure_id,
            plan_external_id, cattle_variety, planned_quantity, entry_quantity, current_quantity, leave_quantity, death_quantity,
            start_time, end_time, manager_user_id, batch_status, external_create_time,
            data_source, last_sync_time, del_flag, create_by, create_time, remark
        ) values (
            #{externalId}, #{batchNo}, #{batchName}, #{pastureId}, #{farmExternalId}, #{enclosureExternalId}, #{enclosureId},
            #{planExternalId}, #{cattleVariety}, #{plannedQuantity}, #{entryQuantity}, #{currentQuantity}, #{leaveQuantity}, #{deathQuantity},
            #{startTime, jdbcType=TIMESTAMP}, #{endTime, jdbcType=TIMESTAMP}, #{managerUserId}, #{batchStatus}, #{externalCreateTime, jdbcType=TIMESTAMP},
            #{dataSource}, #{lastSyncTime}, #{delFlag}, #{createBy}, #{createTime, jdbcType=TIMESTAMP}, #{remark}
        )
    </insert>

    <update id="updateBizFarmingBatchFromSync" parameterType="com.ruoyi.web.modules.industryservice.domain.BizFarmingBatch">
        update biz_farming_batch set
            batch_no = #{batchNo},
            batch_name = #{batchName},
            pasture_id = #{pastureId},
            farm_external_id = #{farmExternalId},
            enclosure_external_id = #{enclosureExternalId},
            enclosure_id = #{enclosureId},
            plan_external_id = #{planExternalId},
            cattle_variety = #{cattleVariety},
            planned_quantity = #{plannedQuantity},
            entry_quantity = #{entryQuantity},
            current_quantity = #{currentQuantity},
            leave_quantity = #{leaveQuantity},
            death_quantity = #{deathQuantity},
            start_time = #{startTime, jdbcType=TIMESTAMP},
            end_time = #{endTime, jdbcType=TIMESTAMP},
            manager_user_id = #{managerUserId},
            batch_status = #{batchStatus},
            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>
