Merge remote-tracking branch 'origin/main'

This commit is contained in:
zyh
2026-02-03 14:41:44 +08:00
14 changed files with 396 additions and 261 deletions

View File

@@ -201,6 +201,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -44,6 +44,17 @@ public class DaSheepfoldController extends BaseController
List<DaSheepfold> list = daSheepfoldService.selectDaSheepfoldList(daSheepfold);
return getDataTable(list);
}
/**
* 主表格:羊舍级别汇总列表
*/
@GetMapping("/summaryList")
public TableDataInfo summaryList(DaSheepfold daSheepfold) {
startPage();
List<DaSheepfold> list = daSheepfoldService.selectDaSheepfoldSummaryList(daSheepfold);
return getDataTable(list);
}
/*
* 根据羊舍ids查询羊只id
* */

View File

@@ -115,5 +115,10 @@ public class DaSheepfold extends BaseEntity
@Excel(name = "备注")
private String comment;
// 非数据库字段:单栏位羊数(子表格用)
private Integer sheepCount;
// 非数据库字段:羊舍总羊数(主表格用)
private Integer totalSheepCount;
}

View File

@@ -0,0 +1,28 @@
// 创建文件ExportConfig.java
package com.zhyc.module.base.domain;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* 导出配置类
*/
@Data
public class ExportConfig {
/**
* 要导出的列名列表(前端传递的驼峰命名)
*/
private List<String> columnNames;
/**
* 查询条件
*/
private Map<String, Object> queryParams;
/**
* 自定义筛选条件
*/
private Map<String, Object> customFilterParams;
}

View File

