种公羊档案修改

This commit is contained in:
zyk 2025-12-25 16:38:38 +08:00
parent fe5dffb508
commit 454c5bcb73
18 changed files with 1796 additions and 112 deletions

View File

@ -1,6 +1,210 @@
//package com.zhyc.module.base.controller;
//
//import java.util.List;
//import java.util.Map;
//import javax.servlet.http.HttpServletResponse;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PutMapping;
//import org.springframework.web.bind.annotation.DeleteMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import com.zhyc.common.annotation.Log;
//import com.zhyc.common.enums.BusinessType;
//import com.zhyc.module.base.domain.BreedRamFile;
//import com.zhyc.module.base.service.IBreedRamFileService;
//import com.zhyc.common.core.controller.BaseController;
//import com.zhyc.common.core.domain.AjaxResult;
//import com.zhyc.common.utils.poi.ExcelUtil;
//import com.zhyc.common.core.page.TableDataInfo;
//
///**
// * 种公羊档案Controller
// *
// * @author zhyc
// * @date 2025-07-29
// */
//@RestController
//@RequestMapping("/ram_file/bas_ram_file")
//public class BreedRamFileController extends BaseController
//{
// @Autowired
// private IBreedRamFileService breedRamFileService;
//
// /**
// * 查询种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/list")
// public TableDataInfo list(BreedRamFile breedRamFile)
// {
// startPage();
// List<BreedRamFile> list = breedRamFileService.selectBreedRamFileList(breedRamFile);
// return getDataTable(list);
// }
//
// /**
// * 导出种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:export')")
// @Log(title = "种公羊档案", businessType = BusinessType.EXPORT)
// @PostMapping("/export")
// public void export(HttpServletResponse response, BreedRamFile breedRamFile)
// {
// List<BreedRamFile> list = breedRamFileService.selectBreedRamFileList(breedRamFile);
// ExcelUtil<BreedRamFile> util = new ExcelUtil<BreedRamFile>(BreedRamFile.class);
// util.exportExcel(response, list, "种公羊档案数据");
// }
//
// /**
// * 获取种公羊档案详细信息
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:query')")
// @GetMapping(value = "/{id}")
// public AjaxResult getInfo(@PathVariable("id") Long id)
// {
// return success(breedRamFileService.selectBreedRamFileById(id));
// }
//
// /**
// * 新增种公羊档案
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:add')")
// @Log(title = "种公羊档案", businessType = BusinessType.INSERT)
// @PostMapping
// public AjaxResult add(@RequestBody BreedRamFile breedRamFile)
// {
// return toAjax(breedRamFileService.insertBreedRamFile(breedRamFile));
// }
//
// /**
// * 修改种公羊档案
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:edit')")
// @Log(title = "种公羊档案", businessType = BusinessType.UPDATE)
// @PutMapping
// public AjaxResult edit(@RequestBody BreedRamFile breedRamFile)
// {
// return toAjax(breedRamFileService.updateBreedRamFile(breedRamFile));
// }
//
// /**
// * 删除种公羊档案
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:remove')")
// @Log(title = "种公羊档案", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable Long[] ids)
// {
// return toAjax(breedRamFileService.deleteBreedRamFileByIds(ids));
// }
//
// /**
// * 从sheep_file同步公羊数据
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:sync')")
// @Log(title = "种公羊档案同步", businessType = BusinessType.UPDATE)
// @PostMapping("/sync")
// public AjaxResult syncFromSheepFile()
// {
// int syncCount = breedRamFileService.syncFromSheepFile();
// return AjaxResult.success("成功同步 " + syncCount + " 条公羊数据");
// }
//
// /**
// * 以下方法可以添加到 BreedRamFileController.java
// * 提供更丰富的查询接口
// */
//
// /**
// * 根据普通耳号查询种公羊档案
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:query')")
// @GetMapping("/byEarNumber/{earNumber}")
// public AjaxResult getByEarNumber(@PathVariable("earNumber") String earNumber)
// {
// BreedRamFile ram = breedRamFileService.selectBreedRamFileByEarNumber(earNumber);
// return success(ram);
// }
//
// /**
// * 根据牧场ID查询种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/byRanch/{ranchId}")
// public AjaxResult getByRanchId(@PathVariable("ranchId") Long ranchId)
// {
// List<BreedRamFile> list = breedRamFileService.selectBreedRamFileListByRanchId(ranchId);
// return success(list);
// }
//
// /**
// * 查询核心羊群种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/coreFlock")
// public TableDataInfo getCoreFlockList(BreedRamFile breedRamFile)
// {
// startPage();
// List<BreedRamFile> list = breedRamFileService.selectCoreFlockBreedRamFileList(breedRamFile);
// return getDataTable(list);
// }
//
// /**
// * 查询种用种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/breedingUse")
// public TableDataInfo getBreedingUseList(BreedRamFile breedRamFile)
// {
// startPage();
// List<BreedRamFile> list = breedRamFileService.selectBreedingUseBreedRamFileList(breedRamFile);
// return getDataTable(list);
// }
//
// /**
// * 根据羊舍ID查询种公羊档案列表
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/bySheepfold/{sheepfoldId}")
// public AjaxResult getBySheepfoldId(@PathVariable("sheepfoldId") Long sheepfoldId)
// {
// List<BreedRamFile> list = breedRamFileService.selectBreedRamFileListBySheepfoldId(sheepfoldId);
// return success(list);
// }
//
// /**
// * 批量同步指定公羊的数据
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:sync')")
// @Log(title = "批量同步种公羊数据", businessType = BusinessType.UPDATE)
// @PostMapping("/syncBatch")
// public AjaxResult syncBatch(@RequestBody List<String> earNumbers)
// {
// int syncCount = breedRamFileService.syncSpecificRams(earNumbers);
// return AjaxResult.success("成功同步 " + syncCount + " 条公羊数据");
// }
//
// /**
// * 获取种公羊统计信息
// */
// @PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
// @GetMapping("/statistics")
// public AjaxResult getStatistics()
// {
// Map<String, Object> statistics = breedRamFileService.getBreedRamStatistics();
// return success(statistics);
// }
//}
package com.zhyc.module.base.controller;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +219,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.module.base.domain.BreedRamFile;
import com.zhyc.module.base.domain.ViewBreedRamFile;
import com.zhyc.module.base.service.IBreedRamFileService;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
@ -35,42 +240,42 @@ public class BreedRamFileController extends BaseController
private IBreedRamFileService breedRamFileService;
/**
* 查询种公羊档案列表
* 查询种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/list")
public TableDataInfo list(BreedRamFile breedRamFile)
public TableDataInfo list(ViewBreedRamFile viewBreedRamFile)
{
startPage();
List<BreedRamFile> list = breedRamFileService.selectBreedRamFileList(breedRamFile);
List<ViewBreedRamFile> list = breedRamFileService.selectViewBreedRamFileList(viewBreedRamFile);
return getDataTable(list);
}
/**
* 导出种公羊档案列表
* 导出种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:export')")
@Log(title = "种公羊档案", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BreedRamFile breedRamFile)
public void export(HttpServletResponse response, ViewBreedRamFile viewBreedRamFile)
{
List<BreedRamFile> list = breedRamFileService.selectBreedRamFileList(breedRamFile);
ExcelUtil<BreedRamFile> util = new ExcelUtil<BreedRamFile>(BreedRamFile.class);
List<ViewBreedRamFile> list = breedRamFileService.selectViewBreedRamFileList(viewBreedRamFile);
ExcelUtil<ViewBreedRamFile> util = new ExcelUtil<ViewBreedRamFile>(ViewBreedRamFile.class);
util.exportExcel(response, list, "种公羊档案数据");
}
/**
* 获取种公羊档案详细信息
* 获取种公羊档案详细信息(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(breedRamFileService.selectBreedRamFileById(id));
return success(breedRamFileService.selectViewBreedRamFileById(id));
}
/**
* 新增种公羊档案
* 新增种公羊档案(更新表)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:add')")
@Log(title = "种公羊档案", businessType = BusinessType.INSERT)
@ -81,7 +286,7 @@ public class BreedRamFileController extends BaseController
}
/**
* 修改种公羊档案
* 修改种公羊档案(更新表)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:edit')")
@Log(title = "种公羊档案", businessType = BusinessType.UPDATE)
@ -92,7 +297,7 @@ public class BreedRamFileController extends BaseController
}
/**
* 删除种公羊档案
* 删除种公羊档案(更新表)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:remove')")
@Log(title = "种公羊档案", businessType = BusinessType.DELETE)
@ -101,4 +306,96 @@ public class BreedRamFileController extends BaseController
{
return toAjax(breedRamFileService.deleteBreedRamFileByIds(ids));
}
/**
* 从sheep_file同步公羊数据
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:sync')")
@Log(title = "种公羊档案同步", businessType = BusinessType.UPDATE)
@PostMapping("/sync")
public AjaxResult syncFromSheepFile()
{
int syncCount = breedRamFileService.syncFromSheepFile();
return AjaxResult.success("成功同步 " + syncCount + " 条公羊数据");
}
/**
* 根据普通耳号查询种公羊档案(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:query')")
@GetMapping("/byEarNumber/{earNumber}")
public AjaxResult getByEarNumber(@PathVariable("earNumber") String earNumber)
{
ViewBreedRamFile ram = breedRamFileService.selectViewBreedRamFileByEarNumber(earNumber);
return success(ram);
}
/**
* 根据牧场ID查询种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/byRanch/{ranchId}")
public AjaxResult getByRanchId(@PathVariable("ranchId") Long ranchId)
{
List<ViewBreedRamFile> list = breedRamFileService.selectViewBreedRamFileListByRanchId(ranchId);
return success(list);
}
/**
* 查询核心羊群种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/coreFlock")
public TableDataInfo getCoreFlockList(ViewBreedRamFile viewBreedRamFile)
{
startPage();
List<ViewBreedRamFile> list = breedRamFileService.selectCoreFlockViewBreedRamFileList(viewBreedRamFile);
return getDataTable(list);
}
/**
* 查询种用种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/breedingUse")
public TableDataInfo getBreedingUseList(ViewBreedRamFile viewBreedRamFile)
{
startPage();
List<ViewBreedRamFile> list = breedRamFileService.selectBreedingUseViewBreedRamFileList(viewBreedRamFile);
return getDataTable(list);
}
/**
* 根据羊舍ID查询种公羊档案列表(使用视图)
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/bySheepfold/{sheepfoldId}")
public AjaxResult getBySheepfoldId(@PathVariable("sheepfoldId") Long sheepfoldId)
{
List<ViewBreedRamFile> list = breedRamFileService.selectViewBreedRamFileListBySheepfoldId(sheepfoldId);
return success(list);
}
/**
* 批量同步指定公羊的数据
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:sync')")
@Log(title = "批量同步种公羊数据", businessType = BusinessType.UPDATE)
@PostMapping("/syncBatch")
public AjaxResult syncBatch(@RequestBody List<String> earNumbers)
{
int syncCount = breedRamFileService.syncSpecificRams(earNumbers);
return AjaxResult.success("成功同步 " + syncCount + " 条公羊数据");
}
/**
* 获取种公羊统计信息
*/
@PreAuthorize("@ss.hasPermi('breed_ram_file:breed_ram_file:list')")
@GetMapping("/statistics")
public AjaxResult getStatistics()
{
Map<String, Object> statistics = breedRamFileService.getBreedRamStatistics();
return success(statistics);
}
}

