diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/controller/BreedRamFileController.java b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BreedRamFileController.java index 7274064..501bbef 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/controller/BreedRamFileController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BreedRamFileController.java @@ -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 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 list = breedRamFileService.selectBreedRamFileList(breedRamFile); +// ExcelUtil util = new ExcelUtil(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 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 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 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 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 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 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 list = breedRamFileService.selectBreedRamFileList(breedRamFile); + List 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 list = breedRamFileService.selectBreedRamFileList(breedRamFile); - ExcelUtil util = new ExcelUtil(BreedRamFile.class); + List list = breedRamFileService.selectViewBreedRamFileList(viewBreedRamFile); + ExcelUtil util = new ExcelUtil(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 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 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 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 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 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 statistics = breedRamFileService.getBreedRamStatistics(); + return success(statistics); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/domain/BreedRamFile.java b/zhyc-module/src/main/java/com/zhyc/module/base/domain/BreedRamFile.java index 463308d..10d9f03 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/domain/BreedRamFile.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/domain/BreedRamFile.java @@ -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(); } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BreedRamFileMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BreedRamFileMapper.java index bb6eaa2..a2ba59f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BreedRamFileMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BreedRamFileMapper.java @@ -106,4 +106,10 @@ public interface BreedRamFileMapper * @return 种公羊档案集合 */ public List selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile); + /** + * 根据普通耳号查询种公羊档案 + * + * @param ordinaryEarNumber 普通耳号 + * @return 种公羊档案 + */ } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepFileMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepFileMapper.java index cc04161..ad8821e 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepFileMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepFileMapper.java @@ -101,4 +101,21 @@ public interface SheepFileMapper List selectFieldValuesByProvider(@Param("fieldName") String fieldName); + /** + * 查询所有公羊(gender=2) + * + * @return 公羊列表 + */ + /** + * 查询所有公羊(gender=2) + * @return 公羊列表 + */ + List selectRamList(); + + /** + * 根据管理耳号查询羊只 + * @param manageTags 管理耳号 + * @return 羊只信息 + */ + SheepFile selectSheepFileByManageTags(String manageTags); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/IBreedRamFileService.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBreedRamFileService.java index 847f3b0..541c97a 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/IBreedRamFileService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBreedRamFileService.java @@ -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 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 selectBreedRamFileListByRanchId(Long ranchId); +// +// /** +// * 根据羊舍ID查询种公羊档案列表 +// * +// * @param sheepfoldId 羊舍ID +// * @return 种公羊档案集合 +// */ +// public List selectBreedRamFileListBySheepfoldId(Long sheepfoldId); +// +// /** +// * 查询核心羊群种公羊档案列表 +// * +// * @param breedRamFile 种公羊档案 +// * @return 种公羊档案集合 +// */ +// public List selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile); +// +// /** +// * 查询种用种公羊档案列表 +// * +// * @param breedRamFile 种公羊档案 +// * @return 种公羊档案集合 +// */ +// public List selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile); +// +// /** +// * 批量同步指定公羊的数据 +// * +// * @param earNumbers 耳号列表 +// * @return 同步的记录数 +// */ +// public int syncSpecificRams(List earNumbers); +// +// /** +// * 获取种公羊统计信息 +// * +// * @return 统计信息 +// */ +// public Map 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 selectViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile); + + /** + * 根据普通耳号查询种公羊档案视图 + * + * @param earNumber 普通耳号 + * @return 种公羊档案视图 + */ + public ViewBreedRamFile selectViewBreedRamFileByEarNumber(String earNumber); + + /** + * 根据牧场ID查询种公羊档案视图列表 + * + * @param ranchId 牧场ID + * @return 种公羊档案视图集合 + */ + public List selectViewBreedRamFileListByRanchId(Long ranchId); + + /** + * 根据羊舍ID查询种公羊档案视图列表 + * + * @param sheepfoldId 羊舍ID + * @return 种公羊档案视图集合 + */ + public List selectViewBreedRamFileListBySheepfoldId(Long sheepfoldId); + + /** + * 查询核心羊群种公羊档案视图列表 + * + * @param viewBreedRamFile 种公羊档案视图 + * @return 种公羊档案视图集合 + */ + public List selectCoreFlockViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile); + + /** + * 查询种用种公羊档案视图列表 + * + * @param viewBreedRamFile 种公羊档案视图 + * @return 种公羊档案视图集合 + */ + public List 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 selectBreedRamFileListByRanchId(Long ranchId); + + /** + * 根据羊舍ID查询种公羊档案列表(表) + * + * @param sheepfoldId 羊舍ID + * @return 种公羊档案集合 + */ + public List selectBreedRamFileListBySheepfoldId(Long sheepfoldId); + + /** + * 查询核心羊群种公羊档案列表(表) + * + * @param breedRamFile 种公羊档案 + * @return 种公羊档案集合 + */ + public List selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile); + + /** + * 查询种用种公羊档案列表(表) + * + * @param breedRamFile 种公羊档案 + * @return 种公羊档案集合 + */ + public List selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile); + + /** + * 批量同步指定公羊的数据 + * + * @param earNumbers 耳号列表 + * @return 同步的记录数 + */ + public int syncSpecificRams(List earNumbers); + + /** + * 获取种公羊统计信息 + * + * @return 统计信息 + */ + public Map getBreedRamStatistics(); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepFileService.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepFileService.java index 15eaa6d..1d20e08 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepFileService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepFileService.java @@ -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 params, SheepFile sheepFile ); + + @Transactional + int insertSheepFile(SheepFile sheepFile); + + @Transactional + int updateSheepFile(SheepFile sheepFile); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BreedRamFileServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BreedRamFileServiceImpl.java index 7e7d8fe..0142700 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BreedRamFileServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BreedRamFileServiceImpl.java @@ -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 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 selectBreedRamFileListByRanchId(Long ranchId) { +// return breedRamFileMapper.selectBreedRamFileListByRanchId(ranchId); +// } +// +// @Override +// public List selectBreedRamFileListBySheepfoldId(Long sheepfoldId) { +// return breedRamFileMapper.selectBreedRamFileListBySheepfoldId(sheepfoldId); +// } +// +// @Override +// public List selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile) { +// return breedRamFileMapper.selectCoreFlockBreedRamFileList(breedRamFile); +// } +// +// @Override +// public List selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile) { +// return breedRamFileMapper.selectBreedingUseBreedRamFileList(breedRamFile); +// } +// +// +// @Override +// public BreedRamFile selectBreedRamFileByOrdinaryEarNumber(String ordinaryEarNumber) { +// return breedRamFileMapper.selectBreedRamFileByOrdinaryEarNumber(ordinaryEarNumber); +// } +// +// @Override +// @Transactional +// public int syncSpecificRams(List 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 getBreedRamStatistics() { +// Map statistics = new HashMap<>(); +// +// // 总公羊数 +// BreedRamFile queryParam = new BreedRamFile(); +// List allRams = breedRamFileMapper.selectBreedRamFileList(queryParam); +// statistics.put("totalRams", allRams.size()); +// +// // 核心羊群数 +// List coreFlockRams = breedRamFileMapper.selectCoreFlockBreedRamFileList(queryParam); +// statistics.put("coreFlockRams", coreFlockRams.size()); +// +// // 种用公羊数 +// List breedingUseRams = breedRamFileMapper.selectBreedingUseBreedRamFileList(queryParam); +// statistics.put("breedingUseRams", breedingUseRams.size()); +// +// // 按品种统计 +// Map varietyCount = allRams.stream() +// .collect(Collectors.groupingBy( +// ram -> ram.getVariety() != null ? ram.getVariety() : "未知", +// Collectors.counting() +// )); +// statistics.put("varietyDistribution", varietyCount); +// +// // 按牧场统计 +// Map 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 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_record、sc_lambing_record、sc_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 selectViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) { + return viewBreedRamFileMapper.selectViewBreedRamFileList(viewBreedRamFile); + } + + @Override + public ViewBreedRamFile selectViewBreedRamFileByEarNumber(String earNumber) { + return viewBreedRamFileMapper.selectViewBreedRamFileByOrdinaryEarNumber(earNumber); + } + + @Override + public List selectViewBreedRamFileListByRanchId(Long ranchId) { + return viewBreedRamFileMapper.selectViewBreedRamFileListByRanchId(ranchId); + } + + @Override + public List selectViewBreedRamFileListBySheepfoldId(Long sheepfoldId) { + return viewBreedRamFileMapper.selectViewBreedRamFileListBySheepfoldId(sheepfoldId); + } + + @Override + public List selectCoreFlockViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) { + return viewBreedRamFileMapper.selectCoreFlockViewBreedRamFileList(viewBreedRamFile); + } + + @Override + public List selectBreedingUseViewBreedRamFileList(ViewBreedRamFile viewBreedRamFile) { + return viewBreedRamFileMapper.selectBreedingUseViewBreedRamFileList(viewBreedRamFile); + } + + // ========== 表操作方法实现 ========== + + @Override + public BreedRamFile selectBreedRamFileById(Long id) { return breedRamFileMapper.selectBreedRamFileById(id); } - /** - * 查询种公羊档案列表 - * - * @param breedRamFile 种公羊档案 - * @return 种公羊档案 - */ @Override - public List selectBreedRamFileList(BreedRamFile breedRamFile) - { + public List 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 selectBreedRamFileListByRanchId(Long ranchId) { + return breedRamFileMapper.selectBreedRamFileListByRanchId(ranchId); + } + + @Override + public List selectBreedRamFileListBySheepfoldId(Long sheepfoldId) { + return breedRamFileMapper.selectBreedRamFileListBySheepfoldId(sheepfoldId); + } + + @Override + public List selectCoreFlockBreedRamFileList(BreedRamFile breedRamFile) { + return breedRamFileMapper.selectCoreFlockBreedRamFileList(breedRamFile); + } + + @Override + public List selectBreedingUseBreedRamFileList(BreedRamFile breedRamFile) { + return breedRamFileMapper.selectBreedingUseBreedRamFileList(breedRamFile); + } + + @Override + @Transactional + public int syncSpecificRams(List 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 getBreedRamStatistics() { + Map statistics = new HashMap<>(); + + BreedRamFile queryParam = new BreedRamFile(); + List allRams = breedRamFileMapper.selectBreedRamFileList(queryParam); + statistics.put("totalRams", allRams.size()); + + List coreFlockRams = breedRamFileMapper.selectCoreFlockBreedRamFileList(queryParam); + statistics.put("coreFlockRams", coreFlockRams.size()); + + List breedingUseRams = breedRamFileMapper.selectBreedingUseBreedRamFileList(queryParam); + statistics.put("breedingUseRams", breedingUseRams.size()); + + Map varietyCount = allRams.stream() + .collect(Collectors.groupingBy( + ram -> ram.getVariety() != null ? ram.getVariety() : "未知", + Collectors.counting() + )); + statistics.put("varietyDistribution", varietyCount); + + Map 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 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_record、sc_lambing_record、sc_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(); + } + } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepFileServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepFileServiceImpl.java index 1015935..10c2789 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepFileServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepFileServiceImpl.java @@ -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; + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/RawSpermRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/RawSpermRecordMapper.java index 2d42034..5335801 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/RawSpermRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/RawSpermRecordMapper.java @@ -75,4 +75,12 @@ public interface RawSpermRecordMapper * @return 羊只信息 Map包含id、gender、monthAge、electronicTags等字段 */ public Map selectSheepInfoByManageTags(String manageTags); + // ====================== RawSpermRecordMapper.java 需要添加 ====================== + /** + /** + * 获取指定公羊最新的采精记录 + * @param sheepId 羊只ID + * @return 采精记录 + */ + RawSpermRecord selectLatestByRamId(Long sheepId); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScBreedRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScBreedRecordMapper.java index 4478063..13be12c 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScBreedRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScBreedRecordMapper.java @@ -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); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScLambingRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScLambingRecordMapper.java index 244a3f9..293c56c 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScLambingRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScLambingRecordMapper.java @@ -78,4 +78,11 @@ public interface ScLambingRecordMapper * @return 结果 */ public int deleteScLambingRecordByIds(Long[] ids); + // ====================== ScLambingRecordMapper.java 需要添加 ====================== + /** + * 统计公羊的后代总数 + * @param ramManageTags 公羊管理耳号 + * @return 后代总数 + */ + Long countOffspringByRamId(String ramManageTags); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java index 7a16640..073ec35 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java @@ -84,4 +84,20 @@ public interface ScPregnancyRecordMapper * @return 结果 */ public int updateSheepPregnancyInfo(Map 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); } \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/base/BreedRamFileMapper.xml b/zhyc-module/src/main/resources/mapper/base/BreedRamFileMapper.xml index 6f666ee..32bcbfc 100644 --- a/zhyc-module/src/main/resources/mapper/base/BreedRamFileMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/BreedRamFileMapper.xml @@ -6,7 +6,7 @@ - + @@ -74,13 +74,13 @@ - 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 - + SELECT * FROM breed_ram_file + WHERE manage_tags = #{ordinaryEarNumber} AND is_delete = 0 + LIMIT 1 - + SELECT * FROM breed_ram_file + WHERE electronic_tags = #{electronicTags} + AND is_delete = 0 + LIMIT 1 - + SELECT * FROM breed_ram_file + WHERE ranch_id = #{ranchId} + AND is_delete = 0 + ORDER BY id DESC - + SELECT * FROM breed_ram_file + WHERE sheepfold_id = #{sheepfoldId} + AND is_delete = 0 + ORDER BY id DESC - + SELECT * FROM breed_ram_file + WHERE is_core_flock = 1 + AND is_delete = 0 + + AND ranch_id = #{ranchId} + + + AND variety_id = #{varietyId} + + ORDER BY id DESC - + SELECT * FROM breed_ram_file + WHERE is_breeding_use = 1 + AND is_delete = 0 + + AND ranch_id = #{ranchId} + + + AND variety_id = #{varietyId} + + ORDER BY id DESC + + + insert into breed_ram_file - ordinary_ear_number, + manage_tags, ranch_id, ranch_name, sheepfold_id, @@ -258,6 +276,8 @@ accuracy, information_count, is_paternity_tested, + offspring_count, + prolificacy, create_by, create_time, update_by, @@ -265,7 +285,7 @@ is_delete, - #{ordinaryEarNumber}, + #{manageTags}, #{ranchId}, #{ranchName}, #{sheepfoldId}, @@ -325,6 +345,8 @@ #{accuracy}, #{informationCount}, #{isPaternityTested}, + #{offspringCount}, + #{prolificacy}, #{createBy}, #{createTime}, #{updateBy}, @@ -336,7 +358,7 @@ update breed_ram_file - ordinary_ear_number = #{ordinaryEarNumber}, + manage_tags = #{ordinaryEarNumber}, ranch_id = #{ranchId}, ranch_name = #{ranchName}, sheepfold_id = #{sheepfoldId}, @@ -414,4 +436,5 @@ + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml b/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml index 1301555..2479840 100644 --- a/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml @@ -262,4 +262,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ORDER BY id DESC + + + + + + + + + + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/RawSpermRecordMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/RawSpermRecordMapper.xml index 1531dcc..d62f62a 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/RawSpermRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/RawSpermRecordMapper.xml @@ -148,4 +148,10 @@ limit 1 + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScBreedRecordMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScBreedRecordMapper.xml index b07b862..bbe7a85 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScBreedRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScBreedRecordMapper.xml @@ -417,4 +417,12 @@ where id = #{sheepId} and is_delete = 0 + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScLambingRecordMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScLambingRecordMapper.xml index 7ed7e3b..910ca4f 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScLambingRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScLambingRecordMapper.xml @@ -221,4 +221,13 @@ #{id} + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml index 567457f..161b001 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml @@ -229,4 +229,17 @@ where id = #{sheepId} + + + + \ No newline at end of file