From 4fde560c834a141d8df13ec088752c23ebc2ae6a Mon Sep 17 00:00:00 2001 From: zyh <2066096076@qq.com> Date: Tue, 22 Jul 2025 14:55:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E8=B9=84=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E5=8A=BF=EF=BC=8C=E8=BD=AC=E7=BE=A4=E7=9A=84=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/controller/BasSheepController.java | 68 +++++++---- .../controller/BasSheepTypeController.java | 114 ++++++++++++++++++ .../zhyc/module/base/domain/BasSheepType.java | 51 ++++++++ .../module/base/mapper/BasSheepMapper.java | 2 + .../base/mapper/BasSheepTypeMapper.java | 61 ++++++++++ .../base/mapper/BasSheepVarietyMapper.java | 9 ++ .../module/base/service/IBasSheepService.java | 2 + .../base/service/IBasSheepTypeService.java | 65 ++++++++++ .../service/impl/BasSheepServiceImpl.java | 3 + .../service/impl/BasSheepTypeServiceImpl.java | 89 ++++++++++++++ .../manage_sheep/domain/ScTransGroup.java | 4 +- .../service/impl/ScAddSheepServiceImpl.java | 30 ++++- .../other/controller/ScFixHoofController.java | 36 +++--- .../produce/other/domain/ScCastrate.java | 5 +- .../produce/other/domain/ScFixHoof.java | 3 +- .../produce/other/mapper/ScFixHoofMapper.java | 1 + .../other/service/IScFixHoofService.java | 17 ++- .../service/impl/ScFixHoofServiceImpl.java | 12 +- .../resources/mapper/base/BasSheepMapper.xml | 3 +- .../mapper/base/BasSheepTypeMapper.xml | 56 +++++++++ .../mapper/base/BasSheepVarietyMapper.xml | 7 ++ .../manage_sheep/ScTransGroupMapper.xml | 6 + .../mapper/produce/other/ScCastrateMapper.xml | 25 ++-- .../mapper/produce/other/ScFixHoofMapper.xml | 56 +++++---- 24 files changed, 638 insertions(+), 87 deletions(-) create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepTypeController.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/domain/BasSheepType.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepTypeMapper.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepTypeService.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepTypeServiceImpl.java create mode 100644 zhyc-module/src/main/resources/mapper/base/BasSheepTypeMapper.xml diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepController.java b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepController.java index 54f3003..8334e71 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepController.java @@ -1,5 +1,6 @@ package com.zhyc.module.base.controller; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -18,26 +19,22 @@ import com.zhyc.common.core.page.TableDataInfo; /** * 羊只基本信息Controller - * + * * @author ruoyi * @date 2025-07-15 */ @RestController @RequestMapping("/sheep/sheep") -public class BasSheepController extends BaseController -{ +public class BasSheepController extends BaseController { @Autowired private IBasSheepService basSheepService; - @Autowired - private BasSheepMapper basSheepMapper; /** * 查询羊只基本信息列表 */ @PreAuthorize("@ss.hasPermi('sheep:sheep:list')") @GetMapping("/list") - public TableDataInfo list(BasSheep basSheep) - { + public TableDataInfo list(BasSheep basSheep) { startPage(); List list = basSheepService.selectBasSheepList(basSheep); return getDataTable(list); @@ -49,8 +46,7 @@ public class BasSheepController extends BaseController @PreAuthorize("@ss.hasPermi('sheep:sheep:export')") @Log(title = "羊只基本信息", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, BasSheep basSheep) - { + public void export(HttpServletResponse response, BasSheep basSheep) { List list = basSheepService.selectBasSheepList(basSheep); ExcelUtil util = new ExcelUtil(BasSheep.class); util.exportExcel(response, list, "羊只基本信息数据"); @@ -61,8 +57,7 @@ public class BasSheepController extends BaseController */ @PreAuthorize("@ss.hasPermi('sheep:sheep:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return success(basSheepService.selectBasSheepById(id)); } @@ -72,8 +67,7 @@ public class BasSheepController extends BaseController @PreAuthorize("@ss.hasPermi('sheep:sheep:add')") @Log(title = "羊只基本信息", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody BasSheep basSheep) - { + public AjaxResult add(@RequestBody BasSheep basSheep) { return toAjax(basSheepService.insertBasSheep(basSheep)); } @@ -83,8 +77,7 @@ public class BasSheepController extends BaseController @PreAuthorize("@ss.hasPermi('sheep:sheep:edit')") @Log(title = "羊只基本信息", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody BasSheep basSheep) - { + public AjaxResult edit(@RequestBody BasSheep basSheep) { return toAjax(basSheepService.updateBasSheep(basSheep)); } @@ -93,19 +86,52 @@ public class BasSheepController extends BaseController */ @PreAuthorize("@ss.hasPermi('sheep:sheep:remove')") @Log(title = "羊只基本信息", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(basSheepService.deleteBasSheepByIds(ids)); } - + /** + * 根据耳号查询 + */ @GetMapping("/byManageTags/{manageTags}") - public AjaxResult byManageTags(@PathVariable String manageTags){ + public AjaxResult byManageTags(@PathVariable String manageTags) { BasSheep sheep = basSheepService.selectBasSheepByManageTags(manageTags.trim()); return success(sheep); } + /** + * 根据羊只类型ID查询羊只列表 + */ + @PreAuthorize("@ss.hasPermi('sheep:sheep:query')") + @GetMapping("/listByTypeId") + public TableDataInfo listByTypeId(Integer typeId) { + if (typeId == null) { + // Java 8 中返回空列表的方式,替代 List.of() + return getDataTable(new ArrayList<>()); + } + BasSheep query = new BasSheep(); + query.setTypeId(typeId.longValue()); + startPage(); + List list = basSheepService.selectBasSheepList(query); + return getDataTable(list); + } - + /** + * 根据羊舍ID和羊只类型ID组合查询羊只列表 + */ + @PreAuthorize("@ss.hasPermi('sheep:sheep:query')") + @GetMapping("/listBySheepfoldAndType") + public TableDataInfo listBySheepfoldAndType(Integer sheepfoldId, Integer typeId) { + if (sheepfoldId == null || typeId == null) { + // Java 8 中返回空列表的方式,替代 List.of() + return getDataTable(new ArrayList<>()); + } + BasSheep query = new BasSheep(); + query.setSheepfoldId(sheepfoldId.longValue()); + query.setTypeId(typeId.longValue()); + startPage(); + List list = basSheepService.selectBasSheepList(query); + return getDataTable(list); + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepTypeController.java b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepTypeController.java new file mode 100644 index 0000000..f847204 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/controller/BasSheepTypeController.java @@ -0,0 +1,114 @@ +package com.zhyc.module.base.controller; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; + +import com.zhyc.module.base.domain.BasSheep; +import com.zhyc.module.base.service.IBasSheepService; +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.core.controller.BaseController; +import com.zhyc.common.core.domain.AjaxResult; +import com.zhyc.common.enums.BusinessType; +import com.zhyc.module.base.domain.BasSheepType; +import com.zhyc.module.base.service.IBasSheepTypeService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * 羊只类型Controller + * + * @author ruoyi + * @date 2025-07-22 + */ +@RestController +@RequestMapping("/base/base") +public class BasSheepTypeController extends BaseController +{ + @Autowired + private IBasSheepTypeService basSheepTypeService; + + @Autowired + private IBasSheepService basSheepService; + /** + * 查询羊只类型列表 + */ + @PreAuthorize("@ss.hasPermi('base:base:list')") + @GetMapping("/list") + public TableDataInfo list(BasSheepType basSheepType) + { + startPage(); + List list = basSheepTypeService.selectBasSheepTypeList(basSheepType); + return getDataTable(list); + } + + /** + * 导出羊只类型列表 + */ + @PreAuthorize("@ss.hasPermi('base:base:export')") + @Log(title = "羊只类型", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, BasSheepType basSheepType) + { + List list = basSheepTypeService.selectBasSheepTypeList(basSheepType); + ExcelUtil util = new ExcelUtil(BasSheepType.class); + util.exportExcel(response, list, "羊只类型数据"); + } + + /** + * 获取羊只类型详细信息 + */ + @PreAuthorize("@ss.hasPermi('base:base:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Integer id) + { + return success(basSheepTypeService.selectBasSheepTypeById(id)); + } + + /** + * 新增羊只类型 + */ + @PreAuthorize("@ss.hasPermi('base:base:add')") + @Log(title = "羊只类型", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody BasSheepType basSheepType) + { + return toAjax(basSheepTypeService.insertBasSheepType(basSheepType)); + } + + /** + * 修改羊只类型 + */ + @PreAuthorize("@ss.hasPermi('base:base:edit')") + @Log(title = "羊只类型", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody BasSheepType basSheepType) + { + return toAjax(basSheepTypeService.updateBasSheepType(basSheepType)); + } + + /** + * 删除羊只类型 + */ + @PreAuthorize("@ss.hasPermi('base:base:remove')") + @Log(title = "羊只类型", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Integer[] ids) + { + return toAjax(basSheepTypeService.deleteBasSheepTypeByIds(ids)); + } + + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/domain/BasSheepType.java b/zhyc-module/src/main/java/com/zhyc/module/base/domain/BasSheepType.java new file mode 100644 index 0000000..f0a46a2 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/domain/BasSheepType.java @@ -0,0 +1,51 @@ +package com.zhyc.module.base.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.zhyc.common.annotation.Excel; +import com.zhyc.common.core.domain.BaseEntity; + +/** + * 羊只类型对象 bas_sheep_type + * + * @author ruoyi + * @date 2025-07-22 + */ +public class BasSheepType extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Integer id; + + /** 羊只类型 */ + private String name; + + public void setId(Integer id) + { + this.id = id; + } + + public Integer getId() + { + return id; + } + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("name", getName()) + .toString(); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java index 91febb6..c5a01bb 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java @@ -68,4 +68,6 @@ public interface BasSheepMapper List selectBasSheepBySheepfold(String id); + + } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepTypeMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepTypeMapper.java new file mode 100644 index 0000000..4afe2e9 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepTypeMapper.java @@ -0,0 +1,61 @@ +package com.zhyc.module.base.mapper; + +import java.util.List; +import com.zhyc.module.base.domain.BasSheepType; + +/** + * 羊只类型Mapper接口 + * + * @author ruoyi + * @date 2025-07-22 + */ +public interface BasSheepTypeMapper +{ + /** + * 查询羊只类型 + * + * @param id 羊只类型主键 + * @return 羊只类型 + */ + public BasSheepType selectBasSheepTypeById(Integer id); + + /** + * 查询羊只类型列表 + * + * @param basSheepType 羊只类型 + * @return 羊只类型集合 + */ + public List selectBasSheepTypeList(BasSheepType basSheepType); + + /** + * 新增羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + public int insertBasSheepType(BasSheepType basSheepType); + + /** + * 修改羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + public int updateBasSheepType(BasSheepType basSheepType); + + /** + * 删除羊只类型 + * + * @param id 羊只类型主键 + * @return 结果 + */ + public int deleteBasSheepTypeById(Integer id); + + /** + * 批量删除羊只类型 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteBasSheepTypeByIds(Integer[] ids); +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepVarietyMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepVarietyMapper.java index 4135097..dc6a17e 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepVarietyMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepVarietyMapper.java @@ -59,4 +59,13 @@ public interface BasSheepVarietyMapper * @return 结果 */ public int deleteBasSheepVarietyByIds(Long[] ids); + + + /** + * 根据品种名称查询品种 ID 用于导入羊只 + * + * @param varietyName 品种名称 + * @return 品种 ID + */ + Long selectIdByName(String varietyName); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepService.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepService.java index 5e87c22..dd4da78 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepService.java @@ -61,4 +61,6 @@ public interface IBasSheepService public int deleteBasSheepById(Long id); BasSheep selectBasSheepByManageTags(String trim); + + } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepTypeService.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepTypeService.java new file mode 100644 index 0000000..5f9721d --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/IBasSheepTypeService.java @@ -0,0 +1,65 @@ +package com.zhyc.module.base.service; + +import java.util.List; + +import com.zhyc.module.base.domain.BasSheep; +import com.zhyc.module.base.domain.BasSheepType; + +/** + * 羊只类型Service接口 + * + * @author ruoyi + * @date 2025-07-22 + */ +public interface IBasSheepTypeService +{ + /** + * 查询羊只类型 + * + * @param id 羊只类型主键 + * @return 羊只类型 + */ + public BasSheepType selectBasSheepTypeById(Integer id); + + /** + * 查询羊只类型列表 + * + * @param basSheepType 羊只类型 + * @return 羊只类型集合 + */ + public List selectBasSheepTypeList(BasSheepType basSheepType); + + /** + * 新增羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + public int insertBasSheepType(BasSheepType basSheepType); + + /** + * 修改羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + public int updateBasSheepType(BasSheepType basSheepType); + + /** + * 批量删除羊只类型 + * + * @param ids 需要删除的羊只类型主键集合 + * @return 结果 + */ + public int deleteBasSheepTypeByIds(Integer[] ids); + + /** + * 删除羊只类型信息 + * + * @param id 羊只类型主键 + * @return 结果 + */ + public int deleteBasSheepTypeById(Integer id); + + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepServiceImpl.java index 36c8897..1dc488f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepServiceImpl.java @@ -99,4 +99,7 @@ public class BasSheepServiceImpl implements IBasSheepService public BasSheep selectBasSheepByManageTags(String manageTags){ return basSheepMapper.selectBasSheepByManageTags(manageTags); } + + + } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepTypeServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepTypeServiceImpl.java new file mode 100644 index 0000000..4c1a362 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepTypeServiceImpl.java @@ -0,0 +1,89 @@ +package com.zhyc.module.base.service.impl; + +import java.util.List; + +import com.zhyc.module.base.domain.BasSheep; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.zhyc.module.base.mapper.BasSheepTypeMapper; +import com.zhyc.module.base.domain.BasSheepType; +import com.zhyc.module.base.service.IBasSheepTypeService; + +/** + * 羊只类型Service业务层处理 + * + * @author ruoyi + * @date 2025-07-22 + */ +@Service +public class BasSheepTypeServiceImpl implements IBasSheepTypeService { + @Autowired + private BasSheepTypeMapper basSheepTypeMapper; + + /** + * 查询羊只类型 + * + * @param id 羊只类型主键 + * @return 羊只类型 + */ + @Override + public BasSheepType selectBasSheepTypeById(Integer id) { + return basSheepTypeMapper.selectBasSheepTypeById(id); + } + + /** + * 查询羊只类型列表 + * + * @param basSheepType 羊只类型 + * @return 羊只类型 + */ + @Override + public List selectBasSheepTypeList(BasSheepType basSheepType) { + return basSheepTypeMapper.selectBasSheepTypeList(basSheepType); + } + + /** + * 新增羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + @Override + public int insertBasSheepType(BasSheepType basSheepType) { + return basSheepTypeMapper.insertBasSheepType(basSheepType); + } + + /** + * 修改羊只类型 + * + * @param basSheepType 羊只类型 + * @return 结果 + */ + @Override + public int updateBasSheepType(BasSheepType basSheepType) { + return basSheepTypeMapper.updateBasSheepType(basSheepType); + } + + /** + * 批量删除羊只类型 + * + * @param ids 需要删除的羊只类型主键 + * @return 结果 + */ + @Override + public int deleteBasSheepTypeByIds(Integer[] ids) { + return basSheepTypeMapper.deleteBasSheepTypeByIds(ids); + } + + /** + * 删除羊只类型信息 + * + * @param id 羊只类型主键 + * @return 结果 + */ + @Override + public int deleteBasSheepTypeById(Integer id) { + return basSheepTypeMapper.deleteBasSheepTypeById(id); + } + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScTransGroup.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScTransGroup.java index da94cbb..2910552 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScTransGroup.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScTransGroup.java @@ -29,9 +29,11 @@ public class ScTransGroup extends BaseEntity { /** * 羊只id */ - @Excel(name = "羊只id") +// @Excel(name = "羊只id") private Integer sheepId; + @Excel(name = "耳号") + private String manageTags; /** * 转入羊舍 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java index f9bcdf9..4b9af86 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java @@ -2,6 +2,7 @@ package com.zhyc.module.produce.manage_sheep.service.impl; import com.zhyc.common.exception.ServiceException; import com.zhyc.common.utils.StringUtils; +import com.zhyc.module.base.mapper.BasSheepVarietyMapper; import com.zhyc.module.produce.manage_sheep.domain.ScAddSheep; import com.zhyc.module.produce.manage_sheep.mapper.ScAddSheepMapper; import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService; @@ -27,6 +28,8 @@ public class ScAddSheepServiceImpl implements IScAddSheepService { @Autowired private IBasSheepService basSheepService; + @Autowired + private BasSheepVarietyMapper basSheepVarietyMapper; // 假设你有这个 mapper @Override public boolean insertScAddSheep(ScAddSheep scAddSheep) { // 1. 重复校验 @@ -75,7 +78,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService { return scAddSheepMapper.deleteScAddSheepByIds(ids) > 0; } - /* ------------------ 导入:羊舍名称 → ID ------------------ */ + /* ------------------ 导入 ------------------ */ @Override public String importSheep(List list, boolean updateSupport, String operName) { if (list == null || list.isEmpty()) { @@ -88,12 +91,32 @@ public class ScAddSheepServiceImpl implements IScAddSheepService { for (int i = 0; i < list.size(); i++) { ScAddSheep sheep = list.get(i); try { + /* 0. 品种名称 → 品种 ID(必须最先处理) */ + if (StringUtils.isNotBlank(sheep.getVarietyName())) { + Long varietyId = basSheepVarietyMapper.selectIdByName(sheep.getVarietyName()); + if (varietyId == null) { + failure++; + failureMsg.append("
第") + .append(i + 1) + .append("行:品种名称不存在【") + .append(sheep.getVarietyName()) + .append("】"); + continue; + } + sheep.setVarietyId(varietyId.intValue()); + } else { + failure++; + failureMsg.append("
第") + .append(i + 1) + .append("行:品种不能为空"); + continue; + } + /* 1. 羊舍名称 → ID */ if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) { DaSheepfold param = new DaSheepfold(); param.setSheepfoldName(sheep.getSheepfoldNameExcel()); List foldList = daSheepfoldMapper.selectDaSheepfoldList(param); - if (foldList == null || foldList.isEmpty()) { failure++; failureMsg.append("
第") @@ -115,7 +138,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService { continue; } - /* 3. 耳号重复校验(增量导入核心) */ + /* 3. 耳号重复校验 */ ScAddSheep exist = scAddSheepMapper.selectByEarNumber(sheep.getEarNumber()); if (exist != null) { failure++; @@ -136,6 +159,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService { insertScAddSheep(sheep); } success++; + } catch (Exception e) { failure++; failureMsg.append("
第") diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/controller/ScFixHoofController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/controller/ScFixHoofController.java index 83e5a18..ae5b47a 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/controller/ScFixHoofController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/controller/ScFixHoofController.java @@ -3,18 +3,12 @@ package com.zhyc.module.produce.other.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.zhyc.common.utils.StringUtils; import com.zhyc.module.produce.other.domain.ScFixHoof; import com.zhyc.module.produce.other.service.IScFixHoofService; 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 org.springframework.web.bind.annotation.*; import com.zhyc.common.annotation.Log; import com.zhyc.common.core.controller.BaseController; import com.zhyc.common.core.domain.AjaxResult; @@ -24,7 +18,7 @@ import com.zhyc.common.core.page.TableDataInfo; /** * 修蹄Controller - * + * * @author ruoyi * @date 2025-07-10 */ @@ -72,14 +66,26 @@ public class ScFixHoofController extends BaseController } /** - * 新增修蹄 + * 新增修蹄记录(支持批量) + * @return 结果 */ @PreAuthorize("@ss.hasPermi('produce:fixHoof:add')") @Log(title = "修蹄", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody ScFixHoof dto){ - dto.setSheepId(scFixHoofService.findIdByManageTags(dto.getManageTags()).intValue()); - return toAjax(scFixHoofService.insertScFixHoof(dto)); + public AjaxResult add(@RequestBody List dtos) { + // 处理多条修蹄记录 + for (ScFixHoof dto : dtos) { + // 验证羊只ID + if (dto.getSheepId() == null && StringUtils.isNotBlank(dto.getManageTags())) { + // 通过管理耳号查找羊只ID + Long sheepId = scFixHoofService.findIdByManageTags(dto.getManageTags()); + dto.setSheepId(sheepId.intValue()); + } + + // 保存修蹄记录 + scFixHoofService.insertScFixHoof(dto); + } + return toAjax(dtos.size()); } /** @@ -98,11 +104,13 @@ public class ScFixHoofController extends BaseController */ @PreAuthorize("@ss.hasPermi('produce:fixHoof:remove')") @Log(title = "修蹄", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") + @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Integer[] ids) { return toAjax(scFixHoofService.deleteScFixHoofByIds(ids)); } + } + diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScCastrate.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScCastrate.java index 69d7d38..39ec5b1 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScCastrate.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScCastrate.java @@ -28,8 +28,11 @@ public class ScCastrate extends BaseEntity { /** * 羊只id */ - @Excel(name = "羊只id") +// @Excel(name = "羊只id") private String sheepId; + /** 耳号(非数据库字段,用于前端) */ + @Excel(name = "耳号") + private String manageTags; // 新增 /** * 羊舍id diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScFixHoof.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScFixHoof.java index 9dafaaa..2cb42c7 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScFixHoof.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/domain/ScFixHoof.java @@ -10,7 +10,7 @@ import com.zhyc.common.core.domain.BaseEntity; /** * 修蹄对象 sc_fix_hoof - * + * * @author ruoyi * @date 2025-07-10 */ @@ -28,7 +28,6 @@ public class ScFixHoof extends BaseEntity private Integer sheepId; /** 管理耳号(仅用于接收参数/返回视图,不存库) */ @Excel(name = "管理耳号") -// @TableField(exist = false) // ← 非数据库字段 private String manageTags; /** 羊舍id */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/mapper/ScFixHoofMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/mapper/ScFixHoofMapper.java index 580a4ca..5462d20 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/mapper/ScFixHoofMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/mapper/ScFixHoofMapper.java @@ -3,6 +3,7 @@ package com.zhyc.module.produce.other.mapper; import java.util.List; import com.zhyc.module.produce.other.domain.ScFixHoof; +import org.apache.ibatis.annotations.Param; /** * 修蹄Mapper接口 diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/IScFixHoofService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/IScFixHoofService.java index b567788..8c3bf3e 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/IScFixHoofService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/IScFixHoofService.java @@ -1,20 +1,19 @@ package com.zhyc.module.produce.other.service; import java.util.List; - import com.zhyc.module.produce.other.domain.ScFixHoof; /** * 修蹄Service接口 - * + * * @author ruoyi * @date 2025-07-10 */ -public interface IScFixHoofService +public interface IScFixHoofService { /** * 查询修蹄 - * + * * @param id 修蹄主键 * @return 修蹄 */ @@ -22,7 +21,7 @@ public interface IScFixHoofService /** * 查询修蹄列表 - * + * * @param scFixHoof 修蹄 * @return 修蹄集合 */ @@ -30,7 +29,7 @@ public interface IScFixHoofService /** * 新增修蹄 - * + * * @param scFixHoof 修蹄 * @return 结果 */ @@ -38,7 +37,7 @@ public interface IScFixHoofService /** * 修改修蹄 - * + * * @param scFixHoof 修蹄 * @return 结果 */ @@ -46,7 +45,7 @@ public interface IScFixHoofService /** * 批量删除修蹄 - * + * * @param ids 需要删除的修蹄主键集合 * @return 结果 */ @@ -54,7 +53,7 @@ public interface IScFixHoofService /** * 删除修蹄信息 - * + * * @param id 修蹄主键 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/impl/ScFixHoofServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/impl/ScFixHoofServiceImpl.java index 201eacc..de7265f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/impl/ScFixHoofServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/other/service/impl/ScFixHoofServiceImpl.java @@ -5,13 +5,15 @@ import java.util.List; import com.zhyc.common.exception.ServiceException; import com.zhyc.common.utils.DateUtils; import com.zhyc.common.utils.StringUtils; -import com.zhyc.module.produce.other.domain.ScFixHoof; -import com.zhyc.module.produce.other.mapper.ScFixHoofMapper; import com.zhyc.module.base.domain.BasSheep; import com.zhyc.module.base.mapper.BasSheepMapper; +import com.zhyc.module.base.service.IDaSheepfoldService; +import com.zhyc.module.produce.other.domain.ScFixHoof; +import com.zhyc.module.produce.other.mapper.ScFixHoofMapper; +import com.zhyc.module.produce.other.service.IScFixHoofService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.zhyc.module.produce.other.service.IScFixHoofService; +import org.springframework.transaction.annotation.Transactional; /** * 修蹄Service业务层处理 @@ -27,6 +29,8 @@ public class ScFixHoofServiceImpl implements IScFixHoofService { @Autowired private BasSheepMapper basSheepMapper; + @Autowired + private IDaSheepfoldService daSheepfoldService; /** * 查询修蹄 * @@ -115,4 +119,4 @@ public class ScFixHoofServiceImpl implements IScFixHoofService { -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml index dc16f45..83ca114 100644 --- a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml @@ -92,7 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT s.id, s.sheepfold_id AS sheepfoldId, sf.sheepfold_name AS sheepfoldName, @@ -119,6 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + insert into bas_sheep diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepTypeMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepTypeMapper.xml new file mode 100644 index 0000000..c1d5cd1 --- /dev/null +++ b/zhyc-module/src/main/resources/mapper/base/BasSheepTypeMapper.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + select id, name from bas_sheep_type + + + + + + + + insert into bas_sheep_type + + name, + + + #{name}, + + + + + update bas_sheep_type + + name = #{name}, + + where id = #{id} + + + + delete from bas_sheep_type where id = #{id} + + + + delete from bas_sheep_type where id in + + #{id} + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepVarietyMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepVarietyMapper.xml index ede615b..04c9deb 100644 --- a/zhyc-module/src/main/resources/mapper/base/BasSheepVarietyMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/BasSheepVarietyMapper.xml @@ -53,4 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransGroupMapper.xml b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransGroupMapper.xml index 93bdee8..4769f12 100644 --- a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransGroupMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransGroupMapper.xml @@ -7,6 +7,7 @@ + @@ -22,6 +23,7 @@ SELECT tg.id, tg.sheep_id, + s.manage_tags AS manageTags, tg.fold_to, tg.fold_from, tg.reason, @@ -35,6 +37,7 @@ sf_from.sheepfold_name AS foldFromName, sf_to.sheepfold_name AS foldToName FROM sc_trans_group tg + LEFT JOIN bas_sheep s ON tg.sheep_id = s.id LEFT JOIN da_sheepfold sf_from ON tg.fold_from = sf_from.id LEFT JOIN da_sheepfold sf_to ON tg.fold_to = sf_to.id LEFT JOIN bas_sheep_variety bv ON tg.variety_id = bv.id @@ -44,6 +47,9 @@ and sheep_id = #{sheepId} + + and s.manage_tags like concat('%', #{manageTags}, '%') + and fold_to = #{foldTo} and fold_from = #{foldFrom} and status = #{status} diff --git a/zhyc-module/src/main/resources/mapper/produce/other/ScCastrateMapper.xml b/zhyc-module/src/main/resources/mapper/produce/other/ScCastrateMapper.xml index c861b13..bb164d3 100644 --- a/zhyc-module/src/main/resources/mapper/produce/other/ScCastrateMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/other/ScCastrateMapper.xml @@ -7,9 +7,12 @@ + - + + + @@ -18,15 +21,17 @@ select sc.id, sc.sheep_id, + bs.manage_tags as manageTags, -- 关联羊只表的耳号 sc.sheepfold, sf.sheepfold_name as sheepfoldName, sc.variety_id, - bv.variety as varietyName, + bv.variety as varietyName, sc.comment, sc.technician, sc.create_by, sc.create_time from sc_castrate sc + left join bas_sheep bs on sc.sheep_id = bs.id -- 关联羊只表获取耳号 left join da_sheepfold sf on sc.sheepfold = sf.id left join bas_sheep_variety bv on sc.variety_id = bv.id @@ -34,16 +39,16 @@ diff --git a/zhyc-module/src/main/resources/mapper/produce/other/ScFixHoofMapper.xml b/zhyc-module/src/main/resources/mapper/produce/other/ScFixHoofMapper.xml index ff66103..21b1abe 100644 --- a/zhyc-module/src/main/resources/mapper/produce/other/ScFixHoofMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/other/ScFixHoofMapper.xml @@ -6,8 +6,9 @@ - + + @@ -17,15 +18,19 @@ select fh.id, - fh.sheep_id, + bs.manage_tags AS manageTags, fh.sheepfold, - sf.sheepfold_name as sheepfoldName, + sf.sheepfold_name AS sheepfoldName, + fh.variety_id, + bv.variety AS varietyName, fh.comment, fh.technician, fh.create_by, fh.create_time from sc_fix_hoof fh + left join bas_sheep bs on fh.sheep_id = bs.id left join da_sheepfold sf on fh.sheepfold = sf.id + left join bas_sheep_variety bv on fh.variety_id = bv.id @@ -44,24 +55,24 @@ where fh.id = #{id} - - insert into sc_fix_hoof - - and fh.sheep_id like concat('%', #{sheepId}, '%') - and fh.sheepfold = #{sheepfold} - comment, - technician, - create_by, - create_time, - - - #{sheepId}, - #{sheepfold}, - #{comment}, - #{technician}, - #{createBy}, - #{createTime}, - + + INSERT INTO sc_fix_hoof + (sheep_id, + sheepfold, + variety_id, + comment, + technician, + create_by, + create_time) + VALUES + (#{sheepId}, + #{sheepfold}, + #{varietyId}, + #{comment}, + #{technician}, + #{createBy}, + #{createTime}) @@ -69,6 +80,7 @@ sheep_id = #{sheepId}, sheepfold = #{sheepfold}, + variety_id=#{varietyId}, comment = #{comment}, technician = #{technician}, create_by = #{createBy}, @@ -89,4 +101,6 @@ #{id} + + \ No newline at end of file From 1971225bc1c39ba59dacfa1adf0f5a71ea3c9d0e Mon Sep 17 00:00:00 2001 From: zyk Date: Tue, 22 Jul 2025 15:38:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AD=95=E6=A3=80=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ScPregnancyRecordController.java | 28 +- .../breed/domain/ScPregnancyRecord.java | 290 ++++++++++++++++-- .../breed/mapper/ScPregnancyRecordMapper.java | 40 ++- .../service/IScPregnancyRecordService.java | 33 +- .../impl/ScPregnancyRecordServiceImpl.java | 115 ++++++- .../produce/breed/ScPregnancyRecordMapper.xml | 153 +++++++-- 6 files changed, 549 insertions(+), 110 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java index 7dd6649..08d5cc1 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java @@ -1,10 +1,8 @@ package com.zhyc.module.produce.breed.controller; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletResponse; - -import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; -import com.zhyc.module.produce.breed.service.IScPregnancyRecordService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -14,20 +12,22 @@ 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.zhyc.common.annotation.Log; import com.zhyc.common.core.controller.BaseController; import com.zhyc.common.core.domain.AjaxResult; import com.zhyc.common.enums.BusinessType; - +import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; +import com.zhyc.module.produce.breed.service.IScPregnancyRecordService; import com.zhyc.common.utils.poi.ExcelUtil; import com.zhyc.common.core.page.TableDataInfo; /** * 孕检记录Controller - * - * @author ruoyi - * @date 2025-07-17 + * + * @author zhyc + * @date 2025-01-21 */ @RestController @RequestMapping("/Pregnancy_Test/Pregnancy_Test") @@ -98,9 +98,19 @@ public class ScPregnancyRecordController extends BaseController */ @PreAuthorize("@ss.hasPermi('Pregnancy_Test:Pregnancy_Test:remove')") @Log(title = "孕检记录", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") + @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(scPregnancyRecordService.deleteScPregnancyRecordByIds(ids)); } -} + + /** + * 根据耳号获取羊只信息 + */ + @GetMapping("/getSheepByManageTags") + public AjaxResult getSheepByManageTags(@RequestParam("manageTags") String manageTags) + { + Map sheepInfo = scPregnancyRecordService.getSheepByManageTags(manageTags); + return success(sheepInfo); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java index 558d1a8..0f3ed36 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java @@ -1,5 +1,6 @@ package com.zhyc.module.produce.breed.domain; +import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -9,17 +10,25 @@ import com.zhyc.common.core.domain.BaseEntity; /** * 孕检记录对象 sc_pregnancy_record - * - * @author ruoyi - * @date 2025-07-17 + * + * @author zhyc + * @date 2025-01-21 */ public class ScPregnancyRecord extends BaseEntity { private static final long serialVersionUID = 1L; - /** $column.columnComment */ + /** 主键ID */ private Long id; + /** 羊只ID */ + @Excel(name = "羊只ID") + private Long sheepId; + + /** 耳号 */ + @Excel(name = "耳号") + private String manageTags; + /** 孕检日期 */ @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "孕检日期", width = 30, dateFormat = "yyyy-MM-dd") @@ -29,89 +38,302 @@ public class ScPregnancyRecord extends BaseEntity @Excel(name = "孕检结果") private String result; - /** $column.columnComment */ - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") - private Long number; + /** 胎儿数量 */ + @Excel(name = "胎儿数量") + private Integer fetusCount; /** 技术员 */ @Excel(name = "技术员") private String technician; - /** $column.columnComment */ - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") - private Long way; + /** 孕检方式 */ + @Excel(name = "孕检方式") + private String way; - public void setId(Long id) + /** 备注 */ + @Excel(name = "备注") + private String remark; + + /** 是否删除 */ + private Integer isDelete; + + // 关联查询字段 + /** 品种 */ + @Excel(name = "品种") + private String variety; + + /** 月龄 */ + @Excel(name = "月龄") + private Long monthAge; + + /** 胎次 */ + @Excel(name = "胎次") + private Integer parity; + + /** 配次 */ + @Excel(name = "配次") + private Integer matingCounts; + + /** 当前羊舍 */ + @Excel(name = "当前羊舍") + private String sheepfoldName; + + /** 繁育状态 */ + @Excel(name = "繁育状态") + private String breedStatus; + + /** 配种公羊耳号 */ + @Excel(name = "配种公羊") + private String fatherManageTags; + + /** 配种公羊品种 */ + @Excel(name = "配种公羊品种") + private String fatherVariety; + + /** 配种类型 */ + @Excel(name = "配种类型") + private String matingTypeName; + + /** 配种日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "配种日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date matingDate; + + /** 预产日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "预产日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date expectedDate; + + /** 上次事件日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "上次事件日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date lastEventDate; + + /** 所在牧场 */ + @Excel(name = "所在牧场") + private String ranchName; + + public void setId(Long id) { this.id = id; } - public Long getId() + public Long getId() { return id; } - public void setDatetime(Date datetime) + public void setSheepId(Long sheepId) + { + this.sheepId = sheepId; + } + + public Long getSheepId() + { + return sheepId; + } + + public void setManageTags(String manageTags) + { + this.manageTags = manageTags; + } + + public String getManageTags() + { + return manageTags; + } + + public void setDatetime(Date datetime) { this.datetime = datetime; } - public Date getDatetime() + public Date getDatetime() { return datetime; } - public void setResult(String result) + public void setResult(String result) { this.result = result; } - public String getResult() + public String getResult() { return result; } - public void setNumber(Long number) + public void setFetusCount(Integer fetusCount) { - this.number = number; + this.fetusCount = fetusCount; } - public Long getNumber() + public Integer getFetusCount() { - return number; + return fetusCount; } - public void setTechnician(String technician) + public void setTechnician(String technician) { this.technician = technician; } - public String getTechnician() + public String getTechnician() { return technician; } - public void setWay(Long way) + public void setWay(String way) { this.way = way; } - public Long getWay() + public String getWay() { return way; } + public void setRemark(String remark) + { + this.remark = remark; + } + + public String getRemark() + { + return remark; + } + + public void setIsDelete(Integer isDelete) + { + this.isDelete = isDelete; + } + + public Integer getIsDelete() + { + return isDelete; + } + + public String getVariety() { + return variety; + } + + public void setVariety(String variety) { + this.variety = variety; + } + + public Long getMonthAge() { + return monthAge; + } + + public void setMonthAge(Long monthAge) { + this.monthAge = monthAge; + } + + public Integer getParity() { + return parity; + } + + public void setParity(Integer parity) { + this.parity = parity; + } + + public Integer getMatingCounts() { + return matingCounts; + } + + public void setMatingCounts(Integer matingCounts) { + this.matingCounts = matingCounts; + } + + public String getSheepfoldName() { + return sheepfoldName; + } + + public void setSheepfoldName(String sheepfoldName) { + this.sheepfoldName = sheepfoldName; + } + + public String getBreedStatus() { + return breedStatus; + } + + public void setBreedStatus(String breedStatus) { + this.breedStatus = breedStatus; + } + + public String getFatherManageTags() { + return fatherManageTags; + } + + public void setFatherManageTags(String fatherManageTags) { + this.fatherManageTags = fatherManageTags; + } + + public String getFatherVariety() { + return fatherVariety; + } + + public void setFatherVariety(String fatherVariety) { + this.fatherVariety = fatherVariety; + } + + public String getMatingTypeName() { + return matingTypeName; + } + + public void setMatingTypeName(String matingTypeName) { + this.matingTypeName = matingTypeName; + } + + public Date getMatingDate() { + return matingDate; + } + + public void setMatingDate(Date matingDate) { + this.matingDate = matingDate; + } + + public Date getExpectedDate() { + return expectedDate; + } + + public void setExpectedDate(Date expectedDate) { + this.expectedDate = expectedDate; + } + + public Date getLastEventDate() { + return lastEventDate; + } + + public void setLastEventDate(Date lastEventDate) { + this.lastEventDate = lastEventDate; + } + + public String getRanchName() { + return ranchName; + } + + public void setRanchName(String ranchName) { + this.ranchName = ranchName; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("datetime", getDatetime()) - .append("result", getResult()) - .append("number", getNumber()) - .append("technician", getTechnician()) - .append("way", getWay()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .toString(); + .append("id", getId()) + .append("sheepId", getSheepId()) + .append("manageTags", getManageTags()) + .append("datetime", getDatetime()) + .append("result", getResult()) + .append("fetusCount", getFetusCount()) + .append("technician", getTechnician()) + .append("way", getWay()) + .append("remark", getRemark()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("isDelete", getIsDelete()) + .toString(); } -} +} \ 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 c0562e1..4962992 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 @@ -1,20 +1,20 @@ package com.zhyc.module.produce.breed.mapper; import java.util.List; - +import java.util.Map; import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; /** * 孕检记录Mapper接口 - * - * @author ruoyi - * @date 2025-07-17 + * + * @author zhyc + * @date 2025-01-21 */ -public interface ScPregnancyRecordMapper +public interface ScPregnancyRecordMapper { /** * 查询孕检记录 - * + * * @param id 孕检记录主键 * @return 孕检记录 */ @@ -22,7 +22,7 @@ public interface ScPregnancyRecordMapper /** * 查询孕检记录列表 - * + * * @param scPregnancyRecord 孕检记录 * @return 孕检记录集合 */ @@ -30,7 +30,7 @@ public interface ScPregnancyRecordMapper /** * 新增孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @@ -38,7 +38,7 @@ public interface ScPregnancyRecordMapper /** * 修改孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @@ -46,7 +46,7 @@ public interface ScPregnancyRecordMapper /** * 删除孕检记录 - * + * * @param id 孕检记录主键 * @return 结果 */ @@ -54,9 +54,25 @@ public interface ScPregnancyRecordMapper /** * 批量删除孕检记录 - * + * * @param ids 需要删除的数据主键集合 * @return 结果 */ public int deleteScPregnancyRecordByIds(Long[] ids); -} + + /** + * 根据耳号查询羊只信息 + * + * @param manageTags 耳号 + * @return 羊只信息 + */ + public Map selectSheepByManageTags(String manageTags); + + /** + * 更新羊只基础表中的孕检相关字段 + * + * @param params 更新参数 + * @return 结果 + */ + public int updateSheepPregnancyInfo(Map params); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java index cb34288..bc0d2e4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java @@ -1,21 +1,20 @@ package com.zhyc.module.produce.breed.service; import java.util.List; - +import java.util.Map; import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; - /** * 孕检记录Service接口 - * - * @author ruoyi - * @date 2025-07-17 + * + * @author zhyc + * @date 2025-01-21 */ -public interface IScPregnancyRecordService +public interface IScPregnancyRecordService { /** * 查询孕检记录 - * + * * @param id 孕检记录主键 * @return 孕检记录 */ @@ -23,7 +22,7 @@ public interface IScPregnancyRecordService /** * 查询孕检记录列表 - * + * * @param scPregnancyRecord 孕检记录 * @return 孕检记录集合 */ @@ -31,7 +30,7 @@ public interface IScPregnancyRecordService /** * 新增孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @@ -39,7 +38,7 @@ public interface IScPregnancyRecordService /** * 修改孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @@ -47,7 +46,7 @@ public interface IScPregnancyRecordService /** * 批量删除孕检记录 - * + * * @param ids 需要删除的孕检记录主键集合 * @return 结果 */ @@ -55,9 +54,17 @@ public interface IScPregnancyRecordService /** * 删除孕检记录信息 - * + * * @param id 孕检记录主键 * @return 结果 */ public int deleteScPregnancyRecordById(Long id); -} + + /** + * 根据耳号查询羊只信息 + * + * @param manageTags 耳号 + * @return 羊只信息 + */ + public Map getSheepByManageTags(String manageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java index 7f50d65..dde2c3d 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java @@ -1,19 +1,24 @@ package com.zhyc.module.produce.breed.service.impl; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Date; +import java.util.Calendar; + import com.zhyc.common.utils.DateUtils; -import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; -import com.zhyc.module.produce.breed.mapper.ScPregnancyRecordMapper; -import com.zhyc.module.produce.breed.service.IScPregnancyRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - +import org.springframework.transaction.annotation.Transactional; +import com.zhyc.module.produce.breed.mapper.ScPregnancyRecordMapper; +import com.zhyc.module.produce.breed.domain.ScPregnancyRecord; +import com.zhyc.module.produce.breed.service.IScPregnancyRecordService; /** * 孕检记录Service业务层处理 - * - * @author ruoyi - * @date 2025-07-17 + * + * @author zhyc + * @date 2025-01-21 */ @Service public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService @@ -23,7 +28,7 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService /** * 查询孕检记录 - * + * * @param id 孕检记录主键 * @return 孕检记录 */ @@ -35,7 +40,7 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService /** * 查询孕检记录列表 - * + * * @param scPregnancyRecord 孕检记录 * @return 孕检记录 */ @@ -47,32 +52,68 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService /** * 新增孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @Override + @Transactional public int insertScPregnancyRecord(ScPregnancyRecord scPregnancyRecord) { scPregnancyRecord.setCreateTime(DateUtils.getNowDate()); - return scPregnancyRecordMapper.insertScPregnancyRecord(scPregnancyRecord); + scPregnancyRecord.setIsDelete(0); + + // 根据耳号获取羊只ID + if (scPregnancyRecord.getManageTags() != null) { + Map sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags()); + if (sheepInfo != null && sheepInfo.get("id") != null) { + scPregnancyRecord.setSheepId(Long.valueOf(sheepInfo.get("id").toString())); + } + } + + int result = scPregnancyRecordMapper.insertScPregnancyRecord(scPregnancyRecord); + + // 如果孕检结果为怀孕,更新羊只基础表相关字段 + if ("怀孕".equals(scPregnancyRecord.getResult()) && scPregnancyRecord.getSheepId() != null) { + updateSheepPregnancyStatus(scPregnancyRecord); + } + + return result; } /** * 修改孕检记录 - * + * * @param scPregnancyRecord 孕检记录 * @return 结果 */ @Override + @Transactional public int updateScPregnancyRecord(ScPregnancyRecord scPregnancyRecord) { - return scPregnancyRecordMapper.updateScPregnancyRecord(scPregnancyRecord); + scPregnancyRecord.setUpdateTime(DateUtils.getNowDate()); + + // 根据耳号获取羊只ID + if (scPregnancyRecord.getManageTags() != null) { + Map sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags()); + if (sheepInfo != null && sheepInfo.get("id") != null) { + scPregnancyRecord.setSheepId(Long.valueOf(sheepInfo.get("id").toString())); + } + } + + int result = scPregnancyRecordMapper.updateScPregnancyRecord(scPregnancyRecord); + + // 如果孕检结果为怀孕,更新羊只基础表相关字段 + if ("怀孕".equals(scPregnancyRecord.getResult()) && scPregnancyRecord.getSheepId() != null) { + updateSheepPregnancyStatus(scPregnancyRecord); + } + + return result; } /** * 批量删除孕检记录 - * + * * @param ids 需要删除的孕检记录主键 * @return 结果 */ @@ -84,7 +125,7 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService /** * 删除孕检记录信息 - * + * * @param id 孕检记录主键 * @return 结果 */ @@ -93,4 +134,46 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService { return scPregnancyRecordMapper.deleteScPregnancyRecordById(id); } -} + + /** + * 根据耳号查询羊只信息 + * + * @param manageTags 耳号 + * @return 羊只信息 + */ + @Override + public Map getSheepByManageTags(String manageTags) + { + return scPregnancyRecordMapper.selectSheepByManageTags(manageTags); + } + + /** + * 更新羊只怀孕状态 + * + * @param scPregnancyRecord 孕检记录 + */ + private void updateSheepPregnancyStatus(ScPregnancyRecord scPregnancyRecord) { + Map params = new HashMap<>(); + params.put("sheepId", scPregnancyRecord.getSheepId()); + params.put("pregDate", scPregnancyRecord.getDatetime()); + + // 设置繁育状态为怀孕状态(假设怀孕状态ID为2) + params.put("breedStatusId", 2); + + // 计算预产日期(羊的妊娠期大约150天) + if (scPregnancyRecord.getDatetime() != null) { + Calendar cal = Calendar.getInstance(); + cal.setTime(scPregnancyRecord.getDatetime()); + cal.add(Calendar.DAY_OF_YEAR, 150); + params.put("expectedDate", cal.getTime()); + } + + // 计算怀孕天数 + if (scPregnancyRecord.getDatetime() != null) { + long days = (System.currentTimeMillis() - scPregnancyRecord.getDatetime().getTime()) / (1000 * 60 * 60 * 24); + params.put("gestationDay", (int) days); + } + + scPregnancyRecordMapper.updateSheepPregnancyInfo(params); + } +} \ 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 7e7175a..3017f1a 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScPregnancyRecordMapper.xml @@ -1,60 +1,147 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + - + + + + + + + + + + + + + + + + + + - select id, datetime, result, number, technician, way, create_by, create_time from sc_pregnancy_record + select + pr.id, + pr.sheep_id, + pr.datetime, + pr.result, + pr.fetus_count, + pr.technician, + pr.way, + pr.remark, + pr.create_by, + pr.create_time, + pr.create_by, + pr.create_time, + sf.bs_manage_tags as manage_tags, + sf.variety, + sf.month_age, + sf.parity, + sf.mating_counts, + sf.sheepfold_name, + sf.breed, + sf.father_manage_tags, + father_sf.variety as father_variety, + mating_type.dict_label as mating_type_name, + sf.mating_date, + sf.expected_date, + sf.lambing_date as last_event_date, + r.ranch as ranch + from sc_pregnancy_record pr + left join sheep_file sf on pr.sheep_id = sf.id + left join sys_dict_data mating_type on sf.mating_type_id = mating_type.dict_value and mating_type.dict_type = 'breed_type' and mating_type.status = '0' + left join da_ranch r on sf.ranch_id = r.id + left join sheep_file father_sf on sf.bs_father_id = father_sf.id - + + + + insert into sc_pregnancy_record + sheep_id, datetime, result, - number, + fetus_count, technician, way, + remark, create_by, create_time, - + is_delete + + #{sheepId}, #{datetime}, #{result}, - #{number}, + #{fetusCount}, #{technician}, #{way}, + #{remark}, #{createBy}, #{createTime}, - + 0 + @@ -62,23 +149,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" datetime = #{datetime}, result = #{result}, - number = #{number}, + fetus_count = #{fetusCount}, technician = #{technician}, way = #{way}, - create_by = #{createBy}, - create_time = #{createTime}, + remark = #{remark}, + create_by = #{updateBy}, + create_time = #{updateTime}, where id = #{id} - - delete from sc_pregnancy_record where id = #{id} - + + update sc_pregnancy_record set is_delete = 1 where id = #{id} + - - delete from sc_pregnancy_record where id in + + update sc_pregnancy_record set is_delete = 1 where id in #{id} - + + + + + update bas_sheep + + preg_date = #{pregDate}, + breed_status_id = #{breedStatusId}, + expected_date = #{expectedDate}, + gestation_day = #{gestationDay}, + create_time = now() + + where id = #{sheepId} + \ No newline at end of file