View File

@ -21,9 +21,9 @@ public class BreedRamFile extends BaseEntity
/** 种公羊id */
private Long id;
/** 普通耳号 */
/** 普通耳号(对应数据库字段 manage_tags */
@Excel(name = "普通耳号")
private String ordinaryEarNumber;
private String manageTags;
/** 牧场id */
@Excel(name = "牧场id")
@ -263,6 +263,32 @@ public class BreedRamFile extends BaseEntity
@Excel(name = "是否亲子鉴定", readConverterExp = "0=否,1=是")
private Long isPaternityTested;
/** 公羊后代数 */
@Excel(name = "公羊后代数")
private Long offspringCount;
/** 多胎性 */
@Excel(name = "多胎性")
private BigDecimal prolificacy;
// 对应的Getter和Setter方法
public Long getOffspringCount() {
return offspringCount;
}
public void setOffspringCount(Long offspringCount) {
this.offspringCount = offspringCount;
}
public BigDecimal getProlificacy() {
return prolificacy;
}
public void setProlificacy(BigDecimal prolificacy) {
this.prolificacy = prolificacy;
}
/** 是否删除0否1是 */
private Long isDelete;
@ -275,15 +301,22 @@ public class BreedRamFile extends BaseEntity
{
return id;
}
public void setOrdinaryEarNumber(String ordinaryEarNumber)
{
this.ordinaryEarNumber = ordinaryEarNumber;
public void setOrdinaryEarNumber(String ordinaryEarNumber) {
this.manageTags = ordinaryEarNumber;
}
public String getOrdinaryEarNumber()
{
return ordinaryEarNumber;
public String getOrdinaryEarNumber() {
return this.manageTags;
}
public void setManageTags(String manageTags) {
this.manageTags = manageTags;
}
public String getManageTags() {
return manageTags;
}
public void setRanchId(Long ranchId)
{
this.ranchId = ranchId;
@ -885,6 +918,9 @@ public class BreedRamFile extends BaseEntity
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("isDelete", getIsDelete())
// 同时在toString()方法中添加这两个字段
.append("offspringCount", getOffspringCount())
.append("prolificacy", getProlificacy())
.toString();
}
}

View File

@ -106,4 +106,10 @@ public interface BreedRamFileMapper
* @return 种公羊档案集合
*/
public List<BreedRamFile> selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile);
/**
* 根据普通耳号查询种公羊档案
*
* @param ordinaryEarNumber 普通耳号
* @return 种公羊档案
*/
}

View File

@ -101,4 +101,21 @@ public interface SheepFileMapper
List<String> selectFieldValuesByProvider(@Param("fieldName") String fieldName);
/**
* 查询所有公羊gender=2
*
* @return 公羊列表
*/
/**
* 查询所有公羊gender=2
* @return 公羊列表
*/
List<SheepFile> selectRamList();
/**
* 根据管理耳号查询羊只
* @param manageTags 管理耳号
* @return 羊只信息
*/
SheepFile selectSheepFileByManageTags(String manageTags);
}

View File

@ -1,7 +1,149 @@
//package com.zhyc.module.base.service;
//
//import java.util.List;
//import java.util.Map;
//
//import com.zhyc.module.base.domain.BreedRamFile;
//
///**
// * 种公羊档案Service接口
// *
// * @author zhyc
// * @date 2025-07-29
// */
//public interface IBreedRamFileService
//{
// /**
// * 查询种公羊档案
// *
// * @param id 种公羊档案主键
// * @return 种公羊档案
// */
// public BreedRamFile selectBreedRamFileById(Long id);
//
// /**
// * 查询种公羊档案列表
// *
// * @param breedRamFile 种公羊档案
// * @return 种公羊档案集合
// */
// public List<BreedRamFile> selectBreedRamFileList(BreedRamFile breedRamFile);
//
// /**
// * 新增种公羊档案
// *
// * @param breedRamFile 种公羊档案
// * @return 结果
// */
// public int insertBreedRamFile(BreedRamFile breedRamFile);
//
// /**
// * 修改种公羊档案
// *
// * @param breedRamFile 种公羊档案
// * @return 结果
// */
// public int updateBreedRamFile(BreedRamFile breedRamFile);
//
// /**
// * 批量删除种公羊档案
// *
// * @param ids 需要删除的种公羊档案主键集合
// * @return 结果
// */
// public int deleteBreedRamFileByIds(Long[] ids);
//
// /**
// * 删除种公羊档案信息
// *
// * @param id 种公羊档案主键
// * @return 结果
// */
// public int deleteBreedRamFileById(Long id);
//
// /**
// * 从sheep_file同步公羊数据到公羊档案
// *
// * @return 同步的记录数
// */
// public int syncFromSheepFile();
//
// // ====================== Service接口中需要添加的方法 ======================
//
// /**
// * 根据普通耳号查询种公羊档案
// *
// * @param earNumber 普通耳号
// * @return 种公羊档案
// */
// public BreedRamFile selectBreedRamFileByEarNumber(String earNumber);
//
// /**
// * 根据牧场ID查询种公羊档案列表
// *
// * @param ranchId 牧场ID
// * @return 种公羊档案集合
// */
// public List<BreedRamFile> selectBreedRamFileListByRanchId(Long ranchId);
//
// /**
// * 根据羊舍ID查询种公羊档案列表
// *
// * @param sheepfoldId 羊舍ID
// * @return 种公羊档案集合
// */
// public List<BreedRamFile> selectBreedRamFileListBySheepfoldId(Long sheepfoldId);
//
// /**
// * 查询核心羊群种公羊档案列表
// *
// * @param breedRamFile 种公羊档案
// * @return 种公羊档案集合
// */
// public List<BreedRamFile> selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile);
//
// /**
// * 查询种用种公羊档案列表
// *
// * @param breedRamFile 种公羊档案
// * @return 种公羊档案集合
// */
// public List<BreedRamFile> selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile);
//
// /**
// * 批量同步指定公羊的数据
// *
// * @param earNumbers 耳号列表
// * @return 同步的记录数
// */
// public int syncSpecificRams(List<String> earNumbers);
//
// /**
// * 获取种公羊统计信息
// *
// * @return 统计信息
// */
// public Map<String, Object> getBreedRamStatistics();
//
// // ============================================
//// 2. IBreedRamFileService.java 接口中添加方法
//// ============================================
//
// /**
// * 根据普通耳号查询种公羊档案
// *
// * @param ordinaryEarNumber 普通耳号
// * @return 种公羊档案
// */
// BreedRamFile selectBreedRamFileByOrdinaryEarNumber(String ordinaryEarNumber);
//}
package com.zhyc.module.base.service;
import java.util.List;
import java.util.Map;
import com.zhyc.module.base.domain.BreedRamFile;
import com.zhyc.module.base.domain.ViewBreedRamFile;
/**
* 种公羊档案Service接口
@ -11,8 +153,68 @@ import com.zhyc.module.base.domain.BreedRamFile;
*/
public interface IBreedRamFileService
{
// ========== 视图查询方法 ==========
/**
* 查询种公羊档案
* 查询种公羊档案视图
*
* @param id 种公羊档案主键
* @return 种公羊档案视图
*/
public ViewBreedRamFile selectViewBreedRamFileById(Long id);
/**
* 查询种公羊档案视图列表
*
* @param viewBreedRamFile 种公羊档案视图
* @return 种公羊档案视图集合
*/
public List<ViewBreedRamFile> selectViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile);
/**
* 根据普通耳号查询种公羊档案视图
*
* @param earNumber 普通耳号
* @return 种公羊档案视图
*/
public ViewBreedRamFile selectViewBreedRamFileByEarNumber(String earNumber);
/**
* 根据牧场ID查询种公羊档案视图列表
*
* @param ranchId 牧场ID
* @return 种公羊档案视图集合
*/
public List<ViewBreedRamFile> selectViewBreedRamFileListByRanchId(Long ranchId);
/**
* 根据羊舍ID查询种公羊档案视图列表
*
* @param sheepfoldId 羊舍ID
* @return 种公羊档案视图集合
*/
public List<ViewBreedRamFile> selectViewBreedRamFileListBySheepfoldId(Long sheepfoldId);
/**
* 查询核心羊群种公羊档案视图列表
*
* @param viewBreedRamFile 种公羊档案视图
* @return 种公羊档案视图集合
*/
public List<ViewBreedRamFile> selectCoreFlockViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile);
/**
* 查询种用种公羊档案视图列表
*
* @param viewBreedRamFile 种公羊档案视图
* @return 种公羊档案视图集合
*/
public List<ViewBreedRamFile> selectBreedingUseViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile);
// ========== 表操作方法 ==========
/**
* 查询种公羊档案()
*
* @param id 种公羊档案主键
* @return 种公羊档案
@ -20,7 +222,7 @@ public interface IBreedRamFileService
public BreedRamFile selectBreedRamFileById(Long id);
/**
* 查询种公羊档案列表
* 查询种公羊档案列表()
*
* @param breedRamFile 种公羊档案
* @return 种公羊档案集合
@ -58,4 +260,66 @@ public interface IBreedRamFileService
* @return 结果
*/
public int deleteBreedRamFileById(Long id);
/**
* 从sheep_file同步公羊数据到公羊档案
*
* @return 同步的记录数
*/
public int syncFromSheepFile();
/**
* 根据普通耳号查询种公羊档案()
*
* @param ordinaryEarNumber 普通耳号
* @return 种公羊档案
*/
public BreedRamFile selectBreedRamFileByOrdinaryEarNumber(String ordinaryEarNumber);
/**
* 根据牧场ID查询种公羊档案列表()
*
* @param ranchId 牧场ID
* @return 种公羊档案集合
*/
public List<BreedRamFile> selectBreedRamFileListByRanchId(Long ranchId);
/**
* 根据羊舍ID查询种公羊档案列表()
*
* @param sheepfoldId 羊舍ID
* @return 种公羊档案集合
*/
public List<BreedRamFile> selectBreedRamFileListBySheepfoldId(Long sheepfoldId);
/**
* 查询核心羊群种公羊档案列表()
*
* @param breedRamFile 种公羊档案
* @return 种公羊档案集合
*/
public List<BreedRamFile> selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile);
/**
* 查询种用种公羊档案列表()
*
* @param breedRamFile 种公羊档案
* @return 种公羊档案集合
*/
public List<BreedRamFile> selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile);
/**
* 批量同步指定公羊的数据
*
* @param earNumbers 耳号列表
* @return 同步的记录数
*/
public int syncSpecificRams(List<String> earNumbers);
/**
* 获取种公羊统计信息
*
* @return 统计信息
*/
public Map<String, Object> getBreedRamStatistics();
}

