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

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

@@ -0,0 +1,155 @@
<?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.zhyc.module.produce.breed.mapper.ScMiscarriageRecordMapper">
<resultMap type="ScMiscarriageRecord" id="ScMiscarriageRecordResult">
<result property="id" column="id" />
<result property="sheepId" column="sheep_id" />
<result property="datetime" column="datetime" />
<result property="comment" column="comment" />
<result property="technician" column="technician" />
<result property="reason" column="reason" />
<result property="exposeType" column="expose_type" />
<result property="status" column="status" />
<result property="miscaLamb" column="misca_lamb" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<!-- 关联查询字段 -->
<result property="bsManageTags" column="bs_manage_tags" />
<result property="variety" column="variety" />
<result property="matingTypeId" column="mating_type_id" />
<result property="matingTypeName" column="mating_type_name" />
<result property="matingDate" column="mating_date" />
<result property="parity" column="parity" />
<result property="ramVariety" column="ram_variety" />
<result property="monthAge" column="month_age" />
<result property="pregnantDays" column="pregnant_days" />
<result property="sheepfoldName" column="sheepfold_name" />
<result property="drRanch" column="dr_ranch" />
</resultMap>
<sql id="selectScMiscarriageRecordVo">
select
smr.id,
smr.sheep_id,
smr.datetime,
smr.comment,
smr.technician,
smr.reason,
smr.expose_type,
smr.status,
smr.misca_lamb,
smr.create_by,
smr.create_time,
sf.bs_manage_tags,
sf.variety,
sf.mating_type_id,
CASE sf.mating_type_id
WHEN 1 THEN '人工授精'
WHEN 2 THEN '自然配种'
WHEN 3 THEN '胚胎移植'
ELSE '未知'
END as mating_type_name,
sf.mating_date,
sf.parity,
sf.variety as ram_variety, -- 这里需要根据实际配种公羊信息调整
sf.month_age,
CASE
WHEN sf.mating_date IS NOT NULL AND smr.datetime IS NOT NULL
THEN DATEDIFF(smr.datetime, sf.mating_date)
ELSE NULL
END as pregnant_days,
sf.sheepfold_name,
sf.dr_ranch
from sc_miscarriage_record smr
left join sheep_file sf on smr.sheep_id = sf.bs_manage_tags
</sql>
<select id="selectScMiscarriageRecordList" parameterType="ScMiscarriageRecord" resultMap="ScMiscarriageRecordResult">
<include refid="selectScMiscarriageRecordVo"/>
<where>
<if test="sheepId != null and sheepId != ''"> and smr.sheep_id = #{sheepId}</if>
<if test="bsManageTags != null and bsManageTags != ''"> and sf.bs_manage_tags like concat('%', #{bsManageTags}, '%')</if>
<if test="datetime != null"> and smr.datetime = #{datetime}</if>
<if test="comment != null and comment != ''"> and smr.comment like concat('%', #{comment}, '%')</if>
<if test="technician != null and technician != ''"> and smr.technician like concat('%', #{technician}, '%')</if>
<if test="reason != null and reason != ''"> and smr.reason = #{reason}</if>
<if test="exposeType != null"> and smr.expose_type = #{exposeType}</if>
<if test="status != null"> and smr.status = #{status}</if>
<if test="miscaLamb != null"> and smr.misca_lamb = #{miscaLamb}</if>
<if test="variety != null and variety != ''"> and sf.variety like concat('%', #{variety}, '%')</if>
</where>
order by smr.create_time desc
</select>
<select id="selectScMiscarriageRecordById" parameterType="Long" resultMap="ScMiscarriageRecordResult">
<include refid="selectScMiscarriageRecordVo"/>
where smr.id = #{id}
</select>
<insert id="insertScMiscarriageRecord" parameterType="ScMiscarriageRecord" useGeneratedKeys="true" keyProperty="id">
insert into sc_miscarriage_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="sheepId != null">sheep_id,</if>
<if test="datetime != null">datetime,</if>
<if test="comment != null">comment,</if>
<if test="technician != null">technician,</if>
<if test="reason != null">reason,</if>
<if test="exposeType != null">expose_type,</if>
<if test="status != null">status,</if>
<if test="miscaLamb != null">misca_lamb,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sheepId != null">#{sheepId},</if>
<if test="datetime != null">#{datetime},</if>
<if test="comment != null">#{comment},</if>
<if test="technician != null">#{technician},</if>
<if test="reason != null">#{reason},</if>
<if test="exposeType != null">#{exposeType},</if>
<if test="status != null">#{status},</if>
<if test="miscaLamb != null">#{miscaLamb},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateScMiscarriageRecord" parameterType="ScMiscarriageRecord">
update sc_miscarriage_record
<trim prefix="SET" suffixOverrides=",">
<if test="sheepId != null">sheep_id = #{sheepId},</if>
<if test="datetime != null">datetime = #{datetime},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="technician != null">technician = #{technician},</if>
<if test="reason != null">reason = #{reason},</if>
<if test="exposeType != null">expose_type = #{exposeType},</if>
<if test="status != null">status = #{status},</if>
<if test="miscaLamb != null">misca_lamb = #{miscaLamb},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteScMiscarriageRecordById" parameterType="Long">
delete from sc_miscarriage_record where id = #{id}
</delete>
<delete id="deleteScMiscarriageRecordByIds" parameterType="String">
delete from sc_miscarriage_record where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<!-- 根据耳号查询羊只信息 -->
<select id="selectSheepByManageTags" parameterType="String" resultType="map">
select bs_manage_tags, variety, parity, month_age, sheepfold_name, dr_ranch
from sheep_file
where bs_manage_tags = #{manageTags}
</select>
</mapper>

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>