完善了死亡部分代码,优化了孕检模块,新建了流产模块

This commit is contained in:
zyk
2025-08-24 00:37:33 +08:00
parent c11faeeace
commit fdd18ba1d3
17 changed files with 1563 additions and 124 deletions

View File

@@ -16,8 +16,6 @@
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="create_by" />
<result property="updateTime" column="create_time" />
<!-- 关联羊只信息字段 -->
<result property="variety" column="variety" />
<result property="monthAge" column="month_age" />
@@ -32,6 +30,7 @@
<result property="expectedDate" column="expected_date" />
<result property="lastEventDate" column="last_event_date" />
<result property="ranchName" column="ranch" />
<result property="daysAfterMating" column="days_after_mating" />
</resultMap>
<sql id="selectScPregnancyRecordVo">
@@ -46,8 +45,6 @@
pr.remark,
pr.create_by,
pr.create_time,
pr.create_by,
pr.create_time,
sf.bs_manage_tags as manage_tags,
sf.variety,
sf.month_age,
@@ -55,18 +52,37 @@
sf.mating_counts,
sf.sheepfold_name,
sf.breed,
sf.father_manage_tags,
father_sf.variety as father_variety,
mating_type.dict_label as mating_type_name,
sf.mating_date,
sf.expected_date,
sf.lambing_date as last_event_date,
r.ranch as ranch
sf.dr_ranch as ranch,
-- 关联配种信息
ram_sf.bs_manage_tags as father_manage_tags,
ram_sf.variety as father_variety,
mating_type.dict_label as mating_type_name,
COALESCE(br.create_time, sf.mating_date) as mating_date,
-- 计算配后天数:孕检日期 - 配种日期
CASE
WHEN COALESCE(br.create_time, sf.mating_date) IS NOT NULL
THEN DATEDIFF(pr.datetime, COALESCE(br.create_time, sf.mating_date))
ELSE NULL
END as days_after_mating
from sc_pregnancy_record pr
left join sheep_file sf on pr.sheep_id = sf.id
left join sys_dict_data mating_type on sf.mating_type_id = mating_type.dict_value and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
left join da_ranch r on sf.ranch_id = r.id
left join sheep_file father_sf on sf.bs_father_id = father_sf.id
-- 关联配种记录表,获取最新的配种记录
left join (
select br1.*
from sc_breed_record br1
inner join (
select ewe_id, max(create_time) as max_time
from sc_breed_record
group by ewe_id
) br2 on br1.ewe_id = br2.ewe_id and br1.create_time = br2.max_time
) br on sf.id = br.ewe_id
-- 关联公羊信息
left join sheep_file ram_sf on br.ram_id = ram_sf.id
-- 关联配种类型字典
left join sys_dict_data mating_type on sf.mating_type_id = mating_type.dict_value
and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
</sql>
<select id="selectScPregnancyRecordList" parameterType="ScPregnancyRecord" resultMap="ScPregnancyRecordResult">
@@ -86,7 +102,7 @@
</otherwise>
</choose>
</if>
<if test="datetime != null "> and pr.datetime = #{datetime}</if>
<if test="datetime != null "> and DATE(pr.datetime) = DATE(#{datetime})</if>
<if test="result != null and result != ''"> and pr.result = #{result}</if>
<if test="technician != null and technician != ''"> and pr.technician like concat('%', #{technician}, '%')</if>
<if test="way != null and way != ''"> and pr.way = #{way}</if>
@@ -116,6 +132,28 @@
limit 1
</select>
<!-- 根据耳号获取配种信息 -->
<select id="selectBreedInfoByManageTags" parameterType="String" resultType="map">
SELECT
sf.bs_manage_tags as manageTags,
-- 从配种记录表获取公羊耳号
ram_sf.bs_manage_tags as fatherManageTags,
ram_sf.variety as fatherVariety,
br.create_time as matingDate,
mating_type.dict_label as matingTypeName,
br.technician as breedTechnician,
br.create_time as breedCreateTime
FROM sheep_file sf
LEFT JOIN sc_breed_record br ON sf.id = br.ewe_id
LEFT JOIN sheep_file ram_sf ON br.ram_id = ram_sf.id
LEFT JOIN sys_dict_data mating_type ON sf.mating_type_id = mating_type.dict_value
AND mating_type.dict_type = 'breed_type' AND mating_type.status = '0'
WHERE sf.bs_manage_tags = #{manageTags}
AND sf.is_delete = 0
ORDER BY br.create_time DESC
LIMIT 1
</select>
<insert id="insertScPregnancyRecord" parameterType="ScPregnancyRecord" useGeneratedKeys="true" keyProperty="id">
insert into sc_pregnancy_record
<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -153,8 +191,6 @@
<if test="technician != null">technician = #{technician},</if>
<if test="way != null">way = #{way},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null">create_by = #{updateBy},</if>
<if test="updateTime != null">create_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
@@ -178,7 +214,6 @@
<if test="breedStatusId != null">breed_status_id = #{breedStatusId},</if>
<if test="expectedDate != null">expected_date = #{expectedDate},</if>
<if test="gestationDay != null">gestation_day = #{gestationDay},</if>
create_time = now()
</set>
where id = #{sheepId}
</update>

View File

@@ -44,6 +44,7 @@
<if test="comment != null and comment != ''"> and comment = #{comment}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
</where>
order by create_time desc
</select>
<select id="selectScSheepDeathById" parameterType="Long" resultMap="ScSheepDeathResult">
@@ -51,11 +52,23 @@
where id = #{id}
</select>
<!-- 根据管理耳号查询sheep_file视图信息 -->
<!-- 根据管理耳号查询sheep_file视图信息 - 修复删除不存在的status字段 -->
<select id="selectSheepFileByManageTags" parameterType="String" resultType="java.util.Map">
select id as sheepId, variety, name as sheepType, gender, day_age as dayAge, parity, sheepfold_name as sheepfoldName, breed as breedStatus, post_lambing_day as postLambingDay, lactation_day as lactationDay, gestation_day as gestationDay
select
id as sheepId,
variety,
name as sheepType,
gender,
day_age as dayAge,
parity,
sheepfold_name as sheepfoldName,
breed as breedStatus,
post_lambing_day as postLambingDay,
lactation_day as lactationDay,
gestation_day as gestationDay
from sheep_file
where bs_manage_tags = #{manageTags} and is_delete = 0
limit 1
</select>
<insert id="insertScSheepDeath" parameterType="ScSheepDeath" useGeneratedKeys="true" keyProperty="id">
@@ -131,4 +144,14 @@
#{id}
</foreach>
</delete>
<!-- 更新羊只状态 - 根据实际的sheep_file表结构调整字段名 -->
<update id="updateSheepFileStatus">
UPDATE sheep_file
SET breed = #{status},
update_time = NOW()
WHERE id = #{sheepId}
AND is_delete = 0
</update>
</mapper>