配种计划重新设计

This commit is contained in:
zyk
2026-03-03 10:21:46 +08:00
parent 204bbc5ee2
commit 4818ed5fc5
5 changed files with 519 additions and 240 deletions

View File

@@ -54,77 +54,77 @@
<!-- 筛选符合条件的母羊 -->
<select id="selectEligibleEwe" resultType="Map">
select
bs.id,
bs.manage_tags as bs_manage_tags,
bv.variety as variety,
bs.family,
bst.name as sheep_type,
bs.gender,
TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) as month_age,
bs.current_weight,
bs.post_lambing_day,
bbs.breed as breed,
bs.parity,
dsf.sheepfold_name,
bs.comment,
CASE WHEN bs.is_core = 1 THEN '是' ELSE '否' END as is_core,
CASE WHEN bs.is_breeding = 1 THEN '是' ELSE '否' END as is_breeding,
CONCAT('胎次:', IFNULL(bs.parity, 0), ' 配种次数:', IFNULL(bs.mating_counts, 0)) as reproduction_info
bs.id,
bs.manage_tags as bs_manage_tags,
bv.variety as variety,
bs.family,
bst.name as sheep_type,
bs.gender,
TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) as month_age,
bs.current_weight,
bs.post_lambing_day,
bbs.breed as breed,
bs.parity,
dsf.sheepfold_name,
bs.comment,
CASE WHEN bs.is_core = 1 THEN '是' ELSE '否' END as is_core,
CASE WHEN bs.is_breeding = 1 THEN '是' ELSE '否' END as is_breeding,
CONCAT('胎次:', IFNULL(bs.parity, 0), ' 配种次数:', IFNULL(bs.mating_counts, 0)) as reproduction_info
from bas_sheep bs
left join bas_sheep_variety bv on bs.variety_id = bv.id
left join bas_sheep_type bst on bs.type_id = bst.id
left join bas_breed_status bbs on bs.breed_status_id = bbs.id
left join da_sheepfold dsf on bs.sheepfold_id = dsf.id
left join bas_sheep_variety bv on bs.variety_id = bv.id
left join bas_sheep_type bst on bs.type_id = bst.id
left join bas_breed_status bbs on bs.breed_status_id = bbs.id
left join da_sheepfold dsf on bs.sheepfold_id = dsf.id
where bs.gender = 1
and bs.is_delete = 0
and bs.is_delete = 0
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags like concat('%', #{manageTags}, '%')
</if>
and (bs.status_id = 1 or bs.status_id is null)
and (
(bst.name in ('青年羊', '超龄羊') and (
(bv.variety = '湖羊' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 7.5 and bs.current_weight &gt;= 33) or
(bv.variety = '东佛里生' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50) or
(bv.variety not in ('湖羊', '东佛里生') and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50)
))
or
(bst.name in ('泌乳羊', '种母羊') and bs.post_lambing_day &gt; 45 and bs.current_weight &gt; 0)
)
and (bs.status_id = 1 or bs.status_id is null)
and (
(bst.name in ('青年羊', '超龄羊') and (
(bv.variety = '湖羊' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 7.5 and bs.current_weight &gt;= 33) or
(bv.variety = '东佛里生' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50) or
(bv.variety not in ('湖羊', '东佛里生') and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50)
))
or
(bst.name in ('泌乳羊', '种母羊') and bs.post_lambing_day &gt; 45 and bs.current_weight &gt; 0)
)
order by bv.variety, TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) desc
</select>
<!-- 筛选符合条件的公羊 -->
<select id="selectEligibleRam" resultType="Map">
select
bs.id,
bs.manage_tags as bs_manage_tags,
bv.variety as variety,
bs.family,
bst.name as sheep_type,
bs.gender,
bs.birthday,
TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) as month_age,
bs.current_weight,
bbs.breed as breed
bs.id,
bs.manage_tags as bs_manage_tags,
bv.variety as variety,
bs.family,
bst.name as sheep_type,
bs.gender,
bs.birthday,
TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) as month_age,
bs.current_weight,
bbs.breed as breed
from bas_sheep bs
left join bas_sheep_variety bv on bs.variety_id = bv.id
left join bas_sheep_type bst on bs.type_id = bst.id
left join bas_breed_status bbs on bs.breed_status_id = bbs.id
left join bas_sheep_variety bv on bs.variety_id = bv.id
left join bas_sheep_type bst on bs.type_id = bst.id
left join bas_breed_status bbs on bs.breed_status_id = bbs.id
where bs.gender = 2
and bs.is_delete = 0
and bs.is_delete = 0
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags like concat('%', #{manageTags}, '%')
</if>
and bs.status_id = 1
and (
(bst.name in ('青年羊', '超龄羊') and (
(bv.variety = '湖羊' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 7.5 and bs.current_weight &gt;= 33) or
(bv.variety = '东佛里生' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50) or
(bv.variety not in ('湖羊', '东佛里生') and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50)
))
or
bst.name not in ('青年羊', '超龄羊')
)
and bs.status_id = 1
and (
(bst.name in ('青年羊', '超龄羊') and (
(bv.variety = '湖羊' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 7.5 and bs.current_weight &gt;= 33) or
(bv.variety = '东佛里生' and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50) or
(bv.variety not in ('湖羊', '东佛里生') and TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) &gt;= 9 and bs.current_weight &gt;= 50)
))
or
bst.name not in ('青年羊', '超龄羊')
)
order by bv.variety, TIMESTAMPDIFF(MONTH, bs.birthday, NOW()) desc
</select>
@@ -325,4 +325,35 @@
ORDER BY sf.bs_manage_tags
LIMIT 50
</select>
<!-- ========== 导出配对表 / 导入配对表 相关查询 ========== -->
<!--
根据ID列表查询羊只耳号
gender: 1=母羊 2=公羊
-->
<select id="selectEarNumbersByIds" resultType="java.util.Map">
SELECT id, manage_tags
FROM bas_sheep
WHERE gender = #{gender}
AND is_delete = 0
AND id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<!--
根据管理耳号查询羊只ID
gender: 1=母羊 2=公羊
-->
<select id="selectSheepIdByManageTags" resultType="java.lang.Long">
SELECT id
FROM bas_sheep
WHERE manage_tags = #{manageTags}
AND gender = #{gender}
AND is_delete = 0
LIMIT 1
</select>
</mapper>