View File

@ -1,6 +1,7 @@
package com.zhyc.module.base.service;
import com.zhyc.module.base.domain.SheepFile;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
@ -66,4 +67,10 @@ public interface ISheepFileService
Map<String, Object> params,
SheepFile sheepFile
);
@Transactional
int insertSheepFile(SheepFile sheepFile);
@Transactional
int updateSheepFile(SheepFile sheepFile);
}

View File

@ -1,11 +1,504 @@
//package com.zhyc.module.base.service.impl;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//import com.zhyc.common.utils.DateUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import com.zhyc.module.base.mapper.BreedRamFileMapper;
//import com.zhyc.module.base.mapper.SheepFileMapper;
//import com.zhyc.module.produce.breed.mapper.RawSpermRecordMapper;
//import com.zhyc.module.produce.breed.mapper.ScBreedRecordMapper;
//import com.zhyc.module.produce.breed.mapper.ScLambingRecordMapper;
//import com.zhyc.module.produce.breed.mapper.ScPregnancyRecordMapper;
//import com.zhyc.module.base.domain.BreedRamFile;
//import com.zhyc.module.base.domain.SheepFile;
//import com.zhyc.module.produce.breed.domain.RawSpermRecord;
//import com.zhyc.module.produce.breed.domain.ScBreedRecord;
//import com.zhyc.module.produce.breed.domain.ScLambingRecord;
//import com.zhyc.module.produce.breed.domain.ScPregnancyRecord;
//import com.zhyc.module.base.service.IBreedRamFileService;
//
///**
// * 种公羊档案Service业务层处理
// *
// * @author zhyc
// * @date 2025-07-29
// */
//@Service
//public class BreedRamFileServiceImpl implements IBreedRamFileService {
// @Autowired
// private BreedRamFileMapper breedRamFileMapper;
//
// @Autowired
// private SheepFileMapper sheepFileMapper;
//
// @Autowired
// private RawSpermRecordMapper rawSpermRecordMapper;
//
// @Autowired
// private ScBreedRecordMapper scBreedRecordMapper;
//
// @Autowired
// private ScLambingRecordMapper scLambingRecordMapper;
//
// @Autowired
// private ScPregnancyRecordMapper scPregnancyRecordMapper;
//
// /**
// * 查询种公羊档案
// *
// * @param id 种公羊档案主键
// * @return 种公羊档案
// */
// @Override
// public BreedRamFile selectBreedRamFileById(Long id) {
// return breedRamFileMapper.selectBreedRamFileById(id);
// }
//
// /**
// * 查询种公羊档案列表
// *
// * @param breedRamFile 种公羊档案
// * @return 种公羊档案
// */
// @Override
// public List<BreedRamFile> selectBreedRamFileList(BreedRamFile breedRamFile) {
// return breedRamFileMapper.selectBreedRamFileList(breedRamFile);
// }
//
// /**
// * 新增种公羊档案
// *
// * @param breedRamFile 种公羊档案
// * @return 结果
// */
// @Override
// @Transactional
// public int insertBreedRamFile(BreedRamFile breedRamFile) {
// breedRamFile.setCreateTime(DateUtils.getNowDate());
// return breedRamFileMapper.insertBreedRamFile(breedRamFile);
// }
//
// /**
// * 修改种公羊档案
// *
// * @param breedRamFile 种公羊档案
// * @return 结果
// */
// @Override
// @Transactional
// public int updateBreedRamFile(BreedRamFile breedRamFile) {
// breedRamFile.setUpdateTime(DateUtils.getNowDate());
// return breedRamFileMapper.updateBreedRamFile(breedRamFile);
// }
//
// /**
// * 批量删除种公羊档案
// *
// * @param ids 需要删除的种公羊档案主键
// * @return 结果
// */
// @Override
// @Transactional
// public int deleteBreedRamFileByIds(Long[] ids) {
// return breedRamFileMapper.deleteBreedRamFileByIds(ids);
// }
//
// /**
// * 删除种公羊档案信息
// *
// * @param id 种公羊档案主键
// * @return 结果
// */
// @Override
// @Transactional
// public int deleteBreedRamFileById(Long id) {
// return breedRamFileMapper.deleteBreedRamFileById(id);
// }
//
// // ====================== Service实现类中对应的实现 ======================
//
// @Override
// public BreedRamFile selectBreedRamFileByEarNumber(String earNumber) {
// return breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(earNumber);
// }
//
// @Override
// public List<BreedRamFile> selectBreedRamFileListByRanchId(Long ranchId) {
// return breedRamFileMapper.selectBreedRamFileListByRanchId(ranchId);
// }
//
// @Override
// public List<BreedRamFile> selectBreedRamFileListBySheepfoldId(Long sheepfoldId) {
// return breedRamFileMapper.selectBreedRamFileListBySheepfoldId(sheepfoldId);
// }
//
// @Override
// public List<BreedRamFile> selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile) {
// return breedRamFileMapper.selectCoreFlockBreedRamFileList(breedRamFile);
// }
//
// @Override
// public List<BreedRamFile> selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile) {
// return breedRamFileMapper.selectBreedingUseBreedRamFileList(breedRamFile);
// }
//
//
// @Override
// public BreedRamFile selectBreedRamFileByOrdinaryEarNumber(String ordinaryEarNumber) {
// return breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(ordinaryEarNumber);
// }
//
// @Override
// @Transactional
// public int syncSpecificRams(List<String> earNumbers) {
// int syncCount = 0;
// for (String earNumber : earNumbers) {
// try {
// // 查询指定耳号的公羊
// SheepFile sheep = sheepFileMapper.selectSheepFileByManageTags(earNumber);
// if (sheep != null && sheep.getGender() == 2) {
// BreedRamFile existingRam = breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(earNumber);
// if (existingRam == null) {
// BreedRamFile newRam = buildRamFileFromSheep(sheep);
// breedRamFileMapper.insertBreedRamFile(newRam);
// } else {
// updateRamFileFromSheep(existingRam, sheep);
// breedRamFileMapper.updateBreedRamFile(existingRam);
// }
// syncCount++;
// }
// } catch (Exception e) {
// System.err.println("同步公羊档案失败,耳号:" + earNumber + ",错误:" + e.getMessage());
// }
// }
// return syncCount;
// }
//
// @Override
// public Map<String, Object> getBreedRamStatistics() {
// Map<String, Object> statistics = new HashMap<>();
//
// // 总公羊数
// BreedRamFile queryParam = new BreedRamFile();
// List<BreedRamFile> allRams = breedRamFileMapper.selectBreedRamFileList(queryParam);
// statistics.put("totalRams", allRams.size());
//
// // 核心羊群数
// List<BreedRamFile> coreFlockRams = breedRamFileMapper.selectCoreFlockBreedRamFileList(queryParam);
// statistics.put("coreFlockRams", coreFlockRams.size());
//
// // 种用公羊数
// List<BreedRamFile> breedingUseRams = breedRamFileMapper.selectBreedingUseBreedRamFileList(queryParam);
// statistics.put("breedingUseRams", breedingUseRams.size());
//
// // 按品种统计
// Map<String, Long> varietyCount = allRams.stream()
// .collect(Collectors.groupingBy(
// ram -> ram.getVariety() != null ? ram.getVariety() : "未知",
// Collectors.counting()
// ));
// statistics.put("varietyDistribution", varietyCount);
//
// // 按牧场统计
// Map<String, Long> ranchCount = allRams.stream()
// .collect(Collectors.groupingBy(
// ram -> ram.getRanchName() != null ? ram.getRanchName() : "未知",
// Collectors.counting()
// ));
// statistics.put("ranchDistribution", ranchCount);
//
// // 平均月龄
// Double avgMonthAge = allRams.stream()
// .filter(ram -> ram.getMonthAge() != null)
// .mapToLong(BreedRamFile::getMonthAge)
// .average()
// .orElse(0.0);
// statistics.put("avgMonthAge", avgMonthAge);
//
// // 平均多胎性
// Double avgProlificacy = allRams.stream()
// .filter(ram -> ram.getProlificacy() != null)
// .mapToDouble(ram -> ram.getProlificacy().doubleValue())
// .average()
// .orElse(0.0);
// statistics.put("avgProlificacy", avgProlificacy);
//
// return statistics;
// }
//
// /**
// * 从sheep_file同步公羊数据到公羊档案
// * 同步逻辑
// * 1. 从sheep_file获取基础信息gender=2的公羊
// * 2. 从raw_sperm_record获取采精相关数据
// * 3. 从sc_breed_record获取配种统计数据
// * 4. 从sc_lambing_record获取后代数统计
// * 5. 从sc_pregnancy_record获取孕检统计数据
// * 6. 计算多胎性受孕率等指标
// *
// * @return 同步的记录数
// */
// /**
// * 从sheep_file同步公羊数据到公羊档案
// */
// @Override
// @Transactional
// public int syncFromSheepFile() {
// // 1. 查询所有gender=2的羊只(公羊)
// List<SheepFile> rams = sheepFileMapper.selectRamList();
// int syncCount = 0;
// int updateCount = 0;
// int insertCount = 0;
//
// System.out.println("开始同步公羊数据,共找到 " + rams.size() + " 只公羊");
//
// for (SheepFile sheep : rams) {
// try {
// // 检查该公羊是否已存在于公羊档案
// BreedRamFile existingRam = breedRamFileMapper
// .selectBreedRamFileByOrdinaryEarNumber(sheep.getBsManageTags());
//
// if (existingRam == null) {
// // 新增公羊档案
// BreedRamFile newRam = buildRamFileFromSheep(sheep);
// int result = breedRamFileMapper.insertBreedRamFile(newRam);
// if (result > 0) {
// insertCount++;
// syncCount++;
// }
// } else {
// // 更新公羊档案
// updateRamFileFromSheep(existingRam, sheep);
// int result = breedRamFileMapper.updateBreedRamFile(existingRam);
// if (result > 0) {
// updateCount++;
// syncCount++;
// }
// }
// } catch (Exception e) {
// System.err.println("同步公羊档案失败,耳号:" + sheep.getBsManageTags()
// + ",错误:" + e.getMessage());
// e.printStackTrace();
// }
// }
//
// System.out.println("同步完成!新增: " + insertCount + " 只,更新: " + updateCount + "");
// return syncCount;
// }
//
// /**
// * 从SheepFile构建完整的BreedRamFile对象
// */
// private BreedRamFile buildRamFileFromSheep(SheepFile sheep) {
// BreedRamFile ram = new BreedRamFile();
//
// // 1. 从sheep_file同步基础信息
// syncBasicInfoFromSheep(ram, sheep);
//
// // 2. 从raw_sperm_record同步采精信息
// syncSpermInfoFromRecords(ram, sheep.getId());
//
// // 3. 从sc_breed_recordsc_lambing_recordsc_pregnancy_record同步配种和繁殖统计
// syncBreedingStatistics(ram, sheep.getBsManageTags());
//
// ram.setCreateTime(DateUtils.getNowDate());
// ram.setIsDelete(0L);
//
// return ram;
// }
//
// /**
// * 从SheepFile更新BreedRamFile
// */
// private void updateRamFileFromSheep(BreedRamFile ram, SheepFile sheep) {
// // 1. 更新基础信息
// syncBasicInfoFromSheep(ram, sheep);
//
// // 2. 更新采精信息
// syncSpermInfoFromRecords(ram, sheep.getId());
//
// // 3. 更新配种和繁殖统计
// syncBreedingStatistics(ram, sheep.getBsManageTags());
//
// ram.setUpdateTime(DateUtils.getNowDate());
// }
//
// /**
// * 同步基础信息从sheep_file
// */
// private void syncBasicInfoFromSheep(BreedRamFile ram, SheepFile sheep) {
// // 重要使用 setManageTags 而不是 setOrdinaryEarNumber
// ram.setManageTags(sheep.getBsManageTags()); // 普通耳号manage_tags
// ram.setRanchId(sheep.getRanchId()); // 牧场id
// ram.setRanchName(sheep.getDrRanch()); // 牧场名称
// ram.setSheepfoldId(sheep.getSheepfoldId()); // 羊舍id
// ram.setSheepfoldName(sheep.getSheepfoldName()); // 羊舍名称
// ram.setElectronicTags(sheep.getElectronicTags()); // 电子耳号
// ram.setVarietyId(sheep.getVarietyId()); // 品种id
// ram.setVariety(sheep.getVariety()); // 品种
// ram.setSheepCategory(sheep.getName()); // 羊只类别
// ram.setCurrentStatus(String.valueOf(sheep.getStatusId())); // 当前状态
// ram.setBirthday(sheep.getBirthday()); // 出生日期
//
// // 关键从sheep_file获取month_age
// ram.setMonthAge(sheep.getMonthAge()); // 月龄
//
// // 体重相关数据
// ram.setBirthWeight(sheep.getBirthWeight() != null ?
// BigDecimal.valueOf(sheep.getBirthWeight()) : null);
// ram.setWeaningDate(sheep.getWeaningDate());
// ram.setWeaningDayAge(sheep.getWeaningDayAge() != null ?
// Long.valueOf(sheep.getWeaningDayAge()) : null);
// ram.setWeaningWeight(sheep.getWeaningWeight() != null ?
// BigDecimal.valueOf(sheep.getWeaningWeight()) : null);
// ram.setWeaningDailyGain(sheep.getWeaningDailyGain() != null ?
// BigDecimal.valueOf(sheep.getWeaningDailyGain()) : null);
// ram.setCurrentWeight(sheep.getCurrentWeight() != null ?
// BigDecimal.valueOf(sheep.getCurrentWeight()) : null);
//
// // 家系信息
// ram.setFatherNumber(sheep.getFatherManageTags());
// ram.setMotherNumber(sheep.getMotherManageTags());
// ram.setGrandfatherNumber(sheep.getGrandfatherManageTags());
// ram.setGrandmotherNumber(sheep.getGrandmotherManageTags());
// ram.setMaternalGrandfatherNumber(sheep.getMaternalGrandfatherManageTags());
// ram.setMaternalGrandmotherNumber(sheep.getMaternalGrandmotherManageTags());
// }
//
// /**
// * 同步采精信息从raw_sperm_record
// */
// private void syncSpermInfoFromRecords(BreedRamFile ram, Long sheepId) {
// if (sheepId == null) {
// return;
// }
//
// try {
// RawSpermRecord latestSperm = rawSpermRecordMapper.selectLatestByRamId(sheepId);
//
// if (latestSperm != null) {
// ram.setSexualStatus(latestSperm.getSexualStatus());
// ram.setScrotumCircumference(latestSperm.getScrotumCircumference());
// ram.setSpermCollectionTime(latestSperm.getPickDate());
// ram.setSpermVolume(latestSperm.getAmount());
// ram.setSpermVitality(latestSperm.getVitallity());
// ram.setSpermDensity(latestSperm.getDensity());
// ram.setSpermQuality(latestSperm.getSemenQuality());
// }
// } catch (Exception e) {
// System.err.println("同步采精信息失败羊只ID" + sheepId + ",错误:" + e.getMessage());
// }
// }
//
// /**
// * 同步配种和繁殖统计数据
// */
// private void syncBreedingStatistics(BreedRamFile ram, String ramManageTags) {
// if (ramManageTags == null || ramManageTags.trim().isEmpty()) {
// return;
// }
//
// try {
// // 1. 统计该公羊配了多少母羊去重
// Long totalMatedEwes = scBreedRecordMapper.countMatedEwesByRamId(ramManageTags);
// ram.setTotalMatedEwes(totalMatedEwes != null ? totalMatedEwes : 0L);
//
// // 2. 统计公羊后代数从产羔记录
// Long offspringCount = scLambingRecordMapper.countOffspringByRamId(ramManageTags);
// ram.setOffspringCount(offspringCount != null ? offspringCount : 0L);
//
// // 3. 计算多胎性 = 公羊后代数 / 配种母羊数
// if (totalMatedEwes != null && totalMatedEwes > 0 && offspringCount != null) {
// BigDecimal prolificacy = BigDecimal.valueOf(offspringCount)
// .divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
// ram.setProlificacy(prolificacy);
// } else {
// ram.setProlificacy(BigDecimal.ZERO);
// }
//
// // 4. 统计孕检相关数据
// syncPregnancyStatistics(ram, ramManageTags, totalMatedEwes);
//
// } catch (Exception e) {
// System.err.println("同步配种统计失败,耳号:" + ramManageTags + ",错误:" + e.getMessage());
// }
// }
//
// /**
// * 同步孕检统计数据
// */
// private void syncPregnancyStatistics(BreedRamFile ram, String ramManageTags, Long totalMatedEwes) {
// try {
// // 本交孕检母羊数配种方式为本交=2的孕检有胎记录
// Long naturalPregnantEwes = scPregnancyRecordMapper
// .countPregnantEwesByRamIdAndBreedType(ramManageTags, 2); // 2=本交
// ram.setNaturalPregnancyCheckEwes(naturalPregnantEwes != null ? naturalPregnantEwes : 0L);
//
// // 本交受孕率%
// if (totalMatedEwes != null && totalMatedEwes > 0 && naturalPregnantEwes != null) {
// BigDecimal naturalRate = BigDecimal.valueOf(naturalPregnantEwes)
// .multiply(BigDecimal.valueOf(100))
// .divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
// ram.setNaturalConceptionRate(naturalRate);
// } else {
// ram.setNaturalConceptionRate(BigDecimal.ZERO);
// }
//
// // 人工孕检母羊数配种方式为人工授精=1的孕检有胎记录
// Long artificialPregnantEwes = scPregnancyRecordMapper
// .countPregnantEwesByRamIdAndBreedType(ramManageTags, 1); // 1=人工授精
// ram.setArtificialPregnancyCheckEwes(artificialPregnantEwes != null ? artificialPregnantEwes : 0L);
//
// // 人工受孕率%
// if (totalMatedEwes != null && totalMatedEwes > 0 && artificialPregnantEwes != null) {
// BigDecimal artificialRate = BigDecimal.valueOf(artificialPregnantEwes)
// .multiply(BigDecimal.valueOf(100))
// .divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
// ram.setArtificialConceptionRate(artificialRate);
// } else {
// ram.setArtificialConceptionRate(BigDecimal.ZERO);
// }
// } catch (Exception e) {
// System.err.println("同步孕检统计失败,耳号:" + ramManageTags + ",错误:" + e.getMessage());
// e.printStackTrace();
// }
// }
//}
package com.zhyc.module.base.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.zhyc.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.zhyc.module.base.mapper.BreedRamFileMapper;
import com.zhyc.module.base.mapper.ViewBreedRamFileMapper;
import com.zhyc.module.base.mapper.SheepFileMapper;
import com.zhyc.module.produce.breed.mapper.RawSpermRecordMapper;
import com.zhyc.module.produce.breed.mapper.ScBreedRecordMapper;
import com.zhyc.module.produce.breed.mapper.ScLambingRecordMapper;
import com.zhyc.module.produce.breed.mapper.ScPregnancyRecordMapper;
import com.zhyc.module.base.domain.BreedRamFile;
import com.zhyc.module.base.domain.ViewBreedRamFile;
import com.zhyc.module.base.domain.SheepFile;
import com.zhyc.module.produce.breed.domain.RawSpermRecord;
import com.zhyc.module.produce.breed.domain.ScBreedRecord;
import com.zhyc.module.produce.breed.domain.ScLambingRecord;
import com.zhyc.module.produce.breed.domain.ScPregnancyRecord;
import com.zhyc.module.base.service.IBreedRamFileService;
/**
@ -15,82 +508,440 @@ import com.zhyc.module.base.service.IBreedRamFileService;
* @date 2025-07-29
*/
@Service
public class BreedRamFileServiceImpl implements IBreedRamFileService
{
public class BreedRamFileServiceImpl implements IBreedRamFileService {
@Autowired
private BreedRamFileMapper breedRamFileMapper;
/**
* 查询种公羊档案
*
* @param id 种公羊档案主键
* @return 种公羊档案
*/
@Autowired
private ViewBreedRamFileMapper viewBreedRamFileMapper;
@Autowired
private SheepFileMapper sheepFileMapper;
@Autowired
private RawSpermRecordMapper rawSpermRecordMapper;
@Autowired
private ScBreedRecordMapper scBreedRecordMapper;
@Autowired
private ScLambingRecordMapper scLambingRecordMapper;
@Autowired
private ScPregnancyRecordMapper scPregnancyRecordMapper;
// ========== 视图查询方法实现 ==========
@Override
public BreedRamFile selectBreedRamFileById(Long id)
{
public ViewBreedRamFile selectViewBreedRamFileById(Long id) {
return viewBreedRamFileMapper.selectViewBreedRamFileById(id);
}
@Override
public List<ViewBreedRamFile> selectViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) {
return viewBreedRamFileMapper.selectViewBreedRamFileList(viewBreedRamFile);
}
@Override
public ViewBreedRamFile selectViewBreedRamFileByEarNumber(String earNumber) {
return viewBreedRamFileMapper.selectViewBreedRamFileByOrdinaryEarNumber(earNumber);
}
@Override
public List<ViewBreedRamFile> selectViewBreedRamFileListByRanchId(Long ranchId) {
return viewBreedRamFileMapper.selectViewBreedRamFileListByRanchId(ranchId);
}
@Override
public List<ViewBreedRamFile> selectViewBreedRamFileListBySheepfoldId(Long sheepfoldId) {
return viewBreedRamFileMapper.selectViewBreedRamFileListBySheepfoldId(sheepfoldId);
}
@Override
public List<ViewBreedRamFile> selectCoreFlockViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) {
return viewBreedRamFileMapper.selectCoreFlockViewBreedRamFileList(viewBreedRamFile);
}
@Override
public List<ViewBreedRamFile> selectBreedingUseViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) {
return viewBreedRamFileMapper.selectBreedingUseViewBreedRamFileList(viewBreedRamFile);
}
// ========== 表操作方法实现 ==========
@Override
public BreedRamFile selectBreedRamFileById(Long id) {
return breedRamFileMapper.selectBreedRamFileById(id);
}
/**
* 查询种公羊档案列表
*
* @param breedRamFile 种公羊档案
* @return 种公羊档案
*/
@Override
public List<BreedRamFile> selectBreedRamFileList(BreedRamFile breedRamFile)
{
public List<BreedRamFile> selectBreedRamFileList(BreedRamFile breedRamFile) {
return breedRamFileMapper.selectBreedRamFileList(breedRamFile);
}
/**
* 新增种公羊档案
*
* @param breedRamFile 种公羊档案
* @return 结果
*/
@Override
public int insertBreedRamFile(BreedRamFile breedRamFile)
{
@Transactional
public int insertBreedRamFile(BreedRamFile breedRamFile) {
breedRamFile.setCreateTime(DateUtils.getNowDate());
return breedRamFileMapper.insertBreedRamFile(breedRamFile);
}
/**
* 修改种公羊档案
*
* @param breedRamFile 种公羊档案
* @return 结果
*/
@Override
public int updateBreedRamFile(BreedRamFile breedRamFile)
{
@Transactional
public int updateBreedRamFile(BreedRamFile breedRamFile) {
breedRamFile.setUpdateTime(DateUtils.getNowDate());
return breedRamFileMapper.updateBreedRamFile(breedRamFile);
}
/**
* 批量删除种公羊档案
*
* @param ids 需要删除的种公羊档案主键
* @return 结果
*/
@Override
public int deleteBreedRamFileByIds(Long[] ids)
{
@Transactional
public int deleteBreedRamFileByIds(Long[] ids) {
return breedRamFileMapper.deleteBreedRamFileByIds(ids);
}
/**
* 删除种公羊档案信息
*
* @param id 种公羊档案主键
* @return 结果
*/
@Override
public int deleteBreedRamFileById(Long id)
{
@Transactional
public int deleteBreedRamFileById(Long id) {
return breedRamFileMapper.deleteBreedRamFileById(id);
}
@Override
public BreedRamFile selectBreedRamFileByOrdinaryEarNumber(String ordinaryEarNumber) {
return breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(ordinaryEarNumber);
}
@Override
public List<BreedRamFile> selectBreedRamFileListByRanchId(Long ranchId) {
return breedRamFileMapper.selectBreedRamFileListByRanchId(ranchId);
}
@Override
public List<BreedRamFile> selectBreedRamFileListBySheepfoldId(Long sheepfoldId) {
return breedRamFileMapper.selectBreedRamFileListBySheepfoldId(sheepfoldId);
}
@Override
public List<BreedRamFile> selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile) {
return breedRamFileMapper.selectCoreFlockBreedRamFileList(breedRamFile);
}
@Override
public List<BreedRamFile> selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile) {
return breedRamFileMapper.selectBreedingUseBreedRamFileList(breedRamFile);
}
@Override
@Transactional
public int syncSpecificRams(List<String> earNumbers) {
int syncCount = 0;
for (String earNumber : earNumbers) {
try {
SheepFile sheep = sheepFileMapper.selectSheepFileByManageTags(earNumber);
if (sheep != null && sheep.getGender() == 2) {
BreedRamFile existingRam = breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(earNumber);
if (existingRam == null) {
BreedRamFile newRam = buildRamFileFromSheep(sheep);
breedRamFileMapper.insertBreedRamFile(newRam);
} else {
updateRamFileFromSheep(existingRam, sheep);
breedRamFileMapper.updateBreedRamFile(existingRam);
}
syncCount++;
}
} catch (Exception e) {
System.err.println("同步公羊档案失败,耳号:" + earNumber + ",错误:" + e.getMessage());
}
}
return syncCount;
}
@Override
public Map<String, Object> getBreedRamStatistics() {
Map<String, Object> statistics = new HashMap<>();
BreedRamFile queryParam = new BreedRamFile();
List<BreedRamFile> allRams = breedRamFileMapper.selectBreedRamFileList(queryParam);
statistics.put("totalRams", allRams.size());
List<BreedRamFile> coreFlockRams = breedRamFileMapper.selectCoreFlockBreedRamFileList(queryParam);
statistics.put("coreFlockRams", coreFlockRams.size());
List<BreedRamFile> breedingUseRams = breedRamFileMapper.selectBreedingUseBreedRamFileList(queryParam);
statistics.put("breedingUseRams", breedingUseRams.size());
Map<String, Long> varietyCount = allRams.stream()
.collect(Collectors.groupingBy(
ram -> ram.getVariety() != null ? ram.getVariety() : "未知",
Collectors.counting()
));
statistics.put("varietyDistribution", varietyCount);
Map<String, Long> ranchCount = allRams.stream()
.collect(Collectors.groupingBy(
ram -> ram.getRanchName() != null ? ram.getRanchName() : "未知",
Collectors.counting()
));
statistics.put("ranchDistribution", ranchCount);
Double avgMonthAge = allRams.stream()
.filter(ram -> ram.getMonthAge() != null)
.mapToLong(BreedRamFile::getMonthAge)
.average()
.orElse(0.0);
statistics.put("avgMonthAge", avgMonthAge);
Double avgProlificacy = allRams.stream()
.filter(ram -> ram.getProlificacy() != null)
.mapToDouble(ram -> ram.getProlificacy().doubleValue())
.average()
.orElse(0.0);
statistics.put("avgProlificacy", avgProlificacy);
return statistics;
}
/**
* 从sheep_file同步公羊数据到公羊档案
*/
@Override
@Transactional
public int syncFromSheepFile() {
List<SheepFile> rams = sheepFileMapper.selectRamList();
int syncCount = 0;
int updateCount = 0;
int insertCount = 0;
System.out.println("开始同步公羊数据,共找到 " + rams.size() + " 只公羊");
for (SheepFile sheep : rams) {
try {
BreedRamFile existingRam = breedRamFileMapper
.selectBreedRamFileByOrdinaryEarNumber(sheep.getBsManageTags());
if (existingRam == null) {
BreedRamFile newRam = buildRamFileFromSheep(sheep);
int result = breedRamFileMapper.insertBreedRamFile(newRam);
if (result > 0) {
insertCount++;
syncCount++;
}
} else {
updateRamFileFromSheep(existingRam, sheep);
int result = breedRamFileMapper.updateBreedRamFile(existingRam);
if (result > 0) {
updateCount++;
syncCount++;
}
}
} catch (Exception e) {
System.err.println("同步公羊档案失败,耳号:" + sheep.getBsManageTags()
+ ",错误:" + e.getMessage());
e.printStackTrace();
}
}
System.out.println("同步完成:新增: " + insertCount + " 只,更新: " + updateCount + "");
return syncCount;
}
/**
* 从SheepFile构建完整的BreedRamFile对象
*/
private BreedRamFile buildRamFileFromSheep(SheepFile sheep) {
BreedRamFile ram = new BreedRamFile();
// 1. 从sheep_file同步基础信息
syncBasicInfoFromSheep(ram, sheep);
// 2. 从raw_sperm_record同步采精信息 - 修复后的版本
syncSpermInfoFromRecords(ram, sheep.getId());
// 3. 从sc_breed_recordsc_lambing_recordsc_pregnancy_record同步配种和繁殖统计
syncBreedingStatistics(ram, sheep.getBsManageTags());
ram.setCreateTime(DateUtils.getNowDate());
ram.setIsDelete(0L);
return ram;
}
/**
* 从SheepFile更新BreedRamFile
*/
private void updateRamFileFromSheep(BreedRamFile ram, SheepFile sheep) {
// 1. 更新基础信息
syncBasicInfoFromSheep(ram, sheep);
// 2. 更新采精信息 - 修复后的版本
syncSpermInfoFromRecords(ram, sheep.getId());
// 3. 更新配种和繁殖统计
syncBreedingStatistics(ram, sheep.getBsManageTags());
ram.setUpdateTime(DateUtils.getNowDate());
}
/**
* 同步基础信息(从sheep_file)
*/
private void syncBasicInfoFromSheep(BreedRamFile ram, SheepFile sheep) {
ram.setManageTags(sheep.getBsManageTags());
ram.setRanchId(sheep.getRanchId());
ram.setRanchName(sheep.getDrRanch());
ram.setSheepfoldId(sheep.getSheepfoldId());
ram.setSheepfoldName(sheep.getSheepfoldName());
ram.setElectronicTags(sheep.getElectronicTags());
ram.setVarietyId(sheep.getVarietyId());
ram.setVariety(sheep.getVariety());
ram.setSheepCategory(sheep.getName());
ram.setCurrentStatus(String.valueOf(sheep.getStatusId()));
ram.setBirthday(sheep.getBirthday());
ram.setMonthAge(sheep.getMonthAge());
ram.setBirthWeight(sheep.getBirthWeight() != null ?
BigDecimal.valueOf(sheep.getBirthWeight()) : null);
ram.setWeaningDate(sheep.getWeaningDate());
ram.setWeaningDayAge(sheep.getWeaningDayAge() != null ?
Long.valueOf(sheep.getWeaningDayAge()) : null);
ram.setWeaningWeight(sheep.getWeaningWeight() != null ?
BigDecimal.valueOf(sheep.getWeaningWeight()) : null);
ram.setWeaningDailyGain(sheep.getWeaningDailyGain() != null ?
BigDecimal.valueOf(sheep.getWeaningDailyGain()) : null);
ram.setCurrentWeight(sheep.getCurrentWeight() != null ?
BigDecimal.valueOf(sheep.getCurrentWeight()) : null);
ram.setFatherNumber(sheep.getFatherManageTags());
ram.setMotherNumber(sheep.getMotherManageTags());
ram.setGrandfatherNumber(sheep.getGrandfatherManageTags());
ram.setGrandmotherNumber(sheep.getGrandmotherManageTags());
ram.setMaternalGrandfatherNumber(sheep.getMaternalGrandfatherManageTags());
ram.setMaternalGrandmotherNumber(sheep.getMaternalGrandmotherManageTags());
}
/**
* 同步采精信息(从raw_sperm_record)
*
* 修复关键问题:
* 1. 正确设置所有字段(性欲情况阴囊周长采精时间精液品质)
* 2. 确保字段名与数据库表字段对应
*/
private void syncSpermInfoFromRecords(BreedRamFile ram, Long sheepId) {
if (sheepId == null) {
return;
}
try {
RawSpermRecord latestSperm = rawSpermRecordMapper.selectLatestByRamId(sheepId);
if (latestSperm != null) {
// 关键修复确保所有字段都正确同步
// 1. 性欲情况 - sexual_status
ram.setSexualStatus(latestSperm.getSexualStatus());
// 2. 阴囊周长 - scrotum_circumference
ram.setScrotumCircumference(latestSperm.getScrotumCircumference());
// 3. 采精时间 - sperm_collection_time (对应 pick_date)
ram.setSpermCollectionTime(latestSperm.getPickDate());
// 4. 精液量 - sperm_volume (对应 amount)
ram.setSpermVolume(latestSperm.getAmount());
// 5. 精液活力 - sperm_vitality (对应 vitallity)
ram.setSpermVitality(latestSperm.getVitallity());
// 6. 精液密度 - sperm_density (对应 density)
ram.setSpermDensity(latestSperm.getDensity());
// 7. 精液品质 - sperm_quality (对应 semen_quality)
ram.setSpermQuality(latestSperm.getSemenQuality());
System.out.println("成功同步采精信息 - 羊只ID: " + sheepId +
", 性欲情况: " + latestSperm.getSexualStatus() +
", 阴囊周长: " + latestSperm.getScrotumCircumference() +
", 采精时间: " + latestSperm.getPickDate() +
", 精液品质: " + latestSperm.getSemenQuality());
} else {
System.out.println("未找到采精记录 - 羊只ID: " + sheepId);
}
} catch (Exception e) {
System.err.println("同步采精信息失败,羊只ID:" + sheepId + ",错误:" + e.getMessage());
e.printStackTrace();
}
}
/**
* 同步配种和繁殖统计数据
*/
private void syncBreedingStatistics(BreedRamFile ram, String ramManageTags) {
if (ramManageTags == null || ramManageTags.trim().isEmpty()) {
return;
}
try {
// 1. 统计该公羊配了多少母羊(去重)
Long totalMatedEwes = scBreedRecordMapper.countMatedEwesByRamId(ramManageTags);
ram.setTotalMatedEwes(totalMatedEwes != null ? totalMatedEwes : 0L);
// 2. 统计公羊后代数(从产羔记录)
Long offspringCount = scLambingRecordMapper.countOffspringByRamId(ramManageTags);
ram.setOffspringCount(offspringCount != null ? offspringCount : 0L);
// 3. 计算多胎性 = 公羊后代数 / 配种母羊数
if (totalMatedEwes != null && totalMatedEwes > 0 && offspringCount != null) {
BigDecimal prolificacy = BigDecimal.valueOf(offspringCount)
.divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
ram.setProlificacy(prolificacy);
} else {
ram.setProlificacy(BigDecimal.ZERO);
}
// 4. 统计孕检相关数据
syncPregnancyStatistics(ram, ramManageTags, totalMatedEwes);
} catch (Exception e) {
System.err.println("同步配种统计失败,耳号:" + ramManageTags + ",错误:" + e.getMessage());
}
}
/**
* 同步孕检统计数据
*/
private void syncPregnancyStatistics(BreedRamFile ram, String ramManageTags, Long totalMatedEwes) {
try {
// 本交孕检母羊数(配种方式为本交=2的孕检有胎记录)
Long naturalPregnantEwes = scPregnancyRecordMapper
.countPregnantEwesByRamIdAndBreedType(ramManageTags, 2);
ram.setNaturalPregnancyCheckEwes(naturalPregnantEwes != null ? naturalPregnantEwes : 0L);
// 本交受孕率%
if (totalMatedEwes != null && totalMatedEwes > 0 && naturalPregnantEwes != null) {
BigDecimal naturalRate = BigDecimal.valueOf(naturalPregnantEwes)
.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
ram.setNaturalConceptionRate(naturalRate);
} else {
ram.setNaturalConceptionRate(BigDecimal.ZERO);
}
// 人工孕检母羊数(配种方式为人工授精=1的孕检有胎记录)
Long artificialPregnantEwes = scPregnancyRecordMapper
.countPregnantEwesByRamIdAndBreedType(ramManageTags, 1);
ram.setArtificialPregnancyCheckEwes(artificialPregnantEwes != null ? artificialPregnantEwes : 0L);
// 人工受孕率%
if (totalMatedEwes != null && totalMatedEwes > 0 && artificialPregnantEwes != null) {
BigDecimal artificialRate = BigDecimal.valueOf(artificialPregnantEwes)
.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(totalMatedEwes), 2, RoundingMode.HALF_UP);
ram.setArtificialConceptionRate(artificialRate);
} else {
ram.setArtificialConceptionRate(BigDecimal.ZERO);
}
} catch (Exception e) {
System.err.println("同步孕检统计失败,耳号:" + ramManageTags + ",错误:" + e.getMessage());
e.printStackTrace();
}
}
}

View File

@ -1,11 +1,15 @@
package com.zhyc.module.base.service.impl;
import com.zhyc.module.base.domain.BreedRamFile;
import com.zhyc.module.base.domain.SheepFile;
import com.zhyc.module.base.mapper.SheepFileMapper;
import com.zhyc.module.base.service.IBreedRamFileService;
import com.zhyc.module.base.service.ISheepFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;import java.util.Map;
@ -98,6 +102,16 @@ public class SheepFileServiceImpl implements ISheepFileService {
}
@Override
public int insertSheepFile(SheepFile sheepFile) {
return 0;
}
@Override
public int updateSheepFile(SheepFile sheepFile) {
return 0;
}
/**
* 处理条件参数确保安全
*/
@ -243,6 +257,80 @@ public class SheepFileServiceImpl implements ISheepFileService {
return false;
}
@Autowired
private IBreedRamFileService breedRamFileService; // 注入种公羊服务
/**
* 新增羊只档案
*/
/**
* 同步公羊数据到种公羊档案表
*/
private void syncToBreedRamFile(SheepFile sheepFile) {
try {
// 检查是否已存在
BreedRamFile existingRam = breedRamFileService.selectBreedRamFileByOrdinaryEarNumber(
sheepFile.getBsManageTags()
);
if (existingRam != null) {
// 已存在更新
BreedRamFile updateRam = convertToBreedRamFile(sheepFile);
updateRam.setId(existingRam.getId());
breedRamFileService.updateBreedRamFile(updateRam);
} else {
// 不存在新增
BreedRamFile newRam = convertToBreedRamFile(sheepFile);
breedRamFileService.insertBreedRamFile(newRam);
}
} catch (Exception e) {
// 记录日志但不影响主流
}
}
/**
* 将SheepFile转换为BreedRamFile
*/
private BreedRamFile convertToBreedRamFile(SheepFile sheepFile) {
BreedRamFile breedRamFile = new BreedRamFile();
// 基本信息
breedRamFile.setOrdinaryEarNumber(sheepFile.getBsManageTags());
breedRamFile.setRanchId(sheepFile.getRanchId());
breedRamFile.setRanchName(sheepFile.getDrRanch());
breedRamFile.setSheepfoldId(sheepFile.getSheepfoldId());
breedRamFile.setSheepfoldName(sheepFile.getSheepfoldName());
breedRamFile.setElectronicTags(sheepFile.getElectronicTags());
breedRamFile.setVarietyId(sheepFile.getVarietyId());
breedRamFile.setVariety(sheepFile.getVariety());
breedRamFile.setSheepCategory(sheepFile.getName());
breedRamFile.setBirthday(sheepFile.getBirthday());
// 体重相关
breedRamFile.setBirthWeight(BigDecimal.valueOf(sheepFile.getBirthWeight()));
breedRamFile.setWeaningDate(sheepFile.getWeaningDate());
breedRamFile.setWeaningDayAge(sheepFile.getWeaningDayAge());
breedRamFile.setWeaningWeight(BigDecimal.valueOf(sheepFile.getWeaningWeight()));
breedRamFile.setWeaningDailyGain(BigDecimal.valueOf(sheepFile.getWeaningDailyGain()));
breedRamFile.setCurrentWeight(BigDecimal.valueOf(sheepFile.getCurrentWeight()));
// 家系信息
breedRamFile.setFatherNumber(sheepFile.getFatherManageTags());
breedRamFile.setMotherNumber(sheepFile.getMotherManageTags());
breedRamFile.setGrandfatherNumber(sheepFile.getGrandfatherManageTags());
breedRamFile.setGrandmotherNumber(sheepFile.getGrandmotherManageTags());
breedRamFile.setMaternalGrandfatherNumber(sheepFile.getMaternalGrandfatherManageTags());
breedRamFile.setMaternalGrandmotherNumber(sheepFile.getMaternalGrandmotherManageTags());
// 审计信息
breedRamFile.setCreateBy(sheepFile.getCreateBy());
breedRamFile.setCreateTime(sheepFile.getCreateTime());
breedRamFile.setUpdateBy(sheepFile.getUpdateBy());
breedRamFile.setUpdateTime(sheepFile.getUpdateTime());
breedRamFile.setIsDelete(sheepFile.getIsDelete());
return breedRamFile;
}
}