@@ -30,6 +30,12 @@ public interface DaSheepfoldMapper
*/
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold);
/**
* 羊舍级别汇总查询(主表格)
*/
List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold);
/**
* 新增羊舍管理
*

View File

@@ -29,6 +29,8 @@ public interface IDaSheepfoldService
*/
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold);
public List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold);
/**
* 新增羊舍管理
*

View File

@@ -5,6 +5,8 @@ import com.zhyc.module.base.domain.DaSheepfold;
import com.zhyc.module.base.mapper.BasSheepMapper;
import com.zhyc.module.base.mapper.DaSheepfoldMapper;
import com.zhyc.module.base.service.IDaSheepfoldService;
import org.slf4j.Logger; // 核心修正导入SLF4J的Logger
import org.slf4j.LoggerFactory; // 核心修正导入SLF4J的LoggerFactory
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -24,6 +26,11 @@ public class DaSheepfoldServiceImpl implements IDaSheepfoldService
@Autowired
private BasSheepMapper basSheepMapper;
// 新增:创建日志对象
private static final Logger log = LoggerFactory.getLogger(DaSheepfoldServiceImpl.class);
/**
* 查询羊舍管理
*
@@ -45,9 +52,44 @@ public class DaSheepfoldServiceImpl implements IDaSheepfoldService
@Override
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold)
{
List<DaSheepfold> sheepfoldList = daSheepfoldMapper.selectDaSheepfoldList(daSheepfold);
// 新增调试打印:输出每个栏位的羊数
log.info("===== 栏位羊数调试 =====");
log.info("查询条件牧场ID={}, 羊舍类型ID={}, 羊舍编号={}",
daSheepfold.getRanchId(), daSheepfold.getSheepfoldTypeId(), daSheepfold.getSheepfoldNo());
log.info("共查询到{}个栏位", sheepfoldList.size());
for (DaSheepfold fold : sheepfoldList) {
log.info("栏位ID={}, 羊舍编号={}, 排号={}, 栏数={}, 羊数={}",
fold.getId(), fold.getSheepfoldNo(), fold.getRowNo(), fold.getColumns(), fold.getSheepCount());
}
log.info("===== 调试结束 =====\n");
return daSheepfoldMapper.selectDaSheepfoldList(daSheepfold);
}
/**
* 羊舍级别汇总查询(主表格)
*/
public List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold) {
// List<DaSheepfold> summaryList = daSheepfoldMapper.selectDaSheepfoldSummaryList(daSheepfold);
//
// // 新增调试打印:输出羊舍汇总羊数
// log.info("===== 羊舍汇总羊数调试 =====");
// log.info("查询条件牧场ID={}, 羊舍类型ID={}",
// daSheepfold.getRanchId(), daSheepfold.getSheepfoldTypeId());
// log.info("共查询到{}个羊舍", summaryList.size());
//
// for (DaSheepfold fold : summaryList) {
// log.info("羊舍编号={}, 羊舍名称={}, 总羊数={}",
// fold.getSheepfoldNo(), fold.getSheepfoldName(), fold.getTotalSheepCount());
// }
// log.info("===== 汇总调试结束 =====\n");
return daSheepfoldMapper.selectDaSheepfoldSummaryList(daSheepfold);
}
/**
* 新增羊舍管理
*

View File

@@ -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-胚胎移植");
}
// 验证技术员

View File

@@ -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 = "配种子类型")

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -13,33 +13,93 @@
<result property="rowNo" column="row_no"/>
<result property="columns" column="columns"/>
<result property="comment" column="comment"/>
<!-- 新增羊只数量映射 -->
<result property="sheepCount" column="sheep_count"/>
</resultMap>
<!-- 基础栏位表查询字段 -->
<sql id="selectDaSheepfoldVo">
select id,
ranch_id,
sheepfold_name,
sheepfold_type_id,
sheepfold_no,
row_no,
columns,
comment
from da_sheepfold
SELECT
ds.id,
ds.ranch_id,
ds.sheepfold_name,
ds.sheepfold_type_id,
ds.sheepfold_no,
ds.row_no,
ds.columns,
ds.comment
FROM da_sheepfold ds
</sql>
<select id="selectDaSheepfoldList" parameterType="DaSheepfold" resultMap="DaSheepfoldResult">
<include refid="selectDaSheepfoldVo"/>
<where>
<if test="ranchId != null ">and ranch_id = #{ranchId}</if>
<if test="sheepfoldTypeId != null ">and sheepfold_type_id = #{sheepfoldTypeId}</if>
</where>
order by
SUBSTRING_INDEX(row_no, '-', 1),
CAST(columns AS UNSIGNED)
<!-- 1. 主表格:羊舍级别汇总查询(统计每个羊舍的总羊数) -->
<select id="selectDaSheepfoldSummaryList" parameterType="DaSheepfold" resultMap="DaSheepfoldSummaryResult">
SELECT
ds.ranch_id,
ds.sheepfold_type_id,
ds.sheepfold_no,
-- 提取羊舍名称(截取栏位名称的羊舍部分,保证唯一)
CONCAT(ds.sheepfold_no, '号', (SELECT dict_label FROM sys_dict_data WHERE dict_value = ds.sheepfold_type_id AND dict_type = 'bas_sheepfold_type')) as sheepfoldName,
MAX(ds.comment) as comment,
-- 汇总该羊舍下所有栏位的羊数总和
SUM(IFNULL(sheep_group.sheep_count, 0)) as totalSheepCount
FROM da_sheepfold ds
-- 左关联羊只表,统计每个栏位的羊数
LEFT JOIN (
SELECT sheepfold_id, COUNT(id) as sheep_count
FROM bas_sheep -- 羊只表
GROUP BY sheepfold_id -- 按栏位ID分组统计羊数
) sheep_group ON ds.id = sheep_group.sheepfold_id -- 关联字段修正为sheepfold_id
<where>
<if test="ranchId != null ">and ds.ranch_id = #{ranchId}</if>
<if test="sheepfoldTypeId != null ">and ds.sheepfold_type_id = #{sheepfoldTypeId}</if>
</where>
-- 按羊舍维度分组(牧场+羊舍类型+羊舍编号 唯一标识一个羊舍)
GROUP BY ds.ranch_id, ds.sheepfold_type_id, ds.sheepfold_no
ORDER BY ds.sheepfold_no
</select>
<!-- 2. 子表格:栏位级别明细查询(统计单个栏位的羊数) -->
<select id="selectDaSheepfoldList" parameterType="DaSheepfold" resultMap="DaSheepfoldResult">
SELECT
ds.id,
ds.ranch_id,
ds.sheepfold_name,
ds.sheepfold_type_id,
ds.sheepfold_no,
ds.row_no,
ds.columns,
ds.comment,
-- 统计当前栏位的羊数(关联羊只表)
IFNULL(sheep_group.sheep_count, 0) as sheep_count
FROM da_sheepfold ds
-- 左关联羊只表,避免无羊的栏位被过滤
LEFT JOIN (
SELECT sheepfold_id, COUNT(id) as sheep_count
FROM bas_sheep -- 羊只表
GROUP BY sheepfold_id
) sheep_group ON ds.id = sheep_group.sheepfold_id -- 关联字段修正为sheepfold_id
<where>
<if test="ranchId != null ">and ds.ranch_id = #{ranchId}</if>
<if test="sheepfoldTypeId != null ">and ds.sheepfold_type_id = #{sheepfoldTypeId}</if>
<if test="sheepfoldNo != null and sheepfoldNo != '' ">and ds.sheepfold_no = #{sheepfoldNo}</if>
</where>
GROUP BY ds.id,ds.ranch_id,ds.sheepfold_name,ds.sheepfold_type_id,ds.sheepfold_no,ds.row_no,ds.columns,ds.comment
ORDER BY SUBSTRING_INDEX(ds.row_no, '-', 1), CAST(ds.columns AS UNSIGNED)
</select>
<!-- 汇总结果映射(主表格用) -->
<resultMap id="DaSheepfoldSummaryResult" type="DaSheepfold">
<result property="ranchId" column="ranch_id"/>
<result property="sheepfoldTypeId" column="sheepfold_type_id"/>
<result property="sheepfoldNo" column="sheepfold_no"/>
<result property="sheepfoldName" column="sheepfoldName"/>
<result property="comment" column="comment"/>
<result property="totalSheepCount" column="totalSheepCount"/> <!-- 羊舍总羊数 -->
</resultMap>
<select id="selectDaSheepfoldById" parameterType="Long" resultMap="DaSheepfoldResult">
<include refid="selectDaSheepfoldVo"/>
where id = #{id}

View File

@@ -4,43 +4,43 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.produce.breed.mapper.ScBreedRecordMapper">
<!-- <resultMap type="ScBreedRecord" id="ScBreedRecordResult">-->
<!-- <result property="id" column="id" />-->
<!-- <result property="sheepId" column="sheep_id" />-->
<!-- <result property="ramId" column="ram_id" />-->
<!-- <result property="eweId" column="ewe_id" />-->
<!-- <result property="technician" column="technician" />-->
<!-- <result property="breedDrugs" column="breed_drugs" />-->
<!-- <result property="breedType" column="breed_type" />-->
<!-- <result property="createBy" column="create_by" / >-->
<!-- <result property="createTime" column="create_time" />-->
<!-- &lt;!&ndash; 显示字段 &ndash;&gt;-->
<!-- <result property="eweManageTags" column="ewe_manage_tags" />-->
<!-- <result property="eweVariety" column="ewe_variety" />-->
<!-- <result property="ramManageTags" column="ram_manage_tags" />-->
<!-- <result property="ramVariety" column="ram_variety" />-->
<!-- <result property="eweParity" column="ewe_parity" />-->
<!-- <result property="eweMonthAge" column="ewe_month_age" />-->
<!-- <result property="eweSheepfoldName" column="ewe_sheepfold_name" />-->
<!-- <result property="eweBreedStatus" column="ewe_breed_status" />-->
<!-- <result property="eweControlled" column="ewe_controlled" />-->
<!-- <result property="eweComment" column="ewe_comment" />-->
<!-- <result property="ranchName" column="ranch_name" />-->
<!-- <result property="matingType" column="mating_type" />-->
<!-- <result property="sheepType" column="sheep_type" />-->
<!-- <result property="matingCount" column="mating_count" />-->
<!-- <result property="timeSincePlanning" column="time_since_planning" />-->
<!-- &lt;!&ndash; 孕检相关字段 &ndash;&gt;-->
<!-- <result property="pregnancyCheckDate" column="pregnancy_check_date" />-->
<!-- <result property="pregnancyResult" column="pregnancy_result" />-->
<!-- <result property="pregnancyWay" column="pregnancy_way" />-->
<!-- <result property="fetusCount" column="fetus_count" />-->
<!-- <result property="pregnancyTechnician" column="pregnancy_technician" />-->
<!-- <result property="pregnancyRemark" column="pregnancy_remark" />-->
<!-- <result property="pregnancyRecordId" column="pregnancy_record_id" />-->
<!-- <result property="daysToPregnancyCheck" column="days_to_pregnancy_check" />-->
<!-- <result property="isPregnancyChecked" column="is_pregnancy_checked" />-->
<!-- </resultMap>-->
<!-- <resultMap type="ScBreedRecord" id="ScBreedRecordResult">-->
<!-- <result property="id" column="id" />-->
<!-- <result property="sheepId" column="sheep_id" />-->
<!-- <result property="ramId" column="ram_id" />-->
<!-- <result property="eweId" column="ewe_id" />-->
<!-- <result property="technician" column="technician" />-->
<!-- <result property="breedDrugs" column="breed_drugs" />-->
<!-- <result property="breedType" column="breed_type" />-->
<!-- <result property="createBy" column="create_by" / >-->
<!-- <result property="createTime" column="create_time" />-->
<!-- &lt;!&ndash; 显示字段 &ndash;&gt;-->
<!-- <result property="eweManageTags" column="ewe_manage_tags" />-->
<!-- <result property="eweVariety" column="ewe_variety" />-->
<!-- <result property="ramManageTags" column="ram_manage_tags" />-->
<!-- <result property="ramVariety" column="ram_variety" />-->
<!-- <result property="eweParity" column="ewe_parity" />-->
<!-- <result property="eweMonthAge" column="ewe_month_age" />-->
<!-- <result property="eweSheepfoldName" column="ewe_sheepfold_name" />-->
<!-- <result property="eweBreedStatus" column="ewe_breed_status" />-->
<!-- <result property="eweControlled" column="ewe_controlled" />-->
<!-- <result property="eweComment" column="ewe_comment" />-->
<!-- <result property="ranchName" column="ranch_name" />-->
<!-- <result property="matingType" column="mating_type" />-->
<!-- <result property="sheepType" column="sheep_type" />-->
<!-- <result property="matingCount" column="mating_count" />-->
<!-- <result property="timeSincePlanning" column="time_since_planning" />-->
<!-- &lt;!&ndash; 孕检相关字段 &ndash;&gt;-->
<!-- <result property="pregnancyCheckDate" column="pregnancy_check_date" />-->
<!-- <result property="pregnancyResult" column="pregnancy_result" />-->
<!-- <result property="pregnancyWay" column="pregnancy_way" />-->
<!-- <result property="fetusCount" column="fetus_count" />-->
<!-- <result property="pregnancyTechnician" column="pregnancy_technician" />-->
<!-- <result property="pregnancyRemark" column="pregnancy_remark" />-->
<!-- <result property="pregnancyRecordId" column="pregnancy_record_id" />-->
<!-- <result property="daysToPregnancyCheck" column="days_to_pregnancy_check" />-->
<!-- <result property="isPregnancyChecked" column="is_pregnancy_checked" />-->
<!-- </resultMap>-->
<resultMap type="ScBreedRecord" id="ScBreedRecordResult">
<result property="id" column="id" />
<result property="sheepId" column="sheep_id" />
@@ -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" />
@@ -86,75 +87,75 @@
<result property="daysToPregnancyCheck" column="days_to_pregnancy_check" />
</resultMap>
<!-- <sql id="selectScBreedRecordVo">-->
<!-- select DISTINCT-->
<!-- br.id,-->
<!-- br.sheep_id,-->
<!-- br.ram_id,-->
<!-- br.ewe_id,-->
<!-- br.technician,-->
<!-- br.breed_drugs,-->
<!-- br.breed_type,-->
<!-- br.create_by,-->
<!-- br.create_time,-->
<!-- &#45;&#45; 母羊信息(从视图获取)-->
<!-- ewe_view.bs_manage_tags as ewe_manage_tags,-->
<!-- ewe_view.variety as ewe_variety,-->
<!-- ewe_view.parity as ewe_parity,-->
<!-- ewe_view.month_age as ewe_month_age,-->
<!-- ewe_view.sheepfold_name as ewe_sheepfold_name,-->
<!-- ewe_view.breed as ewe_breed_status,-->
<!-- ewe_view.controlled as ewe_controlled,-->
<!-- ewe_view.comment as ewe_comment,-->
<!-- ewe_view.dr_ranch as ranch_name,-->
<!-- ewe_view.name as sheep_type,-->
<!-- ewe_view.mating_total as mating_count,-->
<!-- &#45;&#45; 公羊信息(从视图获取)-->
<!-- ram_view.bs_manage_tags as ram_manage_tags,-->
<!-- ram_view.variety as ram_variety,-->
<!-- <sql id="selectScBreedRecordVo">-->
<!-- select DISTINCT-->
<!-- br.id,-->
<!-- br.sheep_id,-->
<!-- br.ram_id,-->
<!-- br.ewe_id,-->
<!-- br.technician,-->
<!-- br.breed_drugs,-->
<!-- br.breed_type,-->
<!-- br.create_by,-->
<!-- br.create_time,-->
<!-- &#45;&#45; 母羊信息(从视图获取)-->
<!-- ewe_view.bs_manage_tags as ewe_manage_tags,-->
<!-- ewe_view.variety as ewe_variety,-->
<!-- ewe_view.parity as ewe_parity,-->
<!-- ewe_view.month_age as ewe_month_age,-->
<!-- ewe_view.sheepfold_name as ewe_sheepfold_name,-->
<!-- ewe_view.breed as ewe_breed_status,-->
<!-- ewe_view.controlled as ewe_controlled,-->
<!-- ewe_view.comment as ewe_comment,-->
<!-- ewe_view.dr_ranch as ranch_name,-->
<!-- ewe_view.name as sheep_type,-->
<!-- ewe_view.mating_total as mating_count,-->
<!-- &#45;&#45; 公羊信息(从视图获取)-->
<!-- ram_view.bs_manage_tags as ram_manage_tags,-->
<!-- ram_view.variety as ram_variety,-->
<!-- &#45;&#45; 配种方式显示-->
<!-- CASE br.breed_type-->
<!-- WHEN 1 THEN '同期发情'-->
<!-- WHEN 2 THEN '本交'-->
<!-- WHEN 3 THEN '冲胚'-->
<!-- WHEN 4 THEN '自然发情人工授精'-->
<!-- ELSE '未知'-->
<!-- END as mating_type,-->
<!-- &#45;&#45; 发情后配种时间(小时数)-->
<!-- TIMESTAMPDIFF(HOUR, br.create_time, NOW()) as time_since_planning,-->
<!-- &#45;&#45; 孕检相关信息-->
<!-- pr.datetime as pregnancy_check_date,-->
<!-- pr.result as pregnancy_result,-->
<!-- pr.way as pregnancy_way,-->
<!-- pr.fetus_count,-->
<!-- pr.technician as pregnancy_technician,-->
<!-- pr.remark as pregnancy_remark,-->
<!-- pr.id as pregnancy_record_id,-->
<!-- &#45;&#45; 配种到孕检间隔天数-->
<!-- CASE-->
<!-- WHEN pr.datetime IS NOT NULL THEN DATEDIFF(pr.datetime, br.create_time)-->
<!-- ELSE NULL-->
<!-- END as days_to_pregnancy_check,-->
<!-- &#45;&#45; 是否已孕检-->
<!-- CASE-->
<!-- WHEN pr.id IS NOT NULL THEN 1-->
<!-- ELSE 0-->
<!-- END as is_pregnancy_checked-->
<!-- from sc_breed_record br-->
<!-- left join sheep_file ewe_view on br.ewe_id = ewe_view.id-->
<!-- left join sheep_file ram_view on br.ram_id = ram_view.id-->
<!-- &#45;&#45; 修复:使用子查询确保只返回一条孕检记录-->
<!-- left join sc_pregnancy_record pr on pr.id = (-->
<!-- select pr2.id-->
<!-- from sc_pregnancy_record pr2-->
<!-- where pr2.sheep_id = br.ewe_id-->
<!-- and pr2.is_delete = 0-->
<!-- and pr2.datetime >= br.create_time-->
<!-- order by pr2.datetime asc, pr2.id asc-->
<!-- limit 1-->
<!-- )-->
<!-- </sql>-->
<!-- &#45;&#45; 配种方式显示-->
<!-- CASE br.breed_type-->
<!-- WHEN 1 THEN '同期发情'-->
<!-- WHEN 2 THEN '本交'-->
<!-- WHEN 3 THEN '冲胚'-->
<!-- WHEN 4 THEN '自然发情人工授精'-->
<!-- ELSE '未知'-->
<!-- END as mating_type,-->
<!-- &#45;&#45; 发情后配种时间(小时数)-->
<!-- TIMESTAMPDIFF(HOUR, br.create_time, NOW()) as time_since_planning,-->
<!-- &#45;&#45; 孕检相关信息-->
<!-- pr.datetime as pregnancy_check_date,-->
<!-- pr.result as pregnancy_result,-->
<!-- pr.way as pregnancy_way,-->
<!-- pr.fetus_count,-->
<!-- pr.technician as pregnancy_technician,-->
<!-- pr.remark as pregnancy_remark,-->
<!-- pr.id as pregnancy_record_id,-->
<!-- &#45;&#45; 配种到孕检间隔天数-->
<!-- CASE-->
<!-- WHEN pr.datetime IS NOT NULL THEN DATEDIFF(pr.datetime, br.create_time)-->
<!-- ELSE NULL-->
<!-- END as days_to_pregnancy_check,-->
<!-- &#45;&#45; 是否已孕检-->
<!-- CASE-->
<!-- WHEN pr.id IS NOT NULL THEN 1-->
<!-- ELSE 0-->
<!-- END as is_pregnancy_checked-->
<!-- from sc_breed_record br-->
<!-- left join sheep_file ewe_view on br.ewe_id = ewe_view.id-->
<!-- left join sheep_file ram_view on br.ram_id = ram_view.id-->
<!-- &#45;&#45; 修复:使用子查询确保只返回一条孕检记录-->
<!-- left join sc_pregnancy_record pr on pr.id = (-->
<!-- select pr2.id-->
<!-- from sc_pregnancy_record pr2-->
<!-- where pr2.sheep_id = br.ewe_id-->
<!-- and pr2.is_delete = 0-->
<!-- and pr2.datetime >= br.create_time-->
<!-- order by pr2.datetime asc, pr2.id asc-->
<!-- limit 1-->
<!-- )-->
<!-- </sql>-->
<sql id="selectScBreedRecordVo">
select DISTINCT
br.id,
@@ -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,
@@ -265,32 +268,32 @@
limit 1
)
</sql>
<!-- <select id="selectScBreedRecordList" parameterType="ScBreedRecord" resultMap="ScBreedRecordResult">-->
<!-- <include refid="selectScBreedRecordVo"/>-->
<!-- <where>-->
<!-- <if test="sheepId != null "> and br.sheep_id = #{sheepId}</if>-->
<!-- <if test="ramId != null and ramId != ''"> and br.ram_id = #{ramId}</if>-->
<!-- <if test="eweId != null and eweId != ''"> and br.ewe_id = #{eweId}</if>-->
<!-- <if test="breedType != null"> and br.breed_type = #{breedType}</if>-->
<!-- <if test="technician != null and technician != ''"> and br.technician like concat('%', #{technician}, '%')</if>-->
<!-- <if test="breedDrugs != null and breedDrugs != ''"> and br.breed_drugs like concat('%', #{breedDrugs}, '%')</if>-->
<!-- <if test="createBy != null and createBy != ''"> and br.create_by like concat('%', #{createBy}, '%')</if>-->
<!-- <if test="createTime != null "> and date_format(br.create_time,'%y-%m-%d') = date_format(#{createTime},'%y-%m-%d')</if>-->
<!-- &lt;!&ndash; 新增耳号查询条件 &ndash;&gt;-->
<!-- <if test="eweManageTags != null and eweManageTags != ''"> and ewe_view.bs_manage_tags like concat('%', #{eweManageTags}, '%')</if>-->
<!-- <if test="ramManageTags != null and ramManageTags != ''"> and ram_view.bs_manage_tags like concat('%', #{ramManageTags}, '%')</if>-->
<!-- <if test="eweVariety != null and eweVariety != ''"> and ewe_view.variety like concat('%', #{eweVariety}, '%')</if>-->
<!-- <if test="ramVariety != null and ramVariety != ''"> and ram_view.variety like concat('%', #{ramVariety}, '%')</if>-->
<!-- <if test="ranchId != null"> and ewe_view.ranch_id = #{ranchId}</if>-->
<!-- &lt;!&ndash; 孕检相关查询条件 &ndash;&gt;-->
<!-- <if test="pregnancyResult != null and pregnancyResult != ''"> and pr.result like concat('%', #{pregnancyResult}, '%')</if>-->
<!-- <if test="isPregnancyChecked != null">-->
<!-- <if test="isPregnancyChecked == 1"> and pr.id IS NOT NULL</if>-->
<!-- <if test="isPregnancyChecked == 0"> and pr.id IS NULL</if>-->
<!-- </if>-->
<!-- </where>-->
<!-- order by br.create_time desc-->
<!-- </select>-->
<!-- <select id="selectScBreedRecordList" parameterType="ScBreedRecord" resultMap="ScBreedRecordResult">-->
<!-- <include refid="selectScBreedRecordVo"/>-->
<!-- <where>-->
<!-- <if test="sheepId != null "> and br.sheep_id = #{sheepId}</if>-->
<!-- <if test="ramId != null and ramId != ''"> and br.ram_id = #{ramId}</if>-->
<!-- <if test="eweId != null and eweId != ''"> and br.ewe_id = #{eweId}</if>-->
<!-- <if test="breedType != null"> and br.breed_type = #{breedType}</if>-->
<!-- <if test="technician != null and technician != ''"> and br.technician like concat('%', #{technician}, '%')</if>-->
<!-- <if test="breedDrugs != null and breedDrugs != ''"> and br.breed_drugs like concat('%', #{breedDrugs}, '%')</if>-->
<!-- <if test="createBy != null and createBy != ''"> and br.create_by like concat('%', #{createBy}, '%')</if>-->
<!-- <if test="createTime != null "> and date_format(br.create_time,'%y-%m-%d') = date_format(#{createTime},'%y-%m-%d')</if>-->
<!-- &lt;!&ndash; 新增耳号查询条件 &ndash;&gt;-->
<!-- <if test="eweManageTags != null and eweManageTags != ''"> and ewe_view.bs_manage_tags like concat('%', #{eweManageTags}, '%')</if>-->
<!-- <if test="ramManageTags != null and ramManageTags != ''"> and ram_view.bs_manage_tags like concat('%', #{ramManageTags}, '%')</if>-->
<!-- <if test="eweVariety != null and eweVariety != ''"> and ewe_view.variety like concat('%', #{eweVariety}, '%')</if>-->
<!-- <if test="ramVariety != null and ramVariety != ''"> and ram_view.variety like concat('%', #{ramVariety}, '%')</if>-->
<!-- <if test="ranchId != null"> and ewe_view.ranch_id = #{ranchId}</if>-->
<!-- &lt;!&ndash; 孕检相关查询条件 &ndash;&gt;-->
<!-- <if test="pregnancyResult != null and pregnancyResult != ''"> and pr.result like concat('%', #{pregnancyResult}, '%')</if>-->
<!-- <if test="isPregnancyChecked != null">-->
<!-- <if test="isPregnancyChecked == 1"> and pr.id IS NOT NULL</if>-->
<!-- <if test="isPregnancyChecked == 0"> and pr.id IS NULL</if>-->
<!-- </if>-->
<!-- </where>-->
<!-- order by br.create_time desc-->
<!-- </select>-->
<select id="selectScBreedRecordList" parameterType="ScBreedRecord" resultMap="ScBreedRecordResult">
<include refid="selectScBreedRecordVo"/>
<where>
@@ -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
@@ -445,29 +450,29 @@
limit 1
</select>
<!-- <insert id="insertScBreedRecord" parameterType="ScBreedRecord" useGeneratedKeys="true" keyProperty="id">-->
<!-- insert into sc_breed_record-->
<!-- <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id,</if>-->
<!-- <if test="ramId != null">ram_id,</if>-->
<!-- <if test="eweId != null">ewe_id,</if>-->
<!-- <if test="technician != null">technician,</if>-->
<!-- <if test="breedDrugs != null">breed_drugs,</if>-->
<!-- <if test="breedType != null">breed_type,</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="ramId != null">#{ramId},</if>-->
<!-- <if test="eweId != null">#{eweId},</if>-->
<!-- <if test="technician != null">#{technician},</if>-->
<!-- <if test="breedDrugs != null">#{breedDrugs},</if>-->
<!-- <if test="breedType != null">#{breedType},</if>-->
<!-- <if test="createBy != null">#{createBy},</if>-->
<!-- <if test="createTime != null">#{createTime},</if>-->
<!-- </trim>-->
<!-- </insert>-->
<!-- <insert id="insertScBreedRecord" parameterType="ScBreedRecord" useGeneratedKeys="true" keyProperty="id">-->
<!-- insert into sc_breed_record-->
<!-- <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id,</if>-->
<!-- <if test="ramId != null">ram_id,</if>-->
<!-- <if test="eweId != null">ewe_id,</if>-->
<!-- <if test="technician != null">technician,</if>-->
<!-- <if test="breedDrugs != null">breed_drugs,</if>-->
<!-- <if test="breedType != null">breed_type,</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="ramId != null">#{ramId},</if>-->
<!-- <if test="eweId != null">#{eweId},</if>-->
<!-- <if test="technician != null">#{technician},</if>-->
<!-- <if test="breedDrugs != null">#{breedDrugs},</if>-->
<!-- <if test="breedType != null">#{breedType},</if>-->
<!-- <if test="createBy != null">#{createBy},</if>-->
<!-- <if test="createTime != null">#{createTime},</if>-->
<!-- </trim>-->
<!-- </insert>-->
<insert id="insertScBreedRecord" parameterType="ScBreedRecord" useGeneratedKeys="true" keyProperty="id">
insert into sc_breed_record
<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -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>
@@ -503,20 +509,20 @@
</trim>
</insert>
<!-- <update id="updateScBreedRecord" parameterType="ScBreedRecord">-->
<!-- update sc_breed_record-->
<!-- <trim prefix="SET" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id = #{sheepId},</if>-->
<!-- <if test="ramId != null">ram_id = #{ramId},</if>-->
<!-- <if test="eweId != null">ewe_id = #{eweId},</if>-->
<!-- <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="createBy != null">create_by = #{createBy},</if>-->
<!-- <if test="createTime != null">create_time = #{createTime},</if>-->
<!-- </trim>-->
<!-- where id = #{id}-->
<!-- </update>-->
<!-- <update id="updateScBreedRecord" parameterType="ScBreedRecord">-->
<!-- update sc_breed_record-->
<!-- <trim prefix="SET" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id = #{sheepId},</if>-->
<!-- <if test="ramId != null">ram_id = #{ramId},</if>-->
<!-- <if test="eweId != null">ewe_id = #{eweId},</if>-->
<!-- <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="createBy != null">create_by = #{createBy},</if>-->
<!-- <if test="createTime != null">create_time = #{createTime},</if>-->
<!-- </trim>-->
<!-- where id = #{id}-->
<!-- </update>-->
<update id="updateScBreedRecord" parameterType="ScBreedRecord">
update sc_breed_record
<trim prefix="SET" suffixOverrides=",">
@@ -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`.

View File

@@ -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>