种公羊档案修改

This commit is contained in:
zyk
2025-12-25 16:38:38 +08:00
parent fe5dffb508
commit 454c5bcb73
18 changed files with 1796 additions and 112 deletions

View File

@@ -6,7 +6,7 @@
<resultMap type="BreedRamFile" id="BreedRamFileResult">
<result property="id" column="id" />
<result property="ordinaryEarNumber" column="ordinary_ear_number" />
<result property="ordinaryEarNumber" column="manage_tags" />
<result property="ranchId" column="ranch_id" />
<result property="ranchName" column="ranch_name" />
<result property="sheepfoldId" column="sheepfold_id" />
@@ -74,13 +74,13 @@
</resultMap>
<sql id="selectBreedRamFileVo">
select id, ordinary_ear_number, ranch_id, ranch_name, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, sheep_category, current_status, birthday, dynamic_info, month_age, birth_weight, weaning_date, weaning_day_age, weaning_weight, weaning_daily_gain, post_weaning_daily_gain, current_weight, current_weight_date, activity_level, sexual_status, scrotum_circumference, sperm_collection_time, sperm_volume, sperm_vitality, sperm_density, sperm_quality, breeding_status, last_plan_time, current_plan_time, comment, protein_rate_ebv, milk_fat_rate_ebv, scs_ebv, growth_performance_ebv, resistance_ebv, reproduction_performance_ebv, body_type_ebv, comprehensive_breeding_value, father_number, mother_number, grandfather_number, grandmother_number, maternal_grandfather_number, maternal_grandmother_number, is_core_flock, is_breeding_use, pregnancy_check, total_mated_ewes, natural_pregnancy_check_ewes, natural_conception_rate, artificial_pregnancy_check_ewes, artificial_conception_rate, ram_mother_milk_volume, milk_production_ebv, accuracy, information_count, is_paternity_tested, create_by, create_time, update_by, update_time, is_delete from breed_ram_file
select id, manage_tags, ranch_id, ranch_name, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, sheep_category, current_status, birthday, dynamic_info, month_age, birth_weight, weaning_date, weaning_day_age, weaning_weight, weaning_daily_gain, post_weaning_daily_gain, current_weight, current_weight_date, activity_level, sexual_status, scrotum_circumference, sperm_collection_time, sperm_volume, sperm_vitality, sperm_density, sperm_quality, breeding_status, last_plan_time, current_plan_time, comment, protein_rate_ebv, milk_fat_rate_ebv, scs_ebv, growth_performance_ebv, resistance_ebv, reproduction_performance_ebv, body_type_ebv, comprehensive_breeding_value, father_number, mother_number, grandfather_number, grandmother_number, maternal_grandfather_number, maternal_grandmother_number, is_core_flock, is_breeding_use, pregnancy_check, total_mated_ewes, natural_pregnancy_check_ewes, natural_conception_rate, artificial_pregnancy_check_ewes, artificial_conception_rate, ram_mother_milk_volume, milk_production_ebv, accuracy, information_count, is_paternity_tested, create_by, create_time, update_by, update_time, is_delete from breed_ram_file
</sql>
<select id="selectBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
<if test="ordinaryEarNumber != null and ordinaryEarNumber != ''"> and ordinary_ear_number like concat('%', #{ordinaryEarNumber}, '%')</if>
<if test="ordinaryEarNumber != null and ordinaryEarNumber != ''"> and manage_tags like concat('%', #{ordinaryEarNumber}, '%')</if>
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="ranchName != null and ranchName != ''"> and ranch_name like concat('%', #{ranchName}, '%')</if>
<if test="sheepfoldId != null "> and sheepfold_id = #{sheepfoldId}</if>
@@ -149,56 +149,74 @@
where id = #{id}
</select>
<select id="selectBreedRamFileByOrdinaryEarNumber" parameterType="String" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where ordinary_ear_number = #{ordinaryEarNumber}
<!-- ====================== BreedRamFileMapper.xml 需要添加/更新 ====================== -->
<!-- 根据普通耳号查询种公羊档案 -->
<!-- 查询方法也需要修改字段名 -->
<select id="selectBreedRamFileByOrdinaryEarNumber" resultMap="BreedRamFileResult">
SELECT * FROM breed_ram_file
WHERE manage_tags = #{ordinaryEarNumber} AND is_delete = 0
LIMIT 1
</select>
<select id="selectBreedRamFileByElectronicTags" parameterType="String" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where electronic_tags = #{electronicTags}
<!-- 根据电子耳号查询种公羊档案 -->
<select id="selectBreedRamFileByElectronicTags" parameterType="String" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE electronic_tags = #{electronicTags}
AND is_delete = 0
LIMIT 1
</select>
<select id="selectBreedRamFileListByRanchId" parameterType="Long" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where ranch_id = #{ranchId} and (is_delete = 0 or is_delete is null)
order by create_time desc
<!-- 根据牧场ID查询种公羊档案列表 -->
<select id="selectBreedRamFileListByRanchId" parameterType="Long" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE ranch_id = #{ranchId}
AND is_delete = 0
ORDER BY id DESC
</select>
<select id="selectBreedRamFileListBySheepfoldId" parameterType="Long" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where sheepfold_id = #{sheepfoldId} and (is_delete = 0 or is_delete is null)
order by create_time desc
<!-- 根据羊舍ID查询种公羊档案列表 -->
<select id="selectBreedRamFileListBySheepfoldId" parameterType="Long" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE sheepfold_id = #{sheepfoldId}
AND is_delete = 0
ORDER BY id DESC
</select>
<select id="selectCoreFlockBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
is_core_flock = 1
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="varietyId != null "> and variety_id = #{varietyId}</if>
<if test="breedingStatus != null "> and breeding_status = #{breedingStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
</where>
order by create_time desc
<!-- 查询核心羊群种公羊档案列表 -->
<select id="selectCoreFlockBreedRamFileList" parameterType="BreedRamFile" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE is_core_flock = 1
AND is_delete = 0
<if test="ranchId != null">
AND ranch_id = #{ranchId}
</if>
<if test="varietyId != null">
AND variety_id = #{varietyId}
</if>
ORDER BY id DESC
</select>
<select id="selectBreedingUseBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
is_breeding_use = 1
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="varietyId != null "> and variety_id = #{varietyId}</if>
<if test="breedingStatus != null "> and breeding_status = #{breedingStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
</where>
order by create_time desc
<!-- 查询种用种公羊档案列表 -->
<select id="selectBreedingUseBreedRamFileList" parameterType="BreedRamFile" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE is_breeding_use = 1
AND is_delete = 0
<if test="ranchId != null">
AND ranch_id = #{ranchId}
</if>
<if test="varietyId != null">
AND variety_id = #{varietyId}
</if>
ORDER BY id DESC
</select>
<!-- 修正后的 insertBreedRamFile -->
<insert id="insertBreedRamFile" parameterType="BreedRamFile" useGeneratedKeys="true" keyProperty="id">
insert into breed_ram_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ordinaryEarNumber != null">ordinary_ear_number,</if>
<if test="manageTags != null and manageTags != ''">manage_tags,</if>
<if test="ranchId != null">ranch_id,</if>
<if test="ranchName != null">ranch_name,</if>
<if test="sheepfoldId != null">sheepfold_id,</if>
@@ -258,6 +276,8 @@
<if test="accuracy != null">accuracy,</if>
<if test="informationCount != null">information_count,</if>
<if test="isPaternityTested != null">is_paternity_tested,</if>
<if test="offspringCount != null">offspring_count,</if>
<if test="prolificacy != null">prolificacy,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
@@ -265,7 +285,7 @@
<if test="isDelete != null">is_delete,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ordinaryEarNumber != null">#{ordinaryEarNumber},</if>
<if test="manageTags != null and manageTags != ''">#{manageTags},</if>
<if test="ranchId != null">#{ranchId},</if>
<if test="ranchName != null">#{ranchName},</if>
<if test="sheepfoldId != null">#{sheepfoldId},</if>
@@ -325,6 +345,8 @@
<if test="accuracy != null">#{accuracy},</if>
<if test="informationCount != null">#{informationCount},</if>
<if test="isPaternityTested != null">#{isPaternityTested},</if>
<if test="offspringCount != null">#{offspringCount},</if>
<if test="prolificacy != null">#{prolificacy},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
@@ -336,7 +358,7 @@
<update id="updateBreedRamFile" parameterType="BreedRamFile">
update breed_ram_file
<trim prefix="SET" suffixOverrides=",">
<if test="ordinaryEarNumber != null">ordinary_ear_number = #{ordinaryEarNumber},</if>
<if test="ordinaryEarNumber != null">manage_tags = #{ordinaryEarNumber},</if>
<if test="ranchId != null">ranch_id = #{ranchId},</if>
<if test="ranchName != null">ranch_name = #{ranchName},</if>
<if test="sheepfoldId != null">sheepfold_id = #{sheepfoldId},</if>
@@ -414,4 +436,5 @@
</foreach>
</delete>
</mapper>

View File

@@ -262,4 +262,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
ORDER BY id DESC
</select>
<!-- &lt;!&ndash; 查询所有公羊gender=2 &ndash;&gt;-->
<!-- <select id="selectRamList" resultMap="SheepFileResult">-->
<!-- <include refid="selectSheepFileVo"/>-->
<!-- where gender = 2 and (is_delete = 0 or is_delete is null)-->
<!-- order by create_time desc-->
<!-- </select>-->
<!-- 查询所有公羊 -->
<select id="selectRamList" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE gender = 2 AND is_delete = 0
</select>
<!-- 根据管理耳号查询 -->
<select id="selectSheepFileByManageTags" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE bs_manage_tags = #{manageTags} AND is_delete = 0
LIMIT 1
</select>
</mapper>

View File

@@ -148,4 +148,10 @@
limit 1
</select>
<select id="selectLatestByRamId" resultType="RawSpermRecord">
SELECT * FROM raw_sperm_record
WHERE sheep_id = #{sheepId}
ORDER BY pick_date DESC
LIMIT 1
</select>
</mapper>

View File

@@ -417,4 +417,12 @@
where id = #{sheepId}
and is_delete = 0
</update>
<!-- ====================== ScBreedRecordMapper.xml 需要添加 ====================== -->
<!-- 统计该公羊配了多少母羊(去重) -->
<select id="countMatedEwesByRamId" resultType="Long">
SELECT COUNT(DISTINCT ewe_id)
FROM sc_breed_record
WHERE ram_id = #{ramManageTags} AND is_delete = 0
</select>
</mapper>

View File

@@ -221,4 +221,13 @@
#{id}
</foreach>
</delete>
<!-- ====================== ScLambingRecordMapper.xml 需要添加 ====================== -->
<!-- 统计公羊的后代数量 -->
<select id="countOffspringByRamId" resultType="Long">
SELECT IFNULL(SUM(lr.lambs_born), 0)
FROM sc_breed_record br
JOIN sc_lambing_record lr ON br.ewe_id = lr.sheep_id
WHERE br.ram_id = #{ramManageTags} AND br.is_delete = 0
</select>
</mapper>

View File

@@ -229,4 +229,17 @@
</set>
where id = #{sheepId}
</update>
<!-- ====================== ScPregnancyRecordMapper.xml 需要添加 ====================== -->
<!-- 统计孕检有胎的母羊数(按配种方式) -->
<select id="countPregnantEwesByRamIdAndBreedType" resultType="Long">
SELECT COUNT(DISTINCT pr.sheep_id)
FROM sc_breed_record br
JOIN sc_pregnancy_record pr ON br.ewe_id = pr.sheep_id
WHERE br.ram_id = #{ramManageTags}
AND br.is_delete = 0
AND pr.is_delete = 0
AND br.breed_type = #{breedType}
AND pr.result IN ('有胎', '阳性', '怀孕')
</select>
</mapper>