View File

@ -75,4 +75,12 @@ public interface RawSpermRecordMapper
* @return 羊只信息 Map包含idgendermonthAgeelectronicTags等字段
*/
public Map<String, Object> selectSheepInfoByManageTags(String manageTags);
// ====================== RawSpermRecordMapper.java 需要添加 ======================
/**
/**
* 获取指定公羊最新的采精记录
* @param sheepId 羊只ID
* @return 采精记录
*/
RawSpermRecord selectLatestByRamId(Long sheepId);
}

View File

@ -137,4 +137,12 @@ public interface ScBreedRecordMapper
public int incrementSheepMatingCount(@Param("sheepId") Long sheepId,
@Param("matingDate") Date matingDate,
@Param("updateBy") String updateBy);
// ====================== ScBreedRecordMapper.java 需要添加 ======================
/**
* 统计公羊配种的母羊数去重
* @param ramManageTags 公羊管理耳号
* @return 配种母羊数
*/
Long countMatedEwesByRamId(String ramManageTags);
}

View File

@ -78,4 +78,11 @@ public interface ScLambingRecordMapper
* @return 结果
*/
public int deleteScLambingRecordByIds(Long[] ids);
// ====================== ScLambingRecordMapper.java 需要添加 ======================
/**
* 统计公羊的后代总数
* @param ramManageTags 公羊管理耳号
* @return 后代总数
*/
Long countOffspringByRamId(String ramManageTags);
}

