<?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.BizYakReproductionRecordMapper">
    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizYakReproductionRecord" id="BizYakReproductionRecordResult">
        <id property="id" column="id"/>
        <result property="yakAssetId" column="yak_asset_id"/>
        <result property="calvingDate" column="calving_date"/>
        <result property="dayAge" column="day_age"/>
        <result property="parity" column="parity"/>
        <result property="calvingIntervalDays" column="calving_interval_days"/>
        <result property="calfCount" column="calf_count"/>
        <result property="liveCalfCount" column="live_calf_count"/>
        <result property="calfSurvivalRate" column="calf_survival_rate"/>
        <result property="calfBirthWeightKg" column="calf_birth_weight_kg"/>
        <result property="dystociaFlag" column="dystocia_flag"/>
    </resultMap>
    <select id="selectByYakAssetId" resultMap="BizYakReproductionRecordResult">
        select id, yak_asset_id, calving_date, day_age, parity, calving_interval_days, calf_count,
               live_calf_count, calf_survival_rate, calf_birth_weight_kg, dystocia_flag
        from biz_yak_reproduction_record where yak_asset_id = #{yakAssetId} order by parity desc, id desc
    </select>
    <delete id="deleteByYakAssetId">delete from biz_yak_reproduction_record where yak_asset_id = #{yakAssetId}</delete>
    <insert id="batchInsert">
        insert into biz_yak_reproduction_record (yak_asset_id, calving_date, day_age, parity, calving_interval_days,
            calf_count, live_calf_count, calf_survival_rate, calf_birth_weight_kg, dystocia_flag) values
        <foreach collection="list" item="item" separator=",">
            (#{item.yakAssetId}, #{item.calvingDate}, #{item.dayAge}, #{item.parity}, #{item.calvingIntervalDays},
             #{item.calfCount}, #{item.liveCalfCount}, #{item.calfSurvivalRate}, #{item.calfBirthWeightKg}, #{item.dystociaFlag})
        </foreach>
    </insert>
</mapper>
