配种记录和冲胚记录所有逻辑修改完成
This commit is contained in:
@@ -143,8 +143,8 @@ public class ScBreedRecordController extends BaseController
|
||||
if (scBreedRecord.getBreedType() == null) {
|
||||
return error("配种方式不能为空");
|
||||
}
|
||||
if (scBreedRecord.getBreedType() < 1 || scBreedRecord.getBreedType() > 4) {
|
||||
return error("配种方式只能是:1-同期发情、2-本交、3-冲胚、4-自然发情人工授精");
|
||||
if (scBreedRecord.getBreedType() < 1 || scBreedRecord.getBreedType() > 5) {
|
||||
return error("配种方式只能是:1-供体母羊配种、2-同期发情人工授精、3-本交、4-自然发情人工授精、5-胚胎移植");
|
||||
}
|
||||
|
||||
// 验证技术员
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zhyc.module.produce.breed.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -37,6 +38,8 @@ public class ScBreedRecord extends BaseEntity
|
||||
@Excel(name = "事件类型")
|
||||
private String eventType = "配种";
|
||||
|
||||
// 核心注解:指定JSON解析/序列化的日期格式,时区指定为东八区(Asia/Shanghai)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai")
|
||||
@Excel(name = "配种日期", dateFormat = "yyyy-MM-dd")
|
||||
private Date createTime;
|
||||
|
||||
@@ -62,7 +65,7 @@ public class ScBreedRecord extends BaseEntity
|
||||
private Integer embryoCount;
|
||||
|
||||
/** 1-同期发情, 2-本交, 3-自然发情, 4-胚胎移植 */
|
||||
@Excel(name = "配种方式", readConverterExp = "1=同期发情,2=本交,3=自然发情,4=胚胎移植")
|
||||
@Excel(name = "配种方式", readConverterExp = "1=供体母羊配种,2=同期发情人工授精,3=本交,4=胚胎移植,5=自然发情人工授精")
|
||||
private Integer breedType;
|
||||
|
||||
@Excel(name = "配种子类型")
|
||||
|
||||
@@ -217,58 +217,28 @@ public class ScBreedRecordServiceImpl implements IScBreedRecordService
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* 根据母羊耳号获取最新的配种计划信息
|
||||
* 修改逻辑:优先查配种计划 -> 其次查冲胚记录(作为受体)
|
||||
* 简化后的获取配种计划方法:移除冲胚记录自动关联
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getLatestBreedPlanByEweTags(String manageTags)
|
||||
{
|
||||
public Map<String, Object> getLatestBreedPlanByEweTags(String manageTags) {
|
||||
try {
|
||||
// 1. 优先从配种计划生成表获取最新计划 (同期发情/本交等)
|
||||
// 1. 仅从配种计划生成表获取(本交、人工授精等普通计划)
|
||||
Map<String, Object> latestPlan = scBreedRecordMapper.getLatestBreedPlanByEweTags(manageTags);
|
||||
if (latestPlan != null && !latestPlan.isEmpty()) {
|
||||
log.info("从配种计划生成表获取到配种计划: {}", latestPlan);
|
||||
return latestPlan;
|
||||
}
|
||||
|
||||
// 2. 如果生成表中没有,从普通配种计划表获取
|
||||
// 2. 从普通配种计划表获取
|
||||
Map<String, Object> normalPlan = scBreedRecordMapper.getBreedPlanByEweTags(manageTags);
|
||||
if (normalPlan != null && !normalPlan.isEmpty()) {
|
||||
log.info("从配种计划表获取到配种计划: {}", normalPlan);
|
||||
return normalPlan;
|
||||
}
|
||||
|
||||
// 3. 【新增逻辑】如果都没有,尝试从冲胚记录中查找(该羊是否作为受体)
|
||||
// 这里的业务逻辑是:如果这只羊在冲胚记录的"受体列表"中,且是最近的操作,则认为它是去做胚胎移植
|
||||
Map<String, Object> flushRecord = scBreedRecordMapper.getFlushRecordByEweNo(manageTags);
|
||||
if (flushRecord != null && !flushRecord.isEmpty()) {
|
||||
log.info("从冲胚记录获取到移植信息: {}", flushRecord);
|
||||
|
||||
// 构造一个符合前端预期的Map结构
|
||||
Map<String, Object> etPlan = new HashMap<>();
|
||||
etPlan.put("breed_type", 5); // 设定 5 为胚胎移植
|
||||
etPlan.put("breedType", 5); // 驼峰兼容
|
||||
etPlan.put("breed_type_name", "胚胎移植");
|
||||
|
||||
// 填充冲胚记录带来的数据
|
||||
etPlan.put("donorEweNo", flushRecord.get("donor_female_no")); // 供体母羊
|
||||
etPlan.put("donorRamNo", flushRecord.get("donor_male_no")); // 供体公羊
|
||||
etPlan.put("embryoCount", flushRecord.get("transferred")); // 移胚数
|
||||
|
||||
// 拼接配种子类型 (例如: 体内供体 鲜胚)
|
||||
String subType = "";
|
||||
if (flushRecord.get("embryo_type") != null) subType += flushRecord.get("embryo_type");
|
||||
if (flushRecord.get("storage_method") != null) subType += " " + flushRecord.get("storage_method");
|
||||
etPlan.put("embryoSubType", subType.trim());
|
||||
|
||||
return etPlan;
|
||||
}
|
||||
|
||||
log.warn("未找到母羊耳号 {} 的配种或移植计划信息", manageTags);
|
||||
// 胚胎移植逻辑已移至前端手动输入,此处不再查询 sc_embryo_flush
|
||||
log.info("未找到母羊 {} 的普通配种计划", manageTags);
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取配种/移植计划信息时发生异常,母羊耳号: {}", manageTags, e);
|
||||
log.error("获取配种计划异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ public class ScEmbryoFlushServiceImpl implements IScEmbryoFlushService
|
||||
VARIETY_NAME_MAP.put(4, "级杂一代");
|
||||
VARIETY_NAME_MAP.put(5, "级杂二代");
|
||||
VARIETY_NAME_MAP.put(6, "级杂三代");
|
||||
VARIETY_NAME_MAP.put(7, "1世代");
|
||||
VARIETY_NAME_MAP.put(8, "2世代");
|
||||
VARIETY_NAME_MAP.put(9, "3世代");
|
||||
VARIETY_NAME_MAP.put(10, "4世代");
|
||||
VARIETY_NAME_MAP.put(7, "一世代");
|
||||
VARIETY_NAME_MAP.put(8, "二世代");
|
||||
VARIETY_NAME_MAP.put(9, "三世代");
|
||||
VARIETY_NAME_MAP.put(10, "四世代");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,23 +142,24 @@ public class ScEmbryoFlushServiceImpl implements IScEmbryoFlushService
|
||||
// 2. 查询配种记录获取公羊信息
|
||||
Map<String, Object> breedRecord = scEmbryoFlushMapper.selectBreedRecordByEwe(donorFemaleNo);
|
||||
if (breedRecord != null && !breedRecord.isEmpty()) {
|
||||
String ramId = (String) breedRecord.get("ramId");
|
||||
result.put("donorMaleNo", ramId);
|
||||
String maleNo = (String) breedRecord.get("donorMaleNo"); // 这里的 Key 必须对应 SQL 里的别名
|
||||
result.put("donorMaleNo", maleNo);
|
||||
result.put("matingDate", breedRecord.get("matingDate"));
|
||||
|
||||
// 3. 查询公羊品种
|
||||
if (ramId != null && !ramId.trim().isEmpty()) {
|
||||
Map<String, Object> maleInfo = scEmbryoFlushMapper.selectSheepInfoByManageTag(ramId);
|
||||
if (maleNo != null && !maleNo.trim().isEmpty()) {
|
||||
Map<String, Object> maleInfo = scEmbryoFlushMapper.selectSheepInfoByManageTag(maleNo);
|
||||
if (maleInfo != null && !maleInfo.isEmpty()) {
|
||||
String maleVariety = (String) maleInfo.get("variety");
|
||||
Integer maleVarietyId = getIntValue(maleInfo.get("varietyId"));
|
||||
|
||||
result.put("donorMaleVariety", maleVariety);
|
||||
result.put("donorMaleVarietyId", maleVarietyId);
|
||||
|
||||
// 4. 根据品种ID计算胚胎品种
|
||||
if (maleVarietyId != null && femaleVarietyId != null) {
|
||||
String embryoVariety = calculateEmbryoVarietyById(maleVarietyId, femaleVarietyId);
|
||||
// 4. 【关键修复】使用品种名称计算胚胎品种
|
||||
// 这样可以确保无论数据库ID是多少,只要名字是对的就能算出结果
|
||||
Integer mId = getVarietyIdByName(maleVariety);
|
||||
Integer fId = getVarietyIdByName(femaleVariety);
|
||||
|
||||
if (mId != null && fId != null) {
|
||||
String embryoVariety = calculateEmbryoVarietyById(mId, fId);
|
||||
result.put("embryoVariety", embryoVariety);
|
||||
}
|
||||
}
|
||||
@@ -168,6 +169,7 @@ public class ScEmbryoFlushServiceImpl implements IScEmbryoFlushService
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 安全获取Integer值
|
||||
*/
|
||||
@@ -292,23 +294,22 @@ public class ScEmbryoFlushServiceImpl implements IScEmbryoFlushService
|
||||
// 级杂二代(BM)或n世代(SM) × 级杂一代/级杂二代/级杂三代/回交(公) → 世代
|
||||
|
||||
// 判断公羊是否为可产生世代的品种(级杂一代/二代/三代/回交)
|
||||
boolean isMaleForShidai = (male == VARIETY_JIZA_1 || male == VARIETY_JIZA_2 ||
|
||||
male == VARIETY_JIZA_3 || male == VARIETY_HUIJIAO);
|
||||
boolean isMaleCapableOfGeneration = (male >= 3 && male <= 10);
|
||||
|
||||
if (isMaleForShidai) {
|
||||
// 级杂二代(母) × 以上公羊 → 1世代
|
||||
if (isMaleCapableOfGeneration) {
|
||||
// 级杂二代(母) x 任意合格公羊 -> 一世代
|
||||
if (female == VARIETY_JIZA_2) {
|
||||
return VARIETY_NAME_MAP.get(VARIETY_SHIDAI_1);
|
||||
}
|
||||
// 1世代(母) × 以上公羊 → 2世代
|
||||
// 一世代(母) x 任意合格公羊 -> 二世代
|
||||
if (female == VARIETY_SHIDAI_1) {
|
||||
return VARIETY_NAME_MAP.get(VARIETY_SHIDAI_2);
|
||||
}
|
||||
// 2世代(母) × 以上公羊 → 3世代
|
||||
// 二世代(母) x 任意合格公羊 -> 三世代
|
||||
if (female == VARIETY_SHIDAI_2) {
|
||||
return VARIETY_NAME_MAP.get(VARIETY_SHIDAI_3);
|
||||
}
|
||||
// 3世代(母) × 以上公羊 → 4世代
|
||||
// 三世代(母) x 任意合格公羊 -> 四世代
|
||||
if (female == VARIETY_SHIDAI_3) {
|
||||
return VARIETY_NAME_MAP.get(VARIETY_SHIDAI_4);
|
||||
}
|
||||
|
||||
@@ -49,11 +49,12 @@
|
||||
<result property="technician" column="technician" />
|
||||
<result property="breedDrugs" column="breed_drugs" />
|
||||
<result property="breedType" column="breed_type" />
|
||||
<result property="frozenSemenNo" column="frozen_semen_no" /> <result property="createBy" column="create_by" />
|
||||
<result property="frozenSemenNo" column="frozen_sperm_no" /> <result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="comment" column="comment" />
|
||||
|
||||
<result property="embryoCount" column="embryo_count" />
|
||||
<result property="embryoSubType" column="embryoSubType" />
|
||||
<result property="donorEweNo" column="donor_ewe" />
|
||||
<result property="donorRamNo" column="donor_ram" />
|
||||
|
||||
@@ -165,6 +166,7 @@
|
||||
br.breed_drugs,
|
||||
br.breed_type,
|
||||
br.frozen_sperm_no, -- 冻精号
|
||||
br.embryoSubType,
|
||||
br.comment,
|
||||
br.create_by,
|
||||
br.create_time,
|
||||
@@ -192,7 +194,8 @@
|
||||
-- 公羊信息
|
||||
ram_view.bs_manage_tags as ram_manage_tags,
|
||||
ram_view.variety as ram_variety,
|
||||
|
||||
(SELECT variety FROM sheep_file WHERE bs_manage_tags = br.donor_ewe LIMIT 1) as donorEweVariety,
|
||||
(SELECT variety FROM sheep_file WHERE bs_manage_tags = br.donor_ram LIMIT 1) as donorRamVariety,
|
||||
-- 发情后配种时间(小时数)
|
||||
TIMESTAMPDIFF(HOUR, br.create_time, NOW()) as time_since_planning,
|
||||
|
||||
@@ -321,6 +324,8 @@
|
||||
where br.id = #{id}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<!-- 根据母羊耳号查询羊只ID -->
|
||||
<select id="getSheepIdByManageTags" parameterType="String" resultType="Long">
|
||||
select id from sheep_file where bs_manage_tags = #{manageTags} and is_delete = 0
|
||||
@@ -477,13 +482,14 @@
|
||||
<if test="technician != null">technician,</if>
|
||||
<if test="breedDrugs != null">breed_drugs,</if>
|
||||
<if test="breedType != null">breed_type,</if>
|
||||
<if test="frozenSemenNo != null">frozen_semen_no,</if>
|
||||
<if test="frozenSemenNo != null">frozen_sperm_no,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="comment != null">comment,</if>
|
||||
<if test="embryoCount != null">embryo_count,</if>
|
||||
<if test="donorEweNo != null">donor_ewe,</if>
|
||||
<if test="donorRamNo != null">donor_ram,</if>
|
||||
<if test="embryoSubType != null">embryoSubType,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="sheepId != null">#{sheepId},</if>
|
||||
@@ -526,13 +532,14 @@
|
||||
<if test="technician != null">technician = #{technician},</if>
|
||||
<if test="breedDrugs != null">breed_drugs = #{breedDrugs},</if>
|
||||
<if test="breedType != null">breed_type = #{breedType},</if>
|
||||
<if test="frozenSemenNo != null">frozen_semen_no = #{frozenSemenNo},</if>
|
||||
<if test="frozenSemenNo != null">frozen_sperm_no = #{frozenSemenNo},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="comment != null">comment = #{comment},</if>
|
||||
<if test="embryoCount != null">embryo_count = #{embryoCount},</if>
|
||||
<if test="donorEweNo != null">donor_ewe = #{donorEweNo},</if>
|
||||
<if test="donorRamNo != null">donor_ram = #{donorRamNo},</if>
|
||||
<if test="embryoSubType != null">embryoSubType = #{embryoSubType},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@@ -548,8 +555,8 @@
|
||||
-- Assuming linking via recipient tags is complicated,
|
||||
-- usually this is done by matching a recent flush record
|
||||
-- For now, this mimics the logic in your ServiceImpl
|
||||
SELECT id FROM sc_embryo_flush WHERE recipient_list LIKE concat('%', #{manageTags}, '%')
|
||||
ORDER BY created_at DESC LIMIT 1
|
||||
SELECT id FROM sc_embryo_flush WHERE donor_female_no LIKE concat('%', #{manageTags}, '%')
|
||||
ORDER BY flush_time DESC LIMIT 1
|
||||
)
|
||||
-- Note: If your sc_embryo_flush structure is different (one row per recipient), adjust accordingly.
|
||||
-- Based on provided file, it has `recipient_cnt`.
|
||||
|
||||
@@ -203,13 +203,9 @@
|
||||
<!-- ewe_id存的是数字ID,需要先根据耳号找到母羊ID,再查配种记录,再根据公羊ID找到公羊耳号 -->
|
||||
<select id="selectBreedRecordByEwe" resultType="java.util.Map">
|
||||
SELECT
|
||||
ram_sf.bs_manage_tags AS ramId,
|
||||
br.create_time AS matingDate
|
||||
FROM sc_breed_record br
|
||||
INNER JOIN sheep_file ewe_sf ON ewe_sf.id = br.ewe_id
|
||||
INNER JOIN sheep_file ram_sf ON ram_sf.id = br.ram_id
|
||||
WHERE ewe_sf.bs_manage_tags = #{eweManageTag}
|
||||
ORDER BY br.create_time DESC
|
||||
donor_ram AS donorMaleNo, create_time AS matingDate FROM sc_breed_record
|
||||
WHERE donor_ewe = #{eweManageTag} AND (is_delete = 0 OR is_delete IS NULL)
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user