View File

@ -84,4 +84,20 @@ public interface ScPregnancyRecordMapper
* @return 结果
*/
public int updateSheepPregnancyInfo(Map<String, Object> params);
/**
* 统计孕检有胎的母羊数按配种方式
*
* @param ramManageTags 公羊管理耳号
* @param breedType 配种方式1=人工授精2=本交
* @return 孕检有胎的母羊数
*/
/**
* 根据配种方式统计孕检有胎的母羊数
* @param ramManageTags 公羊管理耳号
* @param breedType 配种方式1=人工授精2=本交
* @return 孕检有胎母羊数
*/
Long countPregnantEwesByRamIdAndBreedType(@Param("ramManageTags") String ramManageTags,
@Param("breedType") Integer breedType);
}

View File

@ -6,7 +6,7 @@
<resultMap type="BreedRamFile" id="BreedRamFileResult">
<result property="id" column="id" />
<result property="ordinaryEarNumber" column="ordinary_ear_number" />
<result property="ordinaryEarNumber" column="manage_tags" />
<result property="ranchId" column="ranch_id" />
<result property="ranchName" column="ranch_name" />
<result property="sheepfoldId" column="sheepfold_id" />
@ -74,13 +74,13 @@
</resultMap>
<sql id="selectBreedRamFileVo">
select id, ordinary_ear_number, ranch_id, ranch_name, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, sheep_category, current_status, birthday, dynamic_info, month_age, birth_weight, weaning_date, weaning_day_age, weaning_weight, weaning_daily_gain, post_weaning_daily_gain, current_weight, current_weight_date, activity_level, sexual_status, scrotum_circumference, sperm_collection_time, sperm_volume, sperm_vitality, sperm_density, sperm_quality, breeding_status, last_plan_time, current_plan_time, comment, protein_rate_ebv, milk_fat_rate_ebv, scs_ebv, growth_performance_ebv, resistance_ebv, reproduction_performance_ebv, body_type_ebv, comprehensive_breeding_value, father_number, mother_number, grandfather_number, grandmother_number, maternal_grandfather_number, maternal_grandmother_number, is_core_flock, is_breeding_use, pregnancy_check, total_mated_ewes, natural_pregnancy_check_ewes, natural_conception_rate, artificial_pregnancy_check_ewes, artificial_conception_rate, ram_mother_milk_volume, milk_production_ebv, accuracy, information_count, is_paternity_tested, create_by, create_time, update_by, update_time, is_delete from breed_ram_file
select id, manage_tags, ranch_id, ranch_name, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, sheep_category, current_status, birthday, dynamic_info, month_age, birth_weight, weaning_date, weaning_day_age, weaning_weight, weaning_daily_gain, post_weaning_daily_gain, current_weight, current_weight_date, activity_level, sexual_status, scrotum_circumference, sperm_collection_time, sperm_volume, sperm_vitality, sperm_density, sperm_quality, breeding_status, last_plan_time, current_plan_time, comment, protein_rate_ebv, milk_fat_rate_ebv, scs_ebv, growth_performance_ebv, resistance_ebv, reproduction_performance_ebv, body_type_ebv, comprehensive_breeding_value, father_number, mother_number, grandfather_number, grandmother_number, maternal_grandfather_number, maternal_grandmother_number, is_core_flock, is_breeding_use, pregnancy_check, total_mated_ewes, natural_pregnancy_check_ewes, natural_conception_rate, artificial_pregnancy_check_ewes, artificial_conception_rate, ram_mother_milk_volume, milk_production_ebv, accuracy, information_count, is_paternity_tested, create_by, create_time, update_by, update_time, is_delete from breed_ram_file
</sql>
<select id="selectBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
<if test="ordinaryEarNumber != null and ordinaryEarNumber != ''"> and ordinary_ear_number like concat('%', #{ordinaryEarNumber}, '%')</if>
<if test="ordinaryEarNumber != null and ordinaryEarNumber != ''"> and manage_tags like concat('%', #{ordinaryEarNumber}, '%')</if>
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="ranchName != null and ranchName != ''"> and ranch_name like concat('%', #{ranchName}, '%')</if>
<if test="sheepfoldId != null "> and sheepfold_id = #{sheepfoldId}</if>
@ -149,56 +149,74 @@
where id = #{id}
</select>
<select id="selectBreedRamFileByOrdinaryEarNumber" parameterType="String" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where ordinary_ear_number = #{ordinaryEarNumber}
<!-- ====================== BreedRamFileMapper.xml 需要添加/更新 ====================== -->
<!-- 根据普通耳号查询种公羊档案 -->
<!-- 查询方法也需要修改字段名 -->
<select id="selectBreedRamFileByOrdinaryEarNumber" resultMap="BreedRamFileResult">
SELECT * FROM breed_ram_file
WHERE manage_tags = #{ordinaryEarNumber} AND is_delete = 0
LIMIT 1
</select>
<select id="selectBreedRamFileByElectronicTags" parameterType="String" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where electronic_tags = #{electronicTags}
<!-- 根据电子耳号查询种公羊档案 -->
<select id="selectBreedRamFileByElectronicTags" parameterType="String" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE electronic_tags = #{electronicTags}
AND is_delete = 0
LIMIT 1
</select>
<select id="selectBreedRamFileListByRanchId" parameterType="Long" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where ranch_id = #{ranchId} and (is_delete = 0 or is_delete is null)
order by create_time desc
<!-- 根据牧场ID查询种公羊档案列表 -->
<select id="selectBreedRamFileListByRanchId" parameterType="Long" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE ranch_id = #{ranchId}
AND is_delete = 0
ORDER BY id DESC
</select>
<select id="selectBreedRamFileListBySheepfoldId" parameterType="Long" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
where sheepfold_id = #{sheepfoldId} and (is_delete = 0 or is_delete is null)
order by create_time desc
<!-- 根据羊舍ID查询种公羊档案列表 -->
<select id="selectBreedRamFileListBySheepfoldId" parameterType="Long" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE sheepfold_id = #{sheepfoldId}
AND is_delete = 0
ORDER BY id DESC
</select>
<select id="selectCoreFlockBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
is_core_flock = 1
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="varietyId != null "> and variety_id = #{varietyId}</if>
<if test="breedingStatus != null "> and breeding_status = #{breedingStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
</where>
order by create_time desc
<!-- 查询核心羊群种公羊档案列表 -->
<select id="selectCoreFlockBreedRamFileList" parameterType="BreedRamFile" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE is_core_flock = 1
AND is_delete = 0
<if test="ranchId != null">
AND ranch_id = #{ranchId}
</if>
<if test="varietyId != null">
AND variety_id = #{varietyId}
</if>
ORDER BY id DESC
</select>
<select id="selectBreedingUseBreedRamFileList" parameterType="BreedRamFile" resultMap="BreedRamFileResult">
<include refid="selectBreedRamFileVo"/>
<where>
is_breeding_use = 1
<if test="ranchId != null "> and ranch_id = #{ranchId}</if>
<if test="varietyId != null "> and variety_id = #{varietyId}</if>
<if test="breedingStatus != null "> and breeding_status = #{breedingStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
</where>
order by create_time desc
<!-- 查询种用种公羊档案列表 -->
<select id="selectBreedingUseBreedRamFileList" parameterType="BreedRamFile" resultType="BreedRamFile">
SELECT * FROM breed_ram_file
WHERE is_breeding_use = 1
AND is_delete = 0
<if test="ranchId != null">
AND ranch_id = #{ranchId}
</if>
<if test="varietyId != null">
AND variety_id = #{varietyId}
</if>
ORDER BY id DESC
</select>
<!-- 修正后的 insertBreedRamFile -->
<insert id="insertBreedRamFile" parameterType="BreedRamFile" useGeneratedKeys="true" keyProperty="id">
insert into breed_ram_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ordinaryEarNumber != null">ordinary_ear_number,</if>
<if test="manageTags != null and manageTags != ''">manage_tags,</if>
<if test="ranchId != null">ranch_id,</if>
<if test="ranchName != null">ranch_name,</if>
<if test="sheepfoldId != null">sheepfold_id,</if>
@ -258,6 +276,8 @@
<if test="accuracy != null">accuracy,</if>
<if test="informationCount != null">information_count,</if>
<if test="isPaternityTested != null">is_paternity_tested,</if>
<if test="offspringCount != null">offspring_count,</if>
<if test="prolificacy != null">prolificacy,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
@ -265,7 +285,7 @@
<if test="isDelete != null">is_delete,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ordinaryEarNumber != null">#{ordinaryEarNumber},</if>
<if test="manageTags != null and manageTags != ''">#{manageTags},</if>
<if test="ranchId != null">#{ranchId},</if>
<if test="ranchName != null">#{ranchName},</if>
<if test="sheepfoldId != null">#{sheepfoldId},</if>
@ -325,6 +345,8 @@
<if test="accuracy != null">#{accuracy},</if>
<if test="informationCount != null">#{informationCount},</if>
<if test="isPaternityTested != null">#{isPaternityTested},</if>
<if test="offspringCount != null">#{offspringCount},</if>
<if test="prolificacy != null">#{prolificacy},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
@ -336,7 +358,7 @@
<update id="updateBreedRamFile" parameterType="BreedRamFile">
update breed_ram_file
<trim prefix="SET" suffixOverrides=",">
<if test="ordinaryEarNumber != null">ordinary_ear_number = #{ordinaryEarNumber},</if>
<if test="ordinaryEarNumber != null">manage_tags = #{ordinaryEarNumber},</if>
<if test="ranchId != null">ranch_id = #{ranchId},</if>
<if test="ranchName != null">ranch_name = #{ranchName},</if>
<if test="sheepfoldId != null">sheepfold_id = #{sheepfoldId},</if>
@ -414,4 +436,5 @@
</foreach>
</delete>
</mapper>

View File

@ -262,4 +262,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
ORDER BY id DESC
</select>
<!-- &lt;!&ndash; 查询所有公羊gender=2 &ndash;&gt;-->
<!-- <select id="selectRamList" resultMap="SheepFileResult">-->
<!-- <include refid="selectSheepFileVo"/>-->
<!-- where gender = 2 and (is_delete = 0 or is_delete is null)-->
<!-- order by create_time desc-->
<!-- </select>-->
<!-- 查询所有公羊 -->
<select id="selectRamList" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE gender = 2 AND is_delete = 0
</select>
<!-- 根据管理耳号查询 -->
<select id="selectSheepFileByManageTags" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE bs_manage_tags = #{manageTags} AND is_delete = 0
LIMIT 1
</select>
</mapper>

View File

@ -148,4 +148,10 @@
limit 1
</select>
<select id="selectLatestByRamId" resultType="RawSpermRecord">
SELECT * FROM raw_sperm_record
WHERE sheep_id = #{sheepId}
ORDER BY pick_date DESC
LIMIT 1
</select>
</mapper>

View File

@ -417,4 +417,12 @@
where id = #{sheepId}
and is_delete = 0
</update>
<!-- ====================== ScBreedRecordMapper.xml 需要添加 ====================== -->
<!-- 统计该公羊配了多少母羊(去重) -->
<select id="countMatedEwesByRamId" resultType="Long">
SELECT COUNT(DISTINCT ewe_id)
FROM sc_breed_record
WHERE ram_id = #{ramManageTags} AND is_delete = 0
</select>
</mapper>

View File

@ -221,4 +221,13 @@
#{id}
</foreach>
</delete>
<!-- ====================== ScLambingRecordMapper.xml 需要添加 ====================== -->
<!-- 统计公羊的后代数量 -->
<select id="countOffspringByRamId" resultType="Long">
SELECT IFNULL(SUM(lr.lambs_born), 0)
FROM sc_breed_record br
JOIN sc_lambing_record lr ON br.ewe_id = lr.sheep_id
WHERE br.ram_id = #{ramManageTags} AND br.is_delete = 0
</select>
</mapper>

View File

@ -229,4 +229,17 @@
</set>
where id = #{sheepId}
</update>
<!-- ====================== ScPregnancyRecordMapper.xml 需要添加 ====================== -->
<!-- 统计孕检有胎的母羊数(按配种方式) -->
<select id="countPregnantEwesByRamIdAndBreedType" resultType="Long">
SELECT COUNT(DISTINCT pr.sheep_id)
FROM sc_breed_record br
JOIN sc_pregnancy_record pr ON br.ewe_id = pr.sheep_id
WHERE br.ram_id = #{ramManageTags}
AND br.is_delete = 0
AND pr.is_delete = 0
AND br.breed_type = #{breedType}
AND pr.result IN ('有胎', '阳性', '怀孕')
</select>
</